[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 65/473: Add popping up menu at mouse cursor.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:53:55 CET 2015


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

gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit 278c139dcc31a8f0646fec90d6213d54ccec4dd2
Author: Graeme Gott <graeme at gottcode.org>
Date:   Thu Jul 4 09:00:44 2013 -0400

    Add popping up menu at mouse cursor.
---
 src/menu.cpp         |   47 ++++++++++++++++++++++++++++-------------------
 src/panel_plugin.cpp |   21 ++++++++++++++-------
 src/panel_plugin.hpp |    2 +-
 3 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/src/menu.cpp b/src/menu.cpp
index 7e32008..6ac7fc3 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -228,30 +228,39 @@ void Menu::show(GtkWidget* parent, bool horizontal)
 	// Reset mouse cursor by forcing favorites to hide
 	gtk_widget_show(m_favorites->get_widget());
 
-	// Wait up to half a second for auto-hidden panels to be shown
-	clock_t end = clock() + (CLOCKS_PER_SEC / 2);
-	GtkWindow* parent_window = GTK_WINDOW(gtk_widget_get_toplevel(parent));
-	int parent_x = 0, parent_y = 0;
-	gtk_window_get_position(parent_window, &parent_x, &parent_y);
-	while ((parent_x == -9999) && (parent_y == -9999) && (clock() < end))
-	{
-		while (gtk_events_pending())
+	GdkScreen* screen = NULL;
+	int parent_x = 0, parent_y = 0, parent_w = 0, parent_h = 0;
+	if (parent != NULL)
+	{
+		// Wait up to half a second for auto-hidden panels to be shown
+		clock_t end = clock() + (CLOCKS_PER_SEC / 2);
+		GtkWindow* parent_window = GTK_WINDOW(gtk_widget_get_toplevel(parent));
+		gtk_window_get_position(parent_window, &parent_x, &parent_y);
+		while ((parent_x == -9999) && (parent_y == -9999) && (clock() < end))
 		{
-			gtk_main_iteration();
+			while (gtk_events_pending())
+			{
+				gtk_main_iteration();
+			}
+			gtk_window_get_position(parent_window, &parent_x, &parent_y);
 		}
-		gtk_window_get_position(parent_window, &parent_x, &parent_y);
-	}
 
-	// Fetch parent geometry
-	if (!gtk_widget_get_realized(parent))
+		// Fetch parent geometry
+		if (!gtk_widget_get_realized(parent))
+		{
+			gtk_widget_realize(parent);
+		}
+		GdkWindow* window = gtk_widget_get_window(parent);
+		gdk_window_get_origin(window, &parent_x, &parent_y);
+		screen = gdk_window_get_screen(window);
+		parent_w = gdk_window_get_width(window);
+		parent_h = gdk_window_get_height(window);
+	}
+	else
 	{
-		gtk_widget_realize(parent);
+		GdkDisplay* display = gdk_display_get_default();
+		gdk_display_get_pointer(display, &screen, &parent_x, &parent_y, NULL);
 	}
-	GdkWindow* window = gtk_widget_get_window(parent);
-	GdkScreen* screen = gdk_window_get_screen(window);
-	gdk_window_get_origin(window, &parent_x, &parent_y);
-	int parent_w = gdk_window_get_width(window);
-	int parent_h = gdk_window_get_height(window);
 
 	// Fetch screen geomtry
 	GdkRectangle monitor;
diff --git a/src/panel_plugin.cpp b/src/panel_plugin.cpp
index 1d78c8c..980b0eb 100644
--- a/src/panel_plugin.cpp
+++ b/src/panel_plugin.cpp
@@ -145,7 +145,7 @@ gboolean PanelPlugin::button_clicked(GtkWidget*, GdkEventButton* event)
 	}
 	else
 	{
-		popup_menu();
+		popup_menu(false);
 	}
 
 	return true;
@@ -175,14 +175,14 @@ void PanelPlugin::orientation_changed(XfcePanelPlugin*, GtkOrientation)
 
 //-----------------------------------------------------------------------------
 
-gboolean PanelPlugin::remote_event(XfcePanelPlugin*, gchar* name, GValue*)
+gboolean PanelPlugin::remote_event(XfcePanelPlugin*, gchar* name, GValue* value)
 {
 	if (strcmp(name, "popup") || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_button)))
 	{
 		return false;
 	}
 
-	popup_menu();
+	popup_menu(value && G_VALUE_HOLDS_BOOLEAN(value) && g_value_get_boolean(value));
 
 	return true;
 }
@@ -232,11 +232,18 @@ gboolean PanelPlugin::size_changed(XfcePanelPlugin*, gint size)
 
 //-----------------------------------------------------------------------------
 
-void PanelPlugin::popup_menu()
+void PanelPlugin::popup_menu(bool at_cursor)
 {
-	xfce_panel_plugin_block_autohide(m_plugin, true);
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_button), true);
-	m_menu->show(m_button, xfce_panel_plugin_get_orientation(m_plugin) == GTK_ORIENTATION_HORIZONTAL);
+	if (!at_cursor)
+	{
+		xfce_panel_plugin_block_autohide(m_plugin, true);
+		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_button), true);
+		m_menu->show(m_button, xfce_panel_plugin_get_orientation(m_plugin) == GTK_ORIENTATION_HORIZONTAL);
+	}
+	else
+	{
+		m_menu->show(NULL, true);
+	}
 }
 
 //-----------------------------------------------------------------------------
diff --git a/src/panel_plugin.hpp b/src/panel_plugin.hpp
index 710f943..eef3aaf 100644
--- a/src/panel_plugin.hpp
+++ b/src/panel_plugin.hpp
@@ -62,7 +62,7 @@ private:
 	SLOT_2(gboolean, PanelPlugin, size_changed, XfcePanelPlugin*, gint);
 
 private:
-	void popup_menu();
+	void popup_menu(bool at_cursor);
 
 private:
 	XfcePanelPlugin* m_plugin;

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


More information about the Xfce4-commits mailing list