comparison src/X_supp.c @ 1014:f7bf372a85a3 refine_backend_if

Register _x_mb_handle_connection() with IO manager
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 22 Nov 2010 00:42:30 +0800
parents d5b8853767e7
children c4a567112d29
comparison
equal deleted inserted replaced
1013:d5b8853767e7 1014:f7bf372a85a3
60 60
61 #ifdef XSHM 61 #ifdef XSHM
62 XImage *ximage; 62 XImage *ximage;
63 XShmSegmentInfo shminfo; 63 XShmSegmentInfo shminfo;
64 #endif 64 #endif
65
66 /* For handle connection */
67 int io_hdl;
65 68
66 /* 69 /*
67 * Following variables are used by handle_single_x_event() 70 * Following variables are used by handle_single_x_event()
68 */ 71 */
69 int last_evt_type; /* Type of last event */ 72 int last_evt_type; /* Type of last event */
667 XSHM_update(rt); 670 XSHM_update(rt);
668 #endif 671 #endif
669 XFlush(display); 672 XFlush(display);
670 } 673 }
671 674
672 #if 0 675 static void
673 /*! \brief Handle connection coming data and timeout of timers. 676 _x_mb_handle_connection(int hdl, int fd, MB_IO_TYPE type, void *data) {
674 * 677 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *)data;
675 * \param display is a Display returned by XOpenDisplay(). 678
676 * \param rdman is a redraw manager. 679 handle_x_event(xmb_rt);
677 * \param tman is a timer manager. 680 }
678 *
679 * The display is managed by specified rdman and tman. rdman draws
680 * on the display, and tman trigger actions according timers.
681 */
682 void X_MB_handle_connection(void *be) {
683 X_MB_runtime_t *rt = (X_MB_runtime_t *) be;
684 Display *display = rt->display;
685 redraw_man_t *rdman = rt->rdman;
686 mb_tman_t *tman = rt->tman;
687 int fd;
688 mb_timeval_t now, tmo;
689 struct timeval tv;
690 fd_set rfds,wfds;
691 int nfds;
692 int r, r1,i;
693
694 handle_x_event(rt);
695
696 fd = XConnectionNumber(display);
697 nfds = fd + 1;
698 while(1) {
699 FD_ZERO(&rfds);
700 FD_ZERO(&wfds);
701 FD_SET(fd, &rfds);
702 for(i=0;i<rt->n_monitor;i++) {
703 if (rt->monitors[i].type == MONITOR_READ)
704 FD_SET(rt->monitors[i].fd, &rfds);
705 else if (rt->monitors[i].type == MONITOR_WRITE)
706 FD_SET(rt->monitors[i].fd, &wfds);
707 }
708
709 get_now(&now);
710 r = mb_tman_next_timeout(tman, &now, &tmo);
711
712 if(r == 0) {
713 tv.tv_sec = MB_TIMEVAL_SEC(&tmo);
714 tv.tv_usec = MB_TIMEVAL_USEC(&tmo);
715 r1 = select(nfds, &rfds, NULL, NULL, &tv);
716 } else
717 r1 = select(nfds, &rfds, NULL, NULL, NULL);
718
719 if(r1 == -1) {
720 perror("select");
721 break;
722 }
723
724 if(r1 == 0) {
725 get_now(&now);
726 mb_tman_handle_timeout(tman, &now);
727 rdman_redraw_changed(rdman);
728 #ifdef XSHM
729 XSHM_update(rt);
730 #endif
731 XFlush(display);
732 } else if(FD_ISSET(fd, &rfds)){
733 handle_x_event(rt);
734 } else {
735 for(i=0;i<rt->n_monitor;i++) {
736 if (rt->monitors[i].type == MONITOR_READ) {
737 if (FD_ISSET(rt->monitors[i].fd, &rfds))
738 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
739 } else if (rt->monitors[i].type == MONITOR_WRITE) {
740 if (FD_ISSET(rt->monitors[i].fd, &wfds))
741 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
742 }
743 }
744 }
745 }
746 }
747 #endif /* 0 */
748 681
749 static int X_init_connection(const char *display_name, 682 static int X_init_connection(const char *display_name,
750 int w, int h, 683 int w, int h,
751 Display **displayp, 684 Display **displayp,
752 Visual **visualp, 685 Visual **visualp,
918 */ 851 */
919 static int 852 static int
920 X_MB_init_with_win_internal(X_MB_runtime_t *xmb_rt) { 853 X_MB_init_with_win_internal(X_MB_runtime_t *xmb_rt) {
921 mb_img_ldr_t *img_ldr; 854 mb_img_ldr_t *img_ldr;
922 int w, h; 855 int w, h;
856 int disp_fd;
923 857
924 w = xmb_rt->w; 858 w = xmb_rt->w;
925 h = xmb_rt->h; 859 h = xmb_rt->h;
926 860
927 #ifdef XSHM 861 #ifdef XSHM
965 xmb_rt->last = NULL; 899 xmb_rt->last = NULL;
966 #endif 900 #endif
967 901
968 X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman); 902 X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman);
969 903
904 disp_fd = XConnectionNumber(xmb_rt->display);
905 xmb_rt->io_hdl = xmb_rt->io_man->reg(xmb_rt->io_man, disp_fd,
906 MB_IO_R,
907 _x_mb_handle_connection,
908 xmb_rt);
909
970 return OK; 910 return OK;
971 } 911 }
972 912
973 /*! \brief Initialize a MadButterfy runtime for Xlib. 913 /*! \brief Initialize a MadButterfy runtime for Xlib.
974 * 914 *
1024 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) { 964 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) {
1025 if(xmb_rt->rdman) { 965 if(xmb_rt->rdman) {
1026 redraw_man_destroy(xmb_rt->rdman); 966 redraw_man_destroy(xmb_rt->rdman);
1027 free(xmb_rt->rdman); 967 free(xmb_rt->rdman);
1028 } 968 }
969
970 if(xmb_rt->io_hdl)
971 xmb_rt->io_man->unreg(xmb_rt->io_man, xmb_rt->io_hdl);
1029 972
1030 if(xmb_rt->io_man) 973 if(xmb_rt->io_man)
1031 _io_factory->free(xmb_rt->io_man); 974 _io_factory->free(xmb_rt->io_man);
1032 if(xmb_rt->timer_man) 975 if(xmb_rt->timer_man)
1033 _timer_factory->free(xmb_rt->timer_man); 976 _timer_factory->free(xmb_rt->timer_man);
1191 static int 1134 static int
1192 _x_mb_flush(mb_rt_t *rt) { 1135 _x_mb_flush(mb_rt_t *rt) {
1193 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt; 1136 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
1194 int r; 1137 int r;
1195 1138
1139 #ifdef XSHM
1140 XSHM_update(xmb_rt);
1141 #endif
1196 r = XFlush(xmb_rt->display); 1142 r = XFlush(xmb_rt->display);
1197 return r == 0? ERR: OK; 1143 return r == 0? ERR: OK;
1198 } 1144 }
1199 1145
1200 mb_backend_t backend = { X_MB_new, 1146 mb_backend_t backend = { X_MB_new,