annotate nodejs/X_supp_njs.c @ 880:ac3e8492ad74 abs_n_rel_center

Formalize path data for MadButterfly. Inkscape and other editors would omit 'l' or 'L' after 'm' or 'M'. MadButterfly can not handle it, now. So, we work around it at SVG parser.
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 25 Sep 2010 18:46:37 +0800
parents 67d0fed24120
children 176cba3ad32c
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
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: 753
diff changeset
2 // vim: sw=4:ts=8:sts=4
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 /*! \brief Implement X11 backend for nodejs plugin.
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 *
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 * Since nodejs use libev to handle event loops, part of X11 backend
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 * code can not be used directly. The part of code should be rewrote.
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 * The part is about
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 */
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #include <stdio.h>
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 #include <X11/Xlib.h>
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 #include <X11/Xutil.h>
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 #include <ev.h>
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 #include "mb_X_supp.h"
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 #include "mb_tools.h"
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 556
diff changeset
15 #include "X_supp_njs.h"
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 #ifndef ASSERT
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 #define ASSERT(x)
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 #endif
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 static void timer_cb(EV_P_ ev_timer *tmwatcher, int revent);
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 /*! \brief Register next timeout with libev.
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 */
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 static void
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
26 set_next_timeout(njs_runtime_t *rt) {
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 mb_tman_t *tman;
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 mb_timeval_t now, tmo;
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 ev_tstamp tout;
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 int r;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
31
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
32 tman = X_MB_tman(rt->xrt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 get_now(&now);
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 r = mb_tman_next_timeout(tman, &now, &tmo);
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 if(r == 0) {
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 MB_TIMEVAL_DIFF(&tmo, &now);
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 tout = (ev_tstamp)MB_TIMEVAL_SEC(&tmo) +
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 (ev_tstamp)MB_TIMEVAL_USEC(&tmo) / 1000000;
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
39 ev_timer_init(&rt->tmwatcher, timer_cb, tout, 0);
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
40 ev_timer_start(&rt->tmwatcher);
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
41 rt->enable_timer = 1;
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 } else
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
43 rt->enable_timer = 0;
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 }
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 static void
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 x_conn_cb(EV_P_ ev_io *iowatcher, int revent) {
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
48 njs_runtime_t *rt = MEM2OBJ(iowatcher, njs_runtime_t, iowatcher);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 redraw_man_t *rdman;
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
50 extern void _X_MB_handle_x_event_for_nodejs(void *rt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
52 rdman = X_MB_rdman(rt->xrt);
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
53 _X_MB_handle_x_event_for_nodejs(rt->xrt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 rdman_redraw_changed(rdman);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
55
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
56 if(rt->enable_timer == 0) /* no installed timeout */
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
57 set_next_timeout(rt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 }
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 static void
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 timer_cb(EV_P_ ev_timer *tmwatcher, int revent) {
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
62 njs_runtime_t *rt = MEM2OBJ(tmwatcher, njs_runtime_t, tmwatcher);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 mb_tman_t *tman;
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 redraw_man_t *rdman;
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 mb_timeval_t now;
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 554
diff changeset
66 extern int _X_MB_flush_x_conn_for_nodejs(void *rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
67
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
68 tman = X_MB_tman(rt->xrt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 get_now(&now);
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 mb_tman_handle_timeout(tman, &now);
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
72 rdman = X_MB_rdman(rt->xrt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 rdman_redraw_changed(rdman);
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 554
diff changeset
74 _X_MB_flush_x_conn_for_nodejs(rt->xrt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
75
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
76 set_next_timeout(rt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 }
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 /*! \brief Handle connection coming data and timeout of timers.
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 *
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 * \param rt is a runtime object for X.
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 */
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
83 void
556
c9d23f7279a4 The first testcase that nodejs code can show a MadButterfly window.
Thinker K.F. Li <thinker@branda.to>
parents: 554
diff changeset
84 X_njs_MB_init_handle_connection(njs_runtime_t *rt) {
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
85 void *xrt = rt->xrt;
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 int fd;
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
87 extern int _X_MB_get_x_conn_for_nodejs(void *rt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 /*
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 * Setup watcher for X connection.
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 */
551
9e69c4a0f565 rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents: 550
diff changeset
92 fd = _X_MB_get_x_conn_for_nodejs(xrt);
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
93 ev_io_init(&rt->iowatcher, x_conn_cb, fd, EV_READ);
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
94 ev_io_start(&rt->iowatcher);
554
4caf6090825f Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents: 553
diff changeset
95 rt->enable_io = 1;
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
97 set_next_timeout(rt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 }
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99
551
9e69c4a0f565 rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents: 550
diff changeset
100 /*! \brief Free njs_runtime_t.
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
101 */
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
102 void
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
103 X_njs_MB_free(njs_runtime_t *rt) {
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 /*
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 * stop IO and timer watcher
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 */
554
4caf6090825f Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents: 553
diff changeset
107 if(rt->enable_io)
4caf6090825f Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents: 553
diff changeset
108 ev_io_stop(&rt->iowatcher);
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
109 if(rt->enable_timer)
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
110 ev_timer_stop(&rt->tmwatcher);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
111
554
4caf6090825f Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents: 553
diff changeset
112 X_MB_free(rt->xrt);
4caf6090825f Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents: 553
diff changeset
113 free(rt);
546
249bcbf07eb0 Reuse and adapt X_supp.c by implmeneting X_supp_njs.c
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 }
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
115
871
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
116 /*! \brief Free njs_runtime_t.
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
117 */
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
118 void
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
119 X_njs_MB_free_keep_win(njs_runtime_t *rt) {
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
120 /*
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
121 * stop IO and timer watcher
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
122 */
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
123 if(rt->enable_io)
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
124 ev_io_stop(&rt->iowatcher);
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
125 if(rt->enable_timer)
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
126 ev_timer_stop(&rt->tmwatcher);
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
127
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
128 X_MB_free_keep_win(rt->xrt);
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
129 free(rt);
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
130 }
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
131
571
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
132 int
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
133 X_njs_MB_flush(njs_runtime_t *rt) {
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
134 void *xrt = rt->xrt;
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
135 int r;
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
136 extern int _X_MB_flush_x_conn_for_nodejs(void *rt);
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
137
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
138 _X_MB_flush_x_conn_for_nodejs(xrt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
139
571
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
140 return r;
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
141 }
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
142
551
9e69c4a0f565 rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents: 550
diff changeset
143 njs_runtime_t *
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
144 X_njs_MB_new(char *display_name, int w, int h) {
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
145 njs_runtime_t *rt;
551
9e69c4a0f565 rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents: 550
diff changeset
146 void *xrt;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
147
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
148 rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t));
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
149 ASSERT(rt != NULL);
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
150
551
9e69c4a0f565 rename njs_ev_data_t to njs_runtime_t
Thinker K.F. Li <thinker@branda.to>
parents: 550
diff changeset
151 xrt = X_MB_new(display_name, w, h);
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
152
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
153 rt->xrt = xrt;
554
4caf6090825f Fix leaking on freeing a njs runtime object
Thinker K.F. Li <thinker@branda.to>
parents: 553
diff changeset
154 rt->enable_io = 0;
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
155 rt->enable_timer = 0; /* no timer, now */
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 753
diff changeset
156
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
157 return rt;
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
158 }
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
159
871
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
160 /*! \brief Create a njs_runtime_t for an existed window.
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
161 *
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
162 * The njs_runtime_t created by this function must be free by
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
163 * X_njs_MB_free_keep_win().
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
164 */
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
165 njs_runtime_t *
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
166 X_njs_MB_new_with_win(void *display, long win) {
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
167 njs_runtime_t *rt;
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
168 void *xrt;
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
169
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
170 rt = (njs_runtime_t *)malloc(sizeof(njs_runtime_t));
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
171 ASSERT(rt != NULL);
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
172
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
173 xrt = X_MB_new_with_win((Display *)display, win);
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
174
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
175 rt->xrt = xrt;
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
176 rt->enable_io = 0;
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
177 rt->enable_timer = 0; /* no timer, now */
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
178
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
179 return rt;
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
180 }
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
181
869
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
182 /*! \brief Pass a X event to X runtime.
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
183 */
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
184 void
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
185 X_njs_MB_handle_single_event(njs_runtime_t *rt, void *evt) {
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
186 void *xrt = rt->xrt;
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
187 extern void _X_MB_handle_single_event(void *rt, void *evt);
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
188
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
189 _X_MB_handle_single_event(xrt, evt);
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
190 }
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
191
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
192 /*! \brief Called at end of an iteration of event loop.
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
193 */
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
194 void
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
195 X_njs_MB_no_more_event(njs_runtime_t *rt) {
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
196 void *xrt = rt->xrt;
871
67d0fed24120 Export a function to create a runtime for an existed window for JS
Thinker K.F. Li <thinker@codemud.net>
parents: 869
diff changeset
197 extern void _X_MB_no_more_event(void *rt);
869
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
198
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
199 _X_MB_no_more_event(xrt);
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
200 }
c18058fb48ee Export API for JS to feed X events.
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
201
553
0a77b88500bf rename _X_njs_MB_get_runtime to _X_njs_MB_get_X_runtime
Thinker K.F. Li <thinker@branda.to>
parents: 552
diff changeset
202 /*! \brief Get X runtime that is backend of this njs runtime.
0a77b88500bf rename _X_njs_MB_get_runtime to _X_njs_MB_get_X_runtime
Thinker K.F. Li <thinker@branda.to>
parents: 552
diff changeset
203 */
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
204 void *
553
0a77b88500bf rename _X_njs_MB_get_runtime to _X_njs_MB_get_X_runtime
Thinker K.F. Li <thinker@branda.to>
parents: 552
diff changeset
205 _X_njs_MB_get_X_runtime(njs_runtime_t *rt) {
552
dd8d32b4c899 rename ev_data to rt
Thinker K.F. Li <thinker@branda.to>
parents: 551
diff changeset
206 return rt->xrt;
550
127499ab2412 Upgrade ndoejs plugin to level of a new runtime.
Thinker K.F. Li <thinker@branda.to>
parents: 546
diff changeset
207 }