When we create the root window object, just pass 0 for the window id.
[ruby-ecore.git] / src / ecore_x / rb_ecore_x.c
1 /*
2  * $Id: rb_ecore_x.c 80 2004-08-21 09:41:43Z tilman $
3  *
4  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <ruby.h>
22
23 #include <Ecore.h>
24 #include <Ecore_X.h>
25
26 #include "../ecore/rb_ecore.h"
27 #include "../ecore/rb_event_handler.h"
28 #include "rb_ecore_x.h"
29 #include "rb_window.h"
30
31 #define DEF_CONST(mod, prefix, name) \
32         rb_define_const ((mod), #name, \
33                          INT2FIX (prefix##name));
34
35 static VALUE default_root;
36
37 static void at_exit ()
38 {
39         ecore_x_shutdown ();
40         ecore_shutdown ();
41 }
42
43 static VALUE m_default_root_window_get (VALUE self)
44 {
45         return default_root;
46 }
47
48 static VALUE c_ev_win_show_req_init (VALUE self, VALUE event)
49 {
50         Ecore_X_Event_Window_Show_Request *e = (void *) event;
51
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));
55
56         return self;
57 }
58
59 void Init_ecore_x (void)
60 {
61         VALUE c;
62
63         rb_require ("ecore");
64
65         /* we need to call ecore_x_init () here, to make sure the
66          * event ids are set properly
67          */
68         ecore_init ();
69         ecore_x_init (getenv ("DISPLAY"));
70         atexit (at_exit);
71
72         mX = rb_define_module_under (mEcore, "X");
73         rb_define_module_function (mX, "default_root_window",
74                                    m_default_root_window_get, 0);
75
76         Init_Window ();
77
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);
82
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);
106
107         /* wm protocols */
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);
112
113         /* events */
114         ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
115                    "WindowFocusIn", c);
116         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
117
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);
121
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);
125
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);
129
130         ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
131                    "WindowConfigure", c);
132         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
133
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);
137
138         ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
139         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
140
141         ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
142         rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
143
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);
148
149         rb_define_attr (c, "window", 1, 0);
150         rb_define_attr (c, "parent", 1, 0);
151         rb_define_attr (c, "time", 1, 0);
152 }