Xfce Forum

Sub domains
 

You are not logged in.

#1 2019-09-21 11:43:40

tweakmeister
Member
Registered: 2012-05-02
Posts: 3

[solved] application menu: how to disable drag-and-drop behaviour

If i open the application menu and then drag an item in the menu with my left mouse button (which happens by accident every now and then) a drag-and-drop functionality appears, so you can drag the application somewhere to create a shortcut. I don't use launchers or desktop shortcuts at all so this just gets in my way. Is there a way to disable this feature with settings or even by patching source code?

2019-09-21-091748-1280x800-scrot.png

Last edited by tweakmeister (2019-09-22 08:35:13)

Offline

#2 2019-09-21 13:32:03

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 5,877

Re: [solved] application menu: how to disable drag-and-drop behaviour

Hello and welcome.

I don't believe there is a way to disable this functionality easily. Patching the code will be problematic because the menu code (including the drag/drop functionality) comes from garcon. If you disable it in garcon you will disable it in every Xfce component that uses the garcon support library - which are quite a few.

There might be a way to override those signals, but this is beyond my knowledge.

Options:

  1. Create an enhancement request at the bug tracker to allow for the disabling of the drag'n'drop functionality

  2. Ask at the xfce4-dev mailing list whether it is possible to override the garcon drag and drop signals from within applicationsmenu

  3. #2, followed by a working patch (if possible) then #1

Hope this is helpful.

Offline

#3 2019-09-21 19:08:53

tweakmeister
Member
Registered: 2012-05-02
Posts: 3

Re: [solved] application menu: how to disable drag-and-drop behaviour

Hi thanks for the answer. I didn't realise this was my first post even though my account is 8 years old. The drag and drop behaviour seems to be added pretty recently (or maybe by some GTK3 or Garcon update?. I have been using Xfce for years without it.  I will try the options you mention.

Offline

#4 2019-09-21 22:56:39

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 5,877

Re: [solved] application menu: how to disable drag-and-drop behaviour

tweakmeister wrote:

Hi thanks for the answer. I didn't realise this was my first post even though my account is 8 years old.

Funny. I just noticed the number of posts and not the registered date. 

I will try the options you mention.

Just finished looking closer at this and have a solution. Make sure you patch and build garcon first, then patch and build xfce4-panel second.

First, you need to patch garcon to make the drag'n'drop functionality optional (default is true). Here is the patch file (working off of the git tree):

diff --git a/garcon-gtk/garcon-gtk-menu.c b/garcon-gtk/garcon-gtk-menu.c
index 72e73ac..5c2daa4 100644
--- a/garcon-gtk/garcon-gtk-menu.c
+++ b/garcon-gtk/garcon-gtk-menu.c
@@ -51,6 +51,7 @@ enum
   PROP_SHOW_TOOLTIPS,
   PROP_SHOW_DESKTOP_ACTIONS,
   PROP_RIGHT_CLICK_EDITS,
+  PROP_ALLOW_DND,
   N_PROPERTIES
 };
 
@@ -85,6 +86,7 @@ struct _GarconGtkMenuPrivate
   guint show_tooltips : 1;
   guint show_desktop_actions : 1;
   guint right_click_edits : 1;
+  guint allow_dnd : 1;
 };
 
 
@@ -194,6 +196,19 @@ garcon_gtk_menu_class_init (GarconGtkMenuClass *klass)
                           FALSE,
                           G_PARAM_READWRITE
                           | G_PARAM_STATIC_STRINGS);
+                          
+ /**
+   * GarconMenu:allow-dnd:
+   *
+   *
+   **/
+  menu_props[PROP_ALLOW_DND] =
+    g_param_spec_boolean ("allow-dnd",
+                          "allow-dnd",
+                          "allow drag and drop of menu items",
+                          FALSE,
+                          G_PARAM_READWRITE
+                          | G_PARAM_STATIC_STRINGS);                          
 
   /* install all properties */
   g_object_class_install_properties (gobject_class, N_PROPERTIES, menu_props);
@@ -211,6 +226,7 @@ garcon_gtk_menu_init (GarconGtkMenu *menu)
   menu->priv->show_tooltips = FALSE;
   menu->priv->show_desktop_actions = FALSE;
   menu->priv->right_click_edits = FALSE;
