From f141a9dd6fe8ca6ed5d8e5aad28fc4c99d3243ea Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Sun, 13 Nov 2022 11:03:40 +0100 Subject: [PATCH] account-overview: Close windows when pressing Escape Closes: #511 --- src/calls-account-overview.c | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/calls-account-overview.c b/src/calls-account-overview.c index 5454f86..0ab6e22 100644 --- a/src/calls-account-overview.c +++ b/src/calls-account-overview.c @@ -63,6 +63,8 @@ struct _CallsAccountOverview { GtkWidget *current_account_widget; /* misc */ + GtkEventController *key_controller; + GtkEventController *key_controller_account; CallsAccountOverviewState state; GList *providers; CallsInAppNotification *in_app_notification; @@ -277,11 +279,41 @@ on_providers_changed (CallsAccountOverview *self) gtk_widget_set_sensitive (self->add_btn, !!self->providers); } + +static gboolean +on_key_pressed (GtkEventControllerKey *controller, + guint keyval, + guint keycode, + GdkModifierType modifiers, + GtkWidget *widget) +{ + if (keyval == GDK_KEY_Escape) { + gtk_widget_hide (widget); + return GDK_EVENT_STOP; + } + + return GDK_EVENT_PROPAGATE; +} + +static void +calls_account_overview_dispose (GObject *object) +{ + CallsAccountOverview *self = CALLS_ACCOUNT_OVERVIEW (object); + + g_clear_object (&self->key_controller); + g_clear_object (&self->key_controller_account); + + G_OBJECT_CLASS (calls_account_overview_parent_class)->dispose (object); +} + static void calls_account_overview_class_init (CallsAccountOverviewClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + object_class->dispose = calls_account_overview_dispose; + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/account-overview.ui"); gtk_widget_class_bind_template_child (widget_class, CallsAccountOverview, add_btn); @@ -317,6 +349,18 @@ calls_account_overview_init (CallsAccountOverview *self) gtk_window_set_transient_for (self->account_window, GTK_WINDOW (self)); update_state (self); + + self->key_controller = gtk_event_controller_key_new (GTK_WIDGET (self)); + g_signal_connect (self->key_controller, + "key-pressed", + G_CALLBACK (on_key_pressed), + self); + + self->key_controller_account = gtk_event_controller_key_new (GTK_WIDGET (self->account_window)); + g_signal_connect (self->key_controller_account, + "key-pressed", + G_CALLBACK (on_key_pressed), + self->account_window); }