[gnome-documents] lib: add GdFullscreenFilter



commit b6d4afc682ce7b43931de3e1bbf2196b169356fd
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Mar 5 14:56:19 2012 -0500

    lib: add GdFullscreenFilter
    
    This is a little helper object that installs a Gdk event filter
    listening for motion and button-press/release events.
    Its purpose is to be able to track mouse events while in fullscreen mode
    without the need to connect to event signals of any widget in the scene.

 src/Makefile-lib.am            |    2 +
 src/lib/gd-fullscreen-filter.c |  132 ++++++++++++++++++++++++++++++++++++++++
 src/lib/gd-fullscreen-filter.h |   75 +++++++++++++++++++++++
 3 files changed, 209 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile-lib.am b/src/Makefile-lib.am
index f8a74b8..a28c5d5 100644
--- a/src/Makefile-lib.am
+++ b/src/Makefile-lib.am
@@ -10,6 +10,7 @@ gdprivate_cflags = \
 gdprivate_source_h = \
     lib/gd-gdata-goa-authorizer.h \
     lib/gd-utils.h \
+    lib/gd-fullscreen-filter.h \
     lib/gd-main-toolbar.h \
     lib/gd-main-view-generic.h \
     lib/gd-main-icon-view.h \
@@ -27,6 +28,7 @@ gdprivate_source_h = \
 gdprivate_source_c = \
     lib/gd-gdata-goa-authorizer.c \
     lib/gd-utils.c \
+    lib/gd-fullscreen-filter.c \
     lib/gd-main-toolbar.c \
     lib/gd-main-view-generic.c \
     lib/gd-main-icon-view.c \
diff --git a/src/lib/gd-fullscreen-filter.c b/src/lib/gd-fullscreen-filter.c
new file mode 100644
index 0000000..6206d42
--- /dev/null
+++ b/src/lib/gd-fullscreen-filter.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents 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 General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#include "gd-fullscreen-filter.h"
+
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+#include <X11/extensions/XInput2.h>
+
+G_DEFINE_TYPE (GdFullscreenFilter, gd_fullscreen_filter, G_TYPE_OBJECT)
+
+enum {
+  MOTION_EVENT = 1,
+  NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS] = { 0, };
+
+struct _GdFullscreenFilterPrivate {
+  gboolean is_filtering;
+};
+
+static void
+gd_fullscreen_filter_dispose (GObject *object)
+{
+  GdFullscreenFilter *self = GD_FULLSCREEN_FILTER (object);
+
+  gd_fullscreen_filter_stop (self);
+
+  G_OBJECT_CLASS (gd_fullscreen_filter_parent_class)->dispose (object);
+}
+
+static void
+gd_fullscreen_filter_init (GdFullscreenFilter *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_FULLSCREEN_FILTER,
+                                            GdFullscreenFilterPrivate);
+}
+
+static void
+gd_fullscreen_filter_class_init (GdFullscreenFilterClass *klass)
+{
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+  oclass->dispose = gd_fullscreen_filter_dispose;
+
+  signals[MOTION_EVENT] =
+    g_signal_new ("motion-event",
+                  GD_TYPE_FULLSCREEN_FILTER,
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL, NULL,
+                  G_TYPE_NONE, 0);
+
+  g_type_class_add_private (klass, sizeof (GdFullscreenFilterPrivate));
+}
+
+static GdkFilterReturn
+event_filter_func (GdkXEvent *gdk_xevent,
+                   GdkEvent *event,
+                   gpointer user_data)
+{
+  GdFullscreenFilter *self = user_data;
+  XEvent *xevent = (XEvent *) gdk_xevent;
+
+  if (xevent->xany.type == ButtonPress ||
+      xevent->xany.type == ButtonRelease ||
+      xevent->xany.type == MotionNotify)
+    {
+      g_signal_emit (self, signals[MOTION_EVENT], 0);
+    }
+  else if (xevent->xany.type == GenericEvent)
+    {
+        /* we just assume this is an XI2 event */
+        XIEvent *ev = (XIEvent *) xevent->xcookie.data;
+
+        if (ev->evtype == XI_Motion ||
+            ev->evtype == XI_ButtonRelease ||
+            ev->evtype == XI_ButtonPress)
+          {
+            g_signal_emit (self, signals[MOTION_EVENT], 0);
+          }
+    }
+
+  return GDK_FILTER_CONTINUE;
+}
+
+void
+gd_fullscreen_filter_start (GdFullscreenFilter *self)
+{
+  if (self->priv->is_filtering)
+    return;
+
+  self->priv->is_filtering = TRUE;
+  gdk_window_add_filter (NULL,
+                         event_filter_func, self);
+}
+
+void
+gd_fullscreen_filter_stop (GdFullscreenFilter *self)
+{
+  if (!self->priv->is_filtering)
+    return;
+
+  self->priv->is_filtering = FALSE;
+  gdk_window_remove_filter (NULL,
+                            event_filter_func, self);
+}
+
+GdFullscreenFilter *
+gd_fullscreen_filter_new (void)
+{
+  return g_object_new (GD_TYPE_FULLSCREEN_FILTER, NULL);
+}
diff --git a/src/lib/gd-fullscreen-filter.h b/src/lib/gd-fullscreen-filter.h
new file mode 100644
index 0000000..d2a6b9c
--- /dev/null
+++ b/src/lib/gd-fullscreen-filter.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents 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 General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#ifndef __GD_FULLSCREEN_FILTER_H__
+#define __GD_FULLSCREEN_FILTER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_FULLSCREEN_FILTER gd_fullscreen_filter_get_type()
+
+#define GD_FULLSCREEN_FILTER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   GD_TYPE_FULLSCREEN_FILTER, GdFullscreenFilter))
+
+#define GD_FULLSCREEN_FILTER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   GD_TYPE_FULLSCREEN_FILTER, GdFullscreenFilterClass))
+
+#define GD_IS_FULLSCREEN_FILTER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   GD_TYPE_FULLSCREEN_FILTER))
+
+#define GD_IS_FULLSCREEN_FILTER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   GD_TYPE_FULLSCREEN_FILTER))
+
+#define GD_FULLSCREEN_FILTER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   GD_TYPE_FULLSCREEN_FILTER, GdFullscreenFilterClass))
+
+typedef struct _GdFullscreenFilter GdFullscreenFilter;
+typedef struct _GdFullscreenFilterClass GdFullscreenFilterClass;
+typedef struct _GdFullscreenFilterPrivate GdFullscreenFilterPrivate;
+
+struct _GdFullscreenFilter
+{
+  GObject parent;
+
+  GdFullscreenFilterPrivate *priv;
+};
+
+struct _GdFullscreenFilterClass
+{
+  GObjectClass parent_class;
+};
+
+GType gd_fullscreen_filter_get_type (void) G_GNUC_CONST;
+
+GdFullscreenFilter *gd_fullscreen_filter_new (void);
+void gd_fullscreen_filter_start (GdFullscreenFilter *self);
+void gd_fullscreen_filter_stop (GdFullscreenFilter *self);
+
+G_END_DECLS
+
+#endif /* __GD_FULLSCREEN_FILTER_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]