Mercurial > MadButterfly
annotate src/X_supp.c @ 364:a373b4743e63
Add file dialog to add a new scene file into the project.
author | wycc |
---|---|
date | Sat, 14 Mar 2009 15:35:51 +0800 |
parents | 892f4efe2e48 |
children | 16116d84bc5e |
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> | |
78 | 6 #include <cairo.h> |
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 | 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; |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
38 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
|
39 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
|
40 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
41 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
|
42 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
43 #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
|
44 /* States */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
45 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
|
46 #endif |
122
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 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
49 /*! \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
|
50 * |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
51 * 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
|
52 * 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
|
53 * 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
|
54 * @{ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
55 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
56 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
|
57 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
|
58 int sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
59 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
60 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
|
61 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
|
62 return sym; |
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 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 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
|
69 int r; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
70 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
71 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
|
72 &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
|
73 &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
|
74 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
|
75 return ERR; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
76 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
77 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
|
78 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
|
79 n_syms, |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
80 &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
|
81 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
|
82 return ERR; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
83 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 return ERR; |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
88 /*! \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
|
89 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
|
90 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
91 return OK; |
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 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
98 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
99 /*! \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
|
100 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
101 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
|
102 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
|
103 int sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
104 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
|
105 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
116 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
|
117 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
118 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
119 /* @} */ |
77 | 120 |
78 | 121 static unsigned int get_button_state(unsigned int state) { |
122 unsigned int but = 0; | |
123 | |
124 if(state & Button1Mask) | |
125 but |= MOUSE_BUT1; | |
126 if(state & Button2Mask) | |
127 but |= MOUSE_BUT2; | |
128 if(state & Button3Mask) | |
129 but |= MOUSE_BUT3; | |
130 | |
131 return but; | |
132 } | |
133 | |
134 static unsigned int get_button(unsigned int button) { | |
135 switch(button) { | |
136 case Button1: | |
137 return MOUSE_BUT1; | |
138 case Button2: | |
139 return MOUSE_BUT2; | |
140 case Button3: | |
141 return MOUSE_BUT3; | |
142 } | |
143 return 0; | |
144 } | |
145 | |
146 /*! \brief Notify observers of the shape at specified | |
147 * position for mouse event. | |
148 * | |
149 * Observers of parent shapes may be called if the subject is not | |
150 * with SUBF_STOP_PROPAGATE flag. The subject of mouse event | |
151 * for a shape is returned by sh_get_mouse_event_subject(). | |
152 */ | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 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
|
157 unsigned int button) { |
78 | 158 mouse_event_t mouse_event; |
159 subject_t *subject; | |
160 | |
161 mouse_event.event.type = etype; | |
162 mouse_event.x = x; | |
163 mouse_event.y = y; | |
164 mouse_event.but_state = state; | |
165 mouse_event.button = button; | |
166 | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
167 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
|
168 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
|
169 else |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
170 subject = coord_get_mouse_event((coord_t *)obj); |
78 | 171 |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
172 subject_notify(subject, (event_t *)&mouse_event); |
78 | 173 } |
174 | |
175 /*! \brief Dispatch all X events in the queue. | |
77 | 176 */ |
83 | 177 static void handle_x_event(X_MB_runtime_t *rt) { |
178 Display *display = rt->display; | |
179 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
|
180 XEvent evt, peek_evt; |
77 | 181 XMotionEvent *mevt; |
78 | 182 XButtonEvent *bevt; |
81 | 183 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
|
184 XKeyEvent *xkey; |
81 | 185 co_aix x, y, w, h; |
186 | |
187 int eflag = 0; | |
82 | 188 int ex1=0, ey1=0, ex2=0, ey2=0; |
81 | 189 |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
190 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
|
191 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
|
192 |
78 | 193 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
|
194 int in_stroke; |
77 | 195 int r; |
196 | |
197 while(XEventsQueued(display, QueuedAfterReading) > 0) { | |
198 r = XNextEvent(display, &evt); | |
199 if(r == -1) | |
200 break; | |
201 | |
202 switch(evt.type) { | |
78 | 203 case ButtonPress: |
204 bevt = (XButtonEvent *)&evt; | |
205 x = bevt->x; | |
206 y = bevt->y; | |
207 state = get_button_state(bevt->state); | |
208 button = get_button(bevt->button); | |
209 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
210 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
|
211 &in_stroke); |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 state, button); |
78 | 216 break; |
217 | |
218 case ButtonRelease: | |
219 bevt = (XButtonEvent *)&evt; | |
220 x = bevt->x; | |
221 y = bevt->y; | |
222 state = get_button_state(bevt->state); | |
223 button = get_button(bevt->button); | |
224 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
225 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
|
226 &in_stroke); |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 state, button); |
78 | 231 break; |
232 | |
77 | 233 case MotionNotify: |
350
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
234 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
|
235 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
|
236 if(r == -1) |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
237 break; |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
238 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
|
239 break; |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
240 XNextEvent(display, &evt); |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
241 } |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
242 if(r == -1) |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
243 break; |
892f4efe2e48
Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents:
346
diff
changeset
|
244 |
77 | 245 mevt = (XMotionEvent *)&evt; |
246 x = mevt->x; | |
247 y = mevt->y; | |
78 | 248 state = get_button_state(mevt->state); |
77 | 249 |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
250 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
|
251 &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
|
252 #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
|
253 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
|
254 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
|
255 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
|
256 } else { |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 } |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
261 #else |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
262 if(shape != NULL) { |
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 != shape) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 rt->last = shape; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
270 } else |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
271 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
|
272 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
|
273 } else { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 rt->last = NULL; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
278 } |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
279 } |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
280 #endif |
77 | 281 break; |
282 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
283 case KeyPress: |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
284 case KeyRelease: |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
285 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
|
286 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
|
287 break; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
288 |
77 | 289 case Expose: |
81 | 290 eevt = &evt.xexpose; |
291 x = eevt->x; | |
292 y = eevt->y; | |
293 w = eevt->width; | |
294 h = eevt->height; | |
295 | |
296 if(eflag) { | |
297 if(x < ex1) | |
298 ex1 = x; | |
299 if(y < ey1) | |
300 ey1 = y; | |
301 if((x + w) > ex2) | |
302 ex2 = x + w; | |
303 if((y + h) > ey2) | |
304 ey2 = y + h; | |
305 } else { | |
306 ex1 = x; | |
307 ey1 = y; | |
308 ex2 = x + w; | |
309 ey2 = y + h; | |
310 eflag = 1; | |
311 } | |
77 | 312 break; |
313 } | |
314 } | |
81 | 315 if(eflag) { |
316 rdman_redraw_area(rdman, ex1, ey1, (ex2 - ex1), (ey2 - ey1)); | |
317 eflag = 0; | |
318 } | |
77 | 319 XFlush(display); |
320 } | |
321 | |
322 /*! \brief Handle connection coming data and timeout of timers. | |
78 | 323 * |
324 * \param display is a Display returned by XOpenDisplay(). | |
325 * \param rdman is a redraw manager. | |
326 * \param tman is a timer manager. | |
327 * | |
328 * The display is managed by specified rdman and tman. rdman draws | |
329 * on the display, and tman trigger actions according timers. | |
77 | 330 */ |
83 | 331 void X_MB_handle_connection(X_MB_runtime_t *rt) { |
332 Display *display = rt->display; | |
333 redraw_man_t *rdman = rt->rdman; | |
334 mb_tman_t *tman = rt->tman; | |
77 | 335 int fd; |
336 mb_timeval_t now, tmo; | |
337 struct timeval tv; | |
338 fd_set rfds; | |
339 int nfds; | |
120 | 340 int r, r1; |
77 | 341 |
142
3efe77007127
Do not redraw all at begining, waiting for explosure.
Thinker K.F. Li <thinker@branda.to>
parents:
131
diff
changeset
|
342 handle_x_event(rt); |
78 | 343 |
77 | 344 fd = XConnectionNumber(display); |
345 nfds = fd + 1; | |
346 while(1) { | |
347 FD_ZERO(&rfds); | |
348 FD_SET(fd, &rfds); | |
349 | |
350 get_now(&now); | |
351 r = mb_tman_next_timeout(tman, &now, &tmo); | |
352 | |
353 if(r == 0) { | |
354 tv.tv_sec = MB_TIMEVAL_SEC(&tmo); | |
355 tv.tv_usec = MB_TIMEVAL_USEC(&tmo); | |
120 | 356 r1 = select(nfds, &rfds, NULL, NULL, &tv); |
77 | 357 } else |
120 | 358 r1 = select(nfds, &rfds, NULL, NULL, NULL); |
77 | 359 |
120 | 360 if(r1 == -1) { |
77 | 361 perror("select"); |
362 break; | |
363 } | |
364 | |
120 | 365 if(r1 == 0) { |
77 | 366 get_now(&now); |
367 mb_tman_handle_timeout(tman, &now); | |
368 rdman_redraw_changed(rdman); | |
369 XFlush(display); | |
370 } else if(FD_ISSET(fd, &rfds)){ | |
83 | 371 handle_x_event(rt); |
77 | 372 } |
373 } | |
374 } | |
78 | 375 |
376 #define ERR -1 | |
377 #define OK 0 | |
378 | |
379 static int X_init_connection(const char *display_name, | |
380 int w, int h, | |
381 Display **displayp, | |
382 Visual **visualp, | |
383 Window *winp) { | |
384 Display *display; | |
385 Window root, win; | |
386 Visual *visual; | |
387 int screen; | |
388 XSetWindowAttributes wattr; | |
389 int depth; | |
390 int x, y; | |
391 int r; | |
392 | |
393 display = XOpenDisplay(display_name); | |
394 if(display == NULL) | |
395 return ERR; | |
396 | |
397 screen = DefaultScreen(display); | |
398 root = DefaultRootWindow(display); | |
399 visual = DefaultVisual(display, screen); | |
400 depth = DefaultDepth(display, screen); | |
401 wattr.override_redirect = False; | |
402 x = 10; | |
403 y = 10; | |
404 win = XCreateWindow(display, root, | |
405 x, y, | |
406 w, h, | |
407 1, depth, InputOutput, visual, | |
408 CWOverrideRedirect, &wattr); | |
409 r = XMapWindow(display, win); | |
410 if(r == -1) { | |
411 XCloseDisplay(display); | |
412 return ERR; | |
413 } | |
414 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
415 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
|
416 ButtonPressMask | ButtonReleaseMask | |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
417 KeyPressMask | KeyReleaseMask); |
78 | 418 XFlush(display); |
419 | |
420 *displayp = display; | |
421 *visualp = visual; | |
422 *winp = win; | |
423 | |
424 return OK; | |
425 } | |
426 | |
427 /*! \brief Initialize a MadButterfy runtime for Xlib. | |
428 * | |
429 * It setups a runtime environment to run MadButterfly with Xlib. | |
430 * Users should specify width and height of the opening window. | |
431 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
432 static int X_MB_init(const char *display_name, |
78 | 433 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
|
434 mb_img_ldr_t *img_ldr; |
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
435 |
78 | 436 memset(xmb_rt, 0, sizeof(X_MB_runtime_t)); |
437 | |
438 xmb_rt->w = w; | |
439 xmb_rt->h = h; | |
440 X_init_connection(display_name, w, h, &xmb_rt->display, | |
441 &xmb_rt->visual, &xmb_rt->win); | |
442 | |
443 xmb_rt->surface = | |
444 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); | |
445 | |
446 xmb_rt->backend_surface = | |
447 cairo_xlib_surface_create(xmb_rt->display, | |
448 xmb_rt->win, | |
449 xmb_rt->visual, | |
450 w, h); | |
451 | |
452 xmb_rt->cr = cairo_create(xmb_rt->surface); | |
453 xmb_rt->backend_cr = cairo_create(xmb_rt->backend_surface); | |
454 | |
455 cairo_set_source_surface(xmb_rt->backend_cr, xmb_rt->surface, 0, 0); | |
456 | |
457 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); | |
458 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
|
459 // 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
|
460 // 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
|
461 // 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
|
462 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
|
463 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
|
464 xmb_rt->rdman->h = h; |
78 | 465 |
466 xmb_rt->tman = mb_tman_new(); | |
467 | |
346
b391722bf20e
sh_image_t::img_data is managed by paint_image_t.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
468 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
|
469 xmb_rt->img_ldr = img_ldr; |
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
470 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
|
471 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
472 #ifndef ONLY_MOUSE_MOVE_RAW |
83 | 473 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
|
474 #endif |
83 | 475 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
476 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
|
477 |
78 | 478 return OK; |
479 } | |
480 | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
481 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) { |
78 | 482 if(xmb_rt->rdman) { |
483 redraw_man_destroy(xmb_rt->rdman); | |
484 free(xmb_rt->rdman); | |
485 } | |
486 | |
487 if(xmb_rt->tman) | |
488 mb_tman_free(xmb_rt->tman); | |
489 | |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
490 if(xmb_rt->img_ldr) |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
491 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
|
492 |
78 | 493 if(xmb_rt->cr) |
494 cairo_destroy(xmb_rt->cr); | |
495 if(xmb_rt->backend_cr) | |
496 cairo_destroy(xmb_rt->backend_cr); | |
497 | |
498 if(xmb_rt->surface) | |
499 cairo_surface_destroy(xmb_rt->surface); | |
500 if(xmb_rt->backend_surface) | |
501 cairo_surface_destroy(xmb_rt->backend_surface); | |
502 | |
503 if(xmb_rt->display) | |
504 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
|
505 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
506 X_kb_destroy(&xmb_rt->kbinfo); |
78 | 507 } |
508 | |
122
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 *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
|
510 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
|
511 int r; |
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 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
|
514 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
|
515 return NULL; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
516 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
517 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
|
518 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
|
519 return NULL; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
520 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
521 return rt; |
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 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
524 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
|
525 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
|
526 free(rt); |
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 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
529 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
|
530 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
|
531 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
532 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
533 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
|
534 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
|
535 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
536 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
537 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
|
538 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
|
539 } |
131
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
540 |
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 *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
|
542 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
|
543 |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
544 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
|
545 return factory; |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
546 } |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
547 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
548 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
|
549 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
|
550 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
551 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
|
552 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
553 return img_ldr; |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
554 } |