[gtk/wip/ebassi/shortcut: 249/267] widget: Keep keybindings as a GListStore
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/ebassi/shortcut: 249/267] widget: Keep keybindings as a GListStore
- Date: Thu, 6 Feb 2020 18:24:47 +0000 (UTC)
commit 56d341406fb06ef914efad6c03b0b494a2d00901
Author: Benjamin Otte <otte redhat com>
Date: Mon Aug 20 04:18:28 2018 +0200
widget: Keep keybindings as a GListStore
This way, we can use shortcut_controller_new_for_model() and avoid all
the special casing about run_class.
gtk/gtkshortcutcontroller.c | 19 ------------------
gtk/gtkshortcutcontrollerprivate.h | 2 --
gtk/gtkwidget.c | 40 +++++++++++++++++++++++++-------------
gtk/gtkwidgetprivate.h | 2 --
4 files changed, 27 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index a995cc0d24..57c5528ffc 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -53,7 +53,6 @@ struct _GtkShortcutController
GdkModifierType mnemonics_modifiers;
guint custom_shortcuts : 1;
- guint run_class : 1;
guint run_managed : 1;
};
@@ -244,17 +243,6 @@ gtk_shortcut_controller_run_controllers (GtkEventController *controller,
return TRUE;
}
- if (self->run_class)
- {
- widget = gtk_event_controller_get_widget (controller);
-
- for (l = gtk_widget_class_get_shortcuts (GTK_WIDGET_GET_CLASS (widget)); l; l = l->next)
- {
- if (gtk_shortcut_controller_trigger_shortcut (self, l->data, event, enable_mnemonics))
- return TRUE;
- }
- }
-
if (self->run_managed)
{
GtkPropagationPhase current_phase = gtk_event_controller_get_propagation_phase (controller);
@@ -491,13 +479,6 @@ gtk_shortcut_controller_new_for_model (GListModel *model)
NULL);
}
-void
-gtk_shortcut_controller_set_run_class (GtkShortcutController *controller,
- gboolean run_class)
-{
- controller->run_class = run_class;
-}
-
void
gtk_shortcut_controller_set_run_managed (GtkShortcutController *controller,
gboolean run_managed)
diff --git a/gtk/gtkshortcutcontrollerprivate.h b/gtk/gtkshortcutcontrollerprivate.h
index 42594ea6eb..a7086cd678 100644
--- a/gtk/gtkshortcutcontrollerprivate.h
+++ b/gtk/gtkshortcutcontrollerprivate.h
@@ -22,8 +22,6 @@
#include "gtkshortcutcontroller.h"
-void gtk_shortcut_controller_set_run_class (GtkShortcutController *controller,
- gboolean run_class);
void gtk_shortcut_controller_set_run_managed (GtkShortcutController *controller,
gboolean
run_managed);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 9433b796dd..8bc616bcd2 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -495,7 +495,7 @@ typedef struct {
struct _GtkWidgetClassPrivate
{
GtkWidgetTemplate *template;
- GSList *shortcuts;
+ GListStore *shortcuts;
GType accessible_type;
AtkRole accessible_role;
GQuark css_name;
@@ -796,9 +796,29 @@ static void
gtk_widget_base_class_init (gpointer g_class)
{
GtkWidgetClass *klass = g_class;
+ GtkWidgetClassPrivate *priv;
+
+ priv = klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
+
+ priv->template = NULL;
+
+ if (priv->shortcuts == NULL)
+ {
+ priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
+ }
+ else
+ {
+ GListModel *parent_shortcuts = G_LIST_MODEL (priv->shortcuts);
+ guint i;
- klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
- klass->priv->template = NULL;
+ priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
+ for (i = 0; i < g_list_model_get_n_items (parent_shortcuts); i++)
+ {
+ GtkShortcut *shortcut = g_list_model_get_item (parent_shortcuts, i);
+ g_list_store_append (priv->shortcuts, shortcut);
+ g_object_unref (shortcut);
+ }
+ }
}
static void
@@ -1763,8 +1783,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
static void
gtk_widget_base_class_finalize (GtkWidgetClass *klass)
{
+
template_data_free (klass->priv->template);
- g_slist_free_full (klass->priv->shortcuts, g_object_unref);
+ g_object_unref (klass->priv->shortcuts);
}
static void
@@ -2468,8 +2489,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
if (layout_manager_type != G_TYPE_INVALID)
gtk_widget_set_layout_manager (widget, g_object_new (layout_manager_type, NULL));
- controller = gtk_shortcut_controller_new ();
- gtk_shortcut_controller_set_run_class (GTK_SHORTCUT_CONTROLLER (controller), TRUE);
+ controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (GTK_WIDGET_CLASS
(g_class)->priv->shortcuts));
gtk_widget_add_controller (widget, controller);
}
@@ -4557,13 +4577,7 @@ gtk_widget_class_add_shortcut (GtkWidgetClass *widget_class,
priv = widget_class->priv;
- priv->shortcuts = g_slist_prepend (priv->shortcuts, g_object_ref (shortcut));
-}
-
-const GSList *
-gtk_widget_class_get_shortcuts (GtkWidgetClass *widget_class)
-{
- return widget_class->priv->shortcuts;
+ g_list_store_append (priv->shortcuts, shortcut);
}
static gboolean
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index a2d3083f2c..8da88e94a4 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -236,8 +236,6 @@ void _gtk_widget_add_attached_window (GtkWidget *widget,
void _gtk_widget_remove_attached_window (GtkWidget *widget,
GtkWindow *window);
-const GSList * gtk_widget_class_get_shortcuts (GtkWidgetClass *widget_class);
-
AtkObject * _gtk_widget_peek_accessible (GtkWidget *widget);
void _gtk_widget_set_has_default (GtkWidget *widget,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]