annotate src/X_supp.c @ 249:ab8284c8dcee

* Add loopback reference from rdman to the backend. This is only required when we need to acquire the tman for the animation. This is not a reasonable arrangement since the animation should be backend transparent. We should not touch the backend directly from the animation. We should relocate the tman to the rdman. * Remove reference to the MBApp from the mb_button_t so that it will be easier for us to generate button inside the sprite.
author wycc
date Sun, 04 Jan 2009 09:32:49 +0800
parents 29e1b2bffe4c
children e8a784a306d0
rev   line source
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
2 #include <stdlib.h>
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
3 #include <string.h>
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <X11/Xlib.h>
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <X11/Xutil.h>
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
6 #include <cairo.h>
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
7 #include <cairo-xlib.h>
186
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
8 #include "mb_redraw_man.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
9 #include "mb_timer.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
10 #include "mb_X_supp.h"
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
12 #define ERR -1
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
13 #define OK 0
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
14
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
15 #define ONLY_MOUSE_MOVE_RAW 1
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
16
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
17 /*! \ingroup xkb
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
18 * @{
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
19 */
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
20 struct _X_kb_info {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
21 int keycode_min, keycode_max;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
22 int ksym_per_code;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
23 KeySym *syms;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
24 subject_t *kbevents;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
25 ob_factory_t *ob_factory;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
26 };
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
27
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
28 /* @} */
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
29
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
30 struct _X_MB_runtime {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
31 Display *display;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
32 Window win;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
33 Visual *visual;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
34 cairo_surface_t *surface, *backend_surface;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
35 cairo_t *cr, *backend_cr;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
36 redraw_man_t *rdman;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
37 mb_tman_t *tman;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
38 int w, h;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
39
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
40 X_kb_info_t kbinfo;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
41
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
42 #ifndef ONLY_MOUSE_MOVE_RAW
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
43 /* States */
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
44 shape_t *last;
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
45 #endif
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
46 };
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
47
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
48 /*! \defgroup xkb X Keyboard Handling
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
49 *
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
50 * Accept keyboard events from X server and delivery it to
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
51 * application through observer pattern. There is a subject,
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
52 * per X-connection, for that.
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
53 * @{
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
54 */
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
55 static int keycode2sym(X_kb_info_t *kbinfo, unsigned int keycode) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
56 int sym_idx;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
57 int sym;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
58
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
59 sym_idx = kbinfo->ksym_per_code * (keycode - kbinfo->keycode_min);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
60 sym = kbinfo->syms[sym_idx];
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
61 return sym;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
62 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
63
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
64 static int X_kb_init(X_kb_info_t *kbinfo, Display *display,
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
65 redraw_man_t *rdman) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
66 int n_syms;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
67 ob_factory_t *factory;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
68 int r;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
69
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
70 r = XDisplayKeycodes(display,
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
71 &kbinfo->keycode_min,
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
72 &kbinfo->keycode_max);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
73 if(r == 0)
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
74 return ERR;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
75
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
76 n_syms = kbinfo->keycode_max - kbinfo->keycode_min + 1;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
77 kbinfo->syms = XGetKeyboardMapping(display, kbinfo->keycode_min,
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
78 n_syms,
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
79 &kbinfo->ksym_per_code);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
80 if(kbinfo->syms == NULL)
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
81 return ERR;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
82
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
83 factory = rdman_get_ob_factory(rdman);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
84 kbinfo->kbevents = subject_new(factory, kbinfo, OBJT_KB);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
85 if(kbinfo->kbevents == NULL)
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
86 return ERR;
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
87 /*! \todo Make sure ob_factory is still need. */
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
88 kbinfo->ob_factory = factory;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
89
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
90 return OK;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
91 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
92
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
93 static void X_kb_destroy(X_kb_info_t *kbinfo) {
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
94 subject_free(kbinfo->kbevents);
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
95 XFree(kbinfo->syms);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
96 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
97
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
98 /*! \brief Accept X keyboard events from handle_x_event() and dispatch it.
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
99 */
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
100 static void X_kb_handle_event(X_kb_info_t *kbinfo, XKeyEvent *xkey) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
101 unsigned int code;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
102 int sym;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
103 X_kb_event_t event;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
104
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
105 code = xkey->keycode;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
106 sym = keycode2sym(kbinfo, code);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
107 if(xkey->type == KeyPress)
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
108 event.event.type = EVT_KB_PRESS;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
109 else if(xkey->type == KeyRelease)
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
110 event.event.type = EVT_KB_RELEASE;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
111 event.event.tgt = event.event.cur_tgt = kbinfo->kbevents;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
112 event.keycode = code;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
113 event.sym = sym;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
114
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
115 subject_notify(kbinfo->kbevents, &event.event);
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
116 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
117
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
118 /* @} */
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
120 static unsigned int get_button_state(unsigned int state) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
121 unsigned int but = 0;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
122
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
123 if(state & Button1Mask)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
124 but |= MOUSE_BUT1;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
125 if(state & Button2Mask)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
126 but |= MOUSE_BUT2;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
127 if(state & Button3Mask)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
128 but |= MOUSE_BUT3;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
129
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
130 return but;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
131 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
132
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
133 static unsigned int get_button(unsigned int button) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
134 switch(button) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
135 case Button1:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
136 return MOUSE_BUT1;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
137 case Button2:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
138 return MOUSE_BUT2;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
139 case Button3:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
140 return MOUSE_BUT3;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
141 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
142 return 0;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
143 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
144
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
145 /*! \brief Notify observers of the shape at specified
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
146 * position for mouse event.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
147 *
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
148 * Observers of parent shapes may be called if the subject is not
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
149 * with SUBF_STOP_PROPAGATE flag. The subject of mouse event
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
150 * for a shape is returned by sh_get_mouse_event_subject().
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
151 */
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
152 static void notify_coord_or_shape(redraw_man_t *rdman,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
153 mb_obj_t *obj,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
154 co_aix x, co_aix y, int etype,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
155 unsigned int state,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
156 unsigned int button) {
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
157 mouse_event_t mouse_event;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
158 subject_t *subject;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
159
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
160 mouse_event.event.type = etype;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
161 mouse_event.x = x;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
162 mouse_event.y = y;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
163 mouse_event.but_state = state;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
164 mouse_event.button = button;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
165
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
166 if(IS_MBO_SHAPES(obj))
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
167 subject = sh_get_mouse_event_subject((shape_t *)obj);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
168 else
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
169 subject = coord_get_mouse_event((coord_t *)obj);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
170
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
171 subject_notify(subject, (event_t *)&mouse_event);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
172 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
173
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
174 /*! \brief Dispatch all X events in the queue.
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 */
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
176 static void handle_x_event(X_MB_runtime_t *rt) {
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
177 Display *display = rt->display;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
178 redraw_man_t *rdman = rt->rdman;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 XEvent evt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180 XMotionEvent *mevt;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
181 XButtonEvent *bevt;
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
182 XExposeEvent *eevt;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
183 XKeyEvent *xkey;
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
184 co_aix x, y, w, h;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
185
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
186 int eflag = 0;
82
Thinker K.F. Li <thinker@branda.to>
parents: 81
diff changeset
187 int ex1=0, ey1=0, ex2=0, ey2=0;
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
188
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
189 shape_t *shape;
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
190 coord_t *root;
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
191
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
192 unsigned int state, button;
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
193 int in_stroke;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 int r;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196 while(XEventsQueued(display, QueuedAfterReading) > 0) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197 r = XNextEvent(display, &evt);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
198 if(r == -1)
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
199 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
201 switch(evt.type) {
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
202 case ButtonPress:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
203 bevt = (XButtonEvent *)&evt;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
204 x = bevt->x;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
205 y = bevt->y;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
206 state = get_button_state(bevt->state);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
207 button = get_button(bevt->button);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
208
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
209 shape = find_shape_at_pos(rdman, x, y,
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
210 &in_stroke);
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
211 if(shape)
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
212 notify_coord_or_shape(rdman, (mb_obj_t *)shape,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
213 x, y, EVT_MOUSE_BUT_PRESS,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
214 state, button);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
215 break;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
216
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
217 case ButtonRelease:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
218 bevt = (XButtonEvent *)&evt;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
219 x = bevt->x;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
220 y = bevt->y;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
221 state = get_button_state(bevt->state);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
222 button = get_button(bevt->button);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
223
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
224 shape = find_shape_at_pos(rdman, x, y,
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
225 &in_stroke);
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
226 if(shape)
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
227 notify_coord_or_shape(rdman, (mb_obj_t *)shape,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
228 x, y, EVT_MOUSE_BUT_RELEASE,
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
229 state, button);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
230 break;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
231
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
232 case MotionNotify:
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233 mevt = (XMotionEvent *)&evt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 x = mevt->x;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
235 y = mevt->y;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
236 state = get_button_state(mevt->state);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
237
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
238 shape = find_shape_at_pos(rdman, x, y,
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
239 &in_stroke);
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
240 #ifdef ONLY_MOUSE_MOVE_RAW
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
241 if(shape != NULL) {
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
242 notify_coord_or_shape(rdman, (mb_obj_t *)shape,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
243 x, y, EVT_MOUSE_MOVE_RAW, state, 0);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
244 } else {
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
245 root = rdman_get_root(rdman);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
246 notify_coord_or_shape(rdman, (mb_obj_t *)root,
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
247 x, y, EVT_MOUSE_MOVE_RAW, state, 0);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
248 }
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
249 #else
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
250 if(shape != NULL) {
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
251 if(rt->last != shape) {
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
252 if(rt->last)
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
253 notify_coord_or_shape(rdman, rt->last, x, y,
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
254 EVT_MOUSE_OUT, state, 0);
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
255 notify_coord_or_shape(rdman, shape, x, y,
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
256 EVT_MOUSE_OVER, state, 0);
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
257 rt->last = shape;
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
258 } else
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
259 notify_coord_or_shape(rdman, shape, x, y,
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
260 EVT_MOUSE_MOVE, state, 0);
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
261 } else {
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
262 if(rt->last) {
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
263 notify_coord_or_shape(rdman, rt->last, x, y,
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
264 EVT_MOUSE_OUT, state, 0);
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
265 rt->last = NULL;
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
266 }
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
267 }
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
268 #endif
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
269 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
271 case KeyPress:
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
272 case KeyRelease:
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
273 xkey = &evt.xkey;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
274 X_kb_handle_event(&rt->kbinfo, xkey);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
275 break;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
276
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
277 case Expose:
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
278 eevt = &evt.xexpose;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
279 x = eevt->x;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
280 y = eevt->y;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
281 w = eevt->width;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
282 h = eevt->height;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
283
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
284 if(eflag) {
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
285 if(x < ex1)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
286 ex1 = x;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
287 if(y < ey1)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
288 ey1 = y;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
289 if((x + w) > ex2)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
290 ex2 = x + w;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
291 if((y + h) > ey2)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
292 ey2 = y + h;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
293 } else {
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
294 ex1 = x;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
295 ey1 = y;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
296 ex2 = x + w;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
297 ey2 = y + h;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
298 eflag = 1;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
299 }
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
300 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
302 }
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
303 if(eflag) {
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
304 rdman_redraw_area(rdman, ex1, ey1, (ex2 - ex1), (ey2 - ey1));
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
305 eflag = 0;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
306 }
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
307 XFlush(display);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
308 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
309
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
310 /*! \brief Handle connection coming data and timeout of timers.
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
311 *
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
312 * \param display is a Display returned by XOpenDisplay().
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
313 * \param rdman is a redraw manager.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
314 * \param tman is a timer manager.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
315 *
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
316 * The display is managed by specified rdman and tman. rdman draws
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
317 * on the display, and tman trigger actions according timers.
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
318 */
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
319 void X_MB_handle_connection(X_MB_runtime_t *rt) {
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
320 Display *display = rt->display;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
321 redraw_man_t *rdman = rt->rdman;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
322 mb_tman_t *tman = rt->tman;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
323 int fd;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
324 mb_timeval_t now, tmo;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
325 struct timeval tv;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
326 fd_set rfds;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327 int nfds;
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
328 int r, r1;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
329
142
3efe77007127 Do not redraw all at begining, waiting for explosure.
Thinker K.F. Li <thinker@branda.to>
parents: 131
diff changeset
330 handle_x_event(rt);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
331
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
332 fd = XConnectionNumber(display);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
333 nfds = fd + 1;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
334 while(1) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
335 FD_ZERO(&rfds);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336 FD_SET(fd, &rfds);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
337
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
338 get_now(&now);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
339 r = mb_tman_next_timeout(tman, &now, &tmo);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
340
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341 if(r == 0) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342 tv.tv_sec = MB_TIMEVAL_SEC(&tmo);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 tv.tv_usec = MB_TIMEVAL_USEC(&tmo);
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
344 r1 = select(nfds, &rfds, NULL, NULL, &tv);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345 } else
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
346 r1 = select(nfds, &rfds, NULL, NULL, NULL);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
348 if(r1 == -1) {
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
349 perror("select");
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
350 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
351 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
352
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
353 if(r1 == 0) {
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
354 get_now(&now);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
355 mb_tman_handle_timeout(tman, &now);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
356 rdman_redraw_changed(rdman);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
357 XFlush(display);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
358 } else if(FD_ISSET(fd, &rfds)){
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
359 handle_x_event(rt);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
360 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
361 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
362 }
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
363
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
364 #define ERR -1
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
365 #define OK 0
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
366
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
367 static int X_init_connection(const char *display_name,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
368 int w, int h,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
369 Display **displayp,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
370 Visual **visualp,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
371 Window *winp) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
372 Display *display;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
373 Window root, win;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
374 Visual *visual;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
375 int screen;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
376 XSetWindowAttributes wattr;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
377 int depth;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
378 int x, y;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
379 int r;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
380
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
381 display = XOpenDisplay(display_name);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
382 if(display == NULL)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
383 return ERR;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
384
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
385 screen = DefaultScreen(display);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
386 root = DefaultRootWindow(display);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
387 visual = DefaultVisual(display, screen);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
388 depth = DefaultDepth(display, screen);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
389 wattr.override_redirect = False;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
390 x = 10;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
391 y = 10;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
392 win = XCreateWindow(display, root,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
393 x, y,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
394 w, h,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
395 1, depth, InputOutput, visual,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
396 CWOverrideRedirect, &wattr);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
397 r = XMapWindow(display, win);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
398 if(r == -1) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
399 XCloseDisplay(display);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
400 return ERR;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
401 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
402
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
403 XSelectInput(display, win, PointerMotionMask | ExposureMask |
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
404 ButtonPressMask | ButtonReleaseMask |
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
405 KeyPressMask | KeyReleaseMask);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
406 XFlush(display);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
407
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
408 *displayp = display;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
409 *visualp = visual;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
410 *winp = win;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
411
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
412 return OK;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
413 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
414
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
415 /*! \brief Initialize a MadButterfy runtime for Xlib.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
416 *
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
417 * It setups a runtime environment to run MadButterfly with Xlib.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
418 * Users should specify width and height of the opening window.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
419 */
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
420 static int X_MB_init(const char *display_name,
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
421 int w, int h, X_MB_runtime_t *xmb_rt) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
422 memset(xmb_rt, 0, sizeof(X_MB_runtime_t));
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
423
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
424 xmb_rt->w = w;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
425 xmb_rt->h = h;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
426 X_init_connection(display_name, w, h, &xmb_rt->display,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
427 &xmb_rt->visual, &xmb_rt->win);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
428
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
429 xmb_rt->surface =
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
430 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
431
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
432 xmb_rt->backend_surface =
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
433 cairo_xlib_surface_create(xmb_rt->display,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
434 xmb_rt->win,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
435 xmb_rt->visual,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
436 w, h);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
437
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
438 xmb_rt->cr = cairo_create(xmb_rt->surface);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
439 xmb_rt->backend_cr = cairo_create(xmb_rt->backend_surface);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
440
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
441 cairo_set_source_surface(xmb_rt->backend_cr, xmb_rt->surface, 0, 0);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
442
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
443 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t));
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
444 redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr);
249
ab8284c8dcee * Add loopback reference from rdman to the backend. This is only required when we need to acquire the tman for the animation. This is not a reasonable arrangement since the animation should be backend transparent. We should not touch the backend directly from the animation. We should relocate the tman to the rdman.
wycc
parents: 224
diff changeset
445 // FIXME: This is a wired loopback reference. This is inly required when we need
ab8284c8dcee * Add loopback reference from rdman to the backend. This is only required when we need to acquire the tman for the animation. This is not a reasonable arrangement since the animation should be backend transparent. We should not touch the backend directly from the animation. We should relocate the tman to the rdman.
wycc
parents: 224
diff changeset
446 // to get the xmb_rt->tman for the animation. We should relocate the tman
ab8284c8dcee * Add loopback reference from rdman to the backend. This is only required when we need to acquire the tman for the animation. This is not a reasonable arrangement since the animation should be backend transparent. We should not touch the backend directly from the animation. We should relocate the tman to the rdman.
wycc
parents: 224
diff changeset
447 // to the redraw_man_t instead.
ab8284c8dcee * Add loopback reference from rdman to the backend. This is only required when we need to acquire the tman for the animation. This is not a reasonable arrangement since the animation should be backend transparent. We should not touch the backend directly from the animation. We should relocate the tman to the rdman.
wycc
parents: 224
diff changeset
448 xmb_rt->rdman->rt = xmb_rt;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
449
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
450 xmb_rt->tman = mb_tman_new();
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
451
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
452 #ifndef ONLY_MOUSE_MOVE_RAW
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
453 xmb_rt->last = NULL;
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
454 #endif
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
455
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
456 X_kb_init(&xmb_rt->kbinfo, xmb_rt->display, xmb_rt->rdman);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
457
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
458 return OK;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
459 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
460
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
461 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) {
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
462 if(xmb_rt->rdman) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
463 redraw_man_destroy(xmb_rt->rdman);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
464 free(xmb_rt->rdman);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
465 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
466
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
467 if(xmb_rt->tman)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
468 mb_tman_free(xmb_rt->tman);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
469
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
470 if(xmb_rt->cr)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
471 cairo_destroy(xmb_rt->cr);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
472 if(xmb_rt->backend_cr)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
473 cairo_destroy(xmb_rt->backend_cr);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
474
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
475 if(xmb_rt->surface)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
476 cairo_surface_destroy(xmb_rt->surface);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
477 if(xmb_rt->backend_surface)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
478 cairo_surface_destroy(xmb_rt->backend_surface);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
479
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
480 if(xmb_rt->display)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
481 XCloseDisplay(xmb_rt->display);
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
482
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
483 X_kb_destroy(&xmb_rt->kbinfo);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
484 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
485
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
486 X_MB_runtime_t *X_MB_new(const char *display_name, int w, int h) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
487 X_MB_runtime_t *rt;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
488 int r;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
489
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
490 rt = O_ALLOC(X_MB_runtime_t);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
491 if(rt == NULL)
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
492 return NULL;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
493
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
494 r = X_MB_init(display_name, w, h, rt);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
495 if(r != OK)
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
496 return NULL;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
497
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
498 return rt;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
499 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
500
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
501 void X_MB_free(X_MB_runtime_t *rt) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
502 X_MB_destroy(rt);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
503 free(rt);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
504 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
505
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
506 subject_t *X_MB_kbevents(X_MB_runtime_t *xmb_rt) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
507 return xmb_rt->kbinfo.kbevents;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
508 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
509
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
510 redraw_man_t *X_MB_rdman(X_MB_runtime_t *xmb_rt) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
511 return xmb_rt->rdman;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
512 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
513
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
514 mb_tman_t *X_MB_tman(X_MB_runtime_t *xmb_rt) {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
515 return xmb_rt->tman;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
516 }
131
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
517
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
518 ob_factory_t *X_MB_ob_factory(X_MB_runtime_t *xmb_rt) {
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
519 ob_factory_t *factory;
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
520
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
521 factory = rdman_get_ob_factory(xmb_rt->rdman);
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
522 return factory;
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
523 }