Mercurial > MadButterfly
annotate src/cons_supp.c @ 1395:a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
Ad center object when the bbox-x is not available.
author | wycc |
---|---|
date | Sat, 02 Apr 2011 05:36:36 +0800 |
parents | 17cbb862a8c6 |
children |
rev | line source |
---|---|
1116 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <unistd.h> | |
5 #include <fcntl.h> | |
6 #include <poll.h> | |
7 #include "mb_graph_engine.h" | |
8 #include "mb_redraw_man.h" | |
9 #include "mb_timer.h" | |
10 #include "mb_cons_supp.h" | |
11 #include "mb_backend.h" | |
12 #include "mb_backend_utils.h" | |
13 #include "config.h" | |
14 | |
15 #define ERR -1 | |
16 #define OK 0 | |
17 | |
18 #define FALSE 0 | |
19 #define TRUE 1 | |
20 | |
21 #define ASSERT(x) | |
22 | |
23 #define ONLY_MOUSE_MOVE_RAW 1 | |
24 | |
25 typedef int keysym; | |
26 | |
27 static mb_timer_factory_t *_timer_factory = &tman_timer_factory; | |
28 | |
29 /*! \ingroup console_kb | |
30 * @{ | |
31 */ | |
32 struct _cons_kb_info { | |
33 int kb_fd; | |
34 | |
35 int keycode_min, keycode_max; | |
36 int ksym_per_code; | |
37 keysym *syms; | |
38 subject_t *kbevents; | |
39 observer_factory_t *observer_factory; | |
40 }; | |
41 typedef struct _cons_kb_info cons_kb_info_t; | |
42 | |
43 /* @} */ | |
44 | |
45 struct _cons_supp_runtime { | |
46 MB_DISPLAY display; | |
1117
1de8bb740c46
Add pre-created window for _cons_supp_new_with_win()
Thinker K.F. Li <thinker@codemud.net>
parents:
1116
diff
changeset
|
47 MB_WINDOW win; |
1116 | 48 |
49 mbe_surface_t *surface; | |
50 mbe_t *cr; | |
51 redraw_man_t *rdman; | |
52 mb_img_ldr_t *img_ldr; | |
53 int w, h; | |
54 | |
55 cons_kb_info_t kbinfo; | |
56 mb_IO_man_t *io_man; | |
57 mb_timer_man_t *timer_man; | |
58 | |
59 #ifndef ONLY_MOUSE_MOVE_RAW | |
60 /* States */ | |
61 shape_t *last; | |
62 #endif | |
63 | |
64 /* For handle connection */ | |
65 int io_hdl; | |
66 | |
67 /* | |
68 * Following variables are used by handle_single_cons_event() | |
69 */ | |
70 int last_evt_type; /* Type of last event */ | |
71 int ex1, ey1, ex2, ey2; /* Aggregate expose events */ | |
72 int mx, my; /* Position of last motion event */ | |
73 int mbut_state; /* Button state of last motion event */ | |
74 }; | |
75 typedef struct _cons_supp_runtime cons_supp_runtime_t; | |
76 | |
77 static void _cons_supp_handle_cons_event(cons_supp_runtime_t *rt); | |
78 | |
79 /*! \defgroup cons_supp_io IO manager for console. | |
80 * @{ | |
81 */ | |
82 #define MAX_MONITORS 200 | |
83 | |
84 typedef struct { | |
85 int type; | |
86 int fd; | |
87 mb_IO_cb_t cb; | |
88 void *data; | |
89 } monitor_t; | |
90 | |
91 struct _cons_supp_IO_man { | |
92 mb_IO_man_t io_man; | |
93 monitor_t monitors[MAX_MONITORS]; | |
94 int n_monitor; | |
95 }; | |
96 | |
97 static int _cons_supp_io_man_reg(struct _mb_IO_man *io_man, | |
1118
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
98 int fd, MB_IO_TYPE type, |
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
99 mb_IO_cb_t cb, void *data); |
1116 | 100 static void _cons_supp_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl); |
101 static mb_IO_man_t *_cons_supp_io_man_new(void); | |
102 static void _cons_supp_io_man_free(mb_IO_man_t *io_man); | |
103 | |
104 static mb_IO_factory_t _cons_supp_default_io_factory = { | |
105 _cons_supp_io_man_new, | |
106 _cons_supp_io_man_free | |
107 }; | |
108 static mb_IO_factory_t *_io_factory = &_cons_supp_default_io_factory; | |
109 | |
110 static struct _cons_supp_IO_man _default_io_man = { | |
111 {_cons_supp_io_man_reg, _cons_supp_io_man_unreg}, | |
112 {}, /* monitors */ | |
113 0 /* n_monitor */ | |
114 }; | |
115 | |
116 static mb_IO_man_t * | |
117 _cons_supp_io_man_new(void) { | |
118 return (mb_IO_man_t *)&_default_io_man; | |
119 } | |
120 | |
121 static void | |
122 _cons_supp_io_man_free(mb_IO_man_t *io_man) { | |
123 } | |
124 | |
125 static int | |
126 _cons_supp_io_man_reg(struct _mb_IO_man *io_man, | |
1118
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
127 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data) { |
1116 | 128 struct _cons_supp_IO_man *cmb_io_man = (struct _cons_supp_IO_man *)io_man; |
129 int i; | |
130 | |
131 for(i = 0; i < cmb_io_man->n_monitor; i++) { | |
132 if (cmb_io_man->monitors[i].type == MB_IO_DUMMY) | |
133 break; | |
134 } | |
135 if (i == MAX_MONITORS) | |
136 return ERR; | |
137 | |
138 cmb_io_man->monitors[i].type = type; | |
139 cmb_io_man->monitors[i].fd = fd; | |
140 cmb_io_man->monitors[i].cb = cb; | |
141 cmb_io_man->monitors[i].data = data; | |
142 i++; | |
143 if(i > cmb_io_man->n_monitor) | |
144 cmb_io_man->n_monitor = i; | |
145 return i - 1; | |
146 } | |
147 | |
148 static void | |
149 _cons_supp_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl) { | |
150 struct _cons_supp_IO_man *cmb_io_man = (struct _cons_supp_IO_man *)io_man; | |
151 | |
152 ASSERT(io_hdl < cmb_io_man->n_monitor); | |
153 cmb_io_man->monitors[io_hdl].type = MB_IO_DUMMY; | |
154 } | |
155 | |
156 /*! \brief Handle connection coming data and timeout of timers. | |
157 * | |
158 */ | |
159 static void | |
160 _cons_supp_event_loop(mb_rt_t *rt) { | |
161 struct _cons_supp_runtime *cmb_rt = (struct _cons_supp_runtime *)rt; | |
162 struct _cons_supp_IO_man *io_man = | |
163 (struct _cons_supp_IO_man *)cmb_rt->io_man; | |
164 mb_timer_man_t *timer_man = (mb_timer_man_t *)cmb_rt->timer_man; | |
165 redraw_man_t *rdman; | |
166 mb_tman_t *tman = tman_timer_man_get_tman(timer_man); | |
167 mb_timeval_t now, tmo; | |
168 struct timeval tv; | |
169 fd_set rfds, wfds; | |
170 int nfds = 0; | |
171 int r, r1,i; | |
172 | |
173 rdman = mb_runtime_rdman(rt); | |
174 rdman_redraw_all(rdman); | |
175 | |
176 _cons_supp_handle_cons_event(cmb_rt); | |
177 | |
178 while(1) { | |
179 FD_ZERO(&rfds); | |
180 FD_ZERO(&wfds); | |
181 for(i = 0; i < io_man->n_monitor; i++) { | |
182 if(io_man->monitors[i].type == MB_IO_R || | |
183 io_man->monitors[i].type == MB_IO_RW) { | |
184 FD_SET(io_man->monitors[i].fd, &rfds); | |
185 nfds = MB_MAX(nfds, io_man->monitors[i].fd + 1); | |
186 } | |
187 if(io_man->monitors[i].type == MB_IO_W || | |
188 io_man->monitors[i].type == MB_IO_RW) { | |
189 FD_SET(io_man->monitors[i].fd, &wfds); | |
190 nfds = MB_MAX(nfds, io_man->monitors[i].fd + 1); | |
191 } | |
192 } | |
193 | |
194 get_now(&now); | |
195 r = mb_tman_next_timeout(tman, &now, &tmo); | |
196 | |
197 if(r == 0) { | |
198 tv.tv_sec = MB_TIMEVAL_SEC(&tmo); | |
199 tv.tv_usec = MB_TIMEVAL_USEC(&tmo); | |
200 r1 = select(nfds, &rfds, NULL, NULL, &tv); | |
201 } else | |
202 r1 = select(nfds, &rfds, NULL, NULL, NULL); | |
203 | |
204 if(r1 == -1) { | |
205 perror("select"); | |
206 break; | |
207 } | |
208 | |
209 if(r1 == 0) { | |
210 get_now(&now); | |
211 mb_tman_handle_timeout(tman, &now); | |
212 rdman_redraw_changed(rdman); | |
213 } else { | |
214 for(i = 0; i < io_man->n_monitor; i++) { | |
215 if(io_man->monitors[i].type == MB_IO_R || | |
216 io_man->monitors[i].type == MB_IO_RW) { | |
217 if(FD_ISSET(io_man->monitors[i].fd, &rfds)) | |
218 io_man->monitors[i].cb(i, io_man->monitors[i].fd, | |
219 MB_IO_R, | |
220 io_man->monitors[i].data); | |
221 } | |
222 if(io_man->monitors[i].type == MB_IO_W || | |
223 io_man->monitors[i].type == MB_IO_RW) { | |
224 if(FD_ISSET(io_man->monitors[i].fd, &wfds)) | |
225 io_man->monitors[i].cb(i, io_man->monitors[i].fd, | |
226 MB_IO_W, | |
227 io_man->monitors[i].data); | |
228 } | |
229 } | |
230 } | |
231 } | |
232 } | |
233 | |
234 /* @} */ | |
235 | |
236 /*! \defgroup console_kb Console Keyboard Handling | |
237 * | |
238 * Accept keyboard events from console and delivery it to | |
239 * application through observer pattern. There is a subject, | |
240 * per X-connection, for that. | |
241 * @{ | |
242 */ | |
243 static int keycode2sym(cons_kb_info_t *kbinfo, unsigned int keycode) { | |
244 /* TODO: implement keycode to key symbol translation */ | |
245 return 0; | |
246 } | |
247 | |
248 static int cons_kb_init(cons_kb_info_t *kbinfo, MB_DISPLAY display, | |
1118
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
249 redraw_man_t *rdman) { |
1116 | 250 int n_syms; |
251 observer_factory_t *factory; | |
252 int r; | |
253 | |
254 /* TODO: set keycode_min, keycode_max and syms */ | |
255 if((int)display != -1) | |
256 kbinfo->kb_fd = (int)display; | |
257 else | |
258 kbinfo->kb_fd = STDIN_FILENO; | |
259 | |
260 factory = rdman_get_observer_factory(rdman); | |
261 kbinfo->kbevents = subject_new(factory, kbinfo, OBJT_KB); | |
262 if(kbinfo->kbevents == NULL) | |
263 return ERR; | |
264 /*! \todo Make sure observer_factory is still need. */ | |
265 kbinfo->observer_factory = factory; | |
266 | |
267 return OK; | |
268 } | |
269 | |
270 static void cons_kb_destroy(cons_kb_info_t *kbinfo) { | |
271 subject_free(kbinfo->kbevents); | |
272 } | |
273 /* @} */ | |
274 | |
275 /*! \brief Notify observers of the shape at specified | |
276 * position for mouse event. | |
277 * | |
278 * Observers of parent shapes may be called if the subject is not | |
279 * with SUBF_STOP_PROPAGATE flag. The subject of mouse event | |
280 * for a shape is returned by sh_get_mouse_event_subject(). | |
281 */ | |
282 static void notify_coord_or_shape(redraw_man_t *rdman, | |
283 mb_obj_t *obj, | |
284 co_aix x, co_aix y, int etype, | |
285 unsigned int state, | |
286 unsigned int button) { | |
287 mouse_event_t mouse_event; | |
288 subject_t *subject; | |
289 | |
290 mouse_event.event.type = etype; | |
291 mouse_event.x = x; | |
292 mouse_event.y = y; | |
293 mouse_event.but_state = state; | |
294 mouse_event.button = button; | |
295 | |
296 if(IS_MBO_SHAPES(obj)) | |
297 subject = sh_get_mouse_event_subject((shape_t *)obj); | |
298 else | |
299 subject = coord_get_mouse_event((coord_t *)obj); | |
300 | |
301 subject_notify(subject, (event_t *)&mouse_event); | |
302 } | |
303 | |
304 /*! \brief Handle keyboard event and maintain internal states. | |
305 * | |
306 * It keeps internal state in rt to improve performance. | |
307 */ | |
308 static void | |
309 handle_single_cons_event(cons_supp_runtime_t *rt) { | |
310 /* TODO: handle keyboard and mouse events. */ | |
311 printf("handle_single_cons_event() will be implemented later\n"); | |
312 } | |
313 | |
314 /*! \brief Call when no more event in an event iteration. | |
315 * | |
316 * No more event means event queue is emplty. This function will | |
317 * perform some actions according current internal state. | |
318 */ | |
319 static void | |
320 no_more_event(cons_supp_runtime_t *rt) { | |
321 } | |
322 | |
323 /*! \brief Dispatch all console events in the queue. | |
324 */ | |
325 static void _cons_supp_handle_cons_event(cons_supp_runtime_t *cmb_rt) { | |
326 int console_fd = (int)cmb_rt->display; | |
327 struct pollfd pfd = {console_fd, POLLIN, 0}; | |
328 int r; | |
329 | |
330 while((r = poll(&pfd, 1, 0)) > 0) { | |
331 handle_single_cons_event(cmb_rt); | |
332 } | |
333 no_more_event(cmb_rt); | |
334 } | |
335 | |
336 static void | |
337 _cons_supp_handle_connection(int hdl, int fd, MB_IO_TYPE type, void *data) { | |
338 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *)data; | |
339 | |
340 _cons_supp_handle_cons_event(cmb_rt); | |
341 } | |
342 | |
343 /*! \brief Initialize a MadButterfy runtime for Xlib. | |
344 * | |
345 * This one is very like _cons_supp_init(), except it accepts a | |
346 * cons_supp_runtime_t object initialized with a display connected to a X | |
347 * server and an opened window. | |
348 * | |
349 * Following field of the cons_supp_runtime_t object should be initialized. | |
350 * - w, h | |
351 * - win | |
352 * - display | |
353 * - visual | |
354 */ | |
355 static int | |
356 _cons_supp_init_with_win_internal(cons_supp_runtime_t *cmb_rt) { | |
357 mb_img_ldr_t *img_ldr; | |
358 int w, h; | |
359 int console_fd; | |
360 | |
361 w = cmb_rt->w; | |
362 h = cmb_rt->h; | |
363 | |
364 mbe_init(); | |
365 | |
366 cmb_rt->surface = | |
1117
1de8bb740c46
Add pre-created window for _cons_supp_new_with_win()
Thinker K.F. Li <thinker@codemud.net>
parents:
1116
diff
changeset
|
367 mbe_win_surface_create(cmb_rt->display, cmb_rt->win, |
1116 | 368 MB_IFMT_ARGB32, w, h); |
369 | |
370 cmb_rt->cr = mbe_create(cmb_rt->surface); | |
371 | |
372 cmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); | |
373 redraw_man_init(cmb_rt->rdman, cmb_rt->cr, NULL); | |
374 cmb_rt->rdman->w = w; | |
375 cmb_rt->rdman->h = h; | |
376 /* FIXME: This is a wired loopback reference. This is inly | |
377 * required when we need to get the cmb_rt->tman for the | |
378 * animation. We should relocate the tman to the | |
379 * redraw_man_t instead. | |
380 */ | |
381 cmb_rt->rdman->rt = cmb_rt; | |
382 | |
383 cmb_rt->io_man = mb_io_man_new(_io_factory); | |
384 cmb_rt->timer_man = mb_timer_man_new(_timer_factory); | |
385 | |
386 img_ldr = simple_mb_img_ldr_new(""); | |
387 cmb_rt->img_ldr = img_ldr; | |
388 /*! \todo Remove rdman_set_img_ldr() */ | |
389 rdman_set_img_ldr(cmb_rt->rdman, img_ldr); /* this is ncessary? */ | |
390 | |
391 #ifndef ONLY_MOUSE_MOVE_RAW | |
392 cmb_rt->last = NULL; | |
393 #endif | |
394 | |
395 cons_kb_init(&cmb_rt->kbinfo, cmb_rt->display, cmb_rt->rdman); | |
396 | |
397 console_fd = (int)cmb_rt->display; | |
398 cmb_rt->io_hdl = mb_io_man_reg(cmb_rt->io_man, console_fd, | |
399 MB_IO_R, | |
400 _cons_supp_handle_connection, | |
401 cmb_rt); | |
402 | |
403 return OK; | |
404 } | |
405 | |
406 /*! \brief Initialize a MadButterfy runtime for console. | |
407 * | |
408 * It setups a runtime environment to run MadButterfly with console. | |
409 * Users should specify width and height of the opening window. | |
410 * | |
411 * \param display_name is actually the path to the console/input device. | |
412 */ | |
413 static int _cons_supp_init(cons_supp_runtime_t *cmb_rt, | |
1118
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
414 const char *display_name, |
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
415 int w, int h) { |
1116 | 416 int r; |
417 int console_fd; | |
418 | |
419 memset(cmb_rt, 0, sizeof(cons_supp_runtime_t)); | |
420 | |
421 if(display_name == NULL || strlen(display_name) == 0) | |
422 console_fd = STDIN_FILENO; | |
423 else { | |
424 console_fd = open(display_name, O_RDONLY); | |
425 if(console_fd == -1) | |
426 return ERR; | |
427 } | |
428 | |
429 cmb_rt->display = (MB_DISPLAY)console_fd; | |
1117
1de8bb740c46
Add pre-created window for _cons_supp_new_with_win()
Thinker K.F. Li <thinker@codemud.net>
parents:
1116
diff
changeset
|
430 cmb_rt->win = NULL; |
1116 | 431 cmb_rt->w = w; |
432 cmb_rt->h = h; | |
433 | |
434 r = _cons_supp_init_with_win_internal(cmb_rt); | |
435 | |
436 return r; | |
437 } | |
438 | |
439 /*! \brief Initialize a MadButterfly runtime for a window of console. | |
440 * | |
441 * This function is equivalent to _cons_supp_init() with fixed width | |
442 * and height. Since, there is no window for console. | |
443 * | |
444 * Runtimes initialized with this function should be destroyed with | |
445 * cons_supp_destroy_keep_win(). | |
446 * | |
447 * \param display is actually a file descriptor of console (input device). | |
448 */ | |
449 static int | |
450 _cons_supp_init_with_win(cons_supp_runtime_t *cmb_rt, | |
1118
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
451 MB_DISPLAY display, MB_WINDOW win) { |
1116 | 452 int r; |
453 | |
454 memset(cmb_rt, 0, sizeof(cons_supp_runtime_t)); | |
455 | |
456 cmb_rt->display = display; | |
457 cmb_rt->w = 800; | |
458 cmb_rt->h = 600; | |
459 | |
460 r = _cons_supp_init_with_win_internal(cmb_rt); | |
461 | |
462 return r; | |
463 } | |
464 | |
465 static void cons_supp_destroy_keep_win(cons_supp_runtime_t *cmb_rt); | |
466 | |
467 static void cons_supp_destroy(cons_supp_runtime_t *cmb_rt) { | |
468 int console_fd = cmb_rt = (int)cmb_rt->display; | |
469 | |
470 close(console_fd); | |
471 cons_supp_destroy_keep_win(cmb_rt); | |
472 } | |
473 | |
474 /*! \brief Destroy a MadButterfly runtime initialized with | |
475 * _cons_supp_init_with_win(). | |
476 * | |
477 * Destroying a runtime with this function prevent the window and | |
478 * display associated with the runtime being closed. | |
479 */ | |
480 static void | |
481 cons_supp_destroy_keep_win(cons_supp_runtime_t *cmb_rt) { | |
482 if(cmb_rt->rdman) { | |
483 redraw_man_destroy(cmb_rt->rdman); | |
484 free(cmb_rt->rdman); | |
485 } | |
486 | |
487 if(cmb_rt->io_hdl) | |
488 mb_io_man_unreg(cmb_rt->io_man, cmb_rt->io_hdl); | |
489 | |
490 if(cmb_rt->io_man) | |
491 mb_io_man_free(_io_factory, cmb_rt->io_man); | |
492 if(cmb_rt->timer_man) | |
493 mb_timer_man_free(_timer_factory, cmb_rt->timer_man); | |
494 | |
495 if(cmb_rt->img_ldr) | |
496 MB_IMG_LDR_FREE(cmb_rt->img_ldr); | |
497 | |
498 if(cmb_rt->cr) | |
499 mbe_destroy(cmb_rt->cr); | |
500 | |
501 if(cmb_rt->surface) | |
502 mbe_surface_destroy(cmb_rt->surface); | |
503 | |
504 cons_kb_destroy(&cmb_rt->kbinfo); | |
505 } | |
506 | |
507 static mb_rt_t * | |
508 _cons_supp_new(const char *display_name, int w, int h) { | |
509 cons_supp_runtime_t *rt; | |
510 int r; | |
511 | |
512 rt = O_ALLOC(cons_supp_runtime_t); | |
513 if(rt == NULL) | |
514 return NULL; | |
515 | |
516 r = _cons_supp_init(rt, display_name, w, h); | |
517 if(r != OK) { | |
518 free(rt); | |
519 return NULL; | |
520 } | |
521 | |
522 return (mb_rt_t *)rt; | |
523 } | |
524 | |
1117
1de8bb740c46
Add pre-created window for _cons_supp_new_with_win()
Thinker K.F. Li <thinker@codemud.net>
parents:
1116
diff
changeset
|
525 /*! \brief Create a new runtime for existed window for console. |
1116 | 526 * |
527 * The object returned by this function must be free with | |
528 * _cons_supp_free_keep_win() to prevent the window from closed. | |
529 */ | |
530 static mb_rt_t * | |
531 _cons_supp_new_with_win(MB_DISPLAY display, MB_WINDOW win) { | |
532 cons_supp_runtime_t *rt; | |
533 int r; | |
534 | |
535 rt = O_ALLOC(cons_supp_runtime_t); | |
536 if(rt == NULL) | |
537 return NULL; | |
538 | |
539 r = _cons_supp_init_with_win(rt, display, win); | |
540 if(r != OK) { | |
541 free(rt); | |
542 return NULL; | |
543 } | |
544 | |
545 return (mb_rt_t *)rt; | |
546 } | |
547 | |
548 static void | |
549 _cons_supp_free(mb_rt_t *rt) { | |
550 cons_supp_destroy((cons_supp_runtime_t *) rt); | |
551 free(rt); | |
552 } | |
553 | |
554 /*! \brief Free runtime created with _cons_supp_new_with_win(). | |
555 */ | |
556 static void | |
557 _cons_supp_free_keep_win(mb_rt_t *rt) { | |
558 cons_supp_destroy_keep_win((cons_supp_runtime_t *) rt); | |
559 free(rt); | |
560 } | |
561 | |
562 static subject_t * | |
563 _cons_supp_kbevents(mb_rt_t *rt) { | |
564 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *) rt; | |
565 return cmb_rt->kbinfo.kbevents; | |
566 } | |
567 | |
568 static redraw_man_t * | |
569 _cons_supp_rdman(mb_rt_t *rt) { | |
570 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *) rt; | |
571 return cmb_rt->rdman; | |
572 } | |
573 | |
574 static mb_timer_man_t * | |
575 _cons_supp_timer_man(mb_rt_t *rt) { | |
576 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *) rt; | |
577 return cmb_rt->timer_man; | |
578 } | |
579 | |
580 static observer_factory_t * | |
581 _cons_supp_observer_factory(mb_rt_t *rt) { | |
582 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *) rt; | |
583 observer_factory_t *factory; | |
584 | |
585 factory = rdman_get_observer_factory(cmb_rt->rdman); | |
586 return factory; | |
587 } | |
588 | |
589 static mb_img_ldr_t * | |
590 _cons_supp_img_ldr(mb_rt_t *rt) { | |
591 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *) rt; | |
592 mb_img_ldr_t *img_ldr; | |
593 | |
594 img_ldr = cmb_rt->img_ldr; | |
595 | |
596 return img_ldr; | |
597 } | |
598 | |
599 static int | |
600 _cons_supp_add_event(mb_rt_t *rt, int fd, MB_IO_TYPE type, | |
1118
b319cbbf35c2
Reformat the source for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1117
diff
changeset
|
601 mb_IO_cb_t cb, void *data) |
1116 | 602 { |
603 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *) rt; | |
604 mb_IO_man_t *io_man = cmb_rt->io_man; | |
605 int hdl; | |
606 | |
607 hdl = mb_io_man_reg(io_man, fd, type, cb, data); | |
608 return hdl; | |
609 } | |
610 | |
611 static void | |
612 _cons_supp_remove_event(mb_rt_t *rt, int hdl) | |
613 { | |
614 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *) rt; | |
615 mb_IO_man_t *io_man = cmb_rt->io_man; | |
616 | |
617 mb_io_man_unreg(io_man, hdl); | |
618 } | |
619 | |
620 static int | |
621 _cons_supp_flush(mb_rt_t *rt) { | |
622 cons_supp_runtime_t *cmb_rt = (cons_supp_runtime_t *)rt; | |
623 | |
624 mbe_flush(cmb_rt->cr); | |
625 return OK; | |
626 } | |
627 | |
628 static void | |
629 _cons_supp_reg_IO_factory(mb_IO_factory_t *io_factory) { | |
630 _io_factory = io_factory; | |
631 } | |
632 | |
633 static void | |
634 _cons_supp_reg_timer_factory(mb_timer_factory_t *timer_factory) { | |
635 _timer_factory = timer_factory; | |
636 } | |
637 | |
638 mb_backend_t mb_dfl_backend = { _cons_supp_new, | |
639 _cons_supp_new_with_win, | |
640 | |
641 _cons_supp_free, | |
642 _cons_supp_free_keep_win, | |
643 _cons_supp_add_event, | |
644 _cons_supp_remove_event, | |
645 _cons_supp_event_loop, | |
646 _cons_supp_flush, | |
647 | |
648 _cons_supp_kbevents, | |
649 _cons_supp_rdman, | |
650 _cons_supp_timer_man, | |
651 _cons_supp_observer_factory, | |
652 _cons_supp_img_ldr, | |
653 | |
654 _cons_supp_reg_IO_factory, | |
655 _cons_supp_reg_timer_factory, | |
656 }; | |
1119
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
657 |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
658 /* |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
659 * Local Variables: |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
660 * indent-tabs-mode: t |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
661 * tab-width: 8 |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
662 * c-basic-offset: 4 |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
663 * c-file-style:"stroustrup" |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
664 * fill-column:79 |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
665 * End: |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
666 */ |
17cbb862a8c6
Change modeline for cons_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1118
diff
changeset
|
667 // vim: sw=4:ts=8:sts=4:textwidth=79 |