2 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "../ecore/rb_ecore.h"
26 #include "rb_ecore_x.h"
27 #include "rb_window.h"
28 #include "rb_cursor.h"
32 static void c_mark (RbWindow *w)
34 if (!NIL_P (w->parent))
35 rb_gc_mark (w->parent);
38 static void c_free (RbWindow *w)
41 ecore_x_window_del (w->real);
46 VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w)
49 RbWindow *window = NULL;
51 self = Data_Make_Struct (cWindow, RbWindow, c_mark, free, window);
54 window->parent = parent;
56 rb_obj_call_init (self, 0, NULL);
61 static VALUE c_alloc (VALUE klass)
63 RbWindow *window = NULL;
65 return Data_Make_Struct (cWindow, RbWindow, c_mark, c_free, window);
68 static VALUE c_init (int argc, VALUE *argv, VALUE self)
70 VALUE parent, geom[4];
72 int i, igeom[4] = {0, 0, 0, 0};
73 Ecore_X_Window pwin = 0;
75 GET_OBJ (self, RbWindow, win);
77 rb_scan_args (argc, argv, "05",
78 &parent, &geom[0], &geom[1], &geom[2], &geom[3]);
80 if (!NIL_P (parent)) {
81 CHECK_CLASS (parent, cWindow);
82 Data_Get_Struct (parent, RbWindow, p);
86 for (i = 0; i < 4; i++)
87 if (!NIL_P (geom[i])) {
88 Check_Type (geom[i], T_FIXNUM);
89 igeom[i] = FIX2INT (geom[i]);
92 win->real = ecore_x_window_new (pwin, igeom[0], igeom[1],
96 rb_iv_set (self, "@cursor", Qnil);
101 static VALUE c_inspect (VALUE self)
105 GET_OBJ (self, RbWindow, win);
107 snprintf (buf, sizeof (buf),
108 "#<%s:%p id=%u>", rb_obj_classname (self),
109 (void *) self, win->real);
111 return rb_str_new2 (buf);
114 static VALUE c_equal_value (VALUE self, VALUE other)
116 GET_OBJ (self, RbWindow, w1);
118 CHECK_CLASS (other, cWindow);
119 GET_OBJ (other, RbWindow, w2);
121 return w1->real == w2->real ? Qtrue : Qfalse;
124 static VALUE c_configure (int argc, VALUE *argv, VALUE self)
126 VALUE mask, geom[4], border, sibling, stackm;
127 RbWindow *sibwin = NULL;
130 GET_OBJ (self, RbWindow, win);
132 rb_scan_args (argc, argv, "17", &mask,
133 &geom[0], &geom[1], &geom[2], &geom[3],
134 &border, &sibling, &stackm);
136 Check_Type (mask, T_FIXNUM);
138 for (i = 0; i < 4; i++)
139 if (!NIL_P (geom[i]))
140 Check_Type (geom[i], T_FIXNUM);
143 Check_Type (border, T_FIXNUM);
145 if (!NIL_P (sibling)) {
146 CHECK_CLASS (sibling, cWindow);
147 Data_Get_Struct (sibling, RbWindow, sibwin);
151 Check_Type (stackm, T_FIXNUM);
153 ecore_x_window_configure (win->real, FIX2INT (mask),
154 NIL_P (geom[0]) ? 0 : FIX2INT (geom[0]),
155 NIL_P (geom[1]) ? 0 : FIX2INT (geom[1]),
156 NIL_P (geom[2]) ? 0 : FIX2INT (geom[2]),
157 NIL_P (geom[3]) ? 0 : FIX2INT (geom[3]),
158 NIL_P (border) ? 0 : FIX2INT (border),
159 sibwin ? sibwin->real : 0,
160 NIL_P (stackm) ? 0 : FIX2INT (stackm));
165 static VALUE c_show (VALUE self)
167 GET_OBJ (self, RbWindow, win);
169 ecore_x_window_show (win->real);
174 static VALUE c_hide (VALUE self)
176 GET_OBJ (self, RbWindow, win);
178 ecore_x_window_hide (win->real);
183 static VALUE c_visible_get (VALUE self)
185 GET_OBJ (self, RbWindow, win);
187 return ecore_x_window_visible_get (win->real) ? Qtrue : Qfalse;
190 static VALUE c_delete (VALUE self)
192 GET_OBJ (self, RbWindow, win);
194 ecore_x_window_del (win->real);
199 static VALUE c_send_delete_request (VALUE self)
201 GET_OBJ (self, RbWindow, win);
203 ecore_x_window_delete_request_send (win->real);
208 static VALUE c_raise (VALUE self)
210 GET_OBJ (self, RbWindow, win);
212 ecore_x_window_raise (win->real);
217 static VALUE c_lower (VALUE self)
219 GET_OBJ (self, RbWindow, win);
221 ecore_x_window_lower (win->real);
226 static VALUE c_reparent (VALUE self, VALUE other, VALUE x, VALUE y)
228 GET_OBJ (self, RbWindow, win);
230 CHECK_CLASS (other, cWindow);
231 GET_OBJ (other, RbWindow, o);
233 Check_Type (x, T_FIXNUM);
234 Check_Type (y, T_FIXNUM);
236 ecore_x_window_reparent (win->real, o->real,
237 FIX2INT (x), FIX2INT (y));
242 static VALUE c_focus (VALUE self)
244 GET_OBJ (self, RbWindow, win);
246 ecore_x_window_focus (win->real);
251 static VALUE c_move (VALUE self, VALUE x, VALUE y)
253 GET_OBJ (self, RbWindow, win);
255 Check_Type (x, T_FIXNUM);
256 Check_Type (y, T_FIXNUM);
258 ecore_x_window_move (win->real, FIX2INT (x), FIX2INT (y));
263 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
265 GET_OBJ (self, RbWindow, win);
267 Check_Type (w, T_FIXNUM);
268 Check_Type (h, T_FIXNUM);
270 ecore_x_window_resize (win->real, FIX2INT (w), FIX2INT (h));
275 static VALUE c_size_get (VALUE self)
279 GET_OBJ (self, RbWindow, win);
281 ecore_x_window_size_get (win->real, &w, &h);
283 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
286 static VALUE c_geometry_get (VALUE self)
288 int x = 0, y = 0, w = 0, h = 0;
290 GET_OBJ (self, RbWindow, win);
292 ecore_x_window_geometry_get (win->real, &x, &y, &w, &h);
294 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
295 INT2FIX (w), INT2FIX (h));
298 static VALUE c_border_width_get (VALUE self)
300 GET_OBJ (self, RbWindow, win);
302 return INT2FIX (ecore_x_window_border_width_get (win->real));
305 static VALUE c_border_width_set (VALUE self, VALUE val)
307 GET_OBJ (self, RbWindow, win);
309 Check_Type (val, T_FIXNUM);
311 ecore_x_window_border_width_set (win->real, FIX2INT (val));
316 static VALUE c_depth_get (VALUE self)
318 GET_OBJ (self, RbWindow, win);
320 return INT2FIX (ecore_x_window_depth_get (win->real));
323 static VALUE c_parent_get (VALUE self)
325 GET_OBJ (self, RbWindow, win);
327 return TO_ECORE_X_WINDOW (Qnil,
328 ecore_x_window_parent_get (win->real));
332 static VALUE c_title_get (VALUE self)
336 GET_OBJ (self, RbWindow, win);
338 s = ecore_x_window_prop_title_get (win->real);
340 return s ? rb_str_new2 (s) : Qnil;
343 static VALUE c_title_set (VALUE self, VALUE val)
345 GET_OBJ (self, RbWindow, win);
347 Check_Type (val, T_STRING);
349 ecore_x_window_prop_title_set (win->real, StringValuePtr (val));
355 static VALUE c_set_event_mask (VALUE self, VALUE val)
357 GET_OBJ (self, RbWindow, win);
359 Check_Type (val, T_FIXNUM);
361 ecore_x_event_mask_set (win->real, FIX2INT (val));
366 static VALUE c_unset_event_mask (VALUE self, VALUE val)
368 GET_OBJ (self, RbWindow, win);
370 Check_Type (val, T_FIXNUM);
372 ecore_x_event_mask_unset (win->real, FIX2INT (val));
378 static VALUE c_set_protocol (VALUE self, VALUE proto, VALUE on)
380 GET_OBJ (self, RbWindow, win);
382 Check_Type (proto, T_FIXNUM);
385 ecore_x_window_prop_protocol_set (win->real, FIX2INT (proto),
392 static VALUE c_get_protocol (VALUE self, VALUE proto)
396 GET_OBJ (self, RbWindow, win);
398 s = ecore_x_window_prop_protocol_isset (win->real, FIX2INT (proto));
400 return s ? Qtrue : Qfalse;
404 static VALUE c_sticky_get (VALUE self)
408 GET_OBJ (self, RbWindow, win);
410 s = ecore_x_window_prop_state_isset (win->real,
411 ECORE_X_WINDOW_STATE_STICKY);
413 return s ? Qtrue : Qfalse;
416 static VALUE c_sticky_set (VALUE self, VALUE val)
418 GET_OBJ (self, RbWindow, win);
422 ecore_x_window_prop_sticky_set (win->real, val == Qtrue);
427 static VALUE c_borderless_get (VALUE self)
431 GET_OBJ (self, RbWindow, win);
433 s = ecore_x_window_prop_borderless_get (win->real);
435 return s ? Qtrue : Qfalse;
438 static VALUE c_borderless_set (VALUE self, VALUE val)
440 GET_OBJ (self, RbWindow, win);
444 ecore_x_window_prop_borderless_set (win->real, val == Qtrue);
450 static VALUE c_cursor_set (VALUE self, VALUE val)
452 GET_OBJ (self, RbWindow, win);
454 CHECK_CLASS (val, cCursor);
455 GET_OBJ (val, RbCursor, c);
457 ecore_x_window_cursor_set (win->real, c->real);
458 rb_iv_set (self, "@cursor", val);
463 static VALUE c_manage (VALUE self)
465 GET_OBJ (self, RbWindow, win);
467 ecore_x_window_manage (win->real);
472 static VALUE c_manage_container (VALUE self)
474 GET_OBJ (self, RbWindow, win);
476 ecore_x_window_container_manage (win->real);
481 static VALUE c_manage_client (VALUE self)
483 GET_OBJ (self, RbWindow, win);
485 ecore_x_window_client_manage (win->real);
490 static VALUE c_sniff (VALUE self)
492 GET_OBJ (self, RbWindow, win);
494 ecore_x_window_sniff (win->real);
499 static VALUE c_sniff_client (VALUE self)
501 GET_OBJ (self, RbWindow, win);
503 ecore_x_window_client_sniff (win->real);
508 void Init_Window (void)
510 cWindow = rb_define_class_under (mX, "Window", rb_cObject);
512 rb_define_alloc_func (cWindow, c_alloc);
513 rb_define_method (cWindow, "initialize", c_init, -1);
514 rb_define_method (cWindow, "inspect", c_inspect, 0);
515 rb_define_method (cWindow, "eql?", c_equal_value, 1);
516 rb_define_method (cWindow, "==", c_equal_value, 1);
517 rb_define_method (cWindow, "===", c_equal_value, 1);
518 rb_define_method (cWindow, "configure", c_configure, -1);
519 rb_define_method (cWindow, "show", c_show, 0);
520 rb_define_method (cWindow, "hide", c_hide, 0);
521 rb_define_method (cWindow, "visible?", c_visible_get, 0);
522 rb_define_method (cWindow, "delete", c_delete, 0);
523 rb_define_method (cWindow, "send_delete_request",
524 c_send_delete_request, 0);
525 rb_define_method (cWindow, "raise", c_raise, 0);
526 rb_define_method (cWindow, "lower", c_lower, 0);
527 rb_define_method (cWindow, "reparent", c_reparent, 3);
528 rb_define_method (cWindow, "focus", c_focus, 0);
529 rb_define_method (cWindow, "move", c_move, 2);
530 rb_define_method (cWindow, "resize", c_resize, 2);
531 rb_define_method (cWindow, "size", c_size_get, 0);
532 rb_define_method (cWindow, "geometry", c_geometry_get, 0);
533 rb_define_method (cWindow, "border_width", c_border_width_get, 0);
534 rb_define_method (cWindow, "border_width=", c_border_width_set, 1);
535 rb_define_method (cWindow, "depth", c_depth_get, 0);
536 rb_define_method (cWindow, "parent", c_parent_get, 0);
538 rb_define_method (cWindow, "title", c_title_get, 0);
539 rb_define_method (cWindow, "title=", c_title_set, 1);
541 rb_define_method (cWindow, "set_event_mask", c_set_event_mask, 1);
542 rb_define_method (cWindow, "unset_event_mask",
543 c_unset_event_mask, 1);
545 rb_define_method (cWindow, "set_protocol", c_set_protocol, 2);
547 rb_define_method (cWindow, "get_protocol", c_get_protocol, 1);
549 rb_define_method (cWindow, "sticky?", c_sticky_get, 0);
550 rb_define_method (cWindow, "sticky=", c_sticky_set, 1);
551 rb_define_method (cWindow, "borderless?", c_borderless_get, 0);
552 rb_define_method (cWindow, "borderless=", c_borderless_set, 1);
554 rb_define_method (cWindow, "cursor=", c_cursor_set, 1);
555 rb_define_method (cWindow, "manage", c_manage, 0);
556 rb_define_method (cWindow, "manage_container", c_manage_container, 0);
557 rb_define_method (cWindow, "manage_client", c_manage_client, 0);
558 rb_define_method (cWindow, "sniff", c_sniff, 0);
559 rb_define_method (cWindow, "sniff_client", c_sniff_client, 0);
561 rb_define_attr (cWindow, "cursor", 1, 0);