Remove GDK dependency from registry daemon.
authorMark Doffman <mark.doffman@codethink.co.uk>
Thu, 24 Dec 2009 14:21:15 +0000 (06:21 -0800)
committerMark Doffman <mark.doffman@codethink.co.uk>
Thu, 24 Dec 2009 14:21:15 +0000 (06:21 -0800)
configure.ac
registryd/Makefile.am
registryd/deviceeventcontroller.c
registryd/deviceeventcontroller.h
registryd/display.c [new file with mode: 0644]
registryd/display.h [new file with mode: 0644]
registryd/event-source.c [new file with mode: 0644]
registryd/event-source.h [new file with mode: 0644]
registryd/registry-main.c

index ca1075a..85d60e4 100644 (file)
@@ -44,10 +44,6 @@ PKG_CHECK_MODULES(GOBJ, [gobject-2.0 >= 2.0.0])
 AC_SUBST(GOBJ_LIBS)
 AC_SUBST(GOBJ_CFLAGS)
 
-PKG_CHECK_MODULES(GDK, [gdk-2.0 >= 2.0.0])
-AC_SUBST(GDK_LIBS)
-AC_SUBST(GDK_CFLAGS)
-
 AC_PATH_XTRA
 
 if test x$no_x = xyes ; then
index 52820f6..829d69e 100644 (file)
@@ -3,14 +3,12 @@ libexec_PROGRAMS = at-spi2-registryd
 at_spi2_registryd_CFLAGS = $(DBUS_GLIB_CFLAGS) \
                           $(GOBJ_CFLAGS)       \
                           $(ATK_CFLAGS)        \
-                          $(GDK_CFLAGS)        \
                           -I$(top_srcdir)      \
                           -DATSPI_INTROSPECTION_PATH=\"$(pkgdatadir)/$(DEFAULT_ATSPI_INTROSPECTION_PATH)\"
 
 at_spi2_registryd_LDADD = $(DBUS_GLIB_LIBS)    \
                          $(GOBJ_CFLAGS)        \
                          $(ATK_LIBS)           \
-                         $(GDK_LIBS)           \
                          $(X_LIBS)             \
                          $(SM_LIBS)            \
                          $(XTST_LIBS)          \
@@ -20,6 +18,10 @@ at_spi2_registryd_SOURCES =  \
        de-marshaller.h         \
        de-marshaller.c         \
        de-types.h              \
+       display.h               \
+       display.c               \
+        event-source.h          \
+        event-source.c          \
        keymasks.h              \
        paths.h                 \
        registry-main.c         \
index 9f1b9ae..1afd2ef 100644 (file)
@@ -48,9 +48,6 @@
 #endif /* HAVE_XEVIE */
 
 #include <glib.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h> /* TODO: hide dependency (wrap in single porting file) */
-#include <gdk/gdkkeysyms.h>
 
 #include <dbus/dbus.h>
 
@@ -58,6 +55,7 @@
 #include "keymasks.h"
 #include "de-types.h"
 #include "de-marshaller.h"
+#include "display.h"
 
 #include "deviceeventcontroller.h"
 #include "reentrant-list.h"
@@ -77,8 +75,13 @@ static void wait_for_release_event (XEvent *event, SpiDEController *controller);
 
 /* A pointer to our parent object class */
 static int spi_error_code = 0;
-static GdkPoint last_mouse_pos_static = {0, 0}; 
-static GdkPoint *last_mouse_pos = &last_mouse_pos_static;
+struct _SpiPoint {
+    gint x;
+    gint y;
+};
+typedef struct _SpiPoint SpiPoint;
+static SpiPoint last_mouse_pos_static = {0, 0}; 
+static SpiPoint *last_mouse_pos = &last_mouse_pos_static;
 static unsigned int mouse_mask_state = 0;
 static unsigned int mouse_button_mask =
   Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask;
