2 * $Id: rb_ecore_x.c 89 2004-08-22 15:12:39Z 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", rb_str_new2 (e->keyname));
62 rb_iv_set (self, "@keysymbol", rb_str_new2 (e->keysymbol));
63 rb_iv_set (self, "@key_compose", rb_str_new2 (e->key_compose));
64 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
65 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
66 rb_iv_set (self, "@event_window",
67 TO_ECORE_X_WINDOW (Qnil, e->event_win));
68 rb_iv_set (self, "@time", UINT2NUM (e->time));
73 static VALUE c_ev_mouse_move_init (VALUE self, VALUE event)
75 VALUE c = CLASS_OF (self);
76 Ecore_X_Event_Mouse_Move *e = (void *) event;
78 rb_define_attr (c, "modifiers", 1, 0);
79 rb_define_attr (c, "x", 1, 0);
80 rb_define_attr (c, "y", 1, 0);
81 rb_define_attr (c, "root", 1, 0);
82 rb_define_attr (c, "window", 1, 0);
83 rb_define_attr (c, "event_window", 1, 0);
84 rb_define_attr (c, "time", 1, 0);
86 rb_iv_set (self, "@modifiers", INT2FIX (e->modifiers));
87 rb_iv_set (self, "@x", INT2FIX (e->x));
88 rb_iv_set (self, "@y", INT2FIX (e->y));
89 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
90 INT2FIX (e->root.y)));
91 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
92 rb_iv_set (self, "@event_window",
93 TO_ECORE_X_WINDOW (Qnil, e->event_win));
94 rb_iv_set (self, "@time", UINT2NUM (e->time));
99 static VALUE c_ev_mouse_in_init (VALUE self, VALUE event)
101 VALUE c = CLASS_OF (self);
102 Ecore_X_Event_Mouse_In *e = (void *) event;
104 rb_define_attr (c, "modifiers", 1, 0);
105 rb_define_attr (c, "x", 1, 0);
106 rb_define_attr (c, "y", 1, 0);
107 rb_define_attr (c, "root", 1, 0);
108 rb_define_attr (c, "window", 1, 0);
109 rb_define_attr (c, "event_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, "@modifiers", INT2FIX (e->modifiers));
115 rb_iv_set (self, "@x", INT2FIX (e->x));
116 rb_iv_set (self, "@y", INT2FIX (e->y));
117 rb_iv_set (self, "@root", rb_ary_new3 (2, INT2FIX (e->root.x),
118 INT2FIX (e->root.y)));
119 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
120 rb_iv_set (self, "@event_window",
121 TO_ECORE_X_WINDOW (Qnil, e->event_win));
122 rb_iv_set (self, "@mode", INT2FIX (e->mode));
123 rb_iv_set (self, "@detail", INT2FIX (e->detail));
124 rb_iv_set (self, "@time", UINT2NUM (e->time));
129 static VALUE c_ev_win_focus_change_init (VALUE self, VALUE event)
131 VALUE c = CLASS_OF (self);
132 Ecore_X_Event_Window_Focus_In *e = (void *) event;
134 rb_define_attr (c, "window", 1, 0);
135 rb_define_attr (c, "mode", 1, 0);
136 rb_define_attr (c, "detail", 1, 0);
137 rb_define_attr (c, "time", 1, 0);
139 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
140 rb_iv_set (self, "@mode", INT2FIX (e->mode));
141 rb_iv_set (self, "@detail", INT2FIX (e->detail));
142 rb_iv_set (self, "@time", UINT2NUM (e->time));
147 static VALUE c_ev_win_delete_request_init (VALUE self, VALUE event)
149 VALUE c = CLASS_OF (self);
150 Ecore_X_Event_Window_Delete_Request *e = (void *) event;
152 rb_define_attr (c, "window", 1, 0);
153 rb_define_attr (c, "time", 1, 0);
155 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
156 rb_iv_set (self, "@time", UINT2NUM (e->time));
161 static VALUE c_ev_win_configure_init (VALUE self, VALUE event)
163 VALUE c = CLASS_OF (self);
164 Ecore_X_Event_Window_Configure *e = (void *) event;
166 rb_define_attr (c, "window", 1, 0);
167 rb_define_attr (c, "window_above", 1, 0);
168 rb_define_attr (c, "x", 1, 0);
169 rb_define_attr (c, "y", 1, 0);
170 rb_define_attr (c, "w", 1, 0);
171 rb_define_attr (c, "h", 1, 0);
172 rb_define_attr (c, "border", 1, 0);
173 rb_define_attr (c, "override", 1, 0);
174 rb_define_attr (c, "from_wm", 1, 0);
175 rb_define_attr (c, "time", 1, 0);
177 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
178 rb_iv_set (self, "@window_above", TO_ECORE_X_WINDOW (Qnil,
180 rb_iv_set (self, "@x", INT2FIX (e->x));
181 rb_iv_set (self, "@y", INT2FIX (e->y));
182 rb_iv_set (self, "@w", INT2FIX (e->w));
183 rb_iv_set (self, "@h", INT2FIX (e->h));
184 rb_iv_set (self, "@border", INT2FIX (e->border));
185 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
186 rb_iv_set (self, "@from_wm", e->from_wm ? Qtrue : Qfalse);
187 rb_iv_set (self, "@time", UINT2NUM (e->time));
192 static VALUE c_ev_win_visibility_change_init (VALUE self, VALUE event)
194 VALUE c = CLASS_OF (self);
195 Ecore_X_Event_Window_Visibility_Change *e = (void *) event;
197 rb_define_attr (c, "window", 1, 0);
198 rb_define_attr (c, "fully_obscured", 1, 0);
199 rb_define_attr (c, "time", 1, 0);
201 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
202 rb_iv_set (self, "@fully_obscured", e->fully_obscured ? Qtrue : Qfalse);
203 rb_iv_set (self, "@time", UINT2NUM (e->time));
208 static VALUE c_ev_win_create_init (VALUE self, VALUE event)
210 VALUE c = CLASS_OF (self);
211 Ecore_X_Event_Window_Create *e = (void *) event;
213 rb_define_attr (c, "window", 1, 0);
214 rb_define_attr (c, "override", 1, 0);
215 rb_define_attr (c, "time", 1, 0);
217 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
218 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
219 rb_iv_set (self, "@time", UINT2NUM (e->time));
224 static VALUE c_ev_win_show_request_init (VALUE self, VALUE event)
226 VALUE c = CLASS_OF (self);
227 Ecore_X_Event_Window_Show_Request *e = (void *) event;
229 rb_define_attr (c, "window", 1, 0);
230 rb_define_attr (c, "parent", 1, 0);
231 rb_define_attr (c, "time", 1, 0);
233 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
234 rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
235 rb_iv_set (self, "@time", UINT2NUM (e->time));
240 void Init_ecore_x (void)
244 rb_require ("ecore");
246 /* we need to call ecore_x_init () here, to make sure the
247 * event ids are set properly
250 ecore_x_init (getenv ("DISPLAY"));
253 mX = rb_define_module_under (mEcore, "X");
254 rb_define_module_function (mX, "default_root_window",
255 m_default_root_window_get, 0);
259 /* now create the default root window object */
260 default_root = TO_ECORE_X_WINDOW (Qnil, 0);
261 OBJ_FREEZE (default_root);
262 rb_global_variable (&default_root);
264 /* event mask values */
265 c = rb_define_class_under (mX, "EventMask", rb_cObject);
266 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
267 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
268 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
269 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
270 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
271 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
272 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
273 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
274 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
275 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
276 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
277 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
278 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
279 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
280 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
281 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
282 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
283 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
284 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
285 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
286 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
289 c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
290 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
291 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
292 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
295 c = rb_define_class_under (mX, "EventMode", rb_cObject);
296 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
297 DEF_CONST (c, ECORE_X_EVENT_MODE_, NORMAL);
298 DEF_CONST (c, ECORE_X_EVENT_MODE_, WHILE_GRABBED);
299 DEF_CONST (c, ECORE_X_EVENT_MODE_, GRAB);
300 DEF_CONST (c, ECORE_X_EVENT_MODE_, UNGRAB);
303 c = rb_define_class_under (mX, "EventDetails", rb_cObject);
304 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
305 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, ANCESTOR);
306 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, VIRTUAL);
307 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, INFERIOR);
308 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR);
309 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR_VIRTUAL);
310 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER);
311 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER_ROOT);
312 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, DETAIL_NONE);
315 ADD_EVENT (mX, ECORE_X_EVENT_, KEY_DOWN, "KeyDown", c);
316 rb_define_private_method (c, "initialize",
317 c_ev_key_down_init, 1);
319 ADD_EVENT (mX, ECORE_X_EVENT_, KEY_UP, "KeyUp", c);
320 rb_define_private_method (c, "initialize",
321 c_ev_key_down_init, 1);
323 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_MOVE, "MouseMove", c);
324 rb_define_private_method (c, "initialize",
325 c_ev_mouse_move_init, 1);
327 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_IN, "MouseIn", c);
328 rb_define_private_method (c, "initialize",
329 c_ev_mouse_in_init, 1);
331 ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_OUT, "MouseOut", c);
332 rb_define_private_method (c, "initialize",
333 c_ev_mouse_in_init, 1);
335 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
337 rb_define_private_method (c, "initialize",
338 c_ev_win_focus_change_init, 1);
340 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
341 "WindowFocusOut", c);
342 rb_define_private_method (c, "initialize",
343 c_ev_win_focus_change_init, 1);
345 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
346 "WindowDeleteRequest", c);
347 rb_define_private_method (c, "initialize",
348 c_ev_win_delete_request_init, 1);
350 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
351 "WindowConfigureRequest", c);
352 rb_define_private_method (c, "initialize",
353 c_ev_win_delete_request_init, 1);
355 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
356 "WindowConfigure", c);
357 rb_define_private_method (c, "initialize",
358 c_ev_win_configure_init, 1);
360 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
361 "WindowVisibilityChange", c);
362 rb_define_private_method (c, "initialize",
363 c_ev_win_visibility_change_init, 1);
365 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CREATE, "WindowCreate", c);
366 rb_define_private_method (c, "initialize",
367 c_ev_win_create_init, 1);
369 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DESTROY, "WindowDestroy", c);
370 rb_define_private_method (c, "initialize",
371 c_ev_win_delete_request_init, 1);
373 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
374 rb_define_private_method (c, "initialize",
375 c_ev_win_delete_request_init, 1);
377 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
378 rb_define_private_method (c, "initialize",
379 c_ev_win_delete_request_init, 1);
381 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
382 "WindowShowRequest", c);
383 rb_define_private_method (c, "initialize",
384 c_ev_win_show_request_init, 1);