[recipes] Handle mouse back button



commit 069cc42f81af456201d114d79306df8289a94c98
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Feb 8 23:56:18 2017 -0500

    Handle mouse back button
    
    We do this in other applications as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777582

 src/gr-window.c  |   11 +++++++++++
 src/gr-window.ui |    2 +-
 2 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-window.c b/src/gr-window.c
index 69a569f..7e7e0c1 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -47,6 +47,7 @@ struct _GrWindow
         GtkWidget *header_start_stack;
         GtkWidget *header_title_stack;
         GtkWidget *header_end_stack;
+        GtkWidget *back_button;
         GtkWidget *search_button;
         GtkWidget *cooking_button;
         GtkWidget *search_bar;
@@ -341,12 +342,21 @@ window_buttonpress_handler (GtkWidget *widget,
 {
         GrWindow *window = GR_WINDOW (widget);
         const char *visible;
+        GdkEventButton *e = (GdkEventButton *) event;
 
         visible = gtk_stack_get_visible_child_name (GTK_STACK (window->main_stack));
 
         if (strcmp (visible, "cooking") == 0)
           return gr_cooking_page_handle_event (GR_COOKING_PAGE (window->cooking_page), event);
 
+        /* handle mouse back button like a click on our actual back button */
+        if (e->button == 8 &&
+            gtk_widget_can_activate_accel (window->back_button,
+                                           g_signal_lookup ("clicked", GTK_TYPE_BUTTON))) {
+                gr_window_go_back (window);
+                return GDK_EVENT_STOP;
+        }
+
         return GDK_EVENT_PROPAGATE;
 }
 
@@ -514,6 +524,7 @@ gr_window_class_init (GrWindowClass *klass)
         gtk_widget_class_bind_template_child (widget_class, GrWindow, header_start_stack);
         gtk_widget_class_bind_template_child (widget_class, GrWindow, header_title_stack);
         gtk_widget_class_bind_template_child (widget_class, GrWindow, header_end_stack);
+        gtk_widget_class_bind_template_child (widget_class, GrWindow, back_button);
         gtk_widget_class_bind_template_child (widget_class, GrWindow, search_button);
         gtk_widget_class_bind_template_child (widget_class, GrWindow, cooking_button);
         gtk_widget_class_bind_template_child (widget_class, GrWindow, search_bar);
diff --git a/src/gr-window.ui b/src/gr-window.ui
index c41698c..795ed35 100644
--- a/src/gr-window.ui
+++ b/src/gr-window.ui
@@ -27,7 +27,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton">
+              <object class="GtkButton" id="back_button">
                 <property name="visible">1</property>
                 <signal name="clicked" handler="go_back" swapped="yes"/>
                 <style>


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