[gnome-software/850-gs-shell-close-the-window-on-ctrl-q-key-press] gs-shell: Close the window on Ctrl+Q key press



commit 08d620bc61be75784883aa3528fb5f43573b6ecc
Author: Milan Crha <mcrha redhat com>
Date:   Thu Dec 3 15:16:28 2020 +0100

    gs-shell: Close the window on Ctrl+Q key press
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/850
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/558

 src/gs-shell.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 23711e2a..3c81c208 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -2125,11 +2125,24 @@ gs_shell_add_about_menu_item (GsShell *shell)
        g_menu_append_item (primary_menu, menu_item);
 }
 
+static gboolean
+gs_shell_close_window_accel_cb (GtkAccelGroup *accel_group,
+                               GObject *acceleratable,
+                               guint keyval,
+                               GdkModifierType modifier)
+{
+       gtk_window_close (GTK_WINDOW (acceleratable));
+
+       return TRUE;
+}
+
 void
 gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *cancellable)
 {
        GsShellPrivate *priv = gs_shell_get_instance_private (shell);
        GtkWidget *widget;
+       g_autoptr(GtkAccelGroup) accel_group = NULL;
+       GClosure *closure;
        GtkStyleContext *style_context;
        GsPage *page;
 
@@ -2163,6 +2176,11 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
        g_signal_connect (priv->main_window, "delete-event",
                          G_CALLBACK (main_window_closed_cb), shell);
 
+       accel_group = gtk_accel_group_new ();
+       gtk_window_add_accel_group (priv->main_window, accel_group);
+       closure = g_cclosure_new (G_CALLBACK (gs_shell_close_window_accel_cb), NULL, NULL);
+       gtk_accel_group_connect (accel_group, GDK_KEY_q, GDK_CONTROL_MASK, GTK_ACCEL_LOCKED, closure);
+
        /* fix up the header bar */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "header"));
        if (gs_utils_is_current_desktop ("Unity")) {


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