2 * $Id: rb_ecore_x.c 77 2004-08-19 17:39:29Z 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_win_show_req_init (VALUE self, VALUE event)
51 Ecore_X_Event_Window_Show_Request *e = (void *) event;
53 rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
54 rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
55 rb_iv_set (self, "@time", UINT2NUM (e->time));
60 void Init_ecore_x (void)
67 /* we need to call ecore_x_init () here, to make sure the
68 * event ids are set properly
71 ecore_x_init (getenv ("DISPLAY"));
74 mX = rb_define_module_under (mEcore, "X");
75 rb_define_module_function (mX, "default_root_window",
76 m_default_root_window_get, 0);
80 /* now create the default root window object */
81 w = DefaultRootWindow (ecore_x_display_get ());
82 default_root = TO_ECORE_X_WINDOW (Qnil, w);
83 OBJ_FREEZE (default_root);
84 rb_global_variable (&default_root);
86 /* event mask values */
87 c = rb_define_class_under (mX, "EventMask", rb_cObject);
88 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
89 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
90 DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
91 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
92 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
93 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
94 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
95 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
96 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
97 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
98 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
99 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
100 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
101 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
102 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
103 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
104 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
105 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
106 DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
107 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
108 DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
111 c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
112 rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
113 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
114 DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
117 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
119 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
121 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
122 "WindowFocusOut", c);
123 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
125 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
126 "WindowDeleteRequest", c);
127 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
129 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
130 "WindowConfigureRequest", c);
131 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
133 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
134 "WindowConfigure", c);
135 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
137 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
138 "WindowVisibilityChange", c);
139 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
141 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
142 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
144 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
145 rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
147 ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
148 "WindowShowRequest", c);
149 rb_define_private_method (c, "initialize",
150 c_ev_win_show_req_init, 1);
152 rb_define_attr (c, "window", 1, 0);
153 rb_define_attr (c, "parent", 1, 0);
154 rb_define_attr (c, "time", 1, 0);