Mercurial > MadButterfly
annotate src/X_supp.c @ 986:c39d14139ca5 refine_backend_if
Implement IO manager interface for X
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 00:42:29 +0800 |
parents | 3fe8054457a8 |
children | bf0da8c7d03f |
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 | 3 #include <stdio.h> |
78 | 4 #include <stdlib.h> |
5 #include <string.h> | |
77 | 6 #include <X11/Xlib.h> |
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" |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
13 #include "mb_backend.h" |
694
7e64e0f70cb6
Switch XSHM with autoconf
Thinker K.F. Li <thinker@branda.to>
parents:
693
diff
changeset
|
14 #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
|
15 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
16 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
17 /* \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
|
18 #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
|
19 #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
|
20 #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
|
21 #endif |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
22 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
23 #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
|
24 #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
|
25 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
26 #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
|
27 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
28 /*! \ingroup xkb |
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 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 KeySym *syms; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
35 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
|
36 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
|
37 }; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
38 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
39 /* @} */ |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
40 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
41 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
|
42 Display *display; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
43 Window win; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
44 Visual *visual; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 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
|
49 mb_tman_t *tman; |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
50 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
|
51 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
|
52 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
53 X_kb_info_t kbinfo; |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
54 mb_IO_man_t *io_man; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
55 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
56 #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
|
57 /* States */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
58 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
|
59 #endif |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
60 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
61 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
62 XImage *ximage; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
63 XShmSegmentInfo shminfo; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
64 #endif |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
65 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
66 /* |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
67 * Following variables are used by handle_single_x_event() |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
68 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
69 int last_evt_type; /* Type of last event */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
70 int eflag; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
71 int ex1, ey1, ex2, ey2; /* Aggregate expose events */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
72 int mflag; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
73 int mx, my; /* Position of last motion event */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
74 int mbut_state; /* Button state of last motion event */ |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
75 }; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
76 |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
77 /*! \defgroup x_mb_io IO manager for X. |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
78 * @{ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
79 */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
80 #define MAX_MONITORS 200 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
81 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
82 typedef struct { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
83 int type; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
84 int fd; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
85 mb_IO_cb_t cb; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
86 void *data; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
87 } monitor_t; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
88 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
89 struct _X_MB_IO_man { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
90 mb_IO_man_t io_man; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
91 monitor_t monitors[MAX_MONITORS]; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
92 int n_monitor; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
93 }; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
94 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
95 int _x_mb_io_man_reg(struct _mb_IO_man *io_man, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
96 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
97 void _x_mb_io_man_unreg(struct _mb_IO_Man *io_man, int io_hdl); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
98 mb_IO_man_t *_x_mb_io_man_new(void); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
99 void _x_mb_io_man_free(mb_IO_man_t *io_man); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
100 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
101 static mb_IO_factory_t _X_supp_default_io_factory = { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
102 _x_mb_io_man_new, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
103 _x_mb_io_man_free |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
104 }; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
105 static mb_IO_factory_t *_io_factory = _X_supp_default_io_factory; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
106 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
107 static struct _X_MB_IO_man _default_io_man = { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
108 {_x_mb_io_man_reg, _x_mb_io_man_unreg}, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
109 , /* monitors */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
110 0 /* n_monitor */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
111 }; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
112 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
113 static mb_IO_man_t * |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
114 _x_mb_io_man_new(void) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
115 return (mb_IO_man_t *)&_default_io_man; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
116 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
117 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
118 static void |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
119 _x_mb_io_man_free(mb_IO_man_t *io_man) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
120 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
121 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
122 static int |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
123 _x_mb_io_man_reg(struct _mb_IO_man *io_man, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
124 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
125 struct _x_mb_io_man *xmb_io_man = (struct _x_mb_io_man *)io_man; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
126 int i; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
127 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
128 for(i = 0; i < xmb_io_man->n_monitor; i++) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
129 if (xmb_io_man->monitors[i].type == MB_IO_DUMMY) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
130 break; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
131 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
132 if (i == MAX_MONITORS) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
133 return ERR; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
134 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
135 xmb_io_man->monitors[i].type = type; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
136 xmb_io_man->monitors[i].fd = fd; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
137 xmb_io_man->monitors[i].cb = cb; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
138 xmb_io_man->monitors[i].data = data; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
139 i++; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
140 if(i > xmb_io_man->n_monitor) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
141 xmb_io_man->n_monitor = i; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
142 return i - 1; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
143 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
144 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
145 static void |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
146 _x_mb_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
147 struct _x_mb_io_man *xmb_io_man = (struct _x_mb_io_man *)io_man; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
148 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
149 ASSERT(io_hdl < xmb_io_man->n_monitor); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
150 xmb_io_man->monitors[io_hdl].type = MB_IO_DUMMY; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
151 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
152 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
153 /*! \brief Handle connection coming data and timeout of timers. |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
154 * |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
155 * \param display is a Display returned by XOpenDisplay(). |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
156 * \param rdman is a redraw manager. |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
157 * \param tman is a timer manager. |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
158 * |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
159 * The display is managed by specified rdman and tman. rdman draws |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
160 * on the display, and tman trigger actions according timers. |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
161 */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
162 static void |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
163 _x_mb_handle_connection(struct _mb_IO_man *io_man) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
164 X_MB_runtime_t *rt = (X_MB_runtime_t *) be; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
165 mb_tman_t *tman = rt->tman; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
166 int fd; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
167 mb_timeval_t now, tmo; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
168 struct timeval tv; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
169 fd_set rfds, wfds; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
170 int nfds = 0; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
171 int r, r1,i; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
172 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
173 handle_x_event(rt); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
174 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
175 while(1) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
176 FD_ZERO(&rfds); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
177 FD_ZERO(&wfds); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
178 for(i = 0; i < io_man->n_monitor; i++) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
179 if(io_man->monitors[i].type == MB_IO_R || |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
180 io_man->monitors[i].type == MB_IO_RW) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
181 FD_SET(io_man->monitors[i].fd, &rfds); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
182 if(nfds <= io_man->monitors[i].fd) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
183 nfds = io_man->monitors[i].fd + 1; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
184 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
185 if(io_man->monitors[i].type == MB_IO_W || |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
186 io_man->monitors[i].type == MB_IO_RW) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
187 FD_SET(io_man->monitors[i].fd, &wfds); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
188 if(nfds <= io_man->monitors[i].fd) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
189 nfds = io_man->monitors[i].fd + 1; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
190 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
191 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
192 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
193 get_now(&now); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
194 r = mb_tman_next_timeout(tman, &now, &tmo); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
195 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
196 if(r == 0) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
197 tv.tv_sec = MB_TIMEVAL_SEC(&tmo); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
198 tv.tv_usec = MB_TIMEVAL_USEC(&tmo); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
199 r1 = select(nfds, &rfds, NULL, NULL, &tv); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
200 } else |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
201 r1 = select(nfds, &rfds, NULL, NULL, NULL); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
202 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
203 if(r1 == -1) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
204 perror("select"); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
205 break; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
206 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
207 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
208 if(r1 == 0) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
209 get_now(&now); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
210 mb_tman_handle_timeout(tman, &now); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
211 } else { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
212 for(i = 0; i < io_man->n_monitor; i++) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
213 if(io_man->monitors[i].type == MB_IO_R || |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
214 io_man->monitors[i].type == MB_IO_RW) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
215 if(FD_ISSET(io_man->monitors[i].fd, &rfds)) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
216 ioman->monitors[i].cb(io_man->monitors[i].fd, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
217 MB_IO_R, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
218 rt->monitors[i].data); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
219 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
220 if(io_man->monitors[i].type == MB_IO_W || |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
221 io_man->monitors[i].type == MB_IO_RW) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
222 if(FD_ISSET(io_man->monitors[i].fd, &wfds)) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
223 io_man->monitors[i].cb(io_man->monitors[i].fd, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
224 MB_IO_W, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
225 io_man->monitors[i].data); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
226 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
227 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
228 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
229 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
230 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
231 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
232 /* @} */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
233 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
234 #ifdef XSHM |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
235 static void |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
236 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
|
237 GC gc; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
238 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
239 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
|
240 if(xmb_rt->ximage) { /* support XSHM */ |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
241 XShmPutImage(xmb_rt->display, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
242 xmb_rt->win, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
243 gc, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
244 xmb_rt->ximage, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
245 0, 0, 0, 0, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
246 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
|
247 } |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
248 } |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
249 #endif |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
250 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
251 /*! \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
|
252 * |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
253 * 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
|
254 * 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
|
255 * 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
|
256 * @{ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
257 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
258 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
|
259 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
|
260 int sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
261 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
262 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
|
263 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
|
264 return sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
265 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
266 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 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
|
271 int r; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
272 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
273 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
|
274 &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
|
275 &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
|
276 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
|
277 return ERR; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
278 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
279 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
|
280 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
|
281 n_syms, |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
282 &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
|
283 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
|
284 return ERR; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
285 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 return ERR; |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
290 /*! \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
|
291 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
|
292 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
293 return OK; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
294 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
295 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
300 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
301 /*! \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
|
302 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
303 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
|
304 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
|
305 int sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
306 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
|
307 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
318 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
|
319 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
320 /* @} */ |
77 | 321 |
78 | 322 static unsigned int get_button_state(unsigned int state) { |
323 unsigned int but = 0; | |
324 | |
325 if(state & Button1Mask) | |
326 but |= MOUSE_BUT1; | |
327 if(state & Button2Mask) | |
328 but |= MOUSE_BUT2; | |
329 if(state & Button3Mask) | |
330 but |= MOUSE_BUT3; | |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
331 |
78 | 332 return but; |
333 } | |
334 | |
335 static unsigned int get_button(unsigned int button) { | |
336 switch(button) { | |
337 case Button1: | |
338 return MOUSE_BUT1; | |
339 case Button2: | |
340 return MOUSE_BUT2; | |
341 case Button3: | |
342 return MOUSE_BUT3; | |
343 } | |
344 return 0; | |
345 } | |
346 | |
347 /*! \brief Notify observers of the shape at specified | |
348 * position for mouse event. | |
349 * | |
350 * Observers of parent shapes may be called if the subject is not | |
351 * with SUBF_STOP_PROPAGATE flag. The subject of mouse event | |
352 * for a shape is returned by sh_get_mouse_event_subject(). | |
353 */ | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 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
|
358 unsigned int button) { |
78 | 359 mouse_event_t mouse_event; |
360 subject_t *subject; | |
361 | |
362 mouse_event.event.type = etype; | |
363 mouse_event.x = x; | |
364 mouse_event.y = y; | |
365 mouse_event.but_state = state; | |
366 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
|
367 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
368 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
|
369 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
|
370 else |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
371 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
|
372 |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
373 subject_notify(subject, (event_t *)&mouse_event); |
78 | 374 } |
375 | |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
376 /*! \brief Handle motion event. |
77 | 377 */ |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
378 static void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
379 handle_motion_event(X_MB_runtime_t *rt) { |
83 | 380 redraw_man_t *rdman = rt->rdman; |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
381 int x, y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
382 int state; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
383 shape_t *shape; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
384 coord_t *root; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
385 int in_stroke; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
386 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
387 x = rt->mx; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
388 y = rt->my; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
389 state = rt->mbut_state; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
390 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
391 shape = find_shape_at_pos(rdman, x, y, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
392 &in_stroke); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
393 #ifdef ONLY_MOUSE_MOVE_RAW |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
394 if(shape != NULL) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
395 notify_coord_or_shape(rdman, (mb_obj_t *)shape, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
396 x, y, EVT_MOUSE_MOVE_RAW, state, 0); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
397 } else { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
398 root = rdman_get_root(rdman); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
399 notify_coord_or_shape(rdman, (mb_obj_t *)root, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
400 x, y, EVT_MOUSE_MOVE_RAW, state, 0); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
401 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
402 #else |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
403 if(shape != NULL) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
404 if(rt->last != shape) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
405 if(rt->last) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
406 notify_coord_or_shape(rdman, rt->last, x, y, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
407 EVT_MOUSE_OUT, state, 0); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
408 notify_coord_or_shape(rdman, shape, x, y, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
409 EVT_MOUSE_OVER, state, 0); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
410 rt->last = shape; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
411 } else |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
412 notify_coord_or_shape(rdman, shape, x, y, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
413 EVT_MOUSE_MOVE, state, 0); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
414 } else { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
415 if(rt->last) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
416 notify_coord_or_shape(rdman, rt->last, x, y, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
417 EVT_MOUSE_OUT, state, 0); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
418 rt->last = NULL; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
419 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
420 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
421 #endif |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
422 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
423 rt->mflag = 0; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
424 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
425 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
426 /*! \brief Redraw exposed area. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
427 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
428 static void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
429 handle_expose_event(X_MB_runtime_t *rt) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
430 redraw_man_t *rdman = rt->rdman; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
431 int ex1, ey1, ex2, ey2; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
432 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
433 ex1 = rt->ex1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
434 ey1 = rt->ey1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
435 ex2 = rt->ex2; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
436 ey2 = rt->ey2; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
437 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
438 rdman_redraw_area(rdman, ex1, ey1, (ex2 - ex1), (ey2 - ey1)); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
439 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
440 rt->eflag = 0; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
441 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
442 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
443 /*! \brief Handle single X event and maintain internal states. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
444 * |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
445 * It keeps internal state in rt to improve performance. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
446 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
447 static void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
448 handle_single_x_event(X_MB_runtime_t *rt, XEvent *evt) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
449 redraw_man_t *rdman = rt->rdman; |
77 | 450 XMotionEvent *mevt; |
78 | 451 XButtonEvent *bevt; |
81 | 452 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
|
453 XKeyEvent *xkey; |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
454 int x, y, w, h; |
81 | 455 |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
456 shape_t *shape; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
457 |
78 | 458 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
|
459 int in_stroke; |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
460 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
461 if(evt->type != MotionNotify && rt->mflag) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
462 handle_motion_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
463 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
464 switch(evt->type) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
465 case ButtonPress: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
466 bevt = (XButtonEvent *)evt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
467 x = bevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
468 y = bevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
469 state = get_button_state(bevt->state); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
470 button = get_button(bevt->button); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
471 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
472 shape = find_shape_at_pos(rdman, x, y, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
473 &in_stroke); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
474 if(shape) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
475 notify_coord_or_shape(rdman, (mb_obj_t *)shape, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
476 x, y, EVT_MOUSE_BUT_PRESS, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
477 state, button); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
478 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
479 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
480 case ButtonRelease: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
481 bevt = (XButtonEvent *)evt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
482 x = bevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
483 y = bevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
484 state = get_button_state(bevt->state); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
485 button = get_button(bevt->button); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
486 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
487 shape = find_shape_at_pos(rdman, x, y, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
488 &in_stroke); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
489 if(shape) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
490 notify_coord_or_shape(rdman, (mb_obj_t *)shape, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
491 x, y, EVT_MOUSE_BUT_RELEASE, |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
492 state, button); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
493 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
494 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
495 case MotionNotify: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
496 mevt = (XMotionEvent *)evt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
497 rt->mx = mevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
498 rt->my = mevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
499 rt->mbut_state = get_button_state(mevt->state); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
500 rt->mflag = 1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
501 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
502 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
503 case KeyPress: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
504 case KeyRelease: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
505 xkey = &evt->xkey; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
506 X_kb_handle_event(&rt->kbinfo, xkey); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
507 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
508 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
509 case Expose: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
510 eevt = &evt->xexpose; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
511 x = eevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
512 y = eevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
513 w = eevt->width; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
514 h = eevt->height; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
515 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
516 if(rt->eflag) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
517 if(x < rt->ex1) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
518 rt->ex1 = x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
519 if(y < rt->ey1) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
520 rt->ey1 = y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
521 if((x + w) > rt->ex2) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
522 rt->ex2 = x + w; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
523 if((y + h) > rt->ey2) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
524 rt->ey2 = y + h; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
525 } else { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
526 rt->ex1 = x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
527 rt->ey1 = y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
528 rt->ex2 = x + w; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
529 rt->ey2 = y + h; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
530 rt->eflag = 1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
531 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
532 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
533 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
534 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
535 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
536 /*! \brief Call when no more event in an event iteration. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
537 * |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
538 * No more event means event queue is emplty. This function will |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
539 * perform some actions according current internal state. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
540 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
541 static void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
542 no_more_event(X_MB_runtime_t *rt) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
543 if(rt->mflag) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
544 handle_motion_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
545 if(rt->eflag) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
546 handle_expose_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
547 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
548 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
549 /*! \brief Dispatch all X events in the queue. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
550 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
551 static void handle_x_event(X_MB_runtime_t *rt) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
552 Display *display = rt->display; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
553 XEvent evt; |
77 | 554 int r; |
555 | |
529 | 556 /* XXX: For some unknown reason, it causes a segmentation fault to |
557 * called XEventsQueued() after receiving first Expose event | |
558 * and before redraw for the event. | |
559 */ | |
77 | 560 while(XEventsQueued(display, QueuedAfterReading) > 0) { |
561 r = XNextEvent(display, &evt); | |
562 if(r == -1) | |
563 break; | |
564 | |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
565 handle_single_x_event(rt, &evt); |
77 | 566 } |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
567 no_more_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
568 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
569 #ifdef XSHM |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
570 XSHM_update(rt); |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
571 #endif |
77 | 572 XFlush(display); |
573 } | |
574 | |
575 /*! \brief Handle connection coming data and timeout of timers. | |
78 | 576 * |
577 * \param display is a Display returned by XOpenDisplay(). | |
578 * \param rdman is a redraw manager. | |
579 * \param tman is a timer manager. | |
580 * | |
581 * The display is managed by specified rdman and tman. rdman draws | |
582 * on the display, and tman trigger actions according timers. | |
77 | 583 */ |
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
|
584 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
|
585 X_MB_runtime_t *rt = (X_MB_runtime_t *) be; |
83 | 586 Display *display = rt->display; |
587 redraw_man_t *rdman = rt->rdman; | |
588 mb_tman_t *tman = rt->tman; | |
77 | 589 int fd; |
590 mb_timeval_t now, tmo; | |
591 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
|
592 fd_set rfds,wfds; |
77 | 593 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
|
594 int r, r1,i; |
77 | 595 |
142
3efe77007127
Do not redraw all at begining, waiting for explosure.
Thinker K.F. Li <thinker@branda.to>
parents:
131
diff
changeset
|
596 handle_x_event(rt); |
78 | 597 |
77 | 598 fd = XConnectionNumber(display); |
599 nfds = fd + 1; | |
600 while(1) { | |
601 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
|
602 FD_ZERO(&wfds); |
77 | 603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
610 |
77 | 611 get_now(&now); |
612 r = mb_tman_next_timeout(tman, &now, &tmo); | |
613 | |
614 if(r == 0) { | |
615 tv.tv_sec = MB_TIMEVAL_SEC(&tmo); | |
616 tv.tv_usec = MB_TIMEVAL_USEC(&tmo); | |
120 | 617 r1 = select(nfds, &rfds, NULL, NULL, &tv); |
77 | 618 } else |
120 | 619 r1 = select(nfds, &rfds, NULL, NULL, NULL); |
77 | 620 |
120 | 621 if(r1 == -1) { |
77 | 622 perror("select"); |
623 break; | |
624 } | |
625 | |
120 | 626 if(r1 == 0) { |
77 | 627 get_now(&now); |
628 mb_tman_handle_timeout(tman, &now); | |
629 rdman_redraw_changed(rdman); | |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
630 #ifdef XSHM |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
631 XSHM_update(rt); |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
632 #endif |
77 | 633 XFlush(display); |
634 } else if(FD_ISSET(fd, &rfds)){ | |
83 | 635 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
|
636 } 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 } 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
|
642 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
|
643 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
|
644 } |
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
|
645 } |
77 | 646 } |
647 } | |
648 } | |
78 | 649 |
650 static int X_init_connection(const char *display_name, | |
651 int w, int h, | |
652 Display **displayp, | |
653 Visual **visualp, | |
654 Window *winp) { | |
655 Display *display; | |
656 Window root, win; | |
657 Visual *visual; | |
658 int screen; | |
659 XSetWindowAttributes wattr; | |
660 int depth; | |
661 int x, y; | |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
662 int draw_root = 0; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
663 const char *disp_name; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
664 char disp_buf[32]; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
665 int cp; |
78 | 666 int r; |
667 | |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
668 /* |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
669 * 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
|
670 */ |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
671 disp_name = display_name; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
672 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
|
673 draw_root = 1; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
674 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
|
675 if(cp >= 32) |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
676 cp = 31; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
677 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
|
678 disp_buf[cp] = 0; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
679 disp_name = disp_buf; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
680 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
681 |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
682 display = XOpenDisplay(disp_name); |
78 | 683 if(display == NULL) |
684 return ERR; | |
685 | |
686 screen = DefaultScreen(display); | |
687 root = DefaultRootWindow(display); | |
688 visual = DefaultVisual(display, screen); | |
689 depth = DefaultDepth(display, screen); | |
690 wattr.override_redirect = False; | |
691 x = 10; | |
692 y = 10; | |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
693 if(draw_root) |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
694 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
|
695 else { |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
696 win = XCreateWindow(display, root, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
697 x, y, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
698 w, h, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
699 1, depth, InputOutput, visual, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
700 CWOverrideRedirect, &wattr); |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
701 r = XMapWindow(display, win); |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
702 if(r == -1) { |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
703 XCloseDisplay(display); |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
704 return ERR; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
705 } |
78 | 706 } |
707 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
708 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
|
709 ButtonPressMask | ButtonReleaseMask | |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
710 KeyPressMask | KeyReleaseMask); |
78 | 711 XFlush(display); |
712 | |
713 *displayp = display; | |
714 *visualp = visual; | |
715 *winp = win; | |
716 | |
717 return OK; | |
718 } | |
719 | |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
720 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
721 static void |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
722 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
|
723 XShmSegmentInfo *shminfo; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
724 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
725 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
|
726 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
727 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
|
728 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
|
729 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
730 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
731 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
|
732 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
|
733 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
|
734 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
735 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
736 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
|
737 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
|
738 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
|
739 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
740 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
741 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
|
742 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
|
743 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
|
744 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
745 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
746 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
747 static void |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
748 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
|
749 Display *display; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
750 Visual *visual; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
751 XImage *ximage; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
752 int screen; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
753 int depth; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
754 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
|
755 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
|
756 XShmSegmentInfo *shminfo; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
757 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
|
758 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
759 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
|
760 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
|
761 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
|
762 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
763 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
|
764 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
|
765 return; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
766 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
767 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
|
768 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
|
769 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
770 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
|
771 return; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
772 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
773 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
|
774 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
|
775 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
|
776 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
|
777 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
778 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
|
779 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
|
780 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
|
781 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
|
782 return; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
783 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
784 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
785 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
|
786 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
|
787 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
788 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
|
789 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
790 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
|
791 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
792 switch(depth) { |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
793 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
|
794 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
|
795 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
796 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
797 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
|
798 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
|
799 surf_fmt, |
82836f1290b6
Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents:
694
diff
changeset
|
800 xmb_rt->w, |
82836f1290b6
Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents:
694
diff
changeset
|
801 xmb_rt->h, |
82836f1290b6
Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents:
694
diff
changeset
|
802 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
|
803 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
|
804 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
|
805 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
806 #endif /* XSHM */ |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
807 |
78 | 808 /*! \brief Initialize a MadButterfy runtime for Xlib. |
809 * | |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
810 * 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
|
811 * 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
|
812 * 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
|
813 * |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
814 * 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
|
815 * - 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
|
816 * - win |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
817 * - display |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
818 * - visual |
78 | 819 */ |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
820 static int |
870
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
821 X_MB_init_with_win_internal(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
|
822 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
|
823 int w, h; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
824 |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
825 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
|
826 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
|
827 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
828 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
829 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
|
830 #endif |
78 | 831 |
832 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
|
833 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
|
834 |
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
462
diff
changeset
|
835 xmb_rt->surface_ptn = |
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
462
diff
changeset
|
836 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
|
837 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
838 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
|
839 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
|
840 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
|
841 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
|
842 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
|
843 w, h); |
78 | 844 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
845 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
|
846 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface); |
78 | 847 |
471
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
462
diff
changeset
|
848 mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn); |
78 | 849 |
850 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); | |
851 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
|
852 // 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
|
853 // 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
|
854 // 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
|
855 xmb_rt->rdman->rt = xmb_rt; |
78 | 856 |
857 xmb_rt->tman = mb_tman_new(); | |
858 | |
346
b391722bf20e
sh_image_t::img_data is managed by paint_image_t.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
859 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
|
860 xmb_rt->img_ldr = img_ldr; |
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
861 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
|
862 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
|
863 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
864 #ifndef ONLY_MOUSE_MOVE_RAW |
83 | 865 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
|
866 #endif |
83 | 867 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
868 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
|
869 |
78 | 870 return OK; |
871 } | |
872 | |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
873 /*! \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
|
874 * |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
875 * 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
|
876 * 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
|
877 */ |
870
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
878 static int X_MB_init(X_MB_runtime_t *xmb_rt, const char *display_name, |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
879 int w, int h) { |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
880 int r; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
881 |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
882 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
|
883 |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
884 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
|
885 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
|
886 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
|
887 &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
|
888 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
|
889 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
|
890 |
870
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
891 r = X_MB_init_with_win_internal(xmb_rt); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
892 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
893 return r; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
894 } |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
895 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
896 /*! \brief Initialize a MadButterfly runtime for a window of X. |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
897 * |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
898 * Runtimes initialized with this function should be destroyed with |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
899 * X_MB_destroy_keep_win(). |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
900 */ |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
901 static int |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
902 X_MB_init_with_win(X_MB_runtime_t *xmb_rt, |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
903 Display *display, Window win) { |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
904 XWindowAttributes attrs; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
905 int r; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
906 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
907 r = XGetWindowAttributes(display, win, &attrs); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
908 if(r == 0) |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
909 return ERR; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
910 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
911 memset(xmb_rt, 0, sizeof(X_MB_runtime_t)); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
912 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
913 xmb_rt->display = display; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
914 xmb_rt->win = win; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
915 xmb_rt->visual = attrs.visual; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
916 xmb_rt->w = attrs.width; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
917 xmb_rt->h = attrs.height; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
918 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
919 r = X_MB_init_with_win_internal(xmb_rt); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
920 |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
921 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
|
922 } |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
923 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
924 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) { |
78 | 925 if(xmb_rt->rdman) { |
926 redraw_man_destroy(xmb_rt->rdman); | |
927 free(xmb_rt->rdman); | |
928 } | |
929 | |
930 if(xmb_rt->tman) | |
931 mb_tman_free(xmb_rt->tman); | |
932 | |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
933 if(xmb_rt->img_ldr) |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
934 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
|
935 |
78 | 936 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
|
937 mbe_destroy(xmb_rt->cr); |
78 | 938 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
|
939 mbe_destroy(xmb_rt->backend_cr); |
78 | 940 |
941 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
|
942 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
|
943 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
|
944 mbe_pattern_destroy(xmb_rt->surface_ptn); |
78 | 945 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
|
946 mbe_surface_destroy(xmb_rt->backend_surface); |
78 | 947 |
948 if(xmb_rt->display) | |
949 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
|
950 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
951 X_kb_destroy(&xmb_rt->kbinfo); |
78 | 952 } |
953 | |
870
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
954 /*! \brief Destroy a MadButterfly runtime initialized with |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
955 * X_MB_init_with_win(). |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
956 * |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
957 * Destroying a runtime with this function prevent the window and |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
958 * display associated with the runtime being closed. |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
959 */ |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
960 static void |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
961 X_MB_destroy_keep_win(X_MB_runtime_t *xmb_rt) { |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
962 Display *display; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
963 Window win; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
964 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
965 display = xmb_rt->display; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
966 xmb_rt->display = NULL; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
967 win = xmb_rt->win; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
968 xmb_rt->win = 0; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
969 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
970 X_MB_destroy(xmb_rt); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
971 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
972 xmb_rt->display = display; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
973 xmb_rt->win = win; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
974 } |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
975 |
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
|
976 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
|
977 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
|
978 int r; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
979 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
980 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
|
981 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
|
982 return NULL; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
983 |
870
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
984 r = X_MB_init(rt, display_name, w, h); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
985 if(r != OK) { |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
986 free(rt); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
987 return NULL; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
988 } |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
989 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
990 return rt; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
991 } |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
992 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
993 /*! \brief Create a new runtime for existed window for X. |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
994 * |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
995 * The object returned by this function must be free with |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
996 * X_MB_free_keep_win() to prevent the window from closed. |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
997 */ |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
998 void *X_MB_new_with_win(Display *display, Window win) { |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
999 X_MB_runtime_t *rt; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1000 int r; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1001 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1002 rt = O_ALLOC(X_MB_runtime_t); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1003 if(rt == NULL) |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1004 return NULL; |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1005 |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1006 r = X_MB_init_with_win(rt, display, win); |
528
d687d3395264
Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents:
471
diff
changeset
|
1007 if(r != OK) { |
d687d3395264
Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents:
471
diff
changeset
|
1008 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
|
1009 return NULL; |
528
d687d3395264
Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents:
471
diff
changeset
|
1010 } |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1011 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1012 return rt; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1013 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1014 |
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
|
1015 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
|
1016 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
|
1017 free(rt); |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1018 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1019 |
870
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1020 /*! \brief Free runtime created with X_MB_new_with_win(). |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1021 */ |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1022 void |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1023 X_MB_free_keep_win(void *rt) { |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1024 X_MB_destroy_keep_win((X_MB_runtime_t *) rt); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1025 free(rt); |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1026 } |
512204bcafba
Export the function to create a runtime for an existed window for X.
Thinker K.F. Li <thinker@codemud.net>
parents:
869
diff
changeset
|
1027 |
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
|
1028 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
|
1029 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
|
1030 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
|
1031 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1032 |
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
|
1033 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
|
1034 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
|
1035 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
|
1036 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1037 |
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
|
1038 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
|
1039 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
|
1040 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
|
1041 } |
131
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
1042 |
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
|
1043 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
|
1044 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
|
1045 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
|
1046 |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
1047 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
|
1048 return factory; |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
1049 } |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1050 |
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
|
1051 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
|
1052 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
|
1053 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
|
1054 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1055 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
|
1056 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1057 return img_ldr; |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1058 } |
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
|
1059 |
545
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1060 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
|
1061 { |
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
|
1062 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
|
1063 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
|
1064 |
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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 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
|
1070 } |
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
|
1071 } |
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
|
1072 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
|
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 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
|
1079 } |
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
|
1080 } |
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
|
1081 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
|
1082 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
|
1083 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
|
1084 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
|
1085 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
|
1086 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
|
1087 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
|
1088 } |
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
|
1089 |
545
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1090 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
|
1091 { |
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
|
1092 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
|
1093 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
|
1094 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
|
1095 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
|
1096 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
|
1097 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
|
1098 } |
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
|
1099 } |
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
|
1100 } |
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
|
1101 mb_backend_t backend = { X_MB_new, |
984
3fe8054457a8
Change interface of mb_backend_t for more concise
Thinker K.F. Li <thinker@codemud.net>
parents:
870
diff
changeset
|
1102 X_MB_new_with_window, |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
1103 |
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
|
1104 X_MB_free, |
545
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1105 X_MB_add_event, |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1106 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
|
1107 X_MB_handle_connection, |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
1108 |
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
|
1109 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
|
1110 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
|
1111 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
|
1112 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
|
1113 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
|
1114 }; |
545
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1115 /*! \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
|
1116 * |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1117 * These functions are for internal using. |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1118 * @{ |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
1119 */ |
545
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1120 /*! \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
|
1121 */ |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
545
diff
changeset
|
1122 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
|
1123 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
|
1124 } |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1125 |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1126 /*! \brief Get X connect for nodejs plugin. |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1127 */ |
550
127499ab2412
Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents:
545
diff
changeset
|
1128 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
|
1129 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
|
1130 } |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1131 |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1132 /*! \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
|
1133 */ |
556
c9d23f7279a4
The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents:
550
diff
changeset
|
1134 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
|
1135 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
|
1136 #ifdef XSHM |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
1137 XSHM_update(xmb_rt); |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
1138 #endif |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
1139 return XFlush(xmb_rt->display); |
545
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1140 } |
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1141 |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1142 /*! \brief Handle single X event. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1143 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1144 void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1145 _X_MB_handle_single_event(void *rt, void *evt) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1146 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *)rt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1147 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1148 handle_single_x_event(xmb_rt, (XEvent *)evt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1149 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1150 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1151 /*! \brief Called at end of an iteration of X event loop. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1152 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1153 void |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1154 _X_MB_no_more_event(void *rt) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1155 X_MB_runtime_t *xmb_rt = (X_MB_runtime_t *)rt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1156 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1157 no_more_event(xmb_rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1158 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1159 |
545
49f8f57f184a
Preparing for nodejs plugin
Thinker K.F. Li <thinker@branda.to>
parents:
529
diff
changeset
|
1160 /* @} */ |