+  menu->priv->allow_dnd = TRUE;
 
   gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
 }
@@ -268,6 +284,10 @@ garcon_gtk_menu_get_property (GObject    *object,
     case PROP_RIGHT_CLICK_EDITS:
       g_value_set_boolean (value, menu->priv->right_click_edits);
       break;
+      
+    case PROP_ALLOW_DND:
+      g_value_set_boolean (value, menu->priv->allow_dnd);
+      break;      
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -311,6 +331,10 @@ garcon_gtk_menu_set_property (GObject      *object,
       garcon_gtk_menu_set_right_click_edits (menu, g_value_get_boolean (value));
       break;
 
+    case PROP_ALLOW_DND:
+      garcon_gtk_menu_set_allow_dnd (menu, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -895,15 +919,18 @@ garcon_gtk_menu_add (GarconGtkMenu *menu,
                 gtk_widget_set_tooltip_text (mi, comment);
             }
 
-          /* support for dnd item to for example the xfce4-panel */
-          gtk_drag_source_set (mi, GDK_BUTTON1_MASK, dnd_target_list,
-              G_N_ELEMENTS (dnd_target_list), GDK_ACTION_COPY);
-          g_signal_connect_swapped (G_OBJECT (mi), "drag-begin",
-              G_CALLBACK (garcon_gtk_menu_item_drag_begin), li->data);
-          g_signal_connect_swapped (G_OBJECT (mi), "drag-data-get",
-              G_CALLBACK (garcon_gtk_menu_item_drag_data_get), li->data);
-          g_signal_connect_swapped (G_OBJECT (mi), "drag-end",
-              G_CALLBACK (garcon_gtk_menu_item_drag_end), menu);
+			 if (menu->priv->allow_dnd)
+			   {
+		         /* support for dnd item to for example the xfce4-panel */
+		         gtk_drag_source_set (mi, GDK_BUTTON1_MASK, dnd_target_list,
+		             G_N_ELEMENTS (dnd_target_list), GDK_ACTION_COPY);
+		         g_signal_connect_swapped (G_OBJECT (mi), "drag-begin",
+		             G_CALLBACK (garcon_gtk_menu_item_drag_begin), li->data);
+		         g_signal_connect_swapped (G_OBJECT (mi), "drag-data-get",
+		             G_CALLBACK (garcon_gtk_menu_item_drag_data_get), li->data);
+		         g_signal_connect_swapped (G_OBJECT (mi), "drag-end",
+		             G_CALLBACK (garcon_gtk_menu_item_drag_end), menu);
+            }
 
           /* doesn't happen, but anyway... */
           command = garcon_menu_item_get_command (li->data);
@@ -1266,3 +1293,42 @@ garcon_gtk_menu_get_right_click_edits (GarconGtkMenu *menu)
   g_return_val_if_fail (GARCON_GTK_IS_MENU (menu), FALSE);
   return menu->priv->right_click_edits;
 }
+
+
+
+/**
+ * garcon_gtk_menu_set_allow_dnd:
+ * @menu  : A #GarconGtkMenu
+ *
+ *
+ **/
+void
+garcon_gtk_menu_set_allow_dnd (GarconGtkMenu *menu,
+                                   gboolean       allow_dnd)
+{
+  g_return_if_fail (GARCON_GTK_IS_MENU (menu));
+
+  if (menu->priv->allow_dnd == allow_dnd)
+    return;
+
+  menu->priv->allow_dnd = !!allow_dnd;
+  g_object_notify_by_pspec (G_OBJECT (menu), menu_props[PROP_ALLOW_DND]);
+
+  garcon_gtk_menu_reload (menu);
+}
+
+
+
+/**
+ * garcon_gtk_menu_get_allow_dnd:
+ * @menu  : A #GarconGtkMenu
+ *
+ * Return value: if drag and drop of menu items is enabled
+ **/
+gboolean
+garcon_gtk_menu_get_allow_dnd (GarconGtkMenu *menu)
+{
+  g_return_val_if_fail (GARCON_GTK_IS_MENU (menu), FALSE);
+  return menu->priv->allow_dnd;
+}
+
diff --git a/garcon-gtk/garcon-gtk-menu.h b/garcon-gtk/garcon-gtk-menu.h
index 2e1f84a..b99f6f7 100644
--- a/garcon-gtk/garcon-gtk-menu.h
+++ b/garcon-gtk/garcon-gtk-menu.h
@@ -83,6 +83,10 @@ void                 garcon_gtk_menu_set_right_click_edits    (GarconGtkMenu *me
                                                                gboolean       enable_right_click_edits);
 gboolean             garcon_gtk_menu_get_right_click_edits    (GarconGtkMenu *menu);
 
+void                 garcon_gtk_menu_set_allow_dnd            (GarconGtkMenu *menu,
+                                                               gboolean       enable_allow_dnd);
+gboolean             garcon_gtk_menu_get_allow_dnd            (GarconGtkMenu *menu);
+
 G_END_DECLS
 
 #endif /* !__GARCON_GTK_MENU_H__ */

Second, you need to patch the applicationsmenu (part of xfce4-panel) to process this new setting ("allow-dnd"). Here is the patch file (built off of git tree):

diff --git a/plugins/applicationsmenu/applicationsmenu.c b/plugins/applicationsmenu/applicationsmenu.c
index ce51d037..f489e34c 100644
--- a/plugins/applicationsmenu/applicationsmenu.c
+++ b/plugins/applicationsmenu/applicationsmenu.c
@@ -85,7 +85,8 @@ enum
   PROP_BUTTON_ICON,
   PROP_CUSTOM_MENU,
   PROP_CUSTOM_MENU_FILE,
-  PROP_MENU_EDITOR
+  PROP_MENU_EDITOR,
+  PROP_ALLOW_DND
 };
 
 
@@ -195,13 +196,21 @@ applications_menu_plugin_class_init (ApplicationsMenuPluginClass *klass)
                                                         NULL, NULL,
                                                         NULL,
                                                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
+                                                        
   g_object_class_install_property (gobject_class,
                                    PROP_MENU_EDITOR,
                                    g_param_spec_string ("menu-editor",
                                                         NULL, NULL,
                                                         DEFAULT_EDITOR,
                                                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+                                                         
+  g_object_class_install_property (gobject_class,
+                                   PROP_ALLOW_DND,
+                                   g_param_spec_boolean ("allow-dnd",
+                                                         NULL, NULL,
+                                                         FALSE,
+                                                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+                                                                                                                  
 }
 
 
@@ -298,6 +307,11 @@ applications_menu_plugin_get_property (GObject    *object,
     case PROP_MENU_EDITOR:
       g_value_set_string (value, plugin->menu_editor);
       break;
+      
+    case PROP_ALLOW_DND:
+      g_value_set_boolean (value,
+          garcon_gtk_menu_get_allow_dnd (GARCON_GTK_MENU (plugin->menu)));
+      break;    
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -384,6 +398,11 @@ applications_menu_plugin_set_property (GObject      *object,
     case PROP_MENU_EDITOR:
       plugin->menu_editor = g_value_dup_string (value);
       break;
+      
+    case PROP_ALLOW_DND:
+      garcon_gtk_menu_set_allow_dnd (GARCON_GTK_MENU (plugin->menu),
+                                         g_value_get_boolean (value));
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -414,6 +433,7 @@ applications_menu_plugin_construct (XfcePanelPlugin *panel_plugin)
     { "custom-menu", G_TYPE_BOOLEAN },
     { "custom-menu-file", G_TYPE_STRING },
     { "menu-editor", G_TYPE_STRING },
+    { "allow-dnd", G_TYPE_BOOLEAN },    
     { NULL }
   };
 

And finally, you need to add a new xfconf setting for the applicationsmenu and set it to false:

xfconf-query -c xfce4-panel -p /plugins/plugin-7/allow-dnd -t bool -s false --create

...note that you need to change "plugin-7" to the actual number of the plugin on your system.

I'll create an enhancement request in the bug tracker to have this added to the code base.

Edit: garcon enhancement request
Edit2: applicationsmenu enhancement request

Last edited by ToZ (2019-09-21 23:06:06)

Offline

#5 2019-09-22 06:09:03

tweakmeister
Member
Registered: 2012-05-02
Posts: 3

Re: [solved] application menu: how to disable drag-and-drop behaviour

Wow that is excellent. Thanks for the help! I hope the enhancement gets accepted.

Offline

Board footer

Powered by FluxBB