[Xfce4-commits] [xfce/xfce4-panel] 02/02: launcher: Show desktop actions in context menu

noreply at xfce.org noreply at xfce.org
Sat Apr 4 21:14:36 CEST 2020


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 7f3dd44de951a74dc1adb446e2b2f643043b1100
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Sat Apr 4 21:11:37 2020 +0200

    launcher: Show desktop actions in context menu
    
    So e.g. for Firefox this includes "Open a New Window" and
    "Open a New Private Window".
    This feature is only available for launchers holding a single
    application (as opposed to launcher menus).
    This feature depends on garcon >= 0.7.0.
---
 plugins/launcher/Makefile.am |  2 ++
 plugins/launcher/launcher.c  | 82 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/plugins/launcher/Makefile.am b/plugins/launcher/Makefile.am
index 2ce91b3..973d25d 100644
--- a/plugins/launcher/Makefile.am
+++ b/plugins/launcher/Makefile.am
@@ -25,6 +25,7 @@ liblauncher_la_CFLAGS = \
 	$(LIBXFCE4UTIL_CFLAGS) \
 	$(LIBXFCE4UI_CFLAGS) \
 	$(GARCON_CFLAGS) \
+	$(GARCON_GTK3_CFLAGS) \
 	$(GIO_CFLAGS) \
 	$(XFCONF_CFLAGS) \
 	$(PLATFORM_CFLAGS)
@@ -43,6 +44,7 @@ liblauncher_la_LIBADD = \
 	$(LIBXFCE4UTIL_LIBS) \
 	$(LIBXFCE4UI_LIBS) \
 	$(GARCON_LIBS) \
+	$(GARCON_GTK3_LIBS) \
 	$(GIO_LIBS) \
 	$(XFCONF_LIBS)
 
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index 5731aca..531fc3e 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -28,6 +28,7 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <garcon/garcon.h>
+#include <garcon-gtk/garcon-gtk.h>
 #include <xfconf/xfconf.h>
 
 #include <libxfce4panel/libxfce4panel.h>
@@ -93,6 +94,9 @@ static void               launcher_plugin_menu_popup_destroyed          (gpointe
 static gboolean           launcher_plugin_menu_popup                    (gpointer              user_data);
 static void               launcher_plugin_menu_destroy                  (LauncherPlugin       *plugin);
 static void               launcher_plugin_button_update                 (LauncherPlugin       *plugin);
+#if GARCON_CHECK_VERSION(0,7,0)
+static void               launcher_plugin_button_update_action_menu     (LauncherPlugin       *plugin);
+#endif
 static void               launcher_plugin_button_state_changed          (GtkWidget            *button_a,
                                                                          GtkStateType         state,
                                                                          GtkWidget            *button_b);
@@ -191,6 +195,9 @@ struct _LauncherPlugin
   GtkWidget         *arrow;
   GtkWidget         *child;
   GtkWidget         *menu;
+#if GARCON_CHECK_VERSION(0,7,0)
+  GtkWidget         *action_menu;
+#endif
 
   GSList            *items;
 
@@ -336,6 +343,9 @@ launcher_plugin_init (LauncherPlugin *plugin)
   plugin->show_label = FALSE;
   plugin->arrow_position = LAUNCHER_ARROW_DEFAULT;
   plugin->menu = NULL;
+#if GARCON_CHECK_VERSION(0,7,0)
+  plugin->action_menu = NULL;
+#endif
   plugin->items = NULL;
   plugin->child = NULL;
   plugin->tooltip_cache = NULL;
@@ -501,7 +511,12 @@ launcher_plugin_item_changed (GarconMenuItem *item,
     {
       /* update the button or destroy the menu */
       if (plugin->items == li)
-        launcher_plugin_button_update (plugin);
+        {
+          launcher_plugin_button_update (plugin);
+#if GARCON_CHECK_VERSION(0,7,0)
+          launcher_plugin_button_update_action_menu (plugin);
+#endif
+        }
       else
         launcher_plugin_menu_destroy (plugin);
     }
@@ -862,6 +877,9 @@ launcher_plugin_set_property (GObject      *object,
 
       /* update the button */
       launcher_plugin_button_update (plugin);
+#if GARCON_CHECK_VERSION(0,7,0)
+      launcher_plugin_button_update_action_menu (plugin);
+#endif
 
       /* update the widget packing */
       goto update_arrow;
@@ -1003,6 +1021,9 @@ launcher_plugin_file_changed (GFileMonitor      *monitor,
     {
       launcher_plugin_button_update (plugin);
       launcher_plugin_menu_destroy (plugin);
+#if GARCON_CHECK_VERSION(0,7,0)
+      launcher_plugin_button_update_action_menu (plugin);
+#endif
 
       /* save the new config */
       launcher_plugin_save_delayed (plugin);
@@ -1835,6 +1856,65 @@ launcher_plugin_button_update (LauncherPlugin *plugin)
 
 
 
+#if GARCON_CHECK_VERSION(0,7,0)
+static void
+launcher_plugin_add_desktop_actions (GtkWidget *widget, gpointer user_data)
+{
+  LauncherPlugin *plugin = XFCE_LAUNCHER_PLUGIN (user_data);
+
+  panel_return_if_fail (GTK_IS_WIDGET (widget));
+  panel_return_if_fail (GTK_IS_MENU (plugin->action_menu));
+  panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
+
+  /* Pack the action menu item into the plugin's context menu */
+  g_object_ref (widget);
+  gtk_container_remove (GTK_CONTAINER (plugin->action_menu), widget);
+  xfce_panel_plugin_menu_insert_item (XFCE_PANEL_PLUGIN (plugin), GTK_MENU_ITEM (widget));
+  g_object_unref (widget);
+}
+
+
+
+static void
+launcher_plugin_button_update_action_menu (LauncherPlugin *plugin)
+{
+  GarconMenuItem      *item = NULL;
+
+  panel_return_if_fail (XFCE_IS_LAUNCHER_PLUGIN (plugin));
+  panel_return_if_fail (plugin->menu == NULL);
+
+  /* If there are >1 items in the launcher don't show the action menu */
+  if (LIST_HAS_TWO_OR_MORE_ENTRIES (plugin->items))
+    {
+      xfce_panel_plugin_menu_destroy (XFCE_PANEL_PLUGIN (plugin));
+      plugin->action_menu = NULL;
+      return;
+    }
+
+  if (G_LIKELY (plugin->items != NULL))
+    item = GARCON_MENU_ITEM (plugin->items->data);
+
+  xfce_panel_plugin_menu_destroy (XFCE_PANEL_PLUGIN (plugin));
+  if (plugin->action_menu)
+    {
+      gtk_widget_destroy (GTK_WIDGET (plugin->action_menu));
+    }
+  else
+    {
+      plugin->action_menu = garcon_gtk_menu_get_desktop_actions_menu (item);
+      gtk_menu_set_reserve_toggle_size (GTK_MENU (plugin->action_menu), FALSE);
+      if (plugin->action_menu)
+        {
+          gtk_container_foreach (GTK_CONTAINER (plugin->action_menu),
+                                 launcher_plugin_add_desktop_actions,
+                                 plugin);
+        }
+    }
+}
+#endif
+
+
+
 static void
 launcher_plugin_button_state_changed (GtkWidget    *button_a,
                                       GtkStateType  state,

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


More information about the Xfce4-commits mailing list