[gnome-software: 33/110] Replace custom key-press handler with shortcut action binding
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 33/110] Replace custom key-press handler with shortcut action binding
- Date: Tue, 5 Oct 2021 20:32:36 +0000 (UTC)
commit 0523a1bc46039845b1ba777ad2f2c4e905648260
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Aug 22 22:14:47 2021 -0300
Replace custom key-press handler with shortcut action binding
Replace all copy-pasted key-press handlers of dialogs with the brand new
shortcut action binding API.
src/gs-first-run-dialog.c | 31 +------------------------------
src/gs-first-run-dialog.ui | 1 -
src/gs-info-window.c | 31 +------------------------------
src/gs-info-window.ui | 1 -
src/gs-repos-dialog.c | 31 +------------------------------
src/gs-repos-dialog.ui | 1 -
src/gs-update-dialog.c | 8 ++------
7 files changed, 5 insertions(+), 99 deletions(-)
---
diff --git a/src/gs-first-run-dialog.c b/src/gs-first-run-dialog.c
index 80b76f3ce..47ed31051 100644
--- a/src/gs-first-run-dialog.c
+++ b/src/gs-first-run-dialog.c
@@ -21,35 +21,6 @@ struct _GsFirstRunDialog
G_DEFINE_TYPE (GsFirstRunDialog, gs_first_run_dialog, ADW_TYPE_WINDOW)
-static gboolean
-key_press_event_cb (GtkWidget *sender,
- GdkEvent *event,
- AdwPreferencesWindow *self)
-{
- guint keyval;
- GdkModifierType state;
- GdkKeymap *keymap;
- GdkEventKey *key_event = (GdkEventKey *) event;
-
- gdk_event_get_state (event, &state);
-
- keymap = gdk_keymap_get_for_display (gtk_widget_get_display (sender));
-
- gdk_keymap_translate_keyboard_state (keymap,
- key_event->hardware_keycode,
- state,
- key_event->group,
- &keyval, NULL, NULL, NULL);
-
- if (keyval == GDK_KEY_Escape) {
- gtk_window_close (GTK_WINDOW (self));
-
- return GDK_EVENT_STOP;
- }
-
- return GDK_EVENT_PROPAGATE;
-}
-
static void
button_clicked_cb (GtkWidget *widget, GsFirstRunDialog *dialog)
{
@@ -79,7 +50,7 @@ gs_first_run_dialog_class_init (GsFirstRunDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsFirstRunDialog, button);
- gtk_widget_class_bind_template_callback (widget_class, key_press_event_cb);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
}
GtkWidget *
diff --git a/src/gs-first-run-dialog.ui b/src/gs-first-run-dialog.ui
index eb9533621..8ff10871c 100644
--- a/src/gs-first-run-dialog.ui
+++ b/src/gs-first-run-dialog.ui
@@ -12,7 +12,6 @@
<property name="default-width">640</property>
<property name="default-height">576</property>
<property name="skip_taskbar_hint">True</property>
- <signal name="key-press-event" handler="key_press_event_cb" after="yes" swapped="no"/>
<style>
<class name="toolbox"/>
</style>
diff --git a/src/gs-info-window.c b/src/gs-info-window.c
index d8ff4ff39..33f0d5949 100644
--- a/src/gs-info-window.c
+++ b/src/gs-info-window.c
@@ -41,35 +41,6 @@ typedef struct
G_DEFINE_TYPE_WITH_PRIVATE (GsInfoWindow, gs_info_window, ADW_TYPE_WINDOW)
-static gboolean
-key_press_event_cb (GtkWidget *sender,
- GdkEvent *event,
- AdwPreferencesWindow *self)
-{
- guint keyval;
- GdkModifierType state;
- GdkKeymap *keymap;
- GdkEventKey *key_event = (GdkEventKey *) event;
-
- gdk_event_get_state (event, &state);
-
- keymap = gdk_keymap_get_for_display (gtk_widget_get_display (sender));
-
- gdk_keymap_translate_keyboard_state (keymap,
- key_event->hardware_keycode,
- state,
- key_event->group,
- &keyval, NULL, NULL, NULL);
-
- if (keyval == GDK_KEY_Escape) {
- gtk_window_close (GTK_WINDOW (self));
-
- return GDK_EVENT_STOP;
- }
-
- return GDK_EVENT_PROPAGATE;
-}
-
static void
gs_info_window_init (GsInfoWindow *self)
{
@@ -153,7 +124,7 @@ gs_info_window_class_init (GsInfoWindowClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GsInfoWindow, overlay);
- gtk_widget_class_bind_template_callback (widget_class, key_press_event_cb);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
}
/**
diff --git a/src/gs-info-window.ui b/src/gs-info-window.ui
index 8b783daef..a679d664e 100644
--- a/src/gs-info-window.ui
+++ b/src/gs-info-window.ui
@@ -9,7 +9,6 @@
<property name="type_hint">dialog</property>
<property name="default-width">640</property>
<property name="default-height">576</property>
- <signal name="key-press-event" handler="key_press_event_cb" after="yes" swapped="no"/>
<style>
<class name="toolbox"/>
</style>
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
index c6cebad9b..7b1e7eb0f 100644
--- a/src/gs-repos-dialog.c
+++ b/src/gs-repos-dialog.c
@@ -59,35 +59,6 @@ install_remove_data_free (InstallRemoveData *data)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstallRemoveData, install_remove_data_free);
-static gboolean
-key_press_event_cb (GtkWidget *sender,
- GdkEvent *event,
- AdwPreferencesWindow *self)
-{
- guint keyval;
- GdkModifierType state;
- GdkKeymap *keymap;
- GdkEventKey *key_event = (GdkEventKey *) event;
-
- gdk_event_get_state (event, &state);
-
- keymap = gdk_keymap_get_for_display (gtk_widget_get_display (sender));
-
- gdk_keymap_translate_keyboard_state (keymap,
- key_event->hardware_keycode,
- state,
- key_event->group,
- &keyval, NULL, NULL, NULL);
-
- if (keyval == GDK_KEY_Escape) {
- gtk_window_close (GTK_WINDOW (self));
-
- return GDK_EVENT_STOP;
- }
-
- return GDK_EVENT_PROPAGATE;
-}
-
static void
repo_enabled_cb (GObject *source,
GAsyncResult *res,
@@ -759,7 +730,7 @@ gs_repos_dialog_class_init (GsReposDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsReposDialog, spinner);
gtk_widget_class_bind_template_child (widget_class, GsReposDialog, stack);
- gtk_widget_class_bind_template_callback (widget_class, key_press_event_cb);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
}
GtkWidget *
diff --git a/src/gs-repos-dialog.ui b/src/gs-repos-dialog.ui
index 5e28f4e24..2f17175be 100644
--- a/src/gs-repos-dialog.ui
+++ b/src/gs-repos-dialog.ui
@@ -11,7 +11,6 @@
<property name="type_hint">dialog</property>
<property name="default-width">640</property>
<property name="default-height">576</property>
- <signal name="key-press-event" handler="key_press_event_cb" after="yes" swapped="no"/>
<child>
<object class="GtkBox">
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 37d492ac8..24af1ae14 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -228,12 +228,6 @@ key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
state = state & gtk_accelerator_get_default_mod_mask ();
is_rtl = gtk_widget_get_direction (GTK_WIDGET (dialog)) == GTK_TEXT_DIR_RTL;
- if (event->keyval == GDK_KEY_Escape) {
- gtk_window_close (GTK_WINDOW (dialog));
-
- return GDK_EVENT_STOP;
- }
-
if ((!is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Left) ||
(is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Right) ||
event->keyval == GDK_KEY_Back) {
@@ -402,6 +396,8 @@ gs_update_dialog_class_init (GsUpdateDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsUpdateDialog, spinner);
gtk_widget_class_bind_template_child (widget_class, GsUpdateDialog, stack);
gtk_widget_class_bind_template_callback (widget_class, deck_child_transition_cb);
+
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
}
GtkWidget *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]