[Goodies-commits] r6176 - in xfce4-places-plugin/trunk: . panel-plugin
Diego Ongaro
ongardie at xfce.org
Sun Nov 23 12:15:21 CET 2008
Author: ongardie
Date: 2008-11-23 11:15:21 +0000 (Sun, 23 Nov 2008)
New Revision: 6176
Added:
xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.c
xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.h
Modified:
xfce4-places-plugin/trunk/ChangeLog
xfce4-places-plugin/trunk/configure.in.in
xfce4-places-plugin/trunk/panel-plugin/Makefile.am
xfce4-places-plugin/trunk/panel-plugin/view.c
Log:
Adds xfce46-compat files for menu positioning
Modified: xfce4-places-plugin/trunk/ChangeLog
===================================================================
--- xfce4-places-plugin/trunk/ChangeLog 2008-11-23 07:58:56 UTC (rev 6175)
+++ xfce4-places-plugin/trunk/ChangeLog 2008-11-23 11:15:21 UTC (rev 6176)
@@ -1,3 +1,8 @@
+2008-11-23 Diego Ongaro <ongardie at gmail.com>
+
+ * view.c, xfce46-compat.{c,h}: Adds xfce46-compat files for menu
+ positioning
+
2008-11-21 Diego Ongaro <ongardie at gmail.com>
* support.{c,h}, model_volumes.c, view.c: Try exo_url_show
Modified: xfce4-places-plugin/trunk/configure.in.in
===================================================================
--- xfce4-places-plugin/trunk/configure.in.in 2008-11-23 07:58:56 UTC (rev 6175)
+++ xfce4-places-plugin/trunk/configure.in.in 2008-11-23 11:15:21 UTC (rev 6176)
@@ -27,6 +27,9 @@
XDT_CHECK_PACKAGE([THUNAR_VFS], [thunar-vfs-1], [0.3.2])
XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.1.1])
+dnl check for optional packages/versions
+XDT_CHECK_OPTIONAL_PACKAGE([LIBXFCE4PANEL_46], [libxfce4panel-1.0], [4.5.92], [libxfce4panel46], [Take advantage of Xfce 4.6 panel changes])
+
dnl check for i18n support
XDT_I18N([@LINGUAS@])
Modified: xfce4-places-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/Makefile.am 2008-11-23 07:58:56 UTC (rev 6175)
+++ xfce4-places-plugin/trunk/panel-plugin/Makefile.am 2008-11-23 11:15:21 UTC (rev 6176)
@@ -38,7 +38,9 @@
model_volumes.c \
model_volumes.h \
button.c \
- button.h
+ button.h \
+ xfce46-compat.c \
+ xfce46-compat.h
Modified: xfce4-places-plugin/trunk/panel-plugin/view.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/view.c 2008-11-23 07:58:56 UTC (rev 6175)
+++ xfce4-places-plugin/trunk/panel-plugin/view.c 2008-11-23 11:15:21 UTC (rev 6176)
@@ -59,6 +59,8 @@
#include <string.h>
+#include "xfce46-compat.h"
+
#include "view.h"
#include "support.h"
#include "cfg.h"
@@ -279,68 +281,6 @@
}
-/* Copied almost verbatim from notes plugin */
-static void
-pview_cb_menu_position(GtkMenu *menu,
- gint *x, gint *y,
- gboolean *push_in,
- XfcePanelPlugin *plugin)
-{
- GtkRequisition requisition;
- GtkWidget *attach_widget;
-
- g_return_if_fail(GTK_IS_MENU(menu));
- g_return_if_fail(XFCE_IS_PANEL_PLUGIN(plugin));
-
- attach_widget = gtk_menu_get_attach_widget(menu);
- g_return_if_fail(GTK_IS_WIDGET(attach_widget));
-
- gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
- gdk_window_get_origin(attach_widget->window, x, y);
-
- switch(xfce_panel_plugin_get_orientation(plugin))
- {
- case GTK_ORIENTATION_HORIZONTAL:
-
- if(*y + attach_widget->allocation.height + requisition.height > gdk_screen_height()){
- /* Show menu above */
- *y -= requisition.height;
- }else{
- /* Show menu below */
- *y += attach_widget->allocation.height;
- }
-
- if(*x + requisition.width > gdk_screen_width()){
- /* Adjust horizontal position */
- *x = gdk_screen_width () - requisition.width;
- }
-
- break;
-
- case GTK_ORIENTATION_VERTICAL:
-
- if(*x + attach_widget->allocation.width + requisition.width > gdk_screen_width()){
- /* Show menu on the right */
- *x -= requisition.width;
- }else{
- /* Show menu on the left */
- *x += attach_widget->allocation.width;
- }
-
- if(*y + requisition.height > gdk_screen_height()){
- /* Adjust vertical position */
- *y = gdk_screen_height() - requisition.height;
- }
-
- break;
-
- default:
- break;
- }
-
- *push_in = FALSE;
-}
-
static void
pview_cb_menu_deact(PlacesView *pd, GtkWidget *menu)
{
@@ -767,14 +707,9 @@
/* toggle the button */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pd->button), TRUE);
- /* Register this menu (for focus, transparency, auto-hide, etc) */
- /* We don't want to register if the menu is visible (hasn't been deactivated) */
- if(!GTK_WIDGET_VISIBLE(pd->menu))
- xfce_panel_plugin_register_menu(pd->plugin, GTK_MENU(pd->menu));
-
/* popup menu */
gtk_menu_popup (GTK_MENU (pd->menu), NULL, NULL,
- (GtkMenuPositionFunc) pview_cb_menu_position,
+ xfce_panel_plugin_position_menu,
pd->plugin, 0,
gtk_get_current_event_time ());
Added: xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.c (rev 0)
+++ xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.c 2008-11-23 11:15:21 UTC (rev 6176)
@@ -0,0 +1,253 @@
+/*
+ * Code was taken from libxfce4panel (LGPL2 or any later version),
+ * distributed here under the GPL.
+ *
+ * Copyright (c) 2005-2007 Jasper Huijsmans <jasper at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef HAVE_LIBXFCE4PANEL_46
+
+#include "xfce46-compat.h"
+
+#include <libxfce4panel/xfce-panel-plugin.h>
+#include <libxfce4panel/xfce-panel-macros.h>
+
+/* support macros for debugging */
+#ifndef NDEBUG
+#define _panel_assert(expr) g_assert (expr)
+#define _panel_assert_not_reached() g_assert_not_reached ()
+#define _panel_return_if_fail(expr) g_return_if_fail (expr)
+#define _panel_return_val_if_fail(expr, val) g_return_val_if_fail (expr, (val))
+#else
+#define _panel_assert(expr) G_STMT_START{ (void)0; }G_STMT_END
+#define _panel_assert_not_reached() G_STMT_START{ (void)0; }G_STMT_END
+#define _panel_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END
+#define _panel_return_val_if_fail(expr, val) G_STMT_START{ (void)0; }G_STMT_END
+#endif
+
+/**
+ * xfce_panel_plugin_arrow_type:
+ * @plugin : an #XfcePanelPlugin
+ *
+ * Determine the #GtkArrowType for a widget that opens a menu and uses
+ * xfce_panel_plugin_position_menu() to position the menu.
+ *
+ * Returns: The #GtkArrowType to use.
+ **/
+static GtkArrowType
+xfce_panel_plugin_arrow_type (XfcePanelPlugin *plugin)
+{
+ XfceScreenPosition position;
+ GdkScreen *screen;
+ GdkRectangle geom;
+ gint mon, x, y;
+
+ if (!GTK_WIDGET_REALIZED (plugin))
+ return GTK_ARROW_UP;
+
+ position = xfce_panel_plugin_get_screen_position (plugin);
+ switch (position)
+ {
+ /* top */
+ case XFCE_SCREEN_POSITION_NW_H:
+ case XFCE_SCREEN_POSITION_N:
+ case XFCE_SCREEN_POSITION_NE_H:
+ return GTK_ARROW_DOWN;
+
+ /* left */
+ case XFCE_SCREEN_POSITION_NW_V:
+ case XFCE_SCREEN_POSITION_W:
+ case XFCE_SCREEN_POSITION_SW_V:
+ return GTK_ARROW_RIGHT;
+
+ /* right */
+ case XFCE_SCREEN_POSITION_NE_V:
+ case XFCE_SCREEN_POSITION_E:
+ case XFCE_SCREEN_POSITION_SE_V:
+ return GTK_ARROW_LEFT;
+
+ /* bottom */
+ case XFCE_SCREEN_POSITION_SW_H:
+ case XFCE_SCREEN_POSITION_S:
+ case XFCE_SCREEN_POSITION_SE_H:
+ return GTK_ARROW_UP;
+
+ /* floating */
+ default:
+ /* get the screen information */
+ screen = gtk_widget_get_screen (GTK_WIDGET (plugin));
+ mon = gdk_screen_get_monitor_at_window (screen, GTK_WIDGET (plugin)->window);
+ gdk_screen_get_monitor_geometry (screen, mon, &geom);
+ gdk_window_get_root_origin (GTK_WIDGET (plugin)->window, &x, &y);
+
+ /* get the position based on the screen position */
+ if (position == XFCE_SCREEN_POSITION_FLOATING_H)
+ return ((y < (geom.y + geom.height / 2)) ? GTK_ARROW_DOWN : GTK_ARROW_UP);
+ else
+ return ((x < (geom.x + geom.width / 2)) ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT);
+ }
+}
+
+
+
+/**
+ * xfce_panel_plugin_position_widget:
+ * @plugin : an #XfcePanelPlugin
+ * @menu_widget : a #GtkWidget that will be used as popup menu
+ * @attach_widget : a #GtkWidget relative to which the menu should be positioned
+ * @x : return location for the x coordinate
+ * @y : return location for the y coordinate
+ *
+ * The menu widget is positioned relative to @attach_widget.
+ * If @attach_widget is NULL, the menu widget is instead positioned
+ * relative to @panel_plugin.
+ *
+ * This function is intended for custom menu widgets.
+ * For a regular #GtkMenu you should use xfce_panel_plugin_position_menu()
+ * instead (as callback argument to gtk_menu_popup()).
+ *
+ * See also: xfce_panel_plugin_position_menu().
+ **/
+static void
+xfce_panel_plugin_position_widget (XfcePanelPlugin *plugin,
+ GtkWidget *menu_widget,
+ GtkWidget *attach_widget,
+ gint *x,
+ gint *y)
+{
+ GtkRequisition req;
+ GdkScreen *screen;
+ GdkRectangle geom;
+ gint mon;
+
+ _panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
+ _panel_return_if_fail (GTK_IS_WIDGET (menu_widget));
+ _panel_return_if_fail (attach_widget == NULL || GTK_IS_WIDGET (attach_widget));
+
+ if (attach_widget == NULL)
+ attach_widget = GTK_WIDGET (plugin);
+
+ if (!GTK_WIDGET_REALIZED (menu_widget))
+ gtk_widget_realize (menu_widget);
+
+ gtk_widget_size_request (menu_widget, &req);
+ gdk_window_get_origin (attach_widget->window, x, y);
+
+ switch (xfce_panel_plugin_arrow_type (plugin))
+ {
+ case GTK_ARROW_UP:
+ *y -= req.height;
+ break;
+
+ case GTK_ARROW_DOWN:
+ *y += attach_widget->allocation.height;
+ break;
+
+ case GTK_ARROW_LEFT:
+ *x -= req.width;
+ break;
+
+ default: /* GTK_ARROW_RIGHT and GTK_ARROW_NONE */
+ *x += attach_widget->allocation.width;
+ break;
+ }
+
+ screen = gtk_widget_get_screen (attach_widget);
+ mon = gdk_screen_get_monitor_at_window (screen, attach_widget->window);
+ gdk_screen_get_monitor_geometry (screen, mon, &geom);
+
+ /* keep inside the screen */
+ if (*x > geom.x + geom.width - req.width)
+ *x = geom.x + geom.width - req.width;
+ if (*x < geom.x)
+ *x = geom.x;
+ if (*y > geom.y + geom.height - req.height)
+ *y = geom.y + geom.height - req.height;
+ if (*y < geom.y)
+ *y = geom.y;
+
+ if (G_LIKELY (GTK_IS_MENU (menu_widget)))
+ gtk_menu_set_screen (GTK_MENU (menu_widget), screen);
+ else if (GTK_IS_WINDOW (menu_widget))
+ gtk_window_set_screen (GTK_WINDOW (menu_widget), screen);
+}
+
+
+
+/**
+ * xfce_panel_plugin_position_menu:
+ * @menu : a #GtkMenu
+ * @x : return location for the x coordinate
+ * @y : return location for the y coordinate
+ * @push_in : keep inside the screen (see #GtkMenuPositionFunc)
+ * @panel_plugin : a pointer to an #XfcePanelPlugin
+ *
+ * Function to be used as #GtkMenuPositionFunc in a call to gtk_menu_popup().
+ * As data argument it needs an #XfcePanelPlugin.
+ *
+ * The menu is normally positioned relative to @panel_plugin. If you want the
+ * menu to be positioned relative to another widget, you can use
+ * gtk_menu_attach_to_widget() to explicitly set a 'parent' widget.
+ *
+ * As a convenience, xfce_panel_plugin_position_menu() calls
+ * xfce_panel_plugin_register_menu() for the menu.
+ *
+ * <example>
+ * void
+ * myplugin_popup_menu (XfcePanelPlugin *plugin,
+ * GtkMenu *menu,
+ * GdkEventButton *ev)
+ * {
+ * gtk_menu_popup (menu, NULL, NULL,
+ * xfce_panel_plugin_position_menu, plugin,
+ * ev->button, ev->time );
+ * }
+ * </example>
+ *
+ * For a custom widget that will be used as a popup menu, use
+ * xfce_panel_plugin_position_widget() instead.
+ *
+ * See also: gtk_menu_popup().
+ **/
+void
+xfce_panel_plugin_position_menu (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer panel_plugin)
+{
+ XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (panel_plugin);
+ GtkWidget *attach_widget;
+
+ attach_widget = gtk_menu_get_attach_widget (menu);
+
+ xfce_panel_plugin_position_widget (plugin,
+ GTK_WIDGET (menu),
+ attach_widget,
+ x, y);
+
+ /* keep inside screen */
+ *push_in = TRUE;
+
+ xfce_panel_plugin_register_menu (plugin, menu);
+}
+
+#endif
Added: xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.h (rev 0)
+++ xfce4-places-plugin/trunk/panel-plugin/xfce46-compat.h 2008-11-23 11:15:21 UTC (rev 6176)
@@ -0,0 +1,18 @@
+#ifndef _XFCE46_COMPAT
+#define _XFCE46_COMPAT
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef HAVE_LIBXFCE4PANEL_46
+
+#include <gtk/gtk.h>
+
+void xfce_panel_plugin_position_menu (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer panel_plugin);
+#endif
+#endif
More information about the Goodies-commits
mailing list