Mercurial > MadButterfly
comparison src/X_supp.c @ 1018:7ccc094bdbe5 refine_backend_if
Move the timer manager based on mb_tman_t to timer.c
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 13:15:33 +0800 |
parents | 7b503c7ed46f |
children | 84006acab6af |
comparison
equal
deleted
inserted
replaced
1017:9b5d4839c5bb | 1018:7ccc094bdbe5 |
---|---|
9 #include "mb_graph_engine.h" | 9 #include "mb_graph_engine.h" |
10 #include "mb_redraw_man.h" | 10 #include "mb_redraw_man.h" |
11 #include "mb_timer.h" | 11 #include "mb_timer.h" |
12 #include "mb_X_supp.h" | 12 #include "mb_X_supp.h" |
13 #include "mb_backend.h" | 13 #include "mb_backend.h" |
14 #include "mb_backend_utils.h" | |
14 #include "config.h" | 15 #include "config.h" |
15 | 16 |
16 #ifdef XSHM | 17 #ifdef XSHM |
17 /* \sa http://www.xfree86.org/current/mit-shm.html */ | 18 /* \sa http://www.xfree86.org/current/mit-shm.html */ |
18 #include <sys/ipc.h> | 19 #include <sys/ipc.h> |
24 #define OK 0 | 25 #define OK 0 |
25 | 26 |
26 #define ASSERT(x) | 27 #define ASSERT(x) |
27 | 28 |
28 #define ONLY_MOUSE_MOVE_RAW 1 | 29 #define ONLY_MOUSE_MOVE_RAW 1 |
30 | |
31 static mb_timer_factory_t *_timer_factory = &tman_timer_factory; | |
29 | 32 |
30 /*! \ingroup xkb | 33 /*! \ingroup xkb |
31 * @{ | 34 * @{ |
32 */ | 35 */ |
33 struct _X_kb_info { | 36 struct _X_kb_info { |
76 int ex1, ey1, ex2, ey2; /* Aggregate expose events */ | 79 int ex1, ey1, ex2, ey2; /* Aggregate expose events */ |
77 int mflag; | 80 int mflag; |
78 int mx, my; /* Position of last motion event */ | 81 int mx, my; /* Position of last motion event */ |
79 int mbut_state; /* Button state of last motion event */ | 82 int mbut_state; /* Button state of last motion event */ |
80 }; | 83 }; |
81 | |
82 /*! \defgroup x_supp_timer Timer manager for X. | |
83 * | |
84 * This implmentation of timer manager is based on mb_tman_t. | |
85 * @{ | |
86 */ | |
87 struct _X_supp_timer_man { | |
88 mb_timer_man_t timer_man; | |
89 mb_tman_t *tman; | |
90 }; | |
91 | |
92 static int _x_supp_timer_man_timeout(struct _mb_timer_man *tm_man, | |
93 mb_timeval_t *tmout, | |
94 mb_timer_cb_t cb, void *data); | |
95 static void _x_supp_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl); | |
96 static mb_timer_man_t *_x_supp_timer_fact_new(void); | |
97 static void _x_supp_timer_fact_free(mb_timer_man_t *timer_man); | |
98 | |
99 static struct _X_supp_timer_man _x_supp_default_timer_man = { | |
100 {_x_supp_timer_man_timeout, _x_supp_timer_man_remove}, | |
101 NULL | |
102 }; | |
103 | |
104 static mb_timer_factory_t _x_supp_default_timer_factory = { | |
105 _x_supp_timer_fact_new, | |
106 _x_supp_timer_fact_free | |
107 }; | |
108 | |
109 static mb_timer_factory_t *_timer_factory = &_x_supp_default_timer_factory; | |
110 | |
111 /*! \brief Content of a timeout request. | |
112 * | |
113 * This is only used by internal of X support. This data structure | |
114 * carry information to adopt mb_tman_t to mb_timer_man_t. | |
115 */ | |
116 struct _X_supp_timeout_data { | |
117 mb_timer_t *timer; /*!< Handle returned by mb_tman_timeout() */ | |
118 mb_timer_cb_t cb; /*!< Real callback function */ | |
119 void *data; /*!< data for real callback */ | |
120 }; | |
121 | |
122 static void | |
123 _x_supp_tmo_hdlr(const mb_timeval_t *tmo, | |
124 const mb_timeval_t *now, | |
125 void *arg) { | |
126 struct _X_supp_timeout_data *data = (struct _X_supp_timeout_data *)arg; | |
127 | |
128 data->cb((int)data, tmo, now, data->data); | |
129 } | |
130 | |
131 static int | |
132 _x_supp_timer_man_timeout(struct _mb_timer_man *tm_man, | |
133 mb_timeval_t *tmout, /* timeout (wall time) */ | |
134 mb_timer_cb_t cb, void *data) { | |
135 struct _X_supp_timer_man *timer_man = (struct _X_supp_timer_man *)tm_man; | |
136 mb_timer_t *timer; | |
137 struct _X_supp_timeout_data *tmout_data; | |
138 | |
139 tmout_data = O_ALLOC(struct _X_supp_timeout_data); | |
140 tmout_data->cb = cb; | |
141 tmout_data->data = data; | |
142 timer = mb_tman_timeout(timer_man->tman, tmout, | |
143 _x_supp_tmo_hdlr, tmout_data); | |
144 if(timer == NULL) | |
145 return ERR; | |
146 tmout_data->timer = timer; | |
147 | |
148 return (int)tmout_data; | |
149 } | |
150 | |
151 static void | |
152 _x_supp_timer_man_remove(struct _mb_timer_man *tm_man, int tm_hdl) { | |
153 struct _X_supp_timer_man *timer_man = (struct _X_supp_timer_man *)tm_man; | |
154 struct _X_supp_timeout_data *tmout_data = | |
155 (struct _X_supp_timeout_data *)tm_hdl; | |
156 | |
157 mb_tman_remove(timer_man->tman, tmout_data->timer); | |
158 free(tmout_data); | |
159 } | |
160 | |
161 static mb_timer_man_t * | |
162 _x_supp_timer_fact_new(void) { | |
163 if(_x_supp_default_timer_man.tman == NULL) | |
164 _x_supp_default_timer_man.tman = mb_tman_new(); | |
165 return (mb_timer_man_t *)&_x_supp_default_timer_man; | |
166 } | |
167 | |
168 static void | |
169 _x_supp_timer_fact_free(mb_timer_man_t *timer_man) { | |
170 } | |
171 | |
172 | |
173 /* @} */ | |
174 | 84 |
175 static void _x_supp_handle_x_event(X_supp_runtime_t *rt); | 85 static void _x_supp_handle_x_event(X_supp_runtime_t *rt); |
176 | 86 |
177 /*! \defgroup x_supp_io IO manager for X. | 87 /*! \defgroup x_supp_io IO manager for X. |
178 * @{ | 88 * @{ |
264 _x_supp_event_loop(mb_rt_t *rt) { | 174 _x_supp_event_loop(mb_rt_t *rt) { |
265 struct _X_supp_runtime *xmb_rt = (struct _X_supp_runtime *)rt; | 175 struct _X_supp_runtime *xmb_rt = (struct _X_supp_runtime *)rt; |
266 struct _X_supp_IO_man *io_man = (struct _X_supp_IO_man *)xmb_rt->io_man; | 176 struct _X_supp_IO_man *io_man = (struct _X_supp_IO_man *)xmb_rt->io_man; |
267 struct _X_supp_timer_man *timer_man = | 177 struct _X_supp_timer_man *timer_man = |
268 (struct _X_supp_timer_man *)xmb_rt->timer_man; | 178 (struct _X_supp_timer_man *)xmb_rt->timer_man; |
269 mb_tman_t *tman = timer_man->tman; | 179 mb_tman_t *tman = tman_timer_man_get_tman(timer_man); |
270 int fd; | 180 int fd; |
271 mb_timeval_t now, tmo; | 181 mb_timeval_t now, tmo; |
272 struct timeval tv; | 182 struct timeval tv; |
273 fd_set rfds, wfds; | 183 fd_set rfds, wfds; |
274 int nfds = 0; | 184 int nfds = 0; |