[epiphany] page-row: Close on middle click



commit a15d7030689eb947665fd42ade1c42687201b7b7
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Sun Feb 24 22:23:15 2019 +0100

    page-row: Close on middle click
    
    Add a event box around page row to catch button-press-event and allow closing the current item with 
middle click.
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/643

 src/ephy-page-row.c           |  17 ++++++
 src/resources/gtk/page-row.ui | 133 +++++++++++++++++++++++++++---------------
 2 files changed, 103 insertions(+), 47 deletions(-)
---
diff --git a/src/ephy-page-row.c b/src/ephy-page-row.c
index 7914f6775..ca63e1697 100644
--- a/src/ephy-page-row.c
+++ b/src/ephy-page-row.c
@@ -82,6 +82,22 @@ close_clicked_cb (EphyPageRow *self)
   g_signal_emit (self, signals[CLOSED], 0);
 }
 
+static gboolean
+button_release_event (GtkWidget   *widget,
+                      GdkEvent    *event,
+                      EphyPageRow *self)
+{
+  GdkEventButton *button_event = (GdkEventButton *)event;
+
+  if (button_event->button == GDK_BUTTON_MIDDLE) {
+    g_signal_emit (self, signals[CLOSED], 0);
+
+    return GDK_EVENT_STOP;
+  }
+
+  return GDK_EVENT_PROPAGATE;
+}
+
 static void
 ephy_page_row_class_init (EphyPageRowClass *klass)
 {
@@ -102,6 +118,7 @@ ephy_page_row_class_init (EphyPageRowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EphyPageRow, spinner);
   gtk_widget_class_bind_template_child (widget_class, EphyPageRow, title);
   gtk_widget_class_bind_template_callback (widget_class, close_clicked_cb);
+  gtk_widget_class_bind_template_callback (widget_class, button_release_event);
 }
 
 static void
diff --git a/src/resources/gtk/page-row.ui b/src/resources/gtk/page-row.ui
index 6bc64369a..2b6fcadfb 100644
--- a/src/resources/gtk/page-row.ui
+++ b/src/resources/gtk/page-row.ui
@@ -1,70 +1,109 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
 <interface>
-  <!-- interface-requires gtk+ 3.16 -->
+  <requires lib="gtk+" version="3.16"/>
   <template class="EphyPageRow" parent="GtkListBoxRow">
+    <property name="can_focus">True</property>
     <child>
-      <object class="GtkBox" id="box">
+      <object class="GtkEventBox">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <signal name="button-release-event" handler="button_release_event" swapped="no"/>
         <child>
-          <object class="GtkStack" id="icon_stack">
+          <object class="GtkBox" id="box">
             <property name="visible">True</property>
-            <property name="margin_start">4</property>
-            <property name="margin_end">4</property>
+            <property name="can_focus">False</property>
             <child>
-              <object class="GtkImage" id="icon">
-                <property name="icon_size">1</property>
+              <object class="GtkStack" id="icon_stack">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_start">4</property>
+                <property name="margin_end">4</property>
+                <child>
+                  <object class="GtkImage" id="icon">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon_size">1</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkSpinner" id="spinner">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
             </child>
             <child>
-              <object class="GtkSpinner" id="spinner">
+              <object class="GtkLabel" id="title">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+                <property name="margin_start">4</property>
+                <property name="hexpand">True</property>
+                <property name="ellipsize">end</property>
+                <property name="single_line_mode">True</property>
+                <property name="xalign">0</property>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
             </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel" id="title">
-            <property name="ellipsize">end</property>
-            <property name="halign">start</property>
-            <property name="hexpand">True</property>
-            <property name="single_line_mode">True</property>
-            <property name="valign">center</property>
-            <property name="visible">True</property>
-            <property name="xalign">0</property>
-            <property name="margin_start">4</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkImage" id="speaker_icon">
-            <property name="icon_name">audio-volume-high-symbolic</property>
-            <property name="icon_size">1</property>
-            <property name="visible">True</property>
-            <property name="margin_start">8</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkButton" id="close_button">
-            <property name="can_focus">True</property>
-            <property name="focus_on_click">False</property>
-            <property name="halign">end</property>
-            <property name="relief">none</property>
-            <property name="tooltip-text" translatable="yes">Close page</property>
-            <property name="valign">center</property>
-            <property name="visible">True</property>
-            <signal name="clicked" handler="close_clicked_cb" swapped="yes"/>
-            <style>
-              <class name="flat"/>
-              <class name="image-button"/>
-              <class name="page-row-close-button"/>
-            </style>
             <child>
-              <object class="GtkImage">
+              <object class="GtkImage" id="speaker_icon">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="icon_name">window-close-symbolic</property>
+                <property name="margin_start">8</property>
+                <property name="icon_name">audio-volume-high-symbolic</property>
                 <property name="icon_size">1</property>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="close_button">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="focus_on_click">False</property>
+                <property name="receives_default">False</property>
+                <property name="tooltip_text" translatable="yes">Close page</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="relief">none</property>
+                <signal name="clicked" handler="close_clicked_cb" swapped="yes"/>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon_name">window-close-symbolic</property>
+                    <property name="icon_size">1</property>
+                  </object>
+                </child>
+                <style>
+                  <class name="flat"/>
+                  <class name="image-button"/>
+                  <class name="page-row-close-button"/>
+                </style>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">3</property>
+              </packing>
             </child>
           </object>
         </child>


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