2 * $Id: rb_ecore_x.c 88 2004-08-22 14:52:37Z tilman $
4 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "../ecore/rb_ecore.h"
27 #include "../ecore/rb_event_handler.h"
28 #include "rb_ecore_x.h"
29 #include "rb_window.h"
31 #define DEF_CONST(mod, prefix, name) \
32 rb_define_const ((mod), #name, \
33 INT2FIX (prefix##name));
35 static VALUE default_root;
37 static void at_exit ()
43 static VALUE m_default_root_window_get (VALUE self)
48 static VALUE c_ev_mouse_move_init (VALUE self, VALUE event)
50 VALUE c = CLASS_OF (self);
51 Ecore_X_Event_Mouse_Move *e = (void *) event;
53 rb_define_attr (c, "modifiers", 1, 0);
54 rb_define_attr (c, "x", 1, 0);
55 rb_define_attr (c, "y", 1, 0);
56 rb_define_attr (c, "root", 1, 0);
57 rb_define_attr (c, "window", 1, 0);
58 rb_define_attr (c, "event_window", 1, 0);
59 rb_define_attr (c, "time", 1, 0);
61 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
62 rb_iv_set (self, "@x", INT2FIX (e->x));
63 rb_iv_set (self, "@y", INT2FIX (e->y));
64 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
65 INT2FIX (e->root.y)));
66 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
67 rb_iv_set (self, "@event_window",
68 TO_ECORE_X_WINDOW (Qnil, e->event_win));
69 rb_iv_set (self, "@time", UINT2NUM (e->time));
74 static VALUE c_ev_mouse_in_init (VALUE self, VALUE event)
76 VALUE c = CLASS_OF (self);
77 Ecore_X_Event_Mouse_In *e = (void *) event;
79 rb_define_attr (c, "modifiers", 1, 0);
80 rb_define_attr (c, "x", 1, 0);
81 rb_define_attr (c, "y", 1, 0);
82 rb_define_attr (c, "root", 1, 0);
83 rb_define_attr (c, "window", 1, 0);
84 rb_define_attr (c, "event_window", 1, 0);
85 rb_define_attr (c, "mode", 1, 0);
86 rb_define_attr (c, "detail", 1, 0);
87 rb_define_attr (c, "time", 1, 0);
89 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
90 rb_iv_set (self, "@x", INT2FIX (e->x));
91 rb_iv_set (self, "@y", INT2FIX (e->y));
92 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
93 INT2FIX (e->root.y)));
94 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
95 rb_iv_set (self, "@event_window",
96 TO_ECORE_X_WINDOW (Qnil, e->event_win));
97 rb_iv_set (self, "@mode", INT2FIX (e->mode));
98 rb_iv_set (self, "@detail", INT2FIX (e->detail));
99 rb_iv_set (self, "@time", UINT2NUM (e->time));
104 static VALUE c_ev_win_focus_change_init (VALUE self, VALUE event)
106 VALUE c = CLASS_OF (self);
107 Ecore_X_Event_Window_Focus_In *e = (void *) event;
109 rb_define_attr (c, "window", 1, 0);
110 rb_define_attr (c, "mode", 1, 0);
111 rb_define_attr (c, "detail", 1, 0);
112 rb_define_attr (c, "time", 1, 0);
114 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
115 rb_iv_set (self, "@mode", INT2FIX (e->mode));
116 rb_iv_set (self, "@detail", INT2FIX (e->detail));
117 rb_iv_set (self, "@time", UINT2NUM (e->time));
122 static VALUE c_ev_win_delete_request_init (VALUE self, VALUE event)
124 VALUE c = CLASS_OF (self);
125 Ecore_X_Event_Window_Delete_Request *e = (void *) event;
127 rb_define_attr (c, "window", 1, 0);
128 rb_define_attr (c, "time", 1, 0);
130 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
131 rb_iv_set (self, "@time", UINT2NUM (e->time));
136 static VALUE c_ev_win_configure_init (VALUE self, VALUE event)
138 VALUE c = CLASS_OF (self);
139 Ecore_X_Event_Window_Configure *e = (void *) event;
141 rb_define_attr (c, "window", 1, 0);
142 rb_define_attr (c, "window_above", 1, 0);
143 rb_define_attr (c, "x", 1, 0);
144 rb_define_attr (c, "y", 1, 0);
145 rb_define_attr (c, "w", 1, 0);
146 rb_define_attr (c, "h", 1, 0);
147 rb_define_attr (c, "border", 1, 0);
148 rb_define_attr (c, "override", 1, 0);
149 rb_define_attr (c, "from_wm", 1, 0);
150 rb_define_attr (c, "time", 1, 0);
152 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
153 rb_iv_set (self, "@window_above", TO_ECORE_X_WINDOW (Qnil,
155 rb_iv_set (self, "@x", INT2FIX (e->x));
156 rb_iv_set (self, "@y", INT2FIX (e->y));
157 rb_iv_set (self, "@w", INT2FIX (e->w));
158 rb_iv_set (self, "@h", INT2FIX (e->h));
159 rb_iv_set (self, "@border", INT2FIX (e->border));
160 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
161 rb_iv_set (self, "@from_wm", e->from_wm ? Qtrue : Qfalse);
162 rb_iv_set (self, "@time", UINT2NUM (e->time));
167 static VALUE c_ev_win_visibility_change_init (VALUE self, VALUE event)
169 VALUE c = CLASS_OF (self);
170 Ecore_X_Event_Window_Visibility_Change *e = (void *) event;
172 rb_define_attr (c, "window", 1, 0);
173 rb_define_attr (c, "fully_obscured", 1, 0);
174 rb_define_attr (c, "time", 1, 0);
176 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
177 rb_iv_set (self, "@fully_obscured", e->fully_obscured ? Qtrue : Qfalse);
178 rb_iv_set (self, "@time", UINT2NUM (e->time));
183 static VALUE c_ev_win_create_init (VALUE self, VALUE event)
185 VALUE c = CLASS_OF (self);
186 Ecore_X_Event_Window_Create *e = (void *) event;
188 rb_define_attr (c, "window", 1, 0);
189 rb_define_attr (c, "override", 1, 0);
190 rb_define_attr (c, "time", 1, 0);
192 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
193 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
194 rb_iv_set (self, "@time", UINT2NUM (e->time));
199 static VALUE c_ev_win_show_request_init (VALUE self, VALUE event)
201 VALUE c = CLASS_OF (self);
202 Ecore_X_Event_Window_Show_Request *e = (void *) event;
204 rb_define_attr (c, "window", 1, 0);
205 rb_define_attr (c, "parent", 1, 0);
206 rb_define_attr (c, "time", 1, 0);
208 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
209 rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
210 rb_iv_set (self, "@time", UINT2NUM (e->time));
215 void Init_ecore_x (void)
219 rb_require ("ecore");
221 /* we need to call ecore_x_init () here, to make sure the
222 * event ids are set properly
225 ecore_x_init (getenv ("DISPLAY"));
228 mX = rb_define_module_under (mEcore, "X");
229 rb_define_module_function (mX, "default_root_window",
230 m_default_root_window_get, 0);
234 /* now create the default root window object */
235 default_root = TO_ECORE_X_WINDOW (Qnil, 0);
236 OBJ_FREEZE (default_root);
237 rb_global_variable (&default_root);
239 /* event mask values */
240 c = rb_define_class_under (mX, "EventMask", rb_cObject);
241 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
242 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
243 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
244 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
245 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
246 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
247 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
248 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
249 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
250 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
251 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
252 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
253 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
254 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
255 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
256 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
257 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
258 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
259 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
260 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
261 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
264 c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
265 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
266 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
267 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
270 c = rb_define_class_under (mX, "EventMode", rb_cObject);
271 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
272 DEF_CONST (c, ECORE_X_EVENT_MODE_, NORMAL);
273 DEF_CONST (c, ECORE_X_EVENT_MODE_, WHILE_GRABBED);
274 DEF_CONST (c, ECORE_X_EVENT_MODE_, GRAB);
275 DEF_CONST (c, ECORE_X_EVENT_MODE_, UNGRAB);
278 c = rb_define_class_under (mX, "EventDetails", rb_cObject);
279 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
280 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, ANCESTOR);
281 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, VIRTUAL);
282 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, INFERIOR);
283 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR);
284 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR_VIRTUAL);
285 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER);
286 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER_ROOT);
287 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, DETAIL_NONE);
290 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_MOVE, "MouseMove", c);
291 rb_define_private_method (c, "initialize",
292 c_ev_mouse_move_init, 1);
294 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_IN, "MouseIn", c);
295 rb_define_private_method (c, "initialize",
296 c_ev_mouse_in_init, 1);
298 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_OUT, "MouseOut", c);
299 rb_define_private_method (c, "initialize",
300 c_ev_mouse_in_init, 1);
302 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
304 rb_define_private_method (c, "initialize",
305 c_ev_win_focus_change_init, 1);
307 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
308 "WindowFocusOut", c);
309 rb_define_private_method (c, "initialize",
310 c_ev_win_focus_change_init, 1);
312 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
313 "WindowDeleteRequest", c);
314 rb_define_private_method (c, "initialize",
315 c_ev_win_delete_request_init, 1);
317 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
318 "WindowConfigureRequest", c);
319 rb_define_private_method (c, "initialize",
320 c_ev_win_delete_request_init, 1);
322 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
323 "WindowConfigure", c);
324 rb_define_private_method (c, "initialize",
325 c_ev_win_configure_init, 1);
327 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
328 "WindowVisibilityChange", c);
329 rb_define_private_method (c, "initialize",
330 c_ev_win_visibility_change_init, 1);
332 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CREATE, "WindowCreate", c);
333 rb_define_private_method (c, "initialize",
334 c_ev_win_create_init, 1);
336 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DESTROY, "WindowDestroy", c);
337 rb_define_private_method (c, "initialize",
338 c_ev_win_delete_request_init, 1);
340 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
341 rb_define_private_method (c, "initialize",
342 c_ev_win_delete_request_init, 1);
344 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
345 rb_define_private_method (c, "initialize",
346 c_ev_win_delete_request_init, 1);
348 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
349 "WindowShowRequest", c);
350 rb_define_private_method (c, "initialize",
351 c_ev_win_show_request_init, 1);