[Goodies-commits] r6177 - in xfce4-datetime-plugin/trunk: . panel-plugin
Diego Ongaro
ongardie at xfce.org
Sun Nov 23 12:42:15 CET 2008
Author: ongardie
Date: 2008-11-23 11:42:15 +0000 (Sun, 23 Nov 2008)
New Revision: 6177
Added:
xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.c
xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.h
Modified:
xfce4-datetime-plugin/trunk/ChangeLog
xfce4-datetime-plugin/trunk/configure.in.in
xfce4-datetime-plugin/trunk/panel-plugin/Makefile.am
xfce4-datetime-plugin/trunk/panel-plugin/datetime.c
Log:
Adds xfce46-compat files for calendar positioning
Modified: xfce4-datetime-plugin/trunk/ChangeLog
===================================================================
--- xfce4-datetime-plugin/trunk/ChangeLog 2008-11-23 11:15:21 UTC (rev 6176)
+++ xfce4-datetime-plugin/trunk/ChangeLog 2008-11-23 11:42:15 UTC (rev 6177)
@@ -1,3 +1,8 @@
+2008-11-23 Diego Ongaro <ongardie at gmail.com>
+
+ * panel-plugin/datetime.c, panel-plugin/xfce46-compat.{c,h}: Adds
+ xfce46-compat files for calendar positioning
+
2008-11-19 Diego Ongaro <ongardie at gmail.com>
* *: 0.6.1 release
Modified: xfce4-datetime-plugin/trunk/configure.in.in
===================================================================
--- xfce4-datetime-plugin/trunk/configure.in.in 2008-11-23 11:15:21 UTC (rev 6176)
+++ xfce4-datetime-plugin/trunk/configure.in.in 2008-11-23 11:42:15 UTC (rev 6177)
@@ -35,6 +35,9 @@
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.3.99.2])
XDT_CHECK_PACKAGE([LIBXFCE4PANEL],[libxfce4panel-1.0],[4.3.99.2])
+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])
+
#CFLAGS="$CFLAGS -Wall -Werror"
dnl Check for debugging support
Modified: xfce4-datetime-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-datetime-plugin/trunk/panel-plugin/Makefile.am 2008-11-23 11:15:21 UTC (rev 6176)
+++ xfce4-datetime-plugin/trunk/panel-plugin/Makefile.am 2008-11-23 11:42:15 UTC (rev 6177)
@@ -7,7 +7,9 @@
datetime.h \
datetime.c \
datetime-dialog.h \
- datetime-dialog.c
+ datetime-dialog.c \
+ xfce46-compat.h \
+ xfce46-compat.c
libdatetime_la_CFLAGS = \
-I$(top_srcdir) \
Modified: xfce4-datetime-plugin/trunk/panel-plugin/datetime.c
===================================================================
--- xfce4-datetime-plugin/trunk/panel-plugin/datetime.c 2008-11-23 11:15:21 UTC (rev 6176)
+++ xfce4-datetime-plugin/trunk/panel-plugin/datetime.c 2008-11-23 11:42:15 UTC (rev 6177)
@@ -33,6 +33,8 @@
#include <libxfce4panel/xfce-panel-plugin.h>
#include <libxfce4panel/xfce-panel-convenience.h>
+#include "xfce46-compat.h"
+
#include "datetime.h"
#include "datetime-dialog.h"
@@ -239,92 +241,13 @@
}
#endif
-static void on_calendar_realized(GtkWidget *widget, gpointer data)
+static void on_calendar_realized(GtkWidget *widget, t_datetime *datetime)
{
- gint parent_x, parent_y, parent_w, parent_h;
- gint root_w, root_h;
- gint width, height, x, y;
- gint orientation;
- GdkScreen *screen;
+ gint x, y;
GtkWidget *parent;
- GtkRequisition requisition;
- orientation = GPOINTER_TO_INT(data);
parent = g_object_get_data(G_OBJECT(widget), "calendar-parent");
-
- gdk_window_get_origin(GDK_WINDOW(parent->window), &parent_x, &parent_y);
- gdk_drawable_get_size(GDK_DRAWABLE(parent->window), &parent_w, &parent_h);
-
- screen = gdk_drawable_get_screen(GDK_DRAWABLE(widget->window));
- root_w = gdk_screen_get_width(GDK_SCREEN(screen));
- root_h = gdk_screen_get_height(GDK_SCREEN(screen));
-
- gtk_widget_size_request(GTK_WIDGET(widget), &requisition);
- width = requisition.width;
- height = requisition.height;
-
- DBG("orientation: %s", (orientation ? "vertical" : "horizontal"));
- DBG("parent: %dx%d +%d+%d", parent_w, parent_h, parent_x, parent_y);
- DBG("root: %dx%d", root_w, root_h);
- DBG("calendar: %dx%d", width, height);
-
- if (orientation == GTK_ORIENTATION_VERTICAL)
- {
- if (parent_x < root_w / 2) {
- if (parent_y < root_h / 2) {
- /* upper left */
- x = parent_x + parent_w;
- y = parent_y;
- } else {
- /* lower left */
- x = parent_x + parent_w;
- y = parent_y + parent_h - height;
- }
- } else {
- if (parent_y < root_h / 2) {
- /* upper right */
- x = parent_x - width;
- y = parent_y;
- } else {
- /* lower right */
- x = parent_x - width;
- y = parent_y + parent_h - height;
- }
- }
- }
- else
- {
- if (parent_x < root_w / 2)
- {
- if (parent_y < root_h / 2)
- {
- /* upper left */
- x = parent_x;
- y = parent_y + parent_h;
- }
- else
- {
- /* lower left */
- x = parent_x;
- y = parent_y - height;
- }
- }
- else
- {
- if (parent_y < root_h / 2)
- {
- /* upper right */
- x = parent_x + parent_w - width;
- y = parent_y + parent_h;
- }
- else
- {
- /* lower right */
- x = parent_x + parent_w - width;
- y = parent_y - height;
- }
- }
- }
+ xfce_panel_plugin_position_widget(datetime->plugin, widget, parent, &x, &y);
gtk_window_move(GTK_WINDOW(widget), x, y);
}
@@ -376,7 +299,7 @@
g_signal_connect_after(G_OBJECT(window), "realize",
G_CALLBACK(on_calendar_realized),
- GINT_TO_POINTER(orientation));
+ datetime);
g_signal_connect_swapped(G_OBJECT(window), "delete-event",
G_CALLBACK(close_calendar_window),
datetime);
Added: xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.c
===================================================================
--- xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.c (rev 0)
+++ xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.c 2008-11-23 11:42:15 UTC (rev 6177)
@@ -0,0 +1,193 @@
+/*
+ * 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().
+ **/
+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);
+}
+
+#endif
Added: xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.h
===================================================================
--- xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.h (rev 0)
+++ xfce4-datetime-plugin/trunk/panel-plugin/xfce46-compat.h 2008-11-23 11:42:15 UTC (rev 6177)
@@ -0,0 +1,20 @@
+#ifndef _XFCE46_COMPAT
+#define _XFCE46_COMPAT
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef HAVE_LIBXFCE4PANEL_46
+
+#include <gtk/gtk.h>
+#include <libxfce4panel/xfce-panel-plugin.h>
+
+void xfce_panel_plugin_position_widget (XfcePanelPlugin *plugin,
+ GtkWidget *menu_widget,
+ GtkWidget *attach_widget,
+ gint *x,
+ gint *y);
+
+#endif
+#endif
More information about the Goodies-commits
mailing list