annotate src/X_supp.c @ 834:9f305d895e8f

Keep width and height of a canvas for mock of canvas
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 17 Sep 2010 12:21:35 +0800
parents 586e50f82c1f
children c18058fb48ee
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
2 // vim: sw=4:ts=8:sts=4
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <stdio.h>
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
4 #include <stdlib.h>
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
5 #include <string.h>
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include <X11/Xlib.h>
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include <X11/Xutil.h>
692
201cc86720a3 Fix compiling time warning about cairo xlib
Thinker K.F. Li <thinker@branda.to>
parents: 691
diff changeset
8 #include <cairo-xlib.h>
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 350
diff changeset
9 #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
10 #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
11 #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
12 #include "mb_X_supp.h"
694
7e64e0f70cb6 Switch XSHM with autoconf
Thinker K.F. Li <thinker@branda.to>
parents: 693
diff changeset
13 #include "config.h"
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
14
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
15 #ifdef XSHM
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
16 /* \sa http://www.xfree86.org/current/mit-shm.html */
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
17 #include <sys/ipc.h>
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
18 #include <sys/shm.h>
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
19 #include <X11/extensions/XShm.h>
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
20 #endif
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
21
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
22 #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
23 #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
24
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
25 #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
26
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
27 /*! \ingroup xkb
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_kb_info {
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
31 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
32 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
33 KeySym *syms;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
34 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
35 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
36 };
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
37
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
38 /* @} */
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
39 #define MAX_MONITORS 200
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
40 typedef struct {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
41 int type;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
42 int fd;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
43 mb_eventcb_t f;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
44 void *arg;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
45 } monitor_t;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
46 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
47 Display *display;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
48 Window win;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
49 Visual *visual;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 350
diff changeset
50 mbe_surface_t *surface, *backend_surface;
471
e98ae1407ca2 Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 462
diff changeset
51 mbe_pattern_t *surface_ptn;
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 350
diff changeset
52 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
53 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
54 mb_tman_t *tman;
259
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
55 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
56 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
57
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
58 X_kb_info_t kbinfo;
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
59 monitor_t monitors[MAX_MONITORS];
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
60 int n_monitor;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
61
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
62 #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
63 /* States */
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
64 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
65 #endif
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
66
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
67 #ifdef XSHM
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
68 XImage *ximage;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
69 XShmSegmentInfo shminfo;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
70 #endif
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
71 };
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
72
693
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
73 #ifdef XSHM
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
74 static void
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
75 XSHM_update(X_MB_runtime_t *xmb_rt) {
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
76 GC gc;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
77
693
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
78 gc = DefaultGC(xmb_rt->display, DefaultScreen(xmb_rt->display));
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
79 if(xmb_rt->ximage) { /* support XSHM */
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
80 XShmPutImage(xmb_rt->display,
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
81 xmb_rt->win,
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
82 gc,
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
83 xmb_rt->ximage,
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
84 0, 0, 0, 0,
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
85 xmb_rt->w, xmb_rt->h, 0);
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
86 }
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
87 }
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
88 #endif
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
89
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
90 /*! \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
91 *
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
92 * 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
93 * 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
94 * 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
95 * @{
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 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
98 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
99 int sym;
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 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
102 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
103 return sym;
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
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
106 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
107 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
108 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
109 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
110 int r;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
111
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
112 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
113 &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
114 &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
115 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
116 return ERR;
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 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
119 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
120 n_syms,
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
121 &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
122 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
123 return ERR;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
124
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
125 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
126 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
127 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
128 return ERR;
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
129 /*! \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
130 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
131
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
132 return OK;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
133 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
134
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
135 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
136 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
137 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
138 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
139
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
140 /*! \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
141 */
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
142 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
143 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
144 int sym;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
145 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
146
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
157 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
158 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
159
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
160 /* @} */
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
162 static unsigned int get_button_state(unsigned int state) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
163 unsigned int but = 0;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
164
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
165 if(state & Button1Mask)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
166 but |= MOUSE_BUT1;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
167 if(state & Button2Mask)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
168 but |= MOUSE_BUT2;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
169 if(state & Button3Mask)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
170 but |= MOUSE_BUT3;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
171
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
172 return but;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
173 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
174
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
175 static unsigned int get_button(unsigned int button) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
176 switch(button) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
177 case Button1:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
178 return MOUSE_BUT1;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
179 case Button2:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
180 return MOUSE_BUT2;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
181 case Button3:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
182 return MOUSE_BUT3;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
183 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
184 return 0;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
185 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
186
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
187 /*! \brief Notify observers of the shape at specified
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
188 * position for mouse event.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
189 *
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
190 * Observers of parent shapes may be called if the subject is not
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
191 * with SUBF_STOP_PROPAGATE flag. The subject of mouse event
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
192 * for a shape is returned by sh_get_mouse_event_subject().
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
193 */
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
194 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
195 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
196 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
197 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
198 unsigned int button) {
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
199 mouse_event_t mouse_event;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
200 subject_t *subject;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
201
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
202 mouse_event.event.type = etype;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
203 mouse_event.x = x;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
204 mouse_event.y = y;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
205 mouse_event.but_state = state;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
206 mouse_event.button = button;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
207
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
208 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
209 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
210 else
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
211 subject = coord_get_mouse_event((coord_t *)obj);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
212
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
213 subject_notify(subject, (event_t *)&mouse_event);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
214 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
215
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
216 /*! \brief Dispatch all X events in the queue.
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217 */
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
218 static void handle_x_event(X_MB_runtime_t *rt) {
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
219 Display *display = rt->display;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
220 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
221 XEvent evt, peek_evt;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
222 XMotionEvent *mevt;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
223 XButtonEvent *bevt;
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
224 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
225 XKeyEvent *xkey;
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
226 co_aix x, y, w, h;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
227
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
228 int eflag = 0;
82
Thinker K.F. Li <thinker@branda.to>
parents: 81
diff changeset
229 int ex1=0, ey1=0, ex2=0, ey2=0;
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
230
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
231 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
232 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
233
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
234 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
235 int in_stroke;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
236 int r;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
237
529
0160cdabaa51 Add a known issue.
Thinker K.F. Li <thinker@branda.to>
parents: 528
diff changeset
238 /* XXX: For some unknown reason, it causes a segmentation fault to
0160cdabaa51 Add a known issue.
Thinker K.F. Li <thinker@branda.to>
parents: 528
diff changeset
239 * called XEventsQueued() after receiving first Expose event
0160cdabaa51 Add a known issue.
Thinker K.F. Li <thinker@branda.to>
parents: 528
diff changeset
240 * and before redraw for the event.
0160cdabaa51 Add a known issue.
Thinker K.F. Li <thinker@branda.to>
parents: 528
diff changeset
241 */
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
242 while(XEventsQueued(display, QueuedAfterReading) > 0) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
243 r = XNextEvent(display, &evt);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
244 if(r == -1)
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
245 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
246
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
247 switch(evt.type) {
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
248 case ButtonPress:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
249 bevt = (XButtonEvent *)&evt;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
250 x = bevt->x;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
251 y = bevt->y;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
252 state = get_button_state(bevt->state);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
253 button = get_button(bevt->button);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
254
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
255 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
256 &in_stroke);
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
257 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
258 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
259 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
260 state, button);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
261 break;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
262
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
263 case ButtonRelease:
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
264 bevt = (XButtonEvent *)&evt;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
265 x = bevt->x;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
266 y = bevt->y;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
267 state = get_button_state(bevt->state);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
268 button = get_button(bevt->button);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
269
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
270 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
271 &in_stroke);
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
272 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
273 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
274 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
275 state, button);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
276 break;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
277
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
278 case MotionNotify:
350
892f4efe2e48 Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents: 346
diff changeset
279 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
280 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
281 if(r == -1)
892f4efe2e48 Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents: 346
diff changeset
282 break;
892f4efe2e48 Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents: 346
diff changeset
283 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
284 break;
892f4efe2e48 Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents: 346
diff changeset
285 XNextEvent(display, &evt);
892f4efe2e48 Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents: 346
diff changeset
286 }
892f4efe2e48 Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents: 346
diff changeset
287 if(r == -1)
892f4efe2e48 Prevent applications from hanging by massive mouse motion events.
Thinker K.F. Li <thinker@branda.to>
parents: 346
diff changeset
288 break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
289
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 mevt = (XMotionEvent *)&evt;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291 x = mevt->x;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292 y = mevt->y;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
293 state = get_button_state(mevt->state);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
295 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
296 &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
297 #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
298 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
299 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
300 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
301 } else {
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
302 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
303 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
304 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
305 }
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
306 #else
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
307 if(shape != NULL) {
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
308 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
309 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
310 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
311 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
312 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
313 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
314 rt->last = shape;
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
315 } else
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
316 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
317 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
318 } else {
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
319 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
320 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
321 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
322 rt->last = NULL;
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
323 }
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
324 }
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
325 #endif
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
326 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
328 case KeyPress:
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
329 case KeyRelease:
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
330 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
331 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
332 break;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
333
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
334 case Expose:
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
335 eevt = &evt.xexpose;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
336 x = eevt->x;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
337 y = eevt->y;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
338 w = eevt->width;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
339 h = eevt->height;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
340
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
341 if(eflag) {
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
342 if(x < ex1)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
343 ex1 = x;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
344 if(y < ey1)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
345 ey1 = y;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
346 if((x + w) > ex2)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
347 ex2 = x + w;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
348 if((y + h) > ey2)
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
349 ey2 = y + h;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
350 } else {
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
351 ex1 = x;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
352 ey1 = y;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
353 ex2 = x + w;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
354 ey2 = y + h;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
355 eflag = 1;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
356 }
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
357 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
358 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
359 }
81
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
360 if(eflag) {
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
361 rdman_redraw_area(rdman, ex1, ey1, (ex2 - ex1), (ey2 - ey1));
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
362 eflag = 0;
13fdf205047b Hide shapes and groups
Thinker K.F. Li <thinker@branda.to>
parents: 78
diff changeset
363 }
693
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
364 #ifdef XSHM
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
365 XSHM_update(rt);
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
366 #endif
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
367 XFlush(display);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
368 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
369
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
370 /*! \brief Handle connection coming data and timeout of timers.
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
371 *
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
372 * \param display is a Display returned by XOpenDisplay().
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
373 * \param rdman is a redraw manager.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
374 * \param tman is a timer manager.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
375 *
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
376 * The display is managed by specified rdman and tman. rdman draws
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
377 * on the display, and tman trigger actions according timers.
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
378 */
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
379 void X_MB_handle_connection(void *be) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
380 X_MB_runtime_t *rt = (X_MB_runtime_t *) be;
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
381 Display *display = rt->display;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
382 redraw_man_t *rdman = rt->rdman;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
383 mb_tman_t *tman = rt->tman;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
384 int fd;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
385 mb_timeval_t now, tmo;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
386 struct timeval tv;
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
387 fd_set rfds,wfds;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
388 int nfds;
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
389 int r, r1,i;
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
390
142
3efe77007127 Do not redraw all at begining, waiting for explosure.
Thinker K.F. Li <thinker@branda.to>
parents: 131
diff changeset
391 handle_x_event(rt);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
392
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
393 fd = XConnectionNumber(display);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
394 nfds = fd + 1;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
395 while(1) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
396 FD_ZERO(&rfds);
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
397 FD_ZERO(&wfds);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
398 FD_SET(fd, &rfds);
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
399 for(i=0;i<rt->n_monitor;i++) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
400 if (rt->monitors[i].type == MONITOR_READ)
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
401 FD_SET(rt->monitors[i].fd, &rfds);
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
402 else if (rt->monitors[i].type == MONITOR_WRITE)
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
403 FD_SET(rt->monitors[i].fd, &wfds);
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
404 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
405
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
406 get_now(&now);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
407 r = mb_tman_next_timeout(tman, &now, &tmo);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
408
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
409 if(r == 0) {
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
410 tv.tv_sec = MB_TIMEVAL_SEC(&tmo);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
411 tv.tv_usec = MB_TIMEVAL_USEC(&tmo);
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
412 r1 = select(nfds, &rfds, NULL, NULL, &tv);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
413 } else
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
414 r1 = select(nfds, &rfds, NULL, NULL, NULL);
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
415
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
416 if(r1 == -1) {
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
417 perror("select");
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
418 break;
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
419 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
420
120
5df7403b6fbc Fix bug of get_now()
Thinker K.F. Li <thinker@branda.to>
parents: 84
diff changeset
421 if(r1 == 0) {
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
422 get_now(&now);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
423 mb_tman_handle_timeout(tman, &now);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
424 rdman_redraw_changed(rdman);
693
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
425 #ifdef XSHM
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
426 XSHM_update(rt);
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
427 #endif
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
428 XFlush(display);
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
429 } else if(FD_ISSET(fd, &rfds)){
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
430 handle_x_event(rt);
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
431 } else {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
432 for(i=0;i<rt->n_monitor;i++) {
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
433 if (rt->monitors[i].type == MONITOR_READ) {
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
434 if (FD_ISSET(rt->monitors[i].fd, &rfds))
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
435 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
436 } else if (rt->monitors[i].type == MONITOR_WRITE) {
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
437 if (FD_ISSET(rt->monitors[i].fd, &wfds))
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
438 rt->monitors[i].f(rt->monitors[i].fd,rt->monitors[i].arg);
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
439 }
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
440 }
77
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
441 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
442 }
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
443 }
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
444
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
445 #define ERR -1
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
446 #define OK 0
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
447
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
448 static int X_init_connection(const char *display_name,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
449 int w, int h,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
450 Display **displayp,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
451 Visual **visualp,
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
452 Window *winp) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
453 Display *display;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
454 Window root, win;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
455 Visual *visual;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
456 int screen;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
457 XSetWindowAttributes wattr;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
458 int depth;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
459 int x, y;
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
460 int draw_root = 0;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
461 const char *disp_name;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
462 char disp_buf[32];
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
463 int cp;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
464 int r;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
465
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
466 /*
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
467 * Support drawing on the root window.
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
468 */
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
469 disp_name = display_name;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
470 if(strstr(display_name, ":root") != NULL) {
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
471 draw_root = 1;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
472 cp = strlen(display_name) - 5;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
473 if(cp >= 32)
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
474 cp = 31;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
475 memcpy(disp_buf, display_name, cp);
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
476 disp_buf[cp] = 0;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
477 disp_name = disp_buf;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
478 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
479
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
480 display = XOpenDisplay(disp_name);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
481 if(display == NULL)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
482 return ERR;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
483
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
484 screen = DefaultScreen(display);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
485 root = DefaultRootWindow(display);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
486 visual = DefaultVisual(display, screen);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
487 depth = DefaultDepth(display, screen);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
488 wattr.override_redirect = False;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
489 x = 10;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
490 y = 10;
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
491 if(draw_root)
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
492 win = RootWindowOfScreen(ScreenOfDisplay(display, screen));
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
493 else {
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
494 win = XCreateWindow(display, root,
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
495 x, y,
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
496 w, h,
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
497 1, depth, InputOutput, visual,
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
498 CWOverrideRedirect, &wattr);
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
499 r = XMapWindow(display, win);
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
500 if(r == -1) {
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
501 XCloseDisplay(display);
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
502 return ERR;
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 755
diff changeset
503 }
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
504 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
505
84
42698de1f653 Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents: 83
diff changeset
506 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
507 ButtonPressMask | ButtonReleaseMask |
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
508 KeyPressMask | KeyReleaseMask);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
509 XFlush(display);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
510
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
511 *displayp = display;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
512 *visualp = visual;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
513 *winp = win;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
514
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
515 return OK;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
516 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
517
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
518 #ifdef XSHM
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
519 static void
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
520 xshm_destroy(X_MB_runtime_t *xmb_rt) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
521 XShmSegmentInfo *shminfo;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
522
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
523 shminfo = &xmb_rt->shminfo;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
524
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
525 if(xmb_rt->shminfo.shmaddr) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
526 XShmDetach(xmb_rt->display, shminfo);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
527 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
528
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
529 if(xmb_rt->ximage) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
530 XDestroyImage(xmb_rt->ximage);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
531 xmb_rt->ximage = NULL;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
532 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
533
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
534 if(shminfo->shmaddr) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
535 shmdt(shminfo->shmaddr);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
536 shminfo->shmaddr = NULL;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
537 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
538
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
539 if(shminfo->shmid) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
540 shmctl(shminfo->shmid, IPC_RMID, 0);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
541 shminfo->shmid = 0;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
542 }
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
543 }
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
544
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
545 static void
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
546 xshm_init(X_MB_runtime_t *xmb_rt) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
547 Display *display;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
548 Visual *visual;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
549 XImage *ximage;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
550 int screen;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
551 int depth;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
552 int support_shm;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
553 int mem_sz;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
554 XShmSegmentInfo *shminfo;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
555 int surf_fmt;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
556
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
557 display = xmb_rt->display;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
558 visual = xmb_rt->visual;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
559 shminfo = &xmb_rt->shminfo;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
560
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
561 support_shm = XShmQueryExtension(display);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
562 if(!support_shm)
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
563 return;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
564
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
565 screen = DefaultScreen(display);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
566 depth = DefaultDepth(display, screen);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
567
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
568 if(depth != 24 && depth != 32)
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
569 return;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
570
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
571 xmb_rt->ximage = XShmCreateImage(display, visual, depth,
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
572 ZPixmap, NULL, shminfo,
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
573 xmb_rt->w, xmb_rt->h);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
574 ximage = xmb_rt->ximage;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
575
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
576 mem_sz = ximage->bytes_per_line * ximage->height;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
577 shminfo->shmid = shmget(IPC_PRIVATE, mem_sz, IPC_CREAT | 0777);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
578 if(shminfo->shmid == -1) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
579 xshm_destroy(xmb_rt);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
580 return;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
581 }
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
582
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
583 shminfo->shmaddr = shmat(shminfo->shmid, 0, 0);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
584 ximage->data = shminfo->shmaddr;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
585
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
586 shminfo->readOnly = 0;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
587
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
588 XShmAttach(display, shminfo);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
589
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
590 switch(depth) {
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
591 case 24: surf_fmt = CAIRO_FORMAT_RGB24; break;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
592 case 32: surf_fmt = CAIRO_FORMAT_ARGB32; break;
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
593 }
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
594
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
595 xmb_rt->backend_surface =
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
596 mbe_image_surface_create_for_data((unsigned char *)ximage->data,
755
82836f1290b6 Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents: 694
diff changeset
597 surf_fmt,
82836f1290b6 Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents: 694
diff changeset
598 xmb_rt->w,
82836f1290b6 Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents: 694
diff changeset
599 xmb_rt->h,
82836f1290b6 Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents: 694
diff changeset
600 ximage->bytes_per_line);
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
601 if(xmb_rt->backend_surface == NULL)
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
602 xshm_destroy(xmb_rt);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
603 }
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
604 #endif /* XSHM */
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
605
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
606 /*! \brief Initialize a MadButterfy runtime for Xlib.
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
607 *
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
608 * This one is very like X_MB_init(), except it accepts a
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
609 * X_MB_runtime_t object initialized with a display connected to a X
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
610 * server and an opened window.
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
611 *
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
612 * Following field of the X_MB_runtime_t object should be initialized.
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
613 * - w, h
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
614 * - win
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
615 * - display
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
616 * - visual
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
617 */
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
618 static int
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
619 X_MB_init_with_win(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
620 mb_img_ldr_t *img_ldr;
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
621 int w, h;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
622
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
623 w = xmb_rt->w;
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
624 h = xmb_rt->h;
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
625
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
626 #ifdef XSHM
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
627 xshm_init(xmb_rt);
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
628 #endif
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
629
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
630 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
631 mbe_image_surface_create(MB_IFMT_ARGB32, w, h);
471
e98ae1407ca2 Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 462
diff changeset
632
e98ae1407ca2 Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 462
diff changeset
633 xmb_rt->surface_ptn =
e98ae1407ca2 Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 462
diff changeset
634 mbe_pattern_create_for_surface(xmb_rt->surface);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
635
693
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
636 if(xmb_rt->backend_surface == NULL) /* xshm_init() may create one */
691
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
637 xmb_rt->backend_surface =
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
638 mbe_xlib_surface_create(xmb_rt->display,
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
639 xmb_rt->win,
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
640 xmb_rt->visual,
05a453e07d01 X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
641 w, h);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
642
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 350
diff changeset
643 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
644 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
645
471
e98ae1407ca2 Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 462
diff changeset
646 mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
647
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
648 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t));
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
649 redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
650 // FIXME: This is a wired loopback reference. This is inly required when we need
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
651 // 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
652 // 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
653 xmb_rt->rdman->rt = xmb_rt;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
654
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
655 xmb_rt->tman = mb_tman_new();
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
656
346
b391722bf20e sh_image_t::img_data is managed by paint_image_t.
Thinker K.F. Li <thinker@branda.to>
parents: 270
diff changeset
657 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
658 xmb_rt->img_ldr = img_ldr;
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
659 rdman_set_img_ldr(xmb_rt->rdman, img_ldr);
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
660 memset(xmb_rt->monitors,0,sizeof(xmb_rt->monitors));
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
661
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
662 #ifndef ONLY_MOUSE_MOVE_RAW
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
663 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
664 #endif
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 82
diff changeset
665
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
666 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
667
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
668 return OK;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
669 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
670
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
671 /*! \brief Initialize a MadButterfy runtime for Xlib.
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
672 *
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
673 * It setups a runtime environment to run MadButterfly with Xlib.
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
674 * Users should specify width and height of the opening window.
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
675 */
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
676 static int X_MB_init(const char *display_name,
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
677 int w, int h, X_MB_runtime_t *xmb_rt) {
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
678 int r;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
679
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
680 memset(xmb_rt, 0, sizeof(X_MB_runtime_t));
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
681
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
682 xmb_rt->w = w;
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
683 xmb_rt->h = h;
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
684 r = X_init_connection(display_name, w, h, &xmb_rt->display,
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
685 &xmb_rt->visual, &xmb_rt->win);
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
686 if(r != OK)
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
687 return ERR;
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
688
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
689 r = X_MB_init_with_win(xmb_rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
690
757
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
691 return r;
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
692 }
f43224bf3524 Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
693
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
694 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) {
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
695 if(xmb_rt->rdman) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
696 redraw_man_destroy(xmb_rt->rdman);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
697 free(xmb_rt->rdman);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
698 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
699
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
700 if(xmb_rt->tman)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
701 mb_tman_free(xmb_rt->tman);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
702
259
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
703 if(xmb_rt->img_ldr)
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
704 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
705
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
706 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
707 mbe_destroy(xmb_rt->cr);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
708 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
709 mbe_destroy(xmb_rt->backend_cr);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
710
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
711 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
712 mbe_surface_destroy(xmb_rt->surface);
471
e98ae1407ca2 Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 462
diff changeset
713 if(xmb_rt->surface_ptn)
e98ae1407ca2 Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 462
diff changeset
714 mbe_pattern_destroy(xmb_rt->surface_ptn);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
715 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
716 mbe_surface_destroy(xmb_rt->backend_surface);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
717
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
718 if(xmb_rt->display)
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
719 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
720
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
721 X_kb_destroy(&xmb_rt->kbinfo);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
722 }
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
723
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
724 void *X_MB_new(const char *display_name, int w, int h) {
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
725 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
726 int r;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
727
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
728 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
729 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
730 return NULL;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
731
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
732 r = X_MB_init(display_name, w, h, rt);
528
d687d3395264 Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents: 471
diff changeset
733 if(r != OK) {
d687d3395264 Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents: 471
diff changeset
734 free(rt);
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
735 return NULL;
528
d687d3395264 Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents: 471
diff changeset
736 }
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
737
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
738 return rt;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
739 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
740
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
741 void X_MB_free(void *rt) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
742 X_MB_destroy((X_MB_runtime_t *) rt);
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
743 free(rt);
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
744 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
745
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
746 subject_t *X_MB_kbevents(void *rt) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
747 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
748 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
749 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
750
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
751 redraw_man_t *X_MB_rdman(void *rt) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
752 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
753 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
754 }
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
755
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
756 mb_tman_t *X_MB_tman(void *rt) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
757 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 120
diff changeset
758 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
759 }
131
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
760
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
761 ob_factory_t *X_MB_ob_factory(void *rt) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
762 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
131
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
763 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
764
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
765 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
766 return factory;
6a8588df68af Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
767 }
259
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
768
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
769 mb_img_ldr_t *X_MB_img_ldr(void *rt) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
770 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
692
201cc86720a3 Fix compiling time warning about cairo xlib
Thinker K.F. Li <thinker@branda.to>
parents: 691
diff changeset
771 mb_img_ldr_t *img_ldr;
259
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
772
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
773 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
774
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
775 return img_ldr;
e8a784a306d0 Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents: 249
diff changeset
776 }
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
777
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
778 void X_MB_add_event(void *rt, int type, int fd, mb_eventcb_t f,void *arg)
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
779 {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
780 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
781 int i;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
782
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
783 for(i=0;i<xmb_rt->n_monitor;i++) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
784 if (xmb_rt->monitors[i].type == type && xmb_rt->monitors[i].fd == fd) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
785 xmb_rt->monitors[i].f = f;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
786 xmb_rt->monitors[i].arg = arg;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
787 return;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
788 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
789 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
790 for(i=0;i<xmb_rt->n_monitor;i++) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
791 if (xmb_rt->monitors[i].type == 0) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
792 xmb_rt->monitors[i].type = type;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
793 xmb_rt->monitors[i].fd = fd;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
794 xmb_rt->monitors[i].f = f;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
795 xmb_rt->monitors[i].arg = arg;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
796 return;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
797 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
798 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
799 if (i == MAX_MONITORS) return;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
800 xmb_rt->monitors[i].type = type;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
801 xmb_rt->monitors[i].fd = fd;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
802 xmb_rt->monitors[i].f = f;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
803 xmb_rt->monitors[i].arg = arg;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
804 i++;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
805 xmb_rt->n_monitor=i;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
806 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
807
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
808 void X_MB_remove_event(void *rt, int type, int fd)
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
809 {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
810 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *) rt;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
811 int i;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
812 for(i=0;i<xmb_rt->n_monitor;i++) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
813 if (xmb_rt->monitors[i].type == type && xmb_rt->monitors[i].fd == fd) {
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
814 xmb_rt->monitors[i].type = 0;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
815 return;
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
816 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
817 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
818 }
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
819 mb_backend_t backend = { X_MB_new,
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
820 X_MB_free,
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
821 X_MB_add_event,
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
822 X_MB_remove_event,
462
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
823 X_MB_handle_connection,
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
824 X_MB_kbevents,
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
825 X_MB_rdman,
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
826 X_MB_tman,
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
827 X_MB_ob_factory,
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
828 X_MB_img_ldr
af4b506ad56f Add backend layer to seperate the backend with the MBAF. Currently, X is the only backend. If we have more than one backend, we need to modify the Makefile to sleect the backend or implement a backend selection mechanism in the runtime.
wycc@122-116-38-188.HINET-IP.hinet.net
parents: 451
diff changeset
829 };
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
830 /*! \defgroup x_supp_nodejs_sup Export functions for supporting nodejs plugin.
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
831 *
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
832 * These functions are for internal using.
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
833 * @{
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 757
diff changeset
834 */
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
835 /*! \brief Exported for nodejs plugin to call handle_x_event.
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
836 */
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 545
diff changeset
837 void _X_MB_handle_x_event_for_nodejs(void *rt) {
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 545
diff changeset
838 handle_x_event((X_MB_runtime_t *)rt);
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
839 }
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
840
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
841 /*! \brief Get X connect for nodejs plugin.
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
842 */
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 545
diff changeset
843 int _X_MB_get_x_conn_for_nodejs(void *rt) {
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 545
diff changeset
844 return XConnectionNumber(((X_MB_runtime_t *)rt)->display);
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
845 }
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
846
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
847 /*! \brief Flush buffer for the X connection of a runtime object.
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
848 */
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 550
diff changeset
849 int _X_MB_flush_x_conn_for_nodejs(void *rt) {
693
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
850 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *)rt;
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
851 #ifdef XSHM
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
852 XSHM_update(xmb_rt);
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
853 #endif
8b7964869f7a Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents: 692
diff changeset
854 return XFlush(xmb_rt->display);
545
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
855 }
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
856
49f8f57f184a Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents: 529
diff changeset
857 /* @} */