[gnome-photos] embed: Enable key navigation



commit 1cba4b8e5a8b12b7c9e9603fb92e54b38a6f97c7
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Nov 18 00:08:34 2012 +0100

    embed: Enable key navigation
    
    We derive from GtkClutterEmbed and remove focusability and key event
    handling. This means that to GTK+ it looks like a dumb container which
    never gets any key events. This makes GTK+ keynav work just like in
    any other container, although it means there will never be any Clutter
    key events. Thats fine though, as we just use Clutter as a rendering
    layer.
    
    Original patch from Alexander Larsson for gnome-boxes.
    Adapted by Cosimo Cecchi for gnome-documents.

 src/Makefile.am           |    2 +
 src/photos-embed-widget.c |   81 +++++++++++++++++++++++++++++++++++++++++++++
 src/photos-embed-widget.h |   75 +++++++++++++++++++++++++++++++++++++++++
 src/photos-embed.c        |    2 +-
 src/photos-embed.h        |    6 ++--
 5 files changed, 162 insertions(+), 4 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0c82a80..571386e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -57,6 +57,8 @@ gnome_photos_SOURCES = \
 	photos-collection-manager.h \
 	photos-embed.c \
 	photos-embed.h \
+	photos-embed-widget.c \
+	photos-embed-widget.h \
 	photos-empty-results-box.c \
 	photos-empty-results-box.h \
 	photos-error-box.c \
diff --git a/src/photos-embed-widget.c b/src/photos-embed-widget.c
new file mode 100644
index 0000000..9b39968
--- /dev/null
+++ b/src/photos-embed-widget.c
@@ -0,0 +1,81 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "photos-embed-widget.h"
+
+
+G_DEFINE_TYPE (PhotosEmbedWidget, photos_embed_widget, GTK_CLUTTER_TYPE_EMBED);
+
+
+static gboolean
+photos_embed_widget_key_press_event (GtkWidget *widget, GdkEventKey *event)
+{
+  return FALSE;
+}
+
+
+static gboolean
+photos_embed_widget_key_release_event (GtkWidget *widget, GdkEventKey *event)
+{
+  return FALSE;
+}
+
+
+static void
+photos_embed_widget_init (PhotosEmbedWidget *self)
+{
+}
+
+
+static void
+photos_embed_widget_class_init (PhotosEmbedWidgetClass *class)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+  /* We overide all keyboard handling of GtkClutterEmbed, as it interfers
+   * with the key event propagation and thus focus navigation in GTK+.
+   * We also make the embed itself non-focusable, as we want to treat it
+   * like a container of GTK+ widget rather than an edge widget which gets
+   * keyboard events.
+   *
+   * This means we will never get any Clutter key events, but that is
+   * fine, as all our keyboard input is into GtkClutterActors, and Clutter
+   * is just used as a nice way of animating and rendering GTK+ widgets
+   * and some non-active graphical things.
+   */
+  widget_class->key_press_event = photos_embed_widget_key_press_event;
+  widget_class->key_release_event = photos_embed_widget_key_release_event;
+}
+
+
+GtkWidget *
+photos_embed_widget_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_EMBED_WIDGET, "use-layout-size", TRUE, "can-focus", FALSE, NULL);
+}
diff --git a/src/photos-embed-widget.h b/src/photos-embed-widget.h
new file mode 100644
index 0000000..6f7097e
--- /dev/null
+++ b/src/photos-embed-widget.h
@@ -0,0 +1,75 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+#ifndef PHOTOS_EMBED_WIDGET_H
+#define PHOTOS_EMBED_WIDGET_H
+
+#include <clutter-gtk/clutter-gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_EMBED_WIDGET (photos_embed_widget_get_type ())
+
+#define PHOTOS_EMBED_WIDGET(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_EMBED_WIDGET, PhotosEmbedWidget))
+
+#define PHOTOS_EMBED_WIDGET_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_EMBED_WIDGET, PhotosEmbedWidgetClass))
+
+#define PHOTOS_IS_EMBED_WIDGET(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_EMBED_WIDGET))
+
+#define PHOTOS_IS_EMBED_WIDGET_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_EMBED_WIDGET))
+
+#define PHOTOS_EMBED_WIDGET_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_EMBED_WIDGET, PhotosEmbedWidgetClass))
+
+typedef struct _PhotosEmbedWidget        PhotosEmbedWidget;
+typedef struct _PhotosEmbedWidgetClass   PhotosEmbedWidgetClass;
+typedef struct _PhotosEmbedWidgetPrivate PhotosEmbedWidgetPrivate;
+
+struct _PhotosEmbedWidget
+{
+  GtkClutterEmbed parent_instance;
+  PhotosEmbedWidgetPrivate *priv;
+};
+
+struct _PhotosEmbedWidgetClass
+{
+  GtkClutterEmbedClass parent_class;
+};
+
+GType               photos_embed_widget_get_type               (void) G_GNUC_CONST;
+
+GtkWidget          *photos_embed_widget_new                    (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_EMBED_WIDGET_H */
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 4d5bd77..82acf7d 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -74,7 +74,7 @@ struct _PhotosEmbedPrivate
 };
 
 
-G_DEFINE_TYPE (PhotosEmbed, photos_embed, GTK_CLUTTER_TYPE_EMBED);
+G_DEFINE_TYPE (PhotosEmbed, photos_embed, PHOTOS_TYPE_EMBED_WIDGET);
 
 
 static void
diff --git a/src/photos-embed.h b/src/photos-embed.h
index eb96180..54f85c2 100644
--- a/src/photos-embed.h
+++ b/src/photos-embed.h
@@ -25,7 +25,7 @@
 #ifndef PHOTOS_EMBED_H
 #define PHOTOS_EMBED_H
 
-#include <clutter-gtk/clutter-gtk.h>
+#include "photos-embed-widget.h"
 
 G_BEGIN_DECLS
 
@@ -57,13 +57,13 @@ typedef struct _PhotosEmbedPrivate PhotosEmbedPrivate;
 
 struct _PhotosEmbed
 {
-  GtkClutterEmbed parent_instance;
+  PhotosEmbedWidget parent_instance;
   PhotosEmbedPrivate *priv;
 };
 
 struct _PhotosEmbedClass
 {
-  GtkClutterEmbedClass parent_class;
+  PhotosEmbedWidgetClass parent_class;
 };
 
 GType                  photos_embed_get_type               (void) G_GNUC_CONST;



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