Mercurial > MadButterfly
annotate src/X_supp.c @ 1067:7b4e80ab671a openvg
merge from default branch
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 01 Dec 2010 12:25:56 +0800 |
parents | bd18951b51d5 e415c55b4a0d |
children | d09f603438d8 |
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" |
1018
7ccc094bdbe5
Move the timer manager based on mb_tman_t to timer.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1016
diff
changeset
|
14 #include "mb_backend_utils.h" |
694
7e64e0f70cb6
Switch XSHM with autoconf
Thinker K.F. Li <thinker@branda.to>
parents:
693
diff
changeset
|
15 #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
|
16 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
17 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
18 /* \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
|
19 #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
|
20 #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
|
21 #include <X11/extensions/XShm.h> |
1049 | 22 static void XSHM_update(X_supp_runtime_t *xmb_rt); |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
23 #endif |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
24 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
25 #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
|
26 #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
|
27 |
1015
c4a567112d29
Mark out functions supprting nodejs in X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1014
diff
changeset
|
28 #define ASSERT(x) |
c4a567112d29
Mark out functions supprting nodejs in X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1014
diff
changeset
|
29 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
30 #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
|
31 |
1018
7ccc094bdbe5
Move the timer manager based on mb_tman_t to timer.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1016
diff
changeset
|
32 static mb_timer_factory_t *_timer_factory = &tman_timer_factory; |
7ccc094bdbe5
Move the timer manager based on mb_tman_t to timer.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1016
diff
changeset
|
33 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
34 /*! \ingroup xkb |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
35 * @{ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
36 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 KeySym *syms; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
41 subject_t *kbevents; |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
42 observer_factory_t *observer_factory; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
43 }; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
44 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
45 /* @} */ |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
46 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
47 struct _X_supp_runtime { |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
48 Display *display; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
49 Window win; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
50 Visual *visual; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 redraw_man_t *rdman; |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
55 mb_img_ldr_t *img_ldr; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
56 int w, h; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
57 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
58 X_kb_info_t kbinfo; |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
59 mb_IO_man_t *io_man; |
1003
4b1bef7e5516
Change _X_MB_runtime and fix _x_mb_event_loop()
Thinker K.F. Li <thinker@codemud.net>
parents:
1002
diff
changeset
|
60 mb_timer_man_t *timer_man; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
61 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
62 #ifndef ONLY_MOUSE_MOVE_RAW |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
63 /* States */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
64 shape_t *last; |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
65 #endif |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
66 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
67 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
68 XImage *ximage; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
69 XShmSegmentInfo shminfo; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
70 #endif |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
71 |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
72 /* For handle connection */ |
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
73 int io_hdl; |
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
74 |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
75 /* |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
76 * 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
|
77 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
78 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
|
79 int eflag; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
80 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
|
81 int mflag; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
82 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
|
83 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
|
84 }; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
85 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
86 static void _x_supp_handle_x_event(X_supp_runtime_t *rt); |
1005
714169f33f13
Fix X_init_connection() to match modification of mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1004
diff
changeset
|
87 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
88 /*! \defgroup x_supp_io IO manager for X. |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
89 * @{ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
90 */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
91 #define MAX_MONITORS 200 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
92 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
93 typedef struct { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
94 int type; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
95 int fd; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
96 mb_IO_cb_t cb; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
97 void *data; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
98 } monitor_t; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
99 |
988
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
100 struct _X_supp_IO_man { |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
101 mb_IO_man_t io_man; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
102 monitor_t monitors[MAX_MONITORS]; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
103 int n_monitor; |
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 |
1000
c92aabb054e2
Declare functions correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
999
diff
changeset
|
106 static int _x_supp_io_man_reg(struct _mb_IO_man *io_man, |
c92aabb054e2
Declare functions correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
999
diff
changeset
|
107 int fd, MB_IO_TYPE type, |
c92aabb054e2
Declare functions correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
999
diff
changeset
|
108 mb_IO_cb_t cb, void *data); |
1001
b462b9e213e8
Fix typo for the name of _mb_IO_man
Thinker K.F. Li <thinker@codemud.net>
parents:
1000
diff
changeset
|
109 static void _x_supp_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl); |
1000
c92aabb054e2
Declare functions correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
999
diff
changeset
|
110 static mb_IO_man_t *_x_supp_io_man_new(void); |
c92aabb054e2
Declare functions correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
999
diff
changeset
|
111 static void _x_supp_io_man_free(mb_IO_man_t *io_man); |
986
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_factory_t _X_supp_default_io_factory = { |
988
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
114 _x_supp_io_man_new, |
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
115 _x_supp_io_man_free |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
116 }; |
999
d975a59d4504
Fix typo on variable reference
Thinker K.F. Li <thinker@codemud.net>
parents:
998
diff
changeset
|
117 static mb_IO_factory_t *_io_factory = &_X_supp_default_io_factory; |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
118 |
988
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
119 static struct _X_supp_IO_man _default_io_man = { |
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
120 {_x_supp_io_man_reg, _x_supp_io_man_unreg}, |
987
bf0da8c7d03f
Add default timer factory for X support
Thinker K.F. Li <thinker@codemud.net>
parents:
986
diff
changeset
|
121 {}, /* monitors */ |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
122 0 /* n_monitor */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
123 }; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
124 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
125 static mb_IO_man_t * |
988
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
126 _x_supp_io_man_new(void) { |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
127 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
|
128 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
129 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
130 static void |
988
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
131 _x_supp_io_man_free(mb_IO_man_t *io_man) { |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
132 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
133 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
134 static int |
988
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
135 _x_supp_io_man_reg(struct _mb_IO_man *io_man, |
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
136 int fd, MB_IO_TYPE type, mb_IO_cb_t cb, void *data) { |
1002
aa0583e0a96b
Fix typo for the naem of struct _X_supp_IO_man
Thinker K.F. Li <thinker@codemud.net>
parents:
1001
diff
changeset
|
137 struct _X_supp_IO_man *xmb_io_man = (struct _X_supp_IO_man *)io_man; |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
138 int i; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
139 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
140 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
|
141 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
|
142 break; |
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 if (i == MAX_MONITORS) |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
145 return ERR; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
146 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 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
|
151 i++; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
152 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
|
153 xmb_io_man->n_monitor = i; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
154 return i - 1; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
155 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
156 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
157 static void |
988
bc8cfcd40d0e
Rename _x_mb_io_man* to _x_supp_io_man*
Thinker K.F. Li <thinker@codemud.net>
parents:
987
diff
changeset
|
158 _x_supp_io_man_unreg(struct _mb_IO_man *io_man, int io_hdl) { |
1002
aa0583e0a96b
Fix typo for the naem of struct _X_supp_IO_man
Thinker K.F. Li <thinker@codemud.net>
parents:
1001
diff
changeset
|
159 struct _X_supp_IO_man *xmb_io_man = (struct _X_supp_IO_man *)io_man; |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
160 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
161 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
|
162 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
|
163 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
164 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
165 /*! \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
|
166 * |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
167 * \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
|
168 * \param rdman is a redraw manager. |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
169 * \param tman is a timer manager. |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
170 * |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
171 * 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
|
172 * 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
|
173 */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
174 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
175 _x_supp_event_loop(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
176 struct _X_supp_runtime *xmb_rt = (struct _X_supp_runtime *)rt; |
1006
3ee2e30b260f
Rename xmbrt to xmb_rt
Thinker K.F. Li <thinker@codemud.net>
parents:
1005
diff
changeset
|
177 struct _X_supp_IO_man *io_man = (struct _X_supp_IO_man *)xmb_rt->io_man; |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
178 mb_timer_man_t *timer_man = (mb_timer_man_t *)xmb_rt->timer_man; |
1026
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
179 redraw_man_t *rdman; |
1018
7ccc094bdbe5
Move the timer manager based on mb_tman_t to timer.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1016
diff
changeset
|
180 mb_tman_t *tman = tman_timer_man_get_tman(timer_man); |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
181 mb_timeval_t now, tmo; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
182 struct timeval tv; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
183 fd_set rfds, wfds; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
184 int nfds = 0; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
185 int r, r1,i; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
186 |
1026
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
187 rdman = mb_runtime_rdman(rt); |
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
188 |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
189 _x_supp_handle_x_event(xmb_rt); |
986
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 while(1) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
192 FD_ZERO(&rfds); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
193 FD_ZERO(&wfds); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 FD_SET(io_man->monitors[i].fd, &rfds); |
1004 | 198 nfds = MB_MAX(nfds, io_man->monitors[i].fd + 1); |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
199 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
200 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
|
201 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
|
202 FD_SET(io_man->monitors[i].fd, &wfds); |
1004 | 203 nfds = MB_MAX(nfds, io_man->monitors[i].fd + 1); |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
204 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
205 } |
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 get_now(&now); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
208 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
|
209 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
210 if(r == 0) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 } else |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
215 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
|
216 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
217 if(r1 == -1) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
218 perror("select"); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
219 break; |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
220 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
221 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
222 if(r1 == 0) { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
223 get_now(&now); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
224 mb_tman_handle_timeout(tman, &now); |
1026
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
225 rdman_redraw_changed(rdman); |
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
226 #ifdef XSHM |
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
227 XSHM_update(xmb_rt); |
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
228 #endif |
407932b8a160
Redraw changed after handling timeout for X_supp.c
Thinker K.F. Li <thinker@codemud.net>
parents:
1022
diff
changeset
|
229 XFlush(xmb_rt->display); |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
230 } else { |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 if(FD_ISSET(io_man->monitors[i].fd, &rfds)) |
1003
4b1bef7e5516
Change _X_MB_runtime and fix _x_mb_event_loop()
Thinker K.F. Li <thinker@codemud.net>
parents:
1002
diff
changeset
|
235 io_man->monitors[i].cb(i, io_man->monitors[i].fd, |
4b1bef7e5516
Change _X_MB_runtime and fix _x_mb_event_loop()
Thinker K.F. Li <thinker@codemud.net>
parents:
1002
diff
changeset
|
236 MB_IO_R, |
4b1bef7e5516
Change _X_MB_runtime and fix _x_mb_event_loop()
Thinker K.F. Li <thinker@codemud.net>
parents:
1002
diff
changeset
|
237 io_man->monitors[i].data); |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
238 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
239 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
|
240 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
|
241 if(FD_ISSET(io_man->monitors[i].fd, &wfds)) |
990
8dd42310dd79
Change signature of callback for IO and timer manager
Thinker K.F. Li <thinker@codemud.net>
parents:
989
diff
changeset
|
242 io_man->monitors[i].cb(i, io_man->monitors[i].fd, |
986
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
243 MB_IO_W, |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
244 io_man->monitors[i].data); |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
245 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
246 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
247 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
248 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
249 } |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
250 |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
251 /* @} */ |
c39d14139ca5
Implement IO manager interface for X
Thinker K.F. Li <thinker@codemud.net>
parents:
984
diff
changeset
|
252 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
253 #ifdef XSHM |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
254 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
255 XSHM_update(X_supp_runtime_t *xmb_rt) { |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
256 GC gc; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
257 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
258 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
|
259 if(xmb_rt->ximage) { /* support XSHM */ |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
260 XShmPutImage(xmb_rt->display, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
261 xmb_rt->win, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
262 gc, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
263 xmb_rt->ximage, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
264 0, 0, 0, 0, |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
265 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
|
266 } |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
267 } |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
268 #endif |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
269 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
270 /*! \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
|
271 * |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
272 * 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
|
273 * 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
|
274 * 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
|
275 * @{ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
276 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
277 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
|
278 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
|
279 int sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
280 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
281 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
|
282 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
|
283 return sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
284 } |
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 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
|
287 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
|
288 int n_syms; |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
289 observer_factory_t *factory; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
290 int r; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
291 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
292 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
|
293 &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
|
294 &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
|
295 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
|
296 return ERR; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
297 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
298 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
|
299 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
|
300 n_syms, |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
301 &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
|
302 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
|
303 return ERR; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
304 |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
305 factory = rdman_get_observer_factory(rdman); |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
306 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
|
307 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
|
308 return ERR; |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
309 /*! \todo Make sure observer_factory is still need. */ |
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
310 kbinfo->observer_factory = factory; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
311 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
312 return OK; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
313 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
314 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
319 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
320 /*! \brief Accept X keyboard events from _x_supp_handle_x_event() and |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
321 * dispatch it. |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
322 */ |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
323 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
|
324 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
|
325 int sym; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
326 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
|
327 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
338 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
|
339 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
340 /* @} */ |
77 | 341 |
78 | 342 static unsigned int get_button_state(unsigned int state) { |
343 unsigned int but = 0; | |
344 | |
345 if(state & Button1Mask) | |
346 but |= MOUSE_BUT1; | |
347 if(state & Button2Mask) | |
348 but |= MOUSE_BUT2; | |
349 if(state & Button3Mask) | |
350 but |= MOUSE_BUT3; | |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
351 |
78 | 352 return but; |
353 } | |
354 | |
355 static unsigned int get_button(unsigned int button) { | |
356 switch(button) { | |
357 case Button1: | |
358 return MOUSE_BUT1; | |
359 case Button2: | |
360 return MOUSE_BUT2; | |
361 case Button3: | |
362 return MOUSE_BUT3; | |
363 } | |
364 return 0; | |
365 } | |
366 | |
367 /*! \brief Notify observers of the shape at specified | |
368 * position for mouse event. | |
369 * | |
370 * Observers of parent shapes may be called if the subject is not | |
371 * with SUBF_STOP_PROPAGATE flag. The subject of mouse event | |
372 * for a shape is returned by sh_get_mouse_event_subject(). | |
373 */ | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
374 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
|
375 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
|
376 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
|
377 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
|
378 unsigned int button) { |
78 | 379 mouse_event_t mouse_event; |
380 subject_t *subject; | |
381 | |
382 mouse_event.event.type = etype; | |
383 mouse_event.x = x; | |
384 mouse_event.y = y; | |
385 mouse_event.but_state = state; | |
386 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
|
387 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
388 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
|
389 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
|
390 else |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
391 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
|
392 |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
393 subject_notify(subject, (event_t *)&mouse_event); |
78 | 394 } |
395 | |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
396 /*! \brief Handle motion event. |
77 | 397 */ |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
398 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
399 handle_motion_event(X_supp_runtime_t *rt) { |
83 | 400 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
|
401 int x, y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
402 int state; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
403 shape_t *shape; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
404 coord_t *root; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
405 int in_stroke; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
406 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
407 x = rt->mx; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
408 y = rt->my; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
409 state = rt->mbut_state; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
410 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
411 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
|
412 &in_stroke); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
413 #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
|
414 if(shape != NULL) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
415 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
|
416 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
|
417 } else { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
422 #else |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
423 if(shape != NULL) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
424 if(rt->last != shape) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
425 if(rt->last) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
426 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
|
427 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
|
428 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
|
429 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
|
430 rt->last = shape; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
431 } else |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
432 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
|
433 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
|
434 } else { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
435 if(rt->last) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
436 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
|
437 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
|
438 rt->last = NULL; |
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 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
441 #endif |
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 rt->mflag = 0; |
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 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
446 /*! \brief Redraw exposed area. |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
447 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
448 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
449 handle_expose_event(X_supp_runtime_t *rt) { |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
450 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
|
451 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
|
452 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
453 ex1 = rt->ex1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
454 ey1 = rt->ey1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
455 ex2 = rt->ex2; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
456 ey2 = rt->ey2; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
457 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
458 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
|
459 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
460 rt->eflag = 0; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
461 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
462 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
463 /*! \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
|
464 * |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
465 * 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
|
466 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
467 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
468 handle_single_x_event(X_supp_runtime_t *rt, XEvent *evt) { |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
469 redraw_man_t *rdman = rt->rdman; |
77 | 470 XMotionEvent *mevt; |
78 | 471 XButtonEvent *bevt; |
81 | 472 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
|
473 XKeyEvent *xkey; |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
474 int x, y, w, h; |
81 | 475 |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
476 shape_t *shape; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
477 |
78 | 478 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
|
479 int in_stroke; |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
480 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
481 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
|
482 handle_motion_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
483 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
484 switch(evt->type) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
485 case ButtonPress: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
486 bevt = (XButtonEvent *)evt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
487 x = bevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
488 y = bevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
489 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
|
490 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
|
491 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
492 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
|
493 &in_stroke); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
494 if(shape) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
495 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
|
496 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
|
497 state, button); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
498 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
499 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
500 case ButtonRelease: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
501 bevt = (XButtonEvent *)evt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
502 x = bevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
503 y = bevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
504 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
|
505 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
|
506 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
507 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
|
508 &in_stroke); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
509 if(shape) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
510 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
|
511 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
|
512 state, button); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
513 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
514 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
515 case MotionNotify: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
516 mevt = (XMotionEvent *)evt; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
517 rt->mx = mevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
518 rt->my = mevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
519 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
|
520 rt->mflag = 1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
521 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
522 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
523 case KeyPress: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
524 case KeyRelease: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
525 xkey = &evt->xkey; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
526 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
|
527 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
528 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
529 case Expose: |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
530 eevt = &evt->xexpose; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
531 x = eevt->x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
532 y = eevt->y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
533 w = eevt->width; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
534 h = eevt->height; |
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 if(rt->eflag) { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
537 if(x < rt->ex1) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
538 rt->ex1 = x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
539 if(y < rt->ey1) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
540 rt->ey1 = y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
541 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
|
542 rt->ex2 = x + w; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
543 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
|
544 rt->ey2 = y + h; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
545 } else { |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
546 rt->ex1 = x; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
547 rt->ey1 = y; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
548 rt->ex2 = x + w; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
549 rt->ey2 = y + h; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
550 rt->eflag = 1; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
551 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
552 break; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
553 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
554 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
555 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
556 /*! \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
|
557 * |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
558 * 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
|
559 * 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
|
560 */ |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
561 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
562 no_more_event(X_supp_runtime_t *rt) { |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
563 if(rt->mflag) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
564 handle_motion_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
565 if(rt->eflag) |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
566 handle_expose_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
567 } |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
568 |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
569 /*! \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
|
570 */ |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
571 static void _x_supp_handle_x_event(X_supp_runtime_t *rt) { |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
572 Display *display = rt->display; |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
573 XEvent evt; |
77 | 574 int r; |
575 | |
529 | 576 /* XXX: For some unknown reason, it causes a segmentation fault to |
577 * called XEventsQueued() after receiving first Expose event | |
578 * and before redraw for the event. | |
579 */ | |
77 | 580 while(XEventsQueued(display, QueuedAfterReading) > 0) { |
581 r = XNextEvent(display, &evt); | |
582 if(r == -1) | |
583 break; | |
584 | |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
585 handle_single_x_event(rt, &evt); |
77 | 586 } |
869
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
587 no_more_event(rt); |
c18058fb48ee
Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
588 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
589 #ifdef XSHM |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
590 XSHM_update(rt); |
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
591 #endif |
77 | 592 XFlush(display); |
593 } | |
594 | |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
595 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
596 _x_supp_handle_connection(int hdl, int fd, MB_IO_TYPE type, void *data) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
597 X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *)data; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
598 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
599 _x_supp_handle_x_event(xmb_rt); |
77 | 600 } |
78 | 601 |
602 static int X_init_connection(const char *display_name, | |
603 int w, int h, | |
604 Display **displayp, | |
605 Visual **visualp, | |
606 Window *winp) { | |
607 Display *display; | |
608 Window root, win; | |
609 Visual *visual; | |
610 int screen; | |
611 XSetWindowAttributes wattr; | |
612 int depth; | |
613 int x, y; | |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
614 int draw_root = 0; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
615 const char *disp_name; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
616 char disp_buf[32]; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
617 int cp; |
78 | 618 int r; |
619 | |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
620 /* |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
621 * 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
|
622 */ |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
623 disp_name = display_name; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
624 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
|
625 draw_root = 1; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
626 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
|
627 if(cp >= 32) |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
628 cp = 31; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
629 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
|
630 disp_buf[cp] = 0; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
631 disp_name = disp_buf; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
632 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
633 |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
634 display = XOpenDisplay(disp_name); |
78 | 635 if(display == NULL) |
636 return ERR; | |
637 | |
638 screen = DefaultScreen(display); | |
639 root = DefaultRootWindow(display); | |
640 visual = DefaultVisual(display, screen); | |
641 depth = DefaultDepth(display, screen); | |
642 wattr.override_redirect = False; | |
643 x = 10; | |
644 y = 10; | |
756
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
645 if(draw_root) |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
646 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
|
647 else { |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
648 win = XCreateWindow(display, root, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
649 x, y, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
650 w, h, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
651 1, depth, InputOutput, visual, |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
652 CWOverrideRedirect, &wattr); |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
653 r = XMapWindow(display, win); |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
654 if(r == -1) { |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
655 XCloseDisplay(display); |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
656 return ERR; |
cceac4ba259e
Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents:
755
diff
changeset
|
657 } |
78 | 658 } |
659 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
660 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
|
661 ButtonPressMask | ButtonReleaseMask | |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
662 KeyPressMask | KeyReleaseMask); |
78 | 663 XFlush(display); |
664 | |
665 *displayp = display; | |
666 *visualp = visual; | |
667 *winp = win; | |
668 | |
669 return OK; | |
670 } | |
671 | |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
672 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
673 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
674 xshm_destroy(X_supp_runtime_t *xmb_rt) { |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
675 XShmSegmentInfo *shminfo; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
676 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
677 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
|
678 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
679 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
|
680 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
|
681 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
682 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
683 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
|
684 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
|
685 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
|
686 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
687 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
688 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
|
689 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
|
690 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
|
691 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
692 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
693 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
|
694 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
|
695 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
|
696 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
697 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
698 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
699 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
700 xshm_init(X_supp_runtime_t *xmb_rt) { |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
701 Display *display; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
702 Visual *visual; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
703 XImage *ximage; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
704 int screen; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
705 int depth; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
706 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
|
707 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
|
708 XShmSegmentInfo *shminfo; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
709 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
|
710 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
711 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
|
712 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
|
713 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
|
714 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
715 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
|
716 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
|
717 return; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
718 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
719 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
|
720 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
|
721 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
722 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
|
723 return; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
724 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
725 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
|
726 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
|
727 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
|
728 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
|
729 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 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
|
734 return; |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
735 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
736 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
737 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
|
738 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
|
739 |
691
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
740 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
|
741 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
742 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
|
743 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
744 switch(depth) { |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
745 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
|
746 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
|
747 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
748 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
749 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
|
750 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
|
751 surf_fmt, |
82836f1290b6
Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents:
694
diff
changeset
|
752 xmb_rt->w, |
82836f1290b6
Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents:
694
diff
changeset
|
753 xmb_rt->h, |
82836f1290b6
Remove cairo_* and use mbe_*
Thinker K.F. Li <thinker@codemud.net>
parents:
694
diff
changeset
|
754 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
|
755 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
|
756 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
|
757 } |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
758 #endif /* XSHM */ |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
759 |
78 | 760 /*! \brief Initialize a MadButterfy runtime for Xlib. |
761 * | |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
762 * This one is very like _x_supp_init(), except it accepts a |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
763 * X_supp_runtime_t object initialized with a display connected to a X |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
764 * 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
|
765 * |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
766 * Following field of the X_supp_runtime_t object should be initialized. |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
767 * - 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
|
768 * - win |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
769 * - display |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
770 * - visual |
78 | 771 */ |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
772 static int |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
773 _x_supp_init_with_win_internal(X_supp_runtime_t *xmb_rt) { |
265
b42ee279669e
Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
774 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
|
775 int w, h; |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
776 int disp_fd; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
777 |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
778 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
|
779 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
|
780 |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
781 #ifdef XSHM |
05a453e07d01
X_supp.c uses XSHM to avoid overhead of transmission
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
782 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
|
783 #endif |
78 | 784 |
785 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
|
786 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
|
787 |
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
462
diff
changeset
|
788 xmb_rt->surface_ptn = |
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
462
diff
changeset
|
789 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
|
790 |
693
8b7964869f7a
Update window with XImage through XSHM
Thinker K.F. Li <thinker@branda.to>
parents:
692
diff
changeset
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 w, h); |
78 | 797 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
350
diff
changeset
|
798 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
|
799 xmb_rt->backend_cr = mbe_create(xmb_rt->backend_surface); |
78 | 800 |
471
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
462
diff
changeset
|
801 mbe_set_source(xmb_rt->backend_cr, xmb_rt->surface_ptn); |
78 | 802 |
803 xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); | |
804 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
|
805 // 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
|
806 // 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
|
807 // 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
|
808 xmb_rt->rdman->rt = xmb_rt; |
78 | 809 |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
810 xmb_rt->io_man = mb_io_man_new(_io_factory); |
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
811 xmb_rt->timer_man = mb_timer_man_new(_timer_factory); |
78 | 812 |
346
b391722bf20e
sh_image_t::img_data is managed by paint_image_t.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
813 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
|
814 xmb_rt->img_ldr = img_ldr; |
1005
714169f33f13
Fix X_init_connection() to match modification of mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1004
diff
changeset
|
815 /*! \todo Remove rdman_set_img_ldr() */ |
714169f33f13
Fix X_init_connection() to match modification of mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1004
diff
changeset
|
816 rdman_set_img_ldr(xmb_rt->rdman, img_ldr); /* this is ncessary? */ |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
817 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
818 #ifndef ONLY_MOUSE_MOVE_RAW |
83 | 819 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
|
820 #endif |
83 | 821 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
822 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
|
823 |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
824 disp_fd = XConnectionNumber(xmb_rt->display); |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
825 xmb_rt->io_hdl = mb_io_man_reg(xmb_rt->io_man, disp_fd, |
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
826 MB_IO_R, |
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
827 _x_supp_handle_connection, |
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
828 xmb_rt); |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
829 |
78 | 830 return OK; |
831 } | |
832 | |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
833 /*! \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
|
834 * |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
835 * 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
|
836 * 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
|
837 */ |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
838 static int _x_supp_init(X_supp_runtime_t *xmb_rt, const char *display_name, |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
839 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
|
840 int r; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
757
diff
changeset
|
841 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
842 memset(xmb_rt, 0, sizeof(X_supp_runtime_t)); |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
843 |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
844 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
|
845 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
|
846 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
|
847 &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
|
848 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
|
849 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
|
850 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
851 r = _x_supp_init_with_win_internal(xmb_rt); |
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
|
852 |
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
|
853 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
|
854 } |
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
|
855 |
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
|
856 /*! \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
|
857 * |
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
|
858 * Runtimes initialized with this function should be destroyed with |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
859 * x_supp_destroy_keep_win(). |
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
|
860 */ |
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
|
861 static int |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
862 _x_supp_init_with_win(X_supp_runtime_t *xmb_rt, |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
863 Display *display, Window win) { |
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
|
864 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
|
865 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
|
866 |
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
|
867 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
|
868 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
|
869 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
|
870 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
871 memset(xmb_rt, 0, sizeof(X_supp_runtime_t)); |
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
|
872 |
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
|
873 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
|
874 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
|
875 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
|
876 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
|
877 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
|
878 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
879 r = _x_supp_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
|
880 |
757
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
881 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
|
882 } |
f43224bf3524
Remove unused variables and refactor to X_MB_init_with_win
Thinker K.F. Li <thinker@codemud.net>
parents:
756
diff
changeset
|
883 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
884 static void x_supp_destroy(X_supp_runtime_t *xmb_rt) { |
78 | 885 if(xmb_rt->rdman) { |
886 redraw_man_destroy(xmb_rt->rdman); | |
887 free(xmb_rt->rdman); | |
888 } | |
889 | |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
890 if(xmb_rt->io_hdl) |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
891 mb_io_man_unreg(xmb_rt->io_man, xmb_rt->io_hdl); |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
892 |
1007
4d724f248365
Free IO manager and timer manager when free a X supp runtime
Thinker K.F. Li <thinker@codemud.net>
parents:
1006
diff
changeset
|
893 if(xmb_rt->io_man) |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
894 mb_io_man_free(_io_factory, xmb_rt->io_man); |
1007
4d724f248365
Free IO manager and timer manager when free a X supp runtime
Thinker K.F. Li <thinker@codemud.net>
parents:
1006
diff
changeset
|
895 if(xmb_rt->timer_man) |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
896 mb_timer_man_free(_timer_factory, xmb_rt->timer_man); |
78 | 897 |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
898 if(xmb_rt->img_ldr) |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
899 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
|
900 |
78 | 901 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
|
902 mbe_destroy(xmb_rt->cr); |
78 | 903 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
|
904 mbe_destroy(xmb_rt->backend_cr); |
78 | 905 |
906 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
|
907 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
|
908 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
|
909 mbe_pattern_destroy(xmb_rt->surface_ptn); |
78 | 910 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
|
911 mbe_surface_destroy(xmb_rt->backend_surface); |
78 | 912 |
913 if(xmb_rt->display) | |
914 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
|
915 |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
916 X_kb_destroy(&xmb_rt->kbinfo); |
78 | 917 } |
918 | |
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
|
919 /*! \brief Destroy a MadButterfly runtime initialized with |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
920 * _x_supp_init_with_win(). |
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
|
921 * |
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
|
922 * 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
|
923 * 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
|
924 */ |
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
|
925 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
926 x_supp_destroy_keep_win(X_supp_runtime_t *xmb_rt) { |
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
|
927 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
|
928 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
|
929 |
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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
935 x_supp_destroy(xmb_rt); |
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
|
936 |
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
|
937 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
|
938 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
|
939 } |
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
|
940 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
941 static mb_rt_t * |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
942 _x_supp_new(const char *display_name, int w, int h) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
943 X_supp_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
|
944 int r; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
945 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
946 rt = O_ALLOC(X_supp_runtime_t); |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
947 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
|
948 return NULL; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
949 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
950 r = _x_supp_init(rt, display_name, w, h); |
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
|
951 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
|
952 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
|
953 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
|
954 } |
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 |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
956 return (mb_rt_t *)rt; |
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
|
957 } |
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 |
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 /*! \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
|
960 * |
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 * The object returned by this function must be free with |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
962 * _x_supp_free_keep_win() to prevent the window from closed. |
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
|
963 */ |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
964 static mb_rt_t * |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
965 _x_supp_new_with_win(MB_DISPLAY display, MB_WINDOW win) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
966 X_supp_runtime_t *rt; |
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
|
967 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
|
968 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
969 rt = O_ALLOC(X_supp_runtime_t); |
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
|
970 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
|
971 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
|
972 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
973 r = _x_supp_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
|
974 if(r != OK) { |
d687d3395264
Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents:
471
diff
changeset
|
975 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
|
976 return NULL; |
528
d687d3395264
Clear variables and draw root coord.
Thinker K.F. Li <thinker@branda.to>
parents:
471
diff
changeset
|
977 } |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
978 |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
979 return (mb_rt_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
|
980 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
981 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
982 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
983 _x_supp_free(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
984 x_supp_destroy((X_supp_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
|
985 free(rt); |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
986 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
987 |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
988 /*! \brief Free runtime created with _x_supp_new_with_win(). |
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
|
989 */ |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
990 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
991 _x_supp_free_keep_win(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
992 x_supp_destroy_keep_win((X_supp_runtime_t *) rt); |
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
|
993 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
|
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 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
996 static subject_t * |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
997 _x_supp_kbevents(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
998 X_supp_runtime_t *xmb_rt = (X_supp_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
|
999 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
|
1000 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1001 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
1002 static redraw_man_t * |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1003 _x_supp_rdman(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1004 X_supp_runtime_t *xmb_rt = (X_supp_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
|
1005 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
|
1006 } |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1007 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
1008 static mb_timer_man_t * |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1009 _x_supp_timer_man(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1010 X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; |
1008
789f67288e1c
Rename X_MB_tman() to X_MB_timer_man()
Thinker K.F. Li <thinker@codemud.net>
parents:
1007
diff
changeset
|
1011 return xmb_rt->timer_man; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
120
diff
changeset
|
1012 } |
131
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
1013 |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
1014 static observer_factory_t * |
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
1015 _x_supp_observer_factory(mb_rt_t *rt) { |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1016 X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
1017 observer_factory_t *factory; |
131
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
1018 |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
1019 factory = rdman_get_observer_factory(xmb_rt->rdman); |
131
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
1020 return factory; |
6a8588df68af
Tank can change direction and navigate on the mud area
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
1021 } |
259
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1022 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
1023 static mb_img_ldr_t * |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1024 _x_supp_img_ldr(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1025 X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; |
692
201cc86720a3
Fix compiling time warning about cairo xlib
Thinker K.F. Li <thinker@branda.to>
parents:
691
diff
changeset
|
1026 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
|
1027 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1028 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
|
1029 |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1030 return img_ldr; |
e8a784a306d0
Initialize an image loader for X runtime
Thinker K.F. Li <thinker@branda.to>
parents:
249
diff
changeset
|
1031 } |
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
|
1032 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
1033 static int |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1034 _x_supp_add_event(mb_rt_t *rt, int fd, MB_IO_TYPE type, |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
1035 mb_IO_cb_t cb, void *data) |
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
|
1036 { |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1037 X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; |
1009
595a06fc0157
Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1008
diff
changeset
|
1038 mb_IO_man_t *io_man = xmb_rt->io_man; |
595a06fc0157
Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1008
diff
changeset
|
1039 int hdl; |
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
|
1040 |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
1041 hdl = mb_io_man_reg(io_man, fd, type, cb, data); |
1009
595a06fc0157
Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1008
diff
changeset
|
1042 return hdl; |
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 } |
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 |
1011
02d52058d352
Make functions of X_supp.c static and fill fields of backend.
Thinker K.F. Li <thinker@codemud.net>
parents:
1010
diff
changeset
|
1045 static void |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1046 _x_supp_remove_event(mb_rt_t *rt, int hdl) |
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
|
1047 { |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1048 X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; |
1009
595a06fc0157
Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1008
diff
changeset
|
1049 mb_IO_man_t *io_man = xmb_rt->io_man; |
595a06fc0157
Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1008
diff
changeset
|
1050 |
1034
e9a134d75c99
To make backend compatible with C++
Thinker K.F. Li <thinker@codemud.net>
parents:
1026
diff
changeset
|
1051 mb_io_man_unreg(io_man, hdl); |
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
|
1052 } |
1009
595a06fc0157
Change X_MB_add/remove_event() to match new mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1008
diff
changeset
|
1053 |
1013
d5b8853767e7
Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1012
diff
changeset
|
1054 static int |
1016
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1055 _x_supp_flush(mb_rt_t *rt) { |
7b503c7ed46f
Change naming convention from X_MB to X_supp or x_supp
Thinker K.F. Li <thinker@codemud.net>
parents:
1015
diff
changeset
|
1056 X_supp_runtime_t *xmb_rt = (X_supp_runtime_t *) rt; |
1013
d5b8853767e7
Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1012
diff
changeset
|
1057 int r; |
d5b8853767e7
Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1012
diff
changeset
|
1058 |
1014
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
1059 #ifdef XSHM |
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
1060 XSHM_update(xmb_rt); |
f7bf372a85a3
Register _x_mb_handle_connection() with IO manager
Thinker K.F. Li <thinker@codemud.net>
parents:
1013
diff
changeset
|
1061 #endif |
1013
d5b8853767e7
Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1012
diff
changeset
|
1062 r = XFlush(xmb_rt->display); |
d5b8853767e7
Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1012
diff
changeset
|
1063 return r == 0? ERR: OK; |
d5b8853767e7
Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1012
diff
changeset
|
1064 } |
d5b8853767e7
Add flush function to mb_backend_t
Thinker K.F. Li <thinker@codemud.net>
parents:
1012
diff
changeset
|
1065 |
1043
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1066 static void |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1067 _x_supp_reg_IO_factory(mb_IO_factory_t *io_factory) { |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1068 _io_factory = io_factory; |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1069 } |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1070 |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1071 static void |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1072 _x_supp_reg_timer_factory(mb_timer_factory_t *timer_factory) { |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1073 _timer_factory = timer_factory; |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1074 } |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1075 |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1076 mb_backend_t mb_dfl_backend = { _x_supp_new, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1077 _x_supp_new_with_win, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1078 |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1079 _x_supp_free, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1080 _x_supp_free_keep_win, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1081 _x_supp_add_event, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1082 _x_supp_remove_event, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1083 _x_supp_event_loop, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1084 _x_supp_flush, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1085 |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1086 _x_supp_kbevents, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1087 _x_supp_rdman, |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1088 _x_supp_timer_man, |
1060
e415c55b4a0d
Stop using ob as acronym observer
Thinker K.F. Li <thinker@codemud.net>
parents:
1049
diff
changeset
|
1089 _x_supp_observer_factory, |
1043
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1090 _x_supp_img_ldr, |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1091 |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1092 _x_supp_reg_IO_factory, |
769921baf111
Add missed functions: _x_supp_reg_IO_factory and _x_supp_reg_timer_factory
Thinker K.F. Li <thinker@codemud.net>
parents:
1034
diff
changeset
|
1093 _x_supp_reg_timer_factory, |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
1018
diff
changeset
|
1094 }; |