2 * $Id: rb_ecore_x.c 80 2004-08-21 09:41:43Z 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_show_req_init (VALUE self, VALUE event)
50 Ecore_X_Event_Window_Show_Request *e = (void *) event;
52 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
53 rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
54 rb_iv_set (self, "@time", UINT2NUM (e->time));
59 void Init_ecore_x (void)
65 /* we need to call ecore_x_init () here, to make sure the
66 * event ids are set properly
69 ecore_x_init (getenv ("DISPLAY"));
72 mX = rb_define_module_under (mEcore, "X");
73 rb_define_module_function (mX, "default_root_window",
74 m_default_root_window_get, 0);
78 /* now create the default root window object */
79 default_root = TO_ECORE_X_WINDOW (Qnil, 0);
80 OBJ_FREEZE (default_root);
81 rb_global_variable (&default_root);
83 /* event mask values */
84 c = rb_define_class_under (mX, "EventMask", rb_cObject);
85 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
86 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
87 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
88 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
89 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
90 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
91 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
92 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
93 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
94 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
95 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
96 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
97 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
98 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
99 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
100 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
101 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
102 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
103 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
104 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
105 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
108 c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
109 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
110 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
111 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
114 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
116 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
118 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
119 "WindowFocusOut", c);
120 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
122 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
123 "WindowDeleteRequest", c);
124 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
126 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
127 "WindowConfigureRequest", c);
128 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
130 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
131 "WindowConfigure", c);
132 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
134 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
135 "WindowVisibilityChange", c);
136 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
138 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
139 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
141 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
142 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
144 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
145 "WindowShowRequest", c);
146 rb_define_private_method (c, "initialize",
147 c_ev_win_show_req_init, 1);
149 rb_define_attr (c, "window", 1, 0);
150 rb_define_attr (c, "parent", 1, 0);
151 rb_define_attr (c, "time", 1, 0);