@@ -162,8 +165,6 @@ static gboolean spi_dec_poll_mouse_moved (gpointer data);
 static gboolean spi_dec_poll_mouse_moving (gpointer data);
 static gboolean spi_dec_poll_mouse_idle (gpointer data);
 
-#define spi_get_display() GDK_DISPLAY()
-
 G_DEFINE_TYPE(SpiDEController, spi_device_event_controller, G_TYPE_OBJECT)
 
 DBusMessage *
@@ -671,7 +672,7 @@ spi_dec_init_mouse_listener (SpiDEController *dec)
   if (display)
     {
       if (XGrabButton (display, AnyButton, AnyModifier,
-                      gdk_x11_get_default_root_xwindow (),
+                      spi_get_root_window (),
                       True, ButtonPressMask | ButtonReleaseMask,
                       GrabModeSync, GrabModeAsync, None, None) != Success) {
 #ifdef SPI_DEBUG
@@ -1180,10 +1181,9 @@ spi_device_event_controller_forward_mouse_event (SpiDEController *controller,
                CurrentTime);
 }
 
-static GdkFilterReturn
-global_filter_fn (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
+static void
+global_filter_fn (XEvent *xevent, void *data)
 {
-  XEvent *xevent = gdk_xevent;
   SpiDEController *controller;
   DEControllerPrivateData *priv;
   Display *display = spi_get_display ();
@@ -1233,7 +1233,7 @@ global_filter_fn (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
             }
         }
 
-      return GDK_FILTER_CONTINUE;
+      return;
     }
   if (xevent->type == ButtonPress || xevent->type == ButtonRelease)
     {
@@ -1306,7 +1306,7 @@ global_filter_fn (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
       XSynchronize (display, FALSE);
     }
   
-  return GDK_FILTER_CONTINUE;
+  return;
 }
 
 static int
@@ -1361,15 +1361,24 @@ spi_controller_register_with_devices (SpiDEController *controller)
              if (XKeycodeToKeysym (spi_get_display (), i, 0) != 0)
              {
                  /* don't use this one if there's a grab client! */
-                 gdk_error_trap_push ();
+
+                 /* Runtime errors are generated from these functions,
+                  * that are then quashed. Equivalent to:
+                  * try
+                  *   {Blah}
+                  * except
+                  *   {;}
+                  */
+
+                 spi_x_error_trap ();
                  XGrabKey (spi_get_display (), i, 0, 
-                           gdk_x11_get_default_root_xwindow (),
+                           spi_get_root_window (),
                            TRUE,
                            GrabModeSync, GrabModeSync);
                  XSync (spi_get_display (), TRUE);
                  XUngrabKey (spi_get_display (), i, 0, 
-                             gdk_x11_get_default_root_xwindow ());
-                 if (!gdk_error_trap_pop ())
+                             spi_get_root_window ());
+                 if (!spi_x_error_release ())
                  {
                      reserved = i;
                      break;
@@ -1398,10 +1407,8 @@ spi_controller_register_with_devices (SpiDEController *controller)
 #endif
     }  
 
-  gdk_window_add_filter (NULL, global_filter_fn, controller);
-
-  gdk_window_set_events (gdk_get_default_root_window (),
-                        GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
+  spi_set_filter (global_filter_fn, controller);
+  spi_set_events (KeyPressMask | KeyReleaseMask);
 
   x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler);
 }
@@ -1771,7 +1778,7 @@ spi_controller_update_key_grabs (SpiDEController           *controller,
          XUngrabKey (spi_get_display (),
                      grab_mask->key_val,
                      grab_mask->mod_mask,
-                     gdk_x11_get_default_root_xwindow ());
+                     spi_get_root_window ());
 
           do_remove = TRUE;
        }
