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