2 * $Id: rb_ecore_x.c 90 2004-08-22 16:23:19Z 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_key_down_init (VALUE self, VALUE event)
50 VALUE c = CLASS_OF (self);
51 Ecore_X_Event_Key_Down *e = (void *) event;
53 rb_define_attr (c, "keyname", 1, 0);
54 rb_define_attr (c, "keysymbol", 1, 0);
55 rb_define_attr (c, "key_compose", 1, 0);
56 rb_define_attr (c, "modifiers", 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, "@keyname",
62 e->keyname ? rb_str_new2 (e->keyname) : Qnil);
63 rb_iv_set (self, "@keysymbol",
64 e->keysymbol ? rb_str_new2 (e->keysymbol) : Qnil);
65 rb_iv_set (self, "@key_compose",
66 e->key_compose ? rb_str_new2 (e->key_compose) : Qnil);
67 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
68 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
69 rb_iv_set (self, "@event_window",
70 TO_ECORE_X_WINDOW (Qnil, e->event_win));
71 rb_iv_set (self, "@time", UINT2NUM (e->time));
76 static VALUE c_ev_mouse_move_init (VALUE self, VALUE event)
78 VALUE c = CLASS_OF (self);
79 Ecore_X_Event_Mouse_Move *e = (void *) event;
81 rb_define_attr (c, "modifiers", 1, 0);
82 rb_define_attr (c, "x", 1, 0);
83 rb_define_attr (c, "y", 1, 0);
84 rb_define_attr (c, "root", 1, 0);
85 rb_define_attr (c, "window", 1, 0);
86 rb_define_attr (c, "event_window", 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, "@time", UINT2NUM (e->time));
102 static VALUE c_ev_mouse_in_init (VALUE self, VALUE event)
104 VALUE c = CLASS_OF (self);
105 Ecore_X_Event_Mouse_In *e = (void *) event;
107 rb_define_attr (c, "modifiers", 1, 0);
108 rb_define_attr (c, "x", 1, 0);
109 rb_define_attr (c, "y", 1, 0);
110 rb_define_attr (c, "root", 1, 0);
111 rb_define_attr (c, "window", 1, 0);
112 rb_define_attr (c, "event_window", 1, 0);
113 rb_define_attr (c, "mode", 1, 0);
114 rb_define_attr (c, "detail", 1, 0);
115 rb_define_attr (c, "time", 1, 0);
117 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
118 rb_iv_set (self, "@x", INT2FIX (e->x));
119 rb_iv_set (self, "@y", INT2FIX (e->y));
120 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
121 INT2FIX (e->root.y)));
122 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
123 rb_iv_set (self, "@event_window",
124 TO_ECORE_X_WINDOW (Qnil, e->event_win));
125 rb_iv_set (self, "@mode", INT2FIX (e->mode));
126 rb_iv_set (self, "@detail", INT2FIX (e->detail));
127 rb_iv_set (self, "@time", UINT2NUM (e->time));
132 static VALUE c_ev_win_focus_change_init (VALUE self, VALUE event)
134 VALUE c = CLASS_OF (self);
135 Ecore_X_Event_Window_Focus_In *e = (void *) event;
137 rb_define_attr (c, "window", 1, 0);
138 rb_define_attr (c, "mode", 1, 0);
139 rb_define_attr (c, "detail", 1, 0);
140 rb_define_attr (c, "time", 1, 0);
142 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
143 rb_iv_set (self, "@mode", INT2FIX (e->mode));
144 rb_iv_set (self, "@detail", INT2FIX (e->detail));
145 rb_iv_set (self, "@time", UINT2NUM (e->time));
150 static VALUE c_ev_win_delete_request_init (VALUE self, VALUE event)
152 VALUE c = CLASS_OF (self);
153 Ecore_X_Event_Window_Delete_Request *e = (void *) event;
155 rb_define_attr (c, "window", 1, 0);
156 rb_define_attr (c, "time", 1, 0);
158 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
159 rb_iv_set (self, "@time", UINT2NUM (e->time));
164 static VALUE c_ev_win_configure_init (VALUE self, VALUE event)
166 VALUE c = CLASS_OF (self);
167 Ecore_X_Event_Window_Configure *e = (void *) event;
169 rb_define_attr (c, "window", 1, 0);
170 rb_define_attr (c, "window_above", 1, 0);
171 rb_define_attr (c, "x", 1, 0);
172 rb_define_attr (c, "y", 1, 0);
173 rb_define_attr (c, "w", 1, 0);
174 rb_define_attr (c, "h", 1, 0);
175 rb_define_attr (c, "border", 1, 0);
176 rb_define_attr (c, "override", 1, 0);
177 rb_define_attr (c, "from_wm", 1, 0);
178 rb_define_attr (c, "time", 1, 0);
180 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
181 rb_iv_set (self, "@window_above", TO_ECORE_X_WINDOW (Qnil,
183 rb_iv_set (self, "@x", INT2FIX (e->x));
184 rb_iv_set (self, "@y", INT2FIX (e->y));
185 rb_iv_set (self, "@w", INT2FIX (e->w));
186 rb_iv_set (self, "@h", INT2FIX (e->h));
187 rb_iv_set (self, "@border", INT2FIX (e->border));
188 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
189 rb_iv_set (self, "@from_wm", e->from_wm ? Qtrue : Qfalse);
190 rb_iv_set (self, "@time", UINT2NUM (e->time));
195 static VALUE c_ev_win_visibility_change_init (VALUE self, VALUE event)
197 VALUE c = CLASS_OF (self);
198 Ecore_X_Event_Window_Visibility_Change *e = (void *) event;
200 rb_define_attr (c, "window", 1, 0);
201 rb_define_attr (c, "fully_obscured", 1, 0);
202 rb_define_attr (c, "time", 1, 0);
204 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
205 rb_iv_set (self, "@fully_obscured", e->fully_obscured ? Qtrue : Qfalse);
206 rb_iv_set (self, "@time", UINT2NUM (e->time));
211 static VALUE c_ev_win_create_init (VALUE self, VALUE event)
213 VALUE c = CLASS_OF (self);
214 Ecore_X_Event_Window_Create *e = (void *) event;
216 rb_define_attr (c, "window", 1, 0);
217 rb_define_attr (c, "override", 1, 0);
218 rb_define_attr (c, "time", 1, 0);
220 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
221 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
222 rb_iv_set (self, "@time", UINT2NUM (e->time));
227 static VALUE c_ev_win_show_request_init (VALUE self, VALUE event)
229 VALUE c = CLASS_OF (self);
230 Ecore_X_Event_Window_Show_Request *e = (void *) event;
232 rb_define_attr (c, "window", 1, 0);
233 rb_define_attr (c, "parent", 1, 0);
234 rb_define_attr (c, "time", 1, 0);
236 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
237 rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
238 rb_iv_set (self, "@time", UINT2NUM (e->time));
243 void Init_ecore_x (void)
247 rb_require ("ecore");
249 /* we need to call ecore_x_init () here, to make sure the
250 * event ids are set properly
253 ecore_x_init (getenv ("DISPLAY"));
256 mX = rb_define_module_under (mEcore, "X");
257 rb_define_module_function (mX, "default_root_window",
258 m_default_root_window_get, 0);
262 /* now create the default root window object */
263 default_root = TO_ECORE_X_WINDOW (Qnil, 0);
264 OBJ_FREEZE (default_root);
265 rb_global_variable (&default_root);
267 /* event mask values */
268 c = rb_define_class_under (mX, "EventMask", rb_cObject);
269 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
270 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
271 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
272 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
273 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
274 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
275 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
276 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
277 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
278 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
279 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
280 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
281 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
282 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
283 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
284 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
285 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
286 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
287 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
288 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
289 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
292 c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
293 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
294 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
295 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
298 c = rb_define_class_under (mX, "EventMode", rb_cObject);
299 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
300 DEF_CONST (c, ECORE_X_EVENT_MODE_, NORMAL);
301 DEF_CONST (c, ECORE_X_EVENT_MODE_, WHILE_GRABBED);
302 DEF_CONST (c, ECORE_X_EVENT_MODE_, GRAB);
303 DEF_CONST (c, ECORE_X_EVENT_MODE_, UNGRAB);
306 c = rb_define_class_under (mX, "EventDetail", rb_cObject);
307 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
308 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, ANCESTOR);
309 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, VIRTUAL);
310 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, INFERIOR);
311 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR);
312 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR_VIRTUAL);
313 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER);
314 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER_ROOT);
315 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, DETAIL_NONE);
318 c = rb_define_class_under (mX, "Modifier", rb_cObject);
319 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
320 DEF_CONST (c, ECORE_X_MODIFIER_, SHIFT);
321 DEF_CONST (c, ECORE_X_MODIFIER_, CTRL);
322 DEF_CONST (c, ECORE_X_MODIFIER_, ALT);
323 DEF_CONST (c, ECORE_X_MODIFIER_, WIN);
326 ADD_EVENT (mX, ECORE_X_EVENT_, KEY_DOWN, "KeyDown", c);
327 rb_define_private_method (c, "initialize",
328 c_ev_key_down_init, 1);
330 ADD_EVENT (mX, ECORE_X_EVENT_, KEY_UP, "KeyUp", c);
331 rb_define_private_method (c, "initialize",
332 c_ev_key_down_init, 1);
334 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_MOVE, "MouseMove", c);
335 rb_define_private_method (c, "initialize",
336 c_ev_mouse_move_init, 1);
338 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_IN, "MouseIn", c);
339 rb_define_private_method (c, "initialize",
340 c_ev_mouse_in_init, 1);
342 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_OUT, "MouseOut", c);
343 rb_define_private_method (c, "initialize",
344 c_ev_mouse_in_init, 1);
346 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
348 rb_define_private_method (c, "initialize",
349 c_ev_win_focus_change_init, 1);
351 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
352 "WindowFocusOut", c);
353 rb_define_private_method (c, "initialize",
354 c_ev_win_focus_change_init, 1);
356 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
357 "WindowDeleteRequest", c);
358 rb_define_private_method (c, "initialize",
359 c_ev_win_delete_request_init, 1);
361 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
362 "WindowConfigureRequest", c);
363 rb_define_private_method (c, "initialize",
364 c_ev_win_delete_request_init, 1);
366 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
367 "WindowConfigure", c);
368 rb_define_private_method (c, "initialize",
369 c_ev_win_configure_init, 1);
371 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
372 "WindowVisibilityChange", c);
373 rb_define_private_method (c, "initialize",
374 c_ev_win_visibility_change_init, 1);
376 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CREATE, "WindowCreate", c);
377 rb_define_private_method (c, "initialize",
378 c_ev_win_create_init, 1);
380 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DESTROY, "WindowDestroy", c);
381 rb_define_private_method (c, "initialize",
382 c_ev_win_delete_request_init, 1);
384 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
385 rb_define_private_method (c, "initialize",
386 c_ev_win_delete_request_init, 1);
388 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
389 rb_define_private_method (c, "initialize",
390 c_ev_win_delete_request_init, 1);
392 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
393 "WindowShowRequest", c);
394 rb_define_private_method (c, "initialize",
395 c_ev_win_show_request_init, 1);