2 * $Id: rb_ecore_x.c 94 2004-08-23 10:53:25Z 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
27 #include "../ecore/rb_ecore.h"
28 #include "../ecore/rb_event_handler.h"
29 #include "rb_ecore_x.h"
30 #include "rb_window.h"
32 #define DEF_CONST(mod, prefix, name) \
33 rb_define_const ((mod), #name, \
34 INT2FIX (prefix##name));
36 static VALUE default_root;
38 static void at_exit ()
44 static VALUE m_default_root_window_get (VALUE self)
49 static VALUE c_ev_key_down_init (VALUE self, VALUE event)
51 VALUE c = CLASS_OF (self);
52 Ecore_X_Event_Key_Down *e = (void *) event;
54 rb_define_attr (c, "keyname", 1, 0);
55 rb_define_attr (c, "keysymbol", 1, 0);
56 rb_define_attr (c, "key_compose", 1, 0);
57 rb_define_attr (c, "modifiers", 1, 0);
58 rb_define_attr (c, "window", 1, 0);
59 rb_define_attr (c, "event_window", 1, 0);
60 rb_define_attr (c, "time", 1, 0);
62 rb_iv_set (self, "@keyname",
63 e->keyname ? rb_str_new2 (e->keyname) : Qnil);
64 rb_iv_set (self, "@keysymbol",
65 e->keysymbol ? rb_str_new2 (e->keysymbol) : Qnil);
66 rb_iv_set (self, "@key_compose",
67 e->key_compose ? rb_str_new2 (e->key_compose) : Qnil);
68 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
69 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
70 rb_iv_set (self, "@event_window",
71 TO_ECORE_X_WINDOW (Qnil, e->event_win));
72 rb_iv_set (self, "@time", UINT2NUM (e->time));
77 static VALUE c_ev_mouse_button_down_init (VALUE self, VALUE event)
79 VALUE c = CLASS_OF (self);
80 Ecore_X_Event_Mouse_Button_Down *e = (void *) event;
82 rb_define_attr (c, "button", 1, 0);
83 rb_define_attr (c, "modifiers", 1, 0);
84 rb_define_attr (c, "x", 1, 0);
85 rb_define_attr (c, "y", 1, 0);
86 rb_define_attr (c, "root", 1, 0);
87 rb_define_attr (c, "window", 1, 0);
88 rb_define_attr (c, "event_window", 1, 0);
89 rb_define_attr (c, "time", 1, 0);
90 rb_define_attr (c, "double_click", 1, 0);
91 rb_define_attr (c, "triple_click", 1, 0);
93 rb_iv_set (self, "@button", INT2FIX (e->button));
94 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
95 rb_iv_set (self, "@x", INT2FIX (e->x));
96 rb_iv_set (self, "@y", INT2FIX (e->x));
97 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
98 INT2FIX (e->root.y)));
99 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
100 rb_iv_set (self, "@event_window",
101 TO_ECORE_X_WINDOW (Qnil, e->event_win));
102 rb_iv_set (self, "@time", UINT2NUM (e->time));
103 rb_iv_set (self, "@double_click",
104 e->double_click ? Qtrue : Qfalse);
105 rb_iv_set (self, "@triple_click",
106 e->triple_click ? Qtrue : Qfalse);
111 static VALUE c_ev_mouse_button_up_init (VALUE self, VALUE event)
113 VALUE c = CLASS_OF (self);
114 Ecore_X_Event_Mouse_Button_Up *e = (void *) event;
116 rb_define_attr (c, "button", 1, 0);
117 rb_define_attr (c, "modifiers", 1, 0);
118 rb_define_attr (c, "x", 1, 0);
119 rb_define_attr (c, "y", 1, 0);
120 rb_define_attr (c, "root", 1, 0);
121 rb_define_attr (c, "window", 1, 0);
122 rb_define_attr (c, "event_window", 1, 0);
123 rb_define_attr (c, "time", 1, 0);
125 rb_iv_set (self, "@button", INT2FIX (e->button));
126 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
127 rb_iv_set (self, "@x", INT2FIX (e->x));
128 rb_iv_set (self, "@y", INT2FIX (e->x));
129 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
130 INT2FIX (e->root.y)));
131 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
132 rb_iv_set (self, "@event_window",
133 TO_ECORE_X_WINDOW (Qnil, e->event_win));
134 rb_iv_set (self, "@time", UINT2NUM (e->time));
139 static VALUE c_ev_mouse_move_init (VALUE self, VALUE event)
141 VALUE c = CLASS_OF (self);
142 Ecore_X_Event_Mouse_Move *e = (void *) event;
144 rb_define_attr (c, "modifiers", 1, 0);
145 rb_define_attr (c, "x", 1, 0);
146 rb_define_attr (c, "y", 1, 0);
147 rb_define_attr (c, "root", 1, 0);
148 rb_define_attr (c, "window", 1, 0);
149 rb_define_attr (c, "event_window", 1, 0);
150 rb_define_attr (c, "time", 1, 0);
152 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
153 rb_iv_set (self, "@x", INT2FIX (e->x));
154 rb_iv_set (self, "@y", INT2FIX (e->y));
155 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
156 INT2FIX (e->root.y)));
157 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
158 rb_iv_set (self, "@event_window",
159 TO_ECORE_X_WINDOW (Qnil, e->event_win));
160 rb_iv_set (self, "@time", UINT2NUM (e->time));
165 static VALUE c_ev_mouse_in_init (VALUE self, VALUE event)
167 VALUE c = CLASS_OF (self);
168 Ecore_X_Event_Mouse_In *e = (void *) event;
170 rb_define_attr (c, "modifiers", 1, 0);
171 rb_define_attr (c, "x", 1, 0);
172 rb_define_attr (c, "y", 1, 0);
173 rb_define_attr (c, "root", 1, 0);
174 rb_define_attr (c, "window", 1, 0);
175 rb_define_attr (c, "event_window", 1, 0);
176 rb_define_attr (c, "mode", 1, 0);
177 rb_define_attr (c, "detail", 1, 0);
178 rb_define_attr (c, "time", 1, 0);
180 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
181 rb_iv_set (self, "@x", INT2FIX (e->x));
182 rb_iv_set (self, "@y", INT2FIX (e->y));
183 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
184 INT2FIX (e->root.y)));
185 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
186 rb_iv_set (self, "@event_window",
187 TO_ECORE_X_WINDOW (Qnil, e->event_win));
188 rb_iv_set (self, "@mode", INT2FIX (e->mode));
189 rb_iv_set (self, "@detail", INT2FIX (e->detail));
190 rb_iv_set (self, "@time", UINT2NUM (e->time));
195 static VALUE c_ev_win_focus_change_init (VALUE self, VALUE event)
197 VALUE c = CLASS_OF (self);
198 Ecore_X_Event_Window_Focus_In *e = (void *) event;
200 rb_define_attr (c, "window", 1, 0);
201 rb_define_attr (c, "mode", 1, 0);
202 rb_define_attr (c, "detail", 1, 0);
203 rb_define_attr (c, "time", 1, 0);
205 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
206 rb_iv_set (self, "@mode", INT2FIX (e->mode));
207 rb_iv_set (self, "@detail", INT2FIX (e->detail));
208 rb_iv_set (self, "@time", UINT2NUM (e->time));
213 static VALUE c_ev_win_delete_request_init (VALUE self, VALUE event)
215 VALUE c = CLASS_OF (self);
216 Ecore_X_Event_Window_Delete_Request *e = (void *) event;
218 rb_define_attr (c, "window", 1, 0);
219 rb_define_attr (c, "time", 1, 0);
221 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
222 rb_iv_set (self, "@time", UINT2NUM (e->time));
227 static VALUE c_ev_win_configure_init (VALUE self, VALUE event)
229 VALUE c = CLASS_OF (self);
230 Ecore_X_Event_Window_Configure *e = (void *) event;
232 rb_define_attr (c, "window", 1, 0);
233 rb_define_attr (c, "window_above", 1, 0);
234 rb_define_attr (c, "x", 1, 0);
235 rb_define_attr (c, "y", 1, 0);
236 rb_define_attr (c, "w", 1, 0);
237 rb_define_attr (c, "h", 1, 0);
238 rb_define_attr (c, "border", 1, 0);
239 rb_define_attr (c, "override", 1, 0);
240 rb_define_attr (c, "from_wm", 1, 0);
241 rb_define_attr (c, "time", 1, 0);
243 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
244 rb_iv_set (self, "@window_above", TO_ECORE_X_WINDOW (Qnil,
246 rb_iv_set (self, "@x", INT2FIX (e->x));
247 rb_iv_set (self, "@y", INT2FIX (e->y));
248 rb_iv_set (self, "@w", INT2FIX (e->w));
249 rb_iv_set (self, "@h", INT2FIX (e->h));
250 rb_iv_set (self, "@border", INT2FIX (e->border));
251 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
252 rb_iv_set (self, "@from_wm", e->from_wm ? Qtrue : Qfalse);
253 rb_iv_set (self, "@time", UINT2NUM (e->time));
258 static VALUE c_ev_win_visibility_change_init (VALUE self, VALUE event)
260 VALUE c = CLASS_OF (self);
261 Ecore_X_Event_Window_Visibility_Change *e = (void *) event;
263 rb_define_attr (c, "window", 1, 0);
264 rb_define_attr (c, "fully_obscured", 1, 0);
265 rb_define_attr (c, "time", 1, 0);
267 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
268 rb_iv_set (self, "@fully_obscured", e->fully_obscured ? Qtrue : Qfalse);
269 rb_iv_set (self, "@time", UINT2NUM (e->time));
274 static VALUE c_ev_win_create_init (VALUE self, VALUE event)
276 VALUE c = CLASS_OF (self);
277 Ecore_X_Event_Window_Create *e = (void *) event;
279 rb_define_attr (c, "window", 1, 0);
280 rb_define_attr (c, "override", 1, 0);
281 rb_define_attr (c, "time", 1, 0);
283 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
284 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
285 rb_iv_set (self, "@time", UINT2NUM (e->time));
290 static VALUE c_ev_win_show_request_init (VALUE self, VALUE event)
292 VALUE c = CLASS_OF (self);
293 Ecore_X_Event_Window_Show_Request *e = (void *) event;
295 rb_define_attr (c, "window", 1, 0);
296 rb_define_attr (c, "parent", 1, 0);
297 rb_define_attr (c, "time", 1, 0);
299 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
300 rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
301 rb_iv_set (self, "@time", UINT2NUM (e->time));
306 void Init_ecore_x (void)
311 rb_require ("ecore");
313 /* we need to call ecore_x_init () here, to make sure the
314 * event ids are set properly
317 ecore_x_init (getenv ("DISPLAY"));
320 mX = rb_define_module_under (mEcore, "X");
321 rb_define_module_function (mX, "default_root_window",
322 m_default_root_window_get, 0);
326 /* now create the default root window object */
327 w = DefaultRootWindow (ecore_x_display_get ());
328 default_root = TO_ECORE_X_WINDOW (Qnil, w);
329 OBJ_FREEZE (default_root);
330 rb_global_variable (&default_root);
332 /* event mask values */
333 c = rb_define_class_under (mX, "EventMask", rb_cObject);
334 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
335 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
336 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
337 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
338 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
339 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
340 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
341 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
342 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
343 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
344 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
345 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
346 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
347 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
348 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
349 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
350 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
351 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
352 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
353 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
354 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
357 c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
358 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
359 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
360 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
363 c = rb_define_class_under (mX, "EventMode", rb_cObject);
364 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
365 DEF_CONST (c, ECORE_X_EVENT_MODE_, NORMAL);
366 DEF_CONST (c, ECORE_X_EVENT_MODE_, WHILE_GRABBED);
367 DEF_CONST (c, ECORE_X_EVENT_MODE_, GRAB);
368 DEF_CONST (c, ECORE_X_EVENT_MODE_, UNGRAB);
371 c = rb_define_class_under (mX, "EventDetail", rb_cObject);
372 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
373 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, ANCESTOR);
374 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, VIRTUAL);
375 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, INFERIOR);
376 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR);
377 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR_VIRTUAL);
378 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER);
379 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER_ROOT);
380 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, DETAIL_NONE);
383 c = rb_define_class_under (mX, "Modifier", rb_cObject);
384 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
385 DEF_CONST (c, ECORE_X_MODIFIER_, SHIFT);
386 DEF_CONST (c, ECORE_X_MODIFIER_, CTRL);
387 DEF_CONST (c, ECORE_X_MODIFIER_, ALT);
388 DEF_CONST (c, ECORE_X_MODIFIER_, WIN);
391 ADD_EVENT (mX, ECORE_X_EVENT_, KEY_DOWN, "KeyDown", c);
392 rb_define_private_method (c, "initialize",
393 c_ev_key_down_init, 1);
395 ADD_EVENT (mX, ECORE_X_EVENT_, KEY_UP, "KeyUp", c);
396 rb_define_private_method (c, "initialize",
397 c_ev_key_down_init, 1);
399 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_BUTTON_DOWN,
400 "MouseButtonDown", c);
401 rb_define_private_method (c, "initialize",
402 c_ev_mouse_button_down_init, 1);
404 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_BUTTON_UP,
406 rb_define_private_method (c, "initialize",
407 c_ev_mouse_button_up_init, 1);
409 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_MOVE, "MouseMove", c);
410 rb_define_private_method (c, "initialize",
411 c_ev_mouse_move_init, 1);
413 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_IN, "MouseIn", c);
414 rb_define_private_method (c, "initialize",
415 c_ev_mouse_in_init, 1);
417 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_OUT, "MouseOut", c);
418 rb_define_private_method (c, "initialize",
419 c_ev_mouse_in_init, 1);
421 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
423 rb_define_private_method (c, "initialize",
424 c_ev_win_focus_change_init, 1);
426 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
427 "WindowFocusOut", c);
428 rb_define_private_method (c, "initialize",
429 c_ev_win_focus_change_init, 1);
431 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
432 "WindowDeleteRequest", c);
433 rb_define_private_method (c, "initialize",
434 c_ev_win_delete_request_init, 1);
436 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
437 "WindowConfigureRequest", c);
438 rb_define_private_method (c, "initialize",
439 c_ev_win_delete_request_init, 1);
441 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
442 "WindowConfigure", c);
443 rb_define_private_method (c, "initialize",
444 c_ev_win_configure_init, 1);
446 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
447 "WindowVisibilityChange", c);
448 rb_define_private_method (c, "initialize",
449 c_ev_win_visibility_change_init, 1);
451 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CREATE, "WindowCreate", c);
452 rb_define_private_method (c, "initialize",
453 c_ev_win_create_init, 1);
455 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DESTROY, "WindowDestroy", c);
456 rb_define_private_method (c, "initialize",
457 c_ev_win_delete_request_init, 1);
459 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
460 rb_define_private_method (c, "initialize",
461 c_ev_win_delete_request_init, 1);
463 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
464 rb_define_private_method (c, "initialize",
465 c_ev_win_delete_request_init, 1);
467 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
468 "WindowShowRequest", c);
469 rb_define_private_method (c, "initialize",
470 c_ev_win_show_request_init, 1);