2 * $Id: rb_ecore_x.c 83 2004-08-21 19:55:35Z 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_win_focus_change_init (VALUE self, VALUE event)
50 VALUE c = CLASS_OF (self);
51 Ecore_X_Event_Window_Focus_In *e = (void *) event;
53 rb_define_attr (c, "window", 1, 0);
54 rb_define_attr (c, "mode", 1, 0);
55 rb_define_attr (c, "detail", 1, 0);
56 rb_define_attr (c, "time", 1, 0);
58 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
59 rb_iv_set (self, "@mode", INT2FIX (e->mode));
60 rb_iv_set (self, "@detail", INT2FIX (e->detail));
61 rb_iv_set (self, "@time", UINT2NUM (e->time));
66 static VALUE c_ev_win_delete_request_init (VALUE self, VALUE event)
68 VALUE c = CLASS_OF (self);
69 Ecore_X_Event_Window_Delete_Request *e = (void *) event;
71 rb_define_attr (c, "window", 1, 0);
72 rb_define_attr (c, "time", 1, 0);
74 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
75 rb_iv_set (self, "@time", UINT2NUM (e->time));
80 static VALUE c_ev_win_configure_init (VALUE self, VALUE event)
82 VALUE c = CLASS_OF (self);
83 Ecore_X_Event_Window_Configure *e = (void *) event;
85 rb_define_attr (c, "window", 1, 0);
86 rb_define_attr (c, "window_above", 1, 0);
87 rb_define_attr (c, "x", 1, 0);
88 rb_define_attr (c, "y", 1, 0);
89 rb_define_attr (c, "w", 1, 0);
90 rb_define_attr (c, "h", 1, 0);
91 rb_define_attr (c, "border", 1, 0);
92 rb_define_attr (c, "override", 1, 0);
93 rb_define_attr (c, "from_wm", 1, 0);
94 rb_define_attr (c, "time", 1, 0);
96 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
97 rb_iv_set (self, "@window_above", TO_ECORE_X_WINDOW (Qnil,
99 rb_iv_set (self, "@x", INT2FIX (e->x));
100 rb_iv_set (self, "@y", INT2FIX (e->y));
101 rb_iv_set (self, "@w", INT2FIX (e->w));
102 rb_iv_set (self, "@h", INT2FIX (e->h));
103 rb_iv_set (self, "@border", INT2FIX (e->border));
104 rb_iv_set (self, "@override", e->override ? Qtrue : Qfalse);
105 rb_iv_set (self, "@from_wm", e->from_wm ? Qtrue : Qfalse);
106 rb_iv_set (self, "@time", UINT2NUM (e->time));
111 static VALUE c_ev_win_visibility_change_init (VALUE self, VALUE event)
113 VALUE c = CLASS_OF (self);
114 Ecore_X_Event_Window_Visibility_Change *e = (void *) event;
116 rb_define_attr (c, "window", 1, 0);
117 rb_define_attr (c, "fully_obscured", 1, 0);
118 rb_define_attr (c, "time", 1, 0);
120 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
121 rb_iv_set (self, "@fully_obscured", e->fully_obscured ? Qtrue : Qfalse);
122 rb_iv_set (self, "@time", UINT2NUM (e->time));
127 static VALUE c_ev_win_show_request_init (VALUE self, VALUE event)
129 VALUE c = CLASS_OF (self);
130 Ecore_X_Event_Window_Show_Request *e = (void *) event;
132 rb_define_attr (c, "window", 1, 0);
133 rb_define_attr (c, "parent", 1, 0);
134 rb_define_attr (c, "time", 1, 0);
136 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
137 rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
138 rb_iv_set (self, "@time", UINT2NUM (e->time));
143 void Init_ecore_x (void)
147 rb_require ("ecore");
149 /* we need to call ecore_x_init () here, to make sure the
150 * event ids are set properly
153 ecore_x_init (getenv ("DISPLAY"));
156 mX = rb_define_module_under (mEcore, "X");
157 rb_define_module_function (mX, "default_root_window",
158 m_default_root_window_get, 0);
162 /* now create the default root window object */
163 default_root = TO_ECORE_X_WINDOW (Qnil, 0);
164 OBJ_FREEZE (default_root);
165 rb_global_variable (&default_root);
167 /* event mask values */
168 c = rb_define_class_under (mX, "EventMask", rb_cObject);
169 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
170 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
171 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
172 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
173 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
174 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
175 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
176 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
177 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
178 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
179 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
180 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
181 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
182 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
183 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
184 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
185 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
186 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
187 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
188 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
189 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
192 c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
193 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
194 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
195 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
198 c = rb_define_class_under (mX, "EventMode", rb_cObject);
199 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
200 DEF_CONST (c, ECORE_X_EVENT_MODE_, NORMAL);
201 DEF_CONST (c, ECORE_X_EVENT_MODE_, WHILE_GRABBED);
202 DEF_CONST (c, ECORE_X_EVENT_MODE_, GRAB);
203 DEF_CONST (c, ECORE_X_EVENT_MODE_, UNGRAB);
206 c = rb_define_class_under (mX, "EventDetails", rb_cObject);
207 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
208 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, ANCESTOR);
209 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, VIRTUAL);
210 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, INFERIOR);
211 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR);
212 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, NON_LINEAR_VIRTUAL);
213 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER);
214 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, POINTER_ROOT);
215 DEF_CONST (c, ECORE_X_EVENT_DETAIL_, DETAIL_NONE);
218 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
220 rb_define_private_method (c, "initialize",
221 c_ev_win_focus_change_init, 1);
223 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
224 "WindowFocusOut", c);
225 rb_define_private_method (c, "initialize",
226 c_ev_win_focus_change_init, 1);
228 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
229 "WindowDeleteRequest", c);
230 rb_define_private_method (c, "initialize",
231 c_ev_win_delete_request_init, 1);
233 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
234 "WindowConfigureRequest", c);
235 rb_define_private_method (c, "initialize",
236 c_ev_win_delete_request_init, 1);
238 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
239 "WindowConfigure", c);
240 rb_define_private_method (c, "initialize",
241 c_ev_win_configure_init, 1);
243 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
244 "WindowVisibilityChange", c);
245 rb_define_private_method (c, "initialize",
246 c_ev_win_visibility_change_init, 1);
248 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
249 rb_define_private_method (c, "initialize",
250 c_ev_win_delete_request_init, 1);
252 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
253 rb_define_private_method (c, "initialize",
254 c_ev_win_delete_request_init, 1);
256 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
257 "WindowShowRequest", c);
258 rb_define_private_method (c, "initialize",
259 c_ev_win_show_request_init, 1);