/*
- * $Id: rb_ecore_x.c 53 2004-08-07 11:22:00Z tilman $
+ * $Id: rb_ecore_x.c 77 2004-08-19 17:39:29Z tilman $
*
- * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <ruby.h>
+#include <Ecore.h>
#include <Ecore_X.h>
+#include <X11/Xlib.h>
#include "../ecore/rb_ecore.h"
+#include "../ecore/rb_event_handler.h"
#include "rb_ecore_x.h"
#include "rb_window.h"
+#define DEF_CONST(mod, prefix, name) \
+ rb_define_const ((mod), #name, \
+ INT2FIX (prefix##name));
+
+static VALUE default_root;
+
+static void at_exit ()
+{
+ ecore_x_shutdown ();
+ ecore_shutdown ();
+}
+
+static VALUE m_default_root_window_get (VALUE self)
+{
+ return default_root;
+}
+
+static VALUE c_ev_win_show_req_init (VALUE self, VALUE event)
+{
+ Ecore_X_Event_Window_Show_Request *e = (void *) event;
+
+ rb_iv_set (self, "@window", TO_ECORE_X_WINDOW (Qnil, e->win));
+ rb_iv_set (self, "@parent", TO_ECORE_X_WINDOW (Qnil, e->parent));
+ rb_iv_set (self, "@time", UINT2NUM (e->time));
+
+ return self;
+}
+
void Init_ecore_x (void)
{
+ Ecore_X_Window w;
+ VALUE c;
+
rb_require ("ecore");
+ /* we need to call ecore_x_init () here, to make sure the
+ * event ids are set properly
+ */
+ ecore_init ();
+ ecore_x_init (getenv ("DISPLAY"));
+ atexit (at_exit);
+
mX = rb_define_module_under (mEcore, "X");
+ rb_define_module_function (mX, "default_root_window",
+ m_default_root_window_get, 0);
Init_Window ();
-}
+ /* now create the default root window object */
+ w = DefaultRootWindow (ecore_x_display_get ());
+ default_root = TO_ECORE_X_WINDOW (Qnil, w);
+ OBJ_FREEZE (default_root);
+ rb_global_variable (&default_root);
+
+ /* event mask values */
+ c = rb_define_class_under (mX, "EventMask", rb_cObject);
+ rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_DOWN);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, KEY_UP);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_DOWN);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_UP);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_IN);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_OUT);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_MOVE);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_DAMAGE);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_VISIBILITY);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CONFIGURE);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_RESIZE_MANAGE);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_MANAGE);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_CHILD_CONFIGURE);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_CHANGE);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_PROPERTY);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_COLORMAP);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_GRAB);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, MOUSE_WHEEL);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_IN);
+ DEF_CONST (c, ECORE_X_EVENT_MASK_, WINDOW_FOCUS_OUT);
+
+ /* wm protocols */
+ c = rb_define_class_under (mX, "WmProtocol", rb_cObject);
+ rb_define_private_method (rb_singleton_class (c), "new", NULL, 0);
+ DEF_CONST (c, ECORE_X_WM_PROTOCOL_, DELETE_REQUEST);
+ DEF_CONST (c, ECORE_X_WM_PROTOCOL_, TAKE_FOCUS);
+
+ /* events */
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
+ "WindowFocusIn", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
+ "WindowFocusOut", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
+ "WindowDeleteRequest", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
+ "WindowConfigureRequest", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
+ "WindowConfigure", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
+ "WindowVisibilityChange", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
+ rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
+
+ ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
+ "WindowShowRequest", c);
+ rb_define_private_method (c, "initialize",
+ c_ev_win_show_req_init, 1);
+
+ rb_define_attr (c, "window", 1, 0);
+ rb_define_attr (c, "parent", 1, 0);
+ rb_define_attr (c, "time", 1, 0);
+}