[Xfce4-commits] [xfce/xfce4-panel] 01/01: show-desktop: Toggle also when DND-ing (Bug #15654)

noreply at xfce.org noreply at xfce.org
Thu Jul 4 23:41:04 CEST 2019


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-panel.

commit 120ed6d766b2ada4beda0d96e69a0e18f629e561
Author: Matias De lellis <mati86dl at gmail.com>
Date:   Thu Jul 4 23:38:56 2019 +0200

    show-desktop: Toggle also when DND-ing (Bug #15654)
    
    When dragging a file to the show-desktop plugin's button the button will
    be activated and the desktop will be shown, enabling users to
    interactively copy items to the desktop in a single mouse-driven
    workflow.
---
 plugins/showdesktop/showdesktop.c | 78 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/plugins/showdesktop/showdesktop.c b/plugins/showdesktop/showdesktop.c
index 9f3b3de..00e02e2 100644
--- a/plugins/showdesktop/showdesktop.c
+++ b/plugins/showdesktop/showdesktop.c
@@ -29,6 +29,10 @@
 
 
 
+#define DRAG_ACTIVATE_TIMEOUT (500)
+
+
+
 static void     show_desktop_plugin_screen_changed          (GtkWidget              *widget,
                                                              GdkScreen              *previous_screen);
 static void     show_desktop_plugin_construct               (XfcePanelPlugin        *panel_plugin);
@@ -42,6 +46,16 @@ static gboolean show_desktop_plugin_button_release_event    (GtkToggleButton
                                                              ShowDesktopPlugin      *plugin);
 static void     show_desktop_plugin_showing_desktop_changed (WnckScreen             *wnck_screen,
                                                              ShowDesktopPlugin      *plugin);
+static void     show_desktop_plugin_drag_leave              (GtkWidget              *widget,
+                                                             GdkDragContext         *context,
+                                                             guint                   time,
+                                                             ShowDesktopPlugin      *plugin);
+static gboolean show_desktop_plugin_drag_motion             (GtkWidget              *widget,
+                                                             GdkDragContext         *context,
+                                                             gint                    x,
+                                                             gint                    y,
+                                                             guint                   time,
+                                                             ShowDesktopPlugin      *plugin);
 
 
 
@@ -58,6 +72,9 @@ struct _ShowDesktopPlugin
   GtkWidget  *button;
   GtkWidget  *icon;
 
+  /* Dnd timeout */
+  guint       drag_timeout;
+
   /* the wnck screen */
   WnckScreen *wnck_screen;
 };
@@ -105,6 +122,13 @@ show_desktop_plugin_init (ShowDesktopPlugin *plugin)
   xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (plugin), button);
   gtk_widget_show (button);
 
+  /* allow toggle the button when drag something.*/
+  gtk_drag_dest_set (GTK_WIDGET (plugin->button), 0, NULL, 0, 0);
+  g_signal_connect (G_OBJECT (plugin->button), "drag_motion",
+      G_CALLBACK (show_desktop_plugin_drag_motion), plugin);
+  g_signal_connect (G_OBJECT (plugin->button), "drag_leave",
+      G_CALLBACK (show_desktop_plugin_drag_leave), plugin);
+
   plugin->icon = gtk_image_new_from_icon_name ("user-desktop", GTK_ICON_SIZE_MENU);
   gtk_container_add (GTK_CONTAINER (button), plugin->icon);
   gtk_widget_show (plugin->icon);
@@ -274,3 +298,57 @@ show_desktop_plugin_showing_desktop_changed (WnckScreen        *wnck_screen,
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->button),
       wnck_screen_get_showing_desktop (wnck_screen));
 }
+
+
+
+static gboolean
+show_desktop_plugin_drag_timeout (gpointer data)
+{
+  ShowDesktopPlugin *plugin = (ShowDesktopPlugin *) data;
+
+  plugin->drag_timeout = 0;
+
+  /* activate button to toggle show desktop */
+  g_signal_emit_by_name (G_OBJECT (plugin->button), "clicked", plugin);
+
+  return FALSE;
+}
+
+
+
+static void
+show_desktop_plugin_drag_leave (GtkWidget         *widget,
+                                GdkDragContext    *context,
+                                guint              time,
+                                ShowDesktopPlugin *plugin)
+{
+  if (plugin->drag_timeout != 0)
+    {
+      g_source_remove (plugin->drag_timeout);
+      plugin->drag_timeout = 0;
+    }
+
+  gtk_drag_unhighlight (GTK_WIDGET (widget));
+}
+
+
+
+static gboolean
+show_desktop_plugin_drag_motion (GtkWidget         *widget,
+                                 GdkDragContext    *context,
+                                 gint               x,
+                                 gint               y,
+                                 guint              time,
+                                 ShowDesktopPlugin *plugin)
+{
+  if (plugin->drag_timeout == 0)
+    plugin->drag_timeout = g_timeout_add (DRAG_ACTIVATE_TIMEOUT,
+                                          show_desktop_plugin_drag_timeout,
+                                          plugin);
+
+  gtk_drag_highlight (GTK_WIDGET (widget));
+
+  gdk_drag_status (context, 0, time);
+
+  return TRUE;
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list