@@ -1784,7 +1791,7 @@ spi_controller_update_key_grabs (SpiDEController           *controller,
           XGrabKey (spi_get_display (),
                    grab_mask->key_val,
                    grab_mask->mod_mask,
-                   gdk_x11_get_default_root_xwindow (),
+                   spi_get_root_window (),
                    True,
                    GrabModeSync,
                    GrabModeSync);
@@ -2455,7 +2462,7 @@ static DBusMessage * impl_generate_keyboard_event (DBusConnection *bus, DBusMess
    * and fall back to XSendEvent() if XTest is not available.
    */
   
-  gdk_error_trap_push ();
+  spi_x_error_trap ();
 
   priv = (DEControllerPrivateData *) 
       g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
@@ -2675,6 +2682,7 @@ handle_io (GIOChannel *source,
 static void
 spi_device_event_controller_init (SpiDEController *device_event_controller)
 {
+  spi_events_init (spi_get_display());
 #ifdef HAVE_XEVIE
   GIOChannel *ioc;
   int fd;
index 0e7c129..f69c57b 100644 (file)
@@ -25,7 +25,6 @@
 #define SPI_DEVICE_EVENT_CONTROLLER_H_
 
 #include <X11/Xlib.h>
-#include <gdk/gdk.h>
 #include <dbus/dbus.h>
 
 typedef struct _SpiDEController SpiDEController;
diff --git a/registryd/display.c b/registryd/display.c
new file mode 100644 (file)
index 0000000..e9c9b16
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "display.h"
+
+static Display *default_display = NULL;
+
+Display *spi_set_display (const char *display_name)
+{
+        /* 
+        * TODO - Should we ever do anything different might need to
+         * close previous display.
+         */
+        default_display = XOpenDisplay (display_name);  
+        if (!default_display)
+        {
+                g_error ("AT-SPI: Cannot open default display");
+                return NULL;
+        }
+}
+
+Display *spi_get_display ()
+{
+       if (!default_display)
+               spi_set_display (NULL);
+
+       return default_display;
+}
+
+Window spi_get_root_window ()
+{
+       if (!default_display)
+               spi_set_display (NULL);
+
+        return DefaultRootWindow (default_display);
+}
+
+static int (*old_x_error_handler) (Display *, XErrorEvent *);
+static int x_error_code;
+
+static int spi_x_error_handler (Display *display, XErrorEvent *error)
+{
+       if (error->error_code)
+               x_error_code = error->error_code;
+       else
+               x_error_code = 0;
+  
+       return 0;
+}
+
+void spi_x_error_trap (void)
+{
+       old_x_error_handler = XSetErrorHandler (spi_x_error_handler);
+}
+
+int spi_x_error_release (void)
+{
+       XSetErrorHandler (old_x_error_handler);
+       return x_error_code;
+}
diff --git a/registryd/display.h b/registryd/display.h
new file mode 100644 (file)
index 0000000..2238a55
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009  Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_DISPLAY_H_
+#define SPI_DISPLAY_H_
+
+#include <X11/Xlib.h>
+
+Display *spi_set_display (const char *display_name);
+Display *spi_get_display ();
+
+Window spi_get_root_window ();
+
+void spi_x_error_trap (void);
+int spi_x_error_release (void);
+
+#endif /* SPI_DISPLAY_H_ */
diff --git a/registryd/event-source.c b/registryd/event-source.c
new file mode 100644 (file)
index 0000000..b8dcff8
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+#include "event-source.h"
+
+typedef struct _DisplaySource
+{
+  GSource source;
+  
+  Display *display;
+  GPollFD  event_poll_fd;
+} DisplaySource;
+
+/*---------------------------------------------------------------------------*/
+
+static void (*_spi_default_filter) (XEvent*, void*) = NULL;
+static void* _spi_default_filter_data = NULL;
+
+/*---------------------------------------------------------------------------*/
+
+static gboolean  
+event_prepare (GSource *source, gint *timeout)
+{
+  Display *display = ((DisplaySource *)source)->display;
+  gboolean retval;
+  
+  *timeout = -1;
+  retval = XPending (display);
+  
+  return retval;
+}
+
+static gboolean  
+event_check (GSource *source) 
+{
+  DisplaySource *display_source = (DisplaySource*)source;
+  gboolean retval;
+
+  if (display_source->event_poll_fd.revents & G_IO_IN)
+    retval = XPending (display_source->display);
+  else
+    retval = FALSE;
+
+  return retval;
+}
+
+static gboolean  
+event_dispatch (GSource *source, GSourceFunc callback, gpointer  user_data)
+{
+  Display *display = ((DisplaySource*)source)->display;
+  XEvent xevent;
+  /* TODO - Should this be "if (XPending (display))"?
+   *        The effect of this might be to run other main loop functions
+   *        before dispatching the next XEvent.
+   */
+  while (XPending (display))
+    {
+      XNextEvent (display, &xevent);
+
+      switch (xevent.type)
+       {
+       case KeyPress:
+       case KeyRelease:
+         break;
+       default:
+         if (XFilterEvent (&xevent, None))
+           continue;
+       }
+      
+      if (_spi_default_filter)
+        {
+          _spi_default_filter (&xevent, _spi_default_filter_data);
+        }  
+    }
+
+  return TRUE;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static GSourceFuncs event_funcs = {
+  event_prepare,
+  event_check,
+  event_dispatch,
+  NULL
+};
+
+static GSource *
+display_source_new (Display *display)
+{
+  GSource *source = g_source_new (&event_funcs, sizeof (DisplaySource));
+  DisplaySource *display_source = (DisplaySource *) source;
+  
+  display_source->display = display;
+  
+  return source;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static DisplaySource *spi_display_source = NULL;
+
+void 
+spi_events_init (Display *display)
+{
+  GSource *source;
+
+  int connection_number = ConnectionNumber (display);
+
+  source = display_source_new (display);
+  spi_display_source = (DisplaySource*) source;
+
+  g_source_set_priority (source, G_PRIORITY_DEFAULT);
+  
+  spi_display_source->event_poll_fd.fd = connection_number;
+  spi_display_source->event_poll_fd.events = G_IO_IN;
+  
+  g_source_add_poll (source, &spi_display_source->event_poll_fd);
+  g_source_set_can_recurse (source, TRUE);
+  g_source_attach (source, NULL);
+}
+
+void
+spi_events_uninit ()
+{
+  if (spi_display_source)
+    {
+      g_source_destroy ((GSource *) spi_display_source);
+      g_source_unref ((GSource *) spi_display_source);
+      spi_display_source = NULL;
+    }
+}
+
+void
+spi_set_events (long event_mask)
+{
+  long xevent_mask = StructureNotifyMask | PropertyChangeMask;
+  xevent_mask |= event_mask;
+      
+  XSelectInput (spi_display_source->display, 
+                DefaultRootWindow (spi_display_source->display),
+                xevent_mask);
+}
+
+void
+spi_set_filter (void (*filter) (XEvent*, void*), void* data)
+{
+  _spi_default_filter = filter;
+  _spi_default_filter_data = data;
+}
+
+/*END------------------------------------------------------------------------*/
diff --git a/registryd/event-source.h b/registryd/event-source.h
new file mode 100644 (file)
index 0000000..55ab663
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009  Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_EVENT_SOURCE_H_
+#define SPI_EVENT_SOURCE_H_
+
+#include <X11/Xlib.h>
+
+void spi_events_init (Display *display);
+void spi_events_uninit ();
+void spi_set_events (long event_mask);
+void spi_set_filter (void (*filter) (XEvent*, void*), void* data);
+
+#endif /* SPI_EVENT_SOURCE_H_ */
index e19c209..51cf7d1 100644 (file)
@@ -25,6 +25,7 @@
 #include <config.h>
 #include <string.h>
 #include <glib.h>
+#include <stdio.h>
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
@@ -291,9 +292,6 @@ main (int argc, char **argv)
 
   g_type_init();
 
-  /* We depend on GDK as well as XLib for device event processing */
-  gdk_init(&argc, &argv);
-
   /*Parse command options*/
   opt = g_option_context_new(NULL);
   g_option_context_add_main_entries(opt, optentries, NULL);