[gtk/shortcuts-rebased-again: 8/159] shortcutcontroller: Introduce



commit 585bff7866bebd78186214ae2aa3dfe50ad30a9f
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jul 30 06:02:20 2018 +0200

    shortcutcontroller: Introduce
    
    This is a very barebones controller that currently does nothing but
    activate the binding signals. Yay.
    
    And because we have bindings on every widget (Yes, a GtkGrid has a
    keybinding - 2 in fact), we need that controller everywhere.

 docs/reference/gtk/gtk4-docs.xml     |  4 ++
 docs/reference/gtk/gtk4-sections.txt | 18 ++++++++
 docs/reference/gtk/gtk4.types.in     |  1 +
 gtk/gtk.h                            |  1 +
 gtk/gtkshortcutcontroller.c          | 88 ++++++++++++++++++++++++++++++++++++
 gtk/gtkshortcutcontroller.h          | 50 ++++++++++++++++++++
 gtk/gtkwidget.c                      |  8 ++--
 gtk/meson.build                      |  2 +
 8 files changed, 167 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-docs.xml b/docs/reference/gtk/gtk4-docs.xml
index e574d082ee..27b7e51b9d 100644
--- a/docs/reference/gtk/gtk4-docs.xml
+++ b/docs/reference/gtk/gtk4-docs.xml
@@ -342,6 +342,10 @@
       <xi:include href="xml/gtkpadcontroller.xml" />
     </chapter>
 
+    <chapter>
+      <title>Keyboard shortcuts</title>
+      <xi:include href="xml/gtkshortcutcontroller.xml" />
+    </chapter>
   </part>
 
   <part  id="gtkbase">
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index e1edea3f3a..39738c6751 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -6690,6 +6690,24 @@ GTK_EVENT_CONTROLLER_MOTION_GET_CLASS
 gtk_event_controller_motion_get_type
 </SECTION>
 
+<SECTION>
+<FILE>gtkshortcutcontroller</FILE>
+<TITLE>GtkShortcutController</TITLE>
+GtkShortcutController
+gtk_shortcut_controller_new
+
+<SUBSECTION Standard>
+GTK_TYPE_SHORTCUT_CONTROLLER
+GTK_SHORTCUT_CONTROLLER
+GTK_SHORTCUT_CONTROLLER_CLASS
+GTK_IS_SHORTCUT_CONTROLLER
+GTK_IS_SHORTCUT_CONTROLLER_CLASS
+GTK_SHORTCUT_CONTROLLER_GET_CLASS
+
+<SUBSECTION Private>
+gtk_shortcut_controller_get_type
+</SECTION>
+
 <SECTION>
 <FILE>gtkeventcontrollerkey</FILE>
 <TITLE>GtkEventControllerKey</TITLE>
diff --git a/docs/reference/gtk/gtk4.types.in b/docs/reference/gtk/gtk4.types.in
index 8073f3ad20..323e6185d0 100644
--- a/docs/reference/gtk/gtk4.types.in
+++ b/docs/reference/gtk/gtk4.types.in
@@ -160,6 +160,7 @@ gtk_separator_get_type
 gtk_separator_menu_item_get_type
 gtk_separator_tool_item_get_type
 gtk_settings_get_type
+gtk_shortcut_controller_get_type
 gtk_shortcut_label_get_type
 gtk_shortcuts_window_get_type
 gtk_shortcuts_section_get_type
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 6691d286c9..091c214aec 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -201,6 +201,7 @@
 #include <gtk/gtkseparatormenuitem.h>
 #include <gtk/gtkseparatortoolitem.h>
 #include <gtk/gtksettings.h>
+#include <gtk/gtkshortcutcontroller.h>
 #include <gtk/gtkshortcutlabel.h>
 #include <gtk/gtkshortcutsgroup.h>
 #include <gtk/gtkshortcutssection.h>
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
new file mode 100644
index 0000000000..45aab98e70
--- /dev/null
+++ b/gtk/gtkshortcutcontroller.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright © 2018 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+
+/**
+ * SECTION:gtkshortcutcontroller
+ * @Short_description: Event controller for shortcuts
+ * @Title: GtkShortcutController
+ * @See_also: #GtkEventController, #GtkShortcut
+ *
+ * #GtkShortcutController is an event controller that manages shortcuts.
+ **/
+
+#include "config.h"
+
+#include "gtkshortcutcontroller.h"
+
+#include "gtkeventcontrollerprivate.h"
+#include "gtkbindings.h"
+
+#include <gdk/gdk.h>
+
+struct _GtkShortcutController
+{
+  GtkEventController parent_instance;
+};
+
+struct _GtkShortcutControllerClass
+{
+  GtkEventControllerClass parent_class;
+};
+
+G_DEFINE_TYPE (GtkShortcutController, gtk_shortcut_controller,
+               GTK_TYPE_EVENT_CONTROLLER)
+
+static void
+gtk_shortcut_controller_finalize (GObject *object)
+{
+  //GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (object);
+
+  G_OBJECT_CLASS (gtk_shortcut_controller_parent_class)->finalize (object);
+}
+
+static gboolean
+gtk_shortcut_controller_handle_event (GtkEventController *controller,
+                                      const GdkEvent     *event)
+{
+  return gtk_bindings_activate_event (G_OBJECT (gtk_event_controller_get_widget (controller)),
+                                      (GdkEventKey *) event);
+}
+
+static void
+gtk_shortcut_controller_class_init (GtkShortcutControllerClass *klass)
+{
+  GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = gtk_shortcut_controller_finalize;
+  controller_class->handle_event = gtk_shortcut_controller_handle_event;
+}
+
+static void
+gtk_shortcut_controller_init (GtkShortcutController *controller)
+{
+}
+
+GtkEventController *
+gtk_shortcut_controller_new (void)
+{
+  return g_object_new (GTK_TYPE_SHORTCUT_CONTROLLER,
+                       NULL);
+}
diff --git a/gtk/gtkshortcutcontroller.h b/gtk/gtkshortcutcontroller.h
new file mode 100644
index 0000000000..91fb97d67c
--- /dev/null
+++ b/gtk/gtkshortcutcontroller.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2018 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+
+#ifndef __GTK_SHORTCUT_CONTROLLER_H__
+#define __GTK_SHORTCUT_CONTROLLER_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkeventcontroller.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SHORTCUT_CONTROLLER         (gtk_shortcut_controller_get_type ())
+#define GTK_SHORTCUT_CONTROLLER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_SHORTCUT_CONTROLLER, 
GtkShortcutController))
+#define GTK_SHORTCUT_CONTROLLER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_SHORTCUT_CONTROLLER, 
GtkShortcutControllerClass))
+#define GTK_IS_SHORTCUT_CONTROLLER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_SHORTCUT_CONTROLLER))
+#define GTK_IS_SHORTCUT_CONTROLLER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_SHORTCUT_CONTROLLER))
+#define GTK_SHORTCUT_CONTROLLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_SHORTCUT_CONTROLLER, 
GtkShortcutControllerClass))
+
+typedef struct _GtkShortcutController GtkShortcutController;
+typedef struct _GtkShortcutControllerClass GtkShortcutControllerClass;
+
+GDK_AVAILABLE_IN_ALL
+GType                   gtk_shortcut_controller_get_type                (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_ALL
+GtkEventController *    gtk_shortcut_controller_new                     (void);
+
+G_END_DECLS
+
+#endif /* __GTK_SHORTCUT_CONTROLLER_H__ */
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 091d954811..05475bc775 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -61,6 +61,7 @@
 #include "gtkscrollable.h"
 #include "gtkselection.h"
 #include "gtksettingsprivate.h"
+#include "gtkshortcutcontroller.h"
 #include "gtksizegroup-private.h"
 #include "gtksnapshotprivate.h"
 #include "gtkstylecontextprivate.h"
@@ -2833,6 +2834,8 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   layout_manager_type = gtk_widget_class_get_layout_manager_type (g_class);
   if (layout_manager_type != G_TYPE_INVALID)
     gtk_widget_set_layout_manager (widget, g_object_new (layout_manager_type, NULL));
+
+  gtk_widget_add_controller (widget, gtk_shortcut_controller_new ());
 }
 
 /**
@@ -5359,11 +5362,6 @@ gtk_widget_event_internal (GtkWidget      *widget,
     return_val |= gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_BUBBLE);
   g_object_unref (event_copy);
 
-  if (return_val == FALSE &&
-      (event->any.type == GDK_KEY_PRESS ||
-       event->any.type == GDK_KEY_RELEASE))
-    return_val |= gtk_bindings_activate_event (G_OBJECT (widget), (GdkEventKey *) event);
-
   return return_val;
 }
 
diff --git a/gtk/meson.build b/gtk/meson.build
index 0b271b6f50..1b23ff5b8c 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -333,6 +333,7 @@ gtk_public_sources = files([
   'gtkseparatormenuitem.c',
   'gtkseparatortoolitem.c',
   'gtksettings.c',
+  'gtkshortcutcontroller.c',
   'gtkshortcutlabel.c',
   'gtkshortcutsgroup.c',
   'gtkshortcutssection.c',
@@ -579,6 +580,7 @@ gtk_public_headers = files([
   'gtkseparatormenuitem.h',
   'gtkseparatortoolitem.h',
   'gtksettings.h',
+  'gtkshortcutcontroller.h',
   'gtkshortcutlabel.h',
   'gtkshortcutsgroup.h',
   'gtkshortcutssection.h',


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