[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Open shortcuts on button release, handle middle click.

Jannis Pohlmann noreply at xfce.org
Fri Dec 9 23:28:01 CET 2011


Updating branch refs/heads/jannis/new-shortcuts-pane
         to f61f14f75dc4a84c8a65c9b38d0135b9b7f160d6 (commit)
       from cf2b167f0cc2cb52e7bc6aa5ca7e821d88f365b0 (commit)

commit f61f14f75dc4a84c8a65c9b38d0135b9b7f160d6
Author: Jannis Pohlmann <jannis.pohlmann at codethink.co.uk>
Date:   Fri Dec 9 23:26:27 2011 +0100

    Open shortcuts on button release, handle middle click.

 thunar/thunar-shortcut.c |   62 +++++++++++++++++++++++++++------------------
 1 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/thunar/thunar-shortcut.c b/thunar/thunar-shortcut.c
index 280b636..a90b5f1 100644
--- a/thunar/thunar-shortcut.c
+++ b/thunar/thunar-shortcut.c
@@ -232,6 +232,8 @@ struct _ThunarShortcut
   ThunarPreferences  *preferences;
   ThunarIconSize      icon_size;
 
+  ThunarShortcutState state;
+
   GCancellable       *cancellable;
 
   guint               drag_highlight : 1;
@@ -239,7 +241,7 @@ struct _ThunarShortcut
   guint               drop_data_ready : 1;
   GList              *drop_file_list;
 
-  ThunarShortcutState state;
+  gint                pressed_button;
 };
 
 
@@ -738,10 +740,19 @@ static gboolean
 thunar_shortcut_button_press_event (GtkWidget      *widget,
                                     GdkEventButton *event)
 {
-  GtkStateType state;
+  ThunarShortcut *shortcut = THUNAR_SHORTCUT (widget);
+  GtkStateType    state;
+  gboolean        result = FALSE;
 
   _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT (widget), FALSE);
 
+  /* reset the pressed button state */
+  shortcut->pressed_button = -1;
+
+  /* ignore double click events */
+  if (event->type == GDK_2BUTTON_PRESS)
+    return TRUE;
+
   /* determine the widget's state */
   state = gtk_widget_get_state (widget);
 
@@ -756,25 +767,23 @@ thunar_shortcut_button_press_event (GtkWidget      *widget,
       gtk_widget_grab_focus (widget);
     }
 
-  /* distinguish between left, right and middle click */
-  if (event->button == 1)
+  if ((event->button == 1 || event->button == 2)
+      && (event->state & GDK_CONTROL_MASK) == 0)
     {
-      /* resolve (e.g. mount) the shortcut and activate it */
-      if (gtk_widget_get_state (widget) == GTK_STATE_SELECTED)
-        thunar_shortcut_resolve_and_activate (THUNAR_SHORTCUT (widget), FALSE);
+      /* first or second mouse button pressed, handle this in the
+       * button release handler */
+      shortcut->pressed_button = event->button;
     }
   else if (event->button == 3)
     {
       /* emit the context menu signal */
-      g_signal_emit (widget, SIGNAL_CONTEXT_MENU, 0);
-    }
-  else if (event->button == 2)
-    {
-      /* TODO we don't handle middle-click events yet */
-      g_debug ("middle button press");
+      g_signal_emit (shortcut, shortcut_signals[SIGNAL_CONTEXT_MENU], 0);
+
+      /* we handled the event */
+      result = TRUE;
     }
 
-  return TRUE;
+  return result;
 }
 
 
@@ -783,23 +792,26 @@ static gboolean
 thunar_shortcut_button_release_event (GtkWidget      *widget,
                                       GdkEventButton *event)
 {
+  ThunarShortcut *shortcut = THUNAR_SHORTCUT (widget);
+
   _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT (widget), FALSE);
 
-  /* distinguish between left, right and middle-click */
-  if (event->button == 3)
+  /* check whether we have an event matching the pressed button */
+  if (shortcut->pressed_button == (gint) event->button)
     {
-      /* TODO abort the menu popup timeout created in reaction to 
-       * the right button press event */
-
-      /* emit the popup-menu signal */
-      g_signal_emit_by_name (widget, "context-menu");
+      /* open in the same window on left click, in a new window on middle click */
+      if (event->button == 1)
+        thunar_shortcut_resolve_and_activate (shortcut, FALSE);
+      else if (event->button == 2)
+        thunar_shortcut_resolve_and_activate (shortcut, TRUE);
 
       return TRUE;
     }
-  else
-    {
-      return FALSE;
-    }
+
+  /* reset the pressd button state */
+  shortcut->pressed_button = -1;
+
+  return FALSE;
 }
 
 


More information about the Xfce4-commits mailing list