Mercurial > MadButterfly
annotate src/X_supp.c @ 451:5c9e2a8a4bd8
Remove all "cairo" wording.
- all cairo are replaced by mbe version
- except pango relative ones.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 05 Aug 2009 16:10:47 +0800 |
parents | a417fd980228 |
children | af4b506ad56f |
rev | line source |
---|---|
77 | 1 #include <stdio.h> |
78 | 2 #include <stdlib.h> |
3 #include <string.h> | |
77 | 4 #include <X11/Xlib.h> |
5 #include <X11/Xutil.h> | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
6 #include "mb_graph_engine.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
|
7 #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
|
8 #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
|
9 #include "mb_X_supp.h" |
77 | 10 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
11 #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
|
12 #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
|
13 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
14 #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
|
15 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
16 /*! \ingroup xkb |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
17 * @{ |
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 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
|
20 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
|
21 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
|
22 KeySym *syms; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
23 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
|
24 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
|
25 }; |
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 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
|
30 Display *display; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
31 Window win; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
32 Visual *visual; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
33 mbe_surface_t *surface, *backend_surface; |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
34 mbe_t *cr, *backend_cr; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
35 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
|
36 mb_tman_t *tman; |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
37 mb_img_ldr_t *img_ldr; |
122
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 | 119 |
78 | 120 static unsigned int get_button_state(unsigned int state) { |
121 unsigned int but = 0; | |
122 | |
123 if(state & Button1Mask) | |
124 but |= MOUSE_BUT1; | |
125 if(state & Button2Mask) | |
126 but |= MOUSE_BUT2; | |
127 if(state & Button3Mask) | |
128 but |= MOUSE_BUT3; | |
129 | |
130 return but; | |
131 } | |
132 | |
133 static unsigned int get_button(unsigned int button) { | |
134 switch(button) { | |
135 case Button1: | |
136 return MOUSE_BUT1; | |
137 case Button2: | |
138 return MOUSE_BUT2; | |
139 case Button3: | |
140 return MOUSE_BUT3; | |
141 } | |
142 return 0; | |
143 } | |
144 | |
145 /*! \brief Notify observers of the shape at specified | |
146 * position for mouse event. | |
147 * | |
148 * Observers of parent shapes may be called if the subject is not | |
149 * with SUBF_STOP_PROPAGATE flag. The subject of mouse event | |
150 * for a shape is returned by sh_get_mouse_event_subject(). | |
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 | 157 mouse_event_t mouse_event; |
158 subject_t *subject; | |
159 | |
160 mouse_event.event.type = etype; | |
161 mouse_event.x = x; | |
162 mouse_event.y = y; | |
163 mouse_event.but_state = state; | |
164 mouse_event.button = button; | |
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 | 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 | 172 } |
173 | |
174 /*! \brief Dispatch all X events in the queue. | |
77 | 175 */ |
83 | 176 static void handle_x_event(X_MB_runtime_t *rt) { |
177 Display *display = rt->display; | |
178 redraw_man_t *rdman = rt->rdman; | |
350
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
179 XEvent evt, peek_evt; |
77 | 180 XMotionEvent *mevt; |
78 | 181 XButtonEvent *bevt; |
81 | 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 | 184 co_aix x, y, w, h; |
185 | |
186 int eflag = 0; | |
82 | 187 int ex1=0, ey1=0, ex2=0, ey2=0; |
81 | 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 | 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 | 194 int r; |
195 | |
196 while(XEventsQueued(display, QueuedAfterReading) > 0) { | |
197 r = XNextEvent(display, &evt); | |
198 if(r == -1) | |
199 break; | |
200 | |
201 switch(evt.type) { | |
78 | 202 case ButtonPress: |
203 bevt = (XButtonEvent *)&evt; | |
204 x = bevt->x; | |
205 y = bevt->y; | |
206 state = get_button_state(bevt->state); | |
207 button = get_button(bevt->button); | |
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 | 215 break; |
216 | |
217 case ButtonRelease: | |
218 bevt = (XButtonEvent *)&evt; | |
219 x = bevt->x; | |
220 y = bevt->y; | |
221 state = get_button_state(bevt->state); | |
222 button = get_button(bevt->button); | |
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 | 230 break; |
231 | |
77 | 232 case MotionNotify: |
350
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
233 while(XEventsQueued(display, QueuedAfterReading) > 0) { |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
234 r = XPeekEvent(display, &peek_evt); |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
235 if(r == -1) |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
236 break; |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
237 if(peek_evt.type != MotionNotify) |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
238 break; |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
239 XNextEvent(display, &evt); |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
240 } |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
241 if(r == -1) |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
242 break; |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
243 |
77 | 244 mevt = (XMotionEvent *)&evt; |
245 x = mevt->x; | |
246 y = mevt->y; | |
78 | 247 state = get_button_state(mevt->state); |
77 | 248 |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
249 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
|
250 &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
|
251 #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
|
252 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
|
253 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
|
254 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
|
255 } else { |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 } |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
260 #else |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
261 if(shape != NULL) { |
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 != shape) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 rt->last = shape; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
269 } else |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
270 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
|
271 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
|
272 } else { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 rt->last = NULL; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
277 } |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
278 } |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
279 #endif |
77 | 280 break; |
281 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
282 case KeyPress: |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
283 case KeyRelease: |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
284 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
|
285 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
|
286 break; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
287 |
77 | 288 case Expose: |
81 | 289 eevt = &evt.xexpose; |
290 x = eevt->x; | |
291 y = eevt->y; | |
292 w = eevt->width; | |
293 h = eevt->height; | |
294 | |
295 if(eflag) { | |
296 if(x < ex1) | |
297 ex1 = x; | |
298 if(y < ey1) | |
299 ey1 = y; | |
300 if((x + w) > ex2) | |
301 ex2 = x + w; | |
302 if((y + h) > ey2) | |
303 ey2 = y + h; | |
304 } else { | |
305 ex1 = x; | |
306 ey1 = y; | |
307 ex2 = x + w; | |
308 ey2 = y + h; | |
309 eflag = 1; | |
310 } | |
77 | 311 break; |
312 } | |
313 } | |
81 | 314 if(eflag) { |
315 rdman_redraw_area(rdman, ex1, ey1, (ex2 - ex1), (ey2 - ey1)); | |
316 eflag = 0; | |
317 } | |
77 | 318 XFlush(display); |
319 } | |
320 | |
321 /*! \brief Handle connection coming data and timeout of timers. | |
78 | 322 * |
323 * \param display is a Display returned by XOpenDisplay(). | |
324 * \param rdman is a redraw manager. | |
325 * \param tman is a timer manager. | |
326 * | |
327 * The display is managed by specified rdman and tman. rdman draws | |
328 * on the display, and tman trigger actions according timers. | |
77 | 329 */ |
83 | 330 void X_MB_handle_connection(X_MB_runtime_t *rt) { |
331 Display *display = rt->display; | |
332 redraw_man_t *rdman = rt->rdman; | |
333 mb_tman_t *tman = rt->tman; | |
77 | 334 int fd; |
335 mb_timeval_t now, tmo; | |
336 struct timeval tv; | |
337 fd_set rfds; | |
338 int nfds; | |
120 | 339 int r, r1; |
77 | 340 |
142
3efe77007127
Do not redraw all at begining, waiting for explosure.
Thinker K.F. Li <thinker@branda.to>
parents:
131
diff
changeset
|
341 handle_x_event(rt); |
78 | 342 |
77 | 343 fd = XConnectionNumber(display); |
344 nfds = fd + 1; | |
345 while(1) { | |
346 FD_ZERO(&rfds); | |
347 FD_SET(fd, &rfds); | |
348 | |
349 get_now(&now); | |
350 r = mb_tman_next_timeout(tman, &now, &tmo); | |
351 | |
352 if(r == 0) { | |
353 tv.tv_sec = MB_TIMEVAL_SEC(&tmo); | |
354 tv.tv_usec = MB_TIMEVAL_USEC(&tmo); | |
120 | 355 r1 = select(nfds, &rfds, NULL, NULL, &tv); |
77 | 356 } else |
120 | 357 r1 = select(nfds, &rfds, NULL, NULL, NULL); |
77 | 358 |
120 | 359 if(r1 == -1) { |
77 | 360 perror("select"); |
361 break; | |
362 } | |
363 | |
120 | 364 if(r1 == 0) { |
77 | 365 get_now(&now); |
366 mb_tman_handle_timeout(tman, &now); | |
367 rdman_redraw_changed(rdman); | |
368 XFlush(display); | |
369 } else if(FD_ISSET(fd, &rfds)){ | |
83 | 370 handle_x_event(rt); |
77 | 371 } |
372 } | |
373 } | |
78 | 374 |
375 #define ERR -1 | |
376 #define OK 0 | |
377 | |
378 static int X_init_connection(const char *display_name, | |
379 int w, int h, | |
380 Display **displayp, | |
381 Visual **visualp, | |
382 Window *winp) { | |
383 Display *display; | |
384 Window root, win; | |
385 Visual *visual; | |
386 int screen; | |
387 XSetWindowAttributes wattr; | |
388 int depth; | |
389 int x, y; | |
390 int r; | |
391 | |
392 display = XOpenDisplay(display_name); | |
393 if(display == NULL) | |
394 return ERR; | |
395 | |
396 screen = DefaultScreen(display); | |
397 root = DefaultRootWindow(display); | |
398 visual = DefaultVisual(display, screen); | |
399 depth = DefaultDepth(display, screen); | |
400 wattr.override_redirect = False; | |
401 x = 10; | |
402 y = 10; | |
403 win = XCreateWindow(display, root, | |
404 x, y, | |
405 w, h, | |
406 1, depth, InputOutput, visual, | |
407 CWOverrideRedirect, &wattr); | |
408 r = XMapWindow(display, win); | |
409 if(r == -1) { | |
410 XCloseDisplay(display); | |
411 return ERR; | |
412 } | |
413 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
414 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
|
415 ButtonPressMask | ButtonReleaseMask | |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
416 KeyPressMask | KeyReleaseMask); |
78 | 417 XFlush(display); |
418 | |
419 *displayp = display; | |
420 *visualp = visual; | |
421 *winp = win; | |
422 | |
423 return OK; | |
424 } | |
425 | |
426 /*! \brief Initialize a MadButterfy runtime for Xlib. | |
427 * | |
428 * It setups a runtime environment to run MadButterfly with Xlib. | |
429 * Users should specify width and height of the opening window. | |
430 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
431 static int X_MB_init(const char *display_name, |
78 | 432 int w, int h, X_MB_runtime_t *xmb_rt) { |
265
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
433 mb_img_ldr_t *img_ldr; |
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
434 |
78 | 435 memset(xmb_rt, 0, sizeof(X_MB_runtime_t)); |
436 | |
437 xmb_rt->w = w; | |
438 xmb_rt->h = h; | |
439 X_init_connection(display_name, w, h, &xmb_rt->display, | |
440 &xmb_rt->visual, &xmb_rt->win); | |
441 | |
442 xmb_rt->surface = | |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
443 mbe_image_surface_create(MB_IFMT_ARGB32, w, h); |
78 | 444 |
445 xmb_rt->backend_surface = | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
446 mbe_xlib_surface_create(xmb_rt->display, |
78 | 447 xmb_rt->win, |
448 xmb_rt->visual, | |
449 w, h); | |
450 | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
451 xmb_rt->cr = mbe_create(xmb_rt->surface); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
452 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface); |
78 | 453 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
454 mbe_set_source_surface(xmb_rt->backend_cr, xmb_rt->surface, 0, 0); |
78 | 455 |
456 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); | |
457 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
|
458 // 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
|
459 // 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
|
460 // 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
|
461 xmb_rt->rdman->rt = xmb_rt; |
270
cd6af7da32c9
Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents:
265
diff
changeset
|
462 xmb_rt->rdman->w = w; |
cd6af7da32c9
Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents:
265
diff
changeset
|
463 xmb_rt->rdman->h = h; |
78 | 464 |
465 xmb_rt->tman = mb_tman_new(); | |
466 | |
346
b391722bf20e
sh_image_t::img_data is managed by paint_image_t.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
467 img_ldr = simple_mb_img_ldr_new(""); |
265
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
468 xmb_rt->img_ldr = img_ldr; |
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
469 rdman_set_img_ldr(xmb_rt->rdman, img_ldr); |
260
29acbd8a0dd0
Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
259
diff
changeset
|
470 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
471 #ifndef ONLY_MOUSE_MOVE_RAW |
83 | 472 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
|
473 #endif |
83 | 474 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
475 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
|
476 |
78 | 477 return OK; |
478 } | |
479 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
480 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) { |
78 | 481 if(xmb_rt->rdman) { |
482 redraw_man_destroy(xmb_rt->rdman); | |
483 free(xmb_rt->rdman); | |
484 } | |
485 | |
486 if(xmb_rt->tman) | |
487 mb_tman_free(xmb_rt->tman); | |
488 | |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
489 if(xmb_rt->img_ldr) |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
490 MB_IMG_LDR_FREE(xmb_rt->img_ldr); |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
491 |
78 | 492 if(xmb_rt->cr) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
493 mbe_destroy(xmb_rt->cr); |
78 | 494 if(xmb_rt->backend_cr) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
495 mbe_destroy(xmb_rt->backend_cr); |
78 | 496 |
497 if(xmb_rt->surface) | |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
498 mbe_surface_destroy(xmb_rt->surface); |
78 | 499 if(xmb_rt->backend_surface) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
500 mbe_surface_destroy(xmb_rt->backend_surface); |
78 | 501 |
502 if(xmb_rt->display) | |
503 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
|
504 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
505 X_kb_destroy(&xmb_rt->kbinfo); |
78 | 506 } |
507 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
508 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
|
509 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
|
510 int r; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
511 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
512 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
|
513 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
|
514 return NULL; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
515 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
516 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
|
517 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
|
518 return NULL; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
519 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
520 return rt; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
521 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
522 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
523 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
|
524 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
|
525 free(rt); |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
526 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
527 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
528 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
|
529 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
|
530 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
531 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
532 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
|
533 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
|
534 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
535 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
536 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
|
537 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
|
538 } |
131
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
539 |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
540 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
|
541 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
|
542 |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
543 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
|
544 return factory; |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
545 } |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
546 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
547 mb_img_ldr_t *X_MB_img_ldr(X_MB_runtime_t *xmb_rt) { |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
548 X_MB_runtime_t *img_ldr; |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
549 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
550 img_ldr = xmb_rt->img_ldr; |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
551 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
552 return img_ldr; |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
553 } |