diff options
Diffstat (limited to 'panel')
-rw-r--r-- | panel/Makefile.am | 63 | ||||
-rw-r--r-- | panel/frap-icon-entry.c | 590 | ||||
-rw-r--r-- | panel/frap-icon-entry.h | 64 | ||||
-rw-r--r-- | panel/main.c | 170 | ||||
-rw-r--r-- | panel/panel-app-messages.c | 140 | ||||
-rw-r--r-- | panel/panel-app-messages.h | 44 | ||||
-rw-r--r-- | panel/panel-app.c | 1089 | ||||
-rw-r--r-- | panel/panel-app.h | 127 | ||||
-rw-r--r-- | panel/panel-config.c | 737 | ||||
-rw-r--r-- | panel/panel-config.h | 33 | ||||
-rw-r--r-- | panel/panel-dialogs.c | 1727 | ||||
-rw-r--r-- | panel/panel-dialogs.h | 27 | ||||
-rw-r--r-- | panel/panel-dnd.c | 104 | ||||
-rw-r--r-- | panel/panel-dnd.h | 41 | ||||
-rw-r--r-- | panel/panel-item-manager.c | 552 | ||||
-rw-r--r-- | panel/panel-item-manager.h | 56 | ||||
-rw-r--r-- | panel/panel-private.h | 81 | ||||
-rw-r--r-- | panel/panel-properties.c | 1562 | ||||
-rw-r--r-- | panel/panel-properties.h | 90 | ||||
-rw-r--r-- | panel/panel.c | 1015 | ||||
-rw-r--r-- | panel/panel.h | 84 |
21 files changed, 0 insertions, 8396 deletions
diff --git a/panel/Makefile.am b/panel/Makefile.am deleted file mode 100644 index 293fb5e9..00000000 --- a/panel/Makefile.am +++ /dev/null @@ -1,63 +0,0 @@ -# $Id$ - -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_builddir) \ - -DG_LOG_DOMAIN=\"xfce4-panel\" \ - -DDATADIR=\"$(datadir)\" \ - -DLIBDIR=\"$(libdir)/xfce4\" \ - -DLIBEXECDIR=\"$(libexecdir)/xfce4\" \ - -DSYSCONFDIR=\"$(sysconfdir)\" \ - -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ - $(PLATFORM_CPPFLAGS) - -bin_PROGRAMS = \ - xfce4-panel - -xfce4_panel_SOURCES = \ - main.c \ - panel.c \ - panel.h \ - panel-app.c \ - panel-app.h \ - panel-app-messages.c \ - panel-app-messages.h \ - panel-config.c \ - panel-config.h \ - panel-dnd.c \ - panel-dnd.h \ - panel-item-manager.c \ - panel-item-manager.h \ - panel-private.h \ - panel-properties.c \ - panel-properties.h \ - panel-dialogs.c \ - panel-dialogs.h \ - frap-icon-entry.c \ - frap-icon-entry.h - -xfce4_panel_CFLAGS = \ - $(LIBX11_CFLAGS) \ - $(LIBSTARTUP_NOTIFICATION_CFLAGS) \ - $(LIBXFCE4UTIL_CFLAGS) \ - $(LIBXFCEGUI4_CFLAGS) \ - $(GMODULE_CFLAGS) \ - $(PLATFORM_CFLAGS) - -xfce4_panel_LDFLAGS = \ - -no-undefined \ - $(PLATFORM_LDFLAGS) - -xfce4_panel_LDADD = \ - $(top_builddir)/libxfce4panel/libxfce4panel.la \ - $(LIBXFCE4UTIL_LIBS) \ - $(LIBXFCEGUI4_LIBS) \ - $(LIBSTARTUP_NOTIFICATION_LIBS) \ - $(GMODULE_LIBS) \ - $(LIBX11_LIBS) \ - -lm - -xfce4_panel_DEPENDENCIES = \ - $(top_builddir)/libxfce4panel/libxfce4panel.la - -# vi:set ts=8 sw=8 noet ai nocindent syntax=automake: diff --git a/panel/frap-icon-entry.c b/panel/frap-icon-entry.c deleted file mode 100644 index 5128d45f..00000000 --- a/panel/frap-icon-entry.c +++ /dev/null @@ -1,590 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005-2006 Benedikt Meurer <benny@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 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 - * - * Based on the ThunarPathEntry class, which is part of the Thunar file manager, - * Copyright (c) 2004-2006 Benedikt Meurer <benny@xfce.org>. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "frap-icon-entry.h" - - - -/* the margin around the icon */ -#define FRAP_ICON_ENTRY_ICON_MARGIN (2) - - - -#define FRAP_ICON_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), FRAP_TYPE_ICON_ENTRY, FrapIconEntryPrivate)) - - - -/* Property identifiers */ -enum -{ - PROP_0, - PROP_SIZE, - PROP_STOCK_ID, -}; - - - -static void frap_icon_entry_finalize (GObject *object); -static void frap_icon_entry_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void frap_icon_entry_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void frap_icon_entry_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void frap_icon_entry_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void frap_icon_entry_realize (GtkWidget *widget); -static void frap_icon_entry_unrealize (GtkWidget *widget); -static gboolean frap_icon_entry_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void frap_icon_entry_get_borders (FrapIconEntry *icon_entry, - gint *xborder_return, - gint *yborder_return); -static void frap_icon_entry_get_text_area_size (FrapIconEntry *icon_entry, - gint *x_return, - gint *y_return, - gint *width_return, - gint *height_return); - - - -struct _FrapIconEntryPrivate -{ - GtkIconSize size; - gchar *stock_id; -}; - - - -G_DEFINE_TYPE (FrapIconEntry, - frap_icon_entry, - GTK_TYPE_ENTRY); - - - -static void -frap_icon_entry_class_init (FrapIconEntryClass *klass) -{ - GtkWidgetClass *gtkwidget_class; - GObjectClass *gobject_class; - - /* add the private instance data */ - g_type_class_add_private (klass, sizeof (FrapIconEntryPrivate)); - - gobject_class = G_OBJECT_CLASS (klass); - gobject_class->finalize = frap_icon_entry_finalize; - gobject_class->get_property = frap_icon_entry_get_property; - gobject_class->set_property = frap_icon_entry_set_property; - - gtkwidget_class = GTK_WIDGET_CLASS (klass); - gtkwidget_class->size_request = frap_icon_entry_size_request; - gtkwidget_class->size_allocate = frap_icon_entry_size_allocate; - gtkwidget_class->realize = frap_icon_entry_realize; - gtkwidget_class->unrealize = frap_icon_entry_unrealize; - gtkwidget_class->expose_event = frap_icon_entry_expose_event; - - /** - * FrapIconEntry:size: - * - * The #GtkIconSize for the icon in this entry. - **/ - g_object_class_install_property (gobject_class, - PROP_SIZE, - g_param_spec_enum ("size", - "Size", - "The size of the icon in the entry", - GTK_TYPE_ICON_SIZE, - GTK_ICON_SIZE_MENU, - G_PARAM_CONSTRUCT | G_PARAM_READWRITE)); - - /** - * FrapIconEntry:stock-id: - * - * The stock-id of the icon to render, or %NULL if no - * icon should be rendered. - **/ - g_object_class_install_property (gobject_class, - PROP_STOCK_ID, - g_param_spec_string ("stock-id", - "Stock Id", - "The stock-id of the icon in the entry", - NULL, - G_PARAM_READWRITE)); -} - - - -static void -frap_icon_entry_init (FrapIconEntry *icon_entry) -{ - icon_entry->priv = FRAP_ICON_ENTRY_GET_PRIVATE (icon_entry); -} - - - -static void -frap_icon_entry_finalize (GObject *object) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (object); - - /* release the stock-id if any */ - g_free (icon_entry->priv->stock_id); - - (*G_OBJECT_CLASS (frap_icon_entry_parent_class)->finalize) (object); -} - - - -static void -frap_icon_entry_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (object); - - switch (prop_id) - { - case PROP_SIZE: - g_value_set_enum (value, frap_icon_entry_get_size (icon_entry)); - break; - - case PROP_STOCK_ID: - g_value_set_string (value, frap_icon_entry_get_stock_id (icon_entry)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - - -static void -frap_icon_entry_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (object); - - switch (prop_id) - { - case PROP_SIZE: - frap_icon_entry_set_size (icon_entry, g_value_get_enum (value)); - break; - - case PROP_STOCK_ID: - frap_icon_entry_set_stock_id (icon_entry, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - - -static void -frap_icon_entry_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (widget); - gint text_height; - gint icon_height; - gint icon_width; - gint xborder; - gint yborder; - - /* determine the size request of the text entry */ - (*GTK_WIDGET_CLASS (frap_icon_entry_parent_class)->size_request) (widget, requisition); - - /* lookup the icon dimensions */ - gtk_icon_size_lookup (icon_entry->priv->size, &icon_width, &icon_height); - - /* determine the text area size */ - frap_icon_entry_get_text_area_size (icon_entry, &xborder, &yborder, NULL, &text_height); - - /* adjust the requisition */ - requisition->width += icon_width + xborder + 2 * FRAP_ICON_ENTRY_ICON_MARGIN; - requisition->height = 2 * yborder + MAX (icon_height + 2 * FRAP_ICON_ENTRY_ICON_MARGIN, text_height); -} - - - -static void -frap_icon_entry_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (widget); - GtkAllocation text_allocation; - GtkAllocation icon_allocation; - gint text_height; - gint icon_height; - gint icon_width; - gint xborder; - gint yborder; - - /* lookup the icon dimensions */ - gtk_icon_size_lookup (icon_entry->priv->size, &icon_width, &icon_height); - - /* determine the text area size */ - frap_icon_entry_get_text_area_size (icon_entry, &xborder, &yborder, NULL, &text_height); - - /* calculate the base text allocation */ - text_allocation.y = yborder; - text_allocation.width = allocation->width - icon_width - 2 * (xborder + FRAP_ICON_ENTRY_ICON_MARGIN); - text_allocation.height = text_height; - - /* calculate the base icon allocation */ - icon_allocation.y = yborder; - icon_allocation.width = icon_width + 2 * FRAP_ICON_ENTRY_ICON_MARGIN; - icon_allocation.height = MAX (icon_height + 2 * FRAP_ICON_ENTRY_ICON_MARGIN, text_height); - - /* the x offset depends on the text direction */ - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) - { - text_allocation.x = xborder; - icon_allocation.x = allocation->width - icon_allocation.width - xborder - 2 * FRAP_ICON_ENTRY_ICON_MARGIN; - } - else - { - icon_allocation.x = xborder; - text_allocation.x = allocation->width - text_allocation.width - xborder; - } - - /* setup the text area */ - (*GTK_WIDGET_CLASS (frap_icon_entry_parent_class)->size_allocate) (widget, allocation); - - /* adjust the dimensions/positions of the areas */ - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move_resize (GTK_ENTRY (icon_entry)->text_area, - text_allocation.x, - text_allocation.y, - text_allocation.width, - text_allocation.height); - - gdk_window_move_resize (icon_entry->icon_area, - icon_allocation.x, - icon_allocation.y, - icon_allocation.width, - icon_allocation.height); - } -} - - - -static void -frap_icon_entry_realize (GtkWidget *widget) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (widget); - GdkWindowAttr attributes; - gint attributes_mask; - gint text_height; - gint icon_height; - gint icon_width; - gint spacing; - - /* let GtkEntry handle the realization of the text area */ - (*GTK_WIDGET_CLASS (frap_icon_entry_parent_class)->realize) (widget); - - /* lookup the icon dimensions */ - gtk_icon_size_lookup (icon_entry->priv->size, &icon_width, &icon_height); - - /* determine the spacing for the icon area */ - frap_icon_entry_get_text_area_size (icon_entry, NULL, NULL, NULL, &text_height); - spacing = widget->requisition.height - text_height; - - /* setup the icon_area attributes */ - attributes.window_type = GDK_WINDOW_CHILD; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget) - | GDK_EXPOSURE_MASK; - attributes.x = widget->allocation.x + widget->allocation.width - icon_width - spacing; - attributes.y = widget->allocation.y + (widget->allocation.height - widget->requisition.height) / 2; - attributes.width = icon_width + spacing; - attributes.height = widget->requisition.height; - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - /* setup the window for the icon area */ - icon_entry->icon_area = gdk_window_new (widget->window, &attributes, attributes_mask); - gdk_window_set_user_data (icon_entry->icon_area, widget); - gdk_window_set_background (icon_entry->icon_area, &widget->style->base[GTK_WIDGET_STATE (widget)]); - gdk_window_show (icon_entry->icon_area); - - /* need to resize the text_area afterwards */ - gtk_widget_queue_resize (widget); -} - - - -static void -frap_icon_entry_unrealize (GtkWidget *widget) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (widget); - - /* destroy the icon_area */ - gdk_window_set_user_data (icon_entry->icon_area, NULL); - gdk_window_destroy (icon_entry->icon_area); - icon_entry->icon_area = NULL; - - (*GTK_WIDGET_CLASS (frap_icon_entry_parent_class)->unrealize) (widget); -} - - - -static gboolean -frap_icon_entry_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - FrapIconEntry *icon_entry = FRAP_ICON_ENTRY (widget); - GdkPixbuf *icon; - gint icon_height; - gint icon_width; - gint height; - gint width; - - /* check if the expose is on the icon_area */ - if (event->window == icon_entry->icon_area) - { - /* determine the size of the icon_area */ - gdk_drawable_get_size (GDK_DRAWABLE (icon_entry->icon_area), &width, &height); - - /* clear the icon area */ - gtk_paint_flat_box (widget->style, icon_entry->icon_area, - GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE, - NULL, widget, "entry_bg", 0, 0, width, height); - - /* check if a stock-id is set */ - if (G_LIKELY (icon_entry->priv->stock_id != NULL)) - { - /* try to render the icon for the stock-id */ - icon = gtk_widget_render_icon (widget, icon_entry->priv->stock_id, icon_entry->priv->size, "icon_entry"); - if (G_LIKELY (icon != NULL)) - { - /* determine the dimensions of the icon */ - icon_width = gdk_pixbuf_get_width (icon); - icon_height = gdk_pixbuf_get_height (icon); - - /* draw the icon */ - gdk_draw_pixbuf (icon_entry->icon_area, - widget->style->black_gc, - icon, 0, 0, - (width - icon_width) / 2, - (height - icon_height) / 2, - icon_width, icon_height, - GDK_RGB_DITHER_NORMAL, 0, 0); - - /* release the icon */ - g_object_unref (G_OBJECT (icon)); - } - } - } - else - { - /* the expose is probably for the text_area */ - return (*GTK_WIDGET_CLASS (frap_icon_entry_parent_class)->expose_event) (widget, event); - } - - return TRUE; -} - - - -static void -frap_icon_entry_get_borders (FrapIconEntry *icon_entry, - gint *xborder_return, - gint *yborder_return) -{ - gboolean interior_focus; - gint focus_width; - - gtk_widget_style_get (GTK_WIDGET (icon_entry), - "focus-line-width", &focus_width, - "interior-focus", &interior_focus, - NULL); - - if (gtk_entry_get_has_frame (GTK_ENTRY (icon_entry))) - { - *xborder_return = GTK_WIDGET (icon_entry)->style->xthickness; - *yborder_return = GTK_WIDGET (icon_entry)->style->ythickness; - } - else - { - *xborder_return = 0; - *yborder_return = 0; - } - - if (!interior_focus) - { - *xborder_return += focus_width; - *yborder_return += focus_width; - } -} - - - -static void -frap_icon_entry_get_text_area_size (FrapIconEntry *icon_entry, - gint *x_return, - gint *y_return, - gint *width_return, - gint *height_return) -{ - GtkRequisition requisition; - gint xborder; - gint yborder; - - gtk_widget_get_child_requisition (GTK_WIDGET (icon_entry), &requisition); - - frap_icon_entry_get_borders (icon_entry, &xborder, &yborder); - - if (x_return != NULL) *x_return = xborder; - if (y_return != NULL) *y_return = yborder; - if (width_return != NULL) *width_return = GTK_WIDGET (icon_entry)->allocation.width - xborder * 2; - if (height_return != NULL) *height_return = requisition.height - yborder * 2; -} - - - -/** - * frap_icon_entry_new: - * - * Allocates a new #FrapIconEntry instance. - * - * Return value: the newly allocated #FrapIconEntry. - **/ -GtkWidget* -frap_icon_entry_new (void) -{ - return g_object_new (FRAP_TYPE_ICON_ENTRY, NULL); -} - - - -/** - * frap_icon_entry_get_size: - * @icon_entry : a #FrapIconEntry. - * - * Returns the #GtkIconSize that is currently set for the - * @icon_entry. - * - * Return value: the icon size for the @icon_entry. - **/ -GtkIconSize -frap_icon_entry_get_size (FrapIconEntry *icon_entry) -{ - g_return_val_if_fail (FRAP_IS_ICON_ENTRY (icon_entry), GTK_ICON_SIZE_INVALID); - return icon_entry->priv->size; -} - - - -/** - * frap_icon_entry_set_size: - * @icon_entry : a #FrapIconEntry. - * @size : the new icon size for the @icon_entry. - * - * Sets the size at which the icon of the @icon_entry is drawn - * to @size. - **/ -void -frap_icon_entry_set_size (FrapIconEntry *icon_entry, - GtkIconSize size) -{ - g_return_if_fail (FRAP_IS_ICON_ENTRY (icon_entry)); - - /* check if we have a new setting */ - if (G_LIKELY (icon_entry->priv->size != size)) - { - /* apply the new setting */ - icon_entry->priv->size = size; - - /* notify listeners */ - g_object_notify (G_OBJECT (icon_entry), "size"); - - /* schedule a resize */ - gtk_widget_queue_resize (GTK_WIDGET (icon_entry)); - } -} - - - -/** - * frap_icon_entry_get_stock_id: - * @icon_entry : a #FrapIconEntry. - * - * Returns the stock-id that is currently set for the @icon_entry - * or %NULL if no stock-id is set. - * - * Return value: the stock-id for the @icon_entry. - **/ -const gchar* -frap_icon_entry_get_stock_id (FrapIconEntry *icon_entry) -{ - g_return_val_if_fail (FRAP_IS_ICON_ENTRY (icon_entry), NULL); - return icon_entry->priv->stock_id; -} - - - -/** - * frap_icon_entry_set_stock_id: - * @icon_entry : a #FrapIconEntry. - * @stock_id : the new stock-id or %NULL to reset. - * - * Sets the stock-id of the icon to be drawn in the @icon_entry to - * @stock_id. - **/ -void -frap_icon_entry_set_stock_id (FrapIconEntry *icon_entry, - const gchar *stock_id) -{ - g_return_if_fail (FRAP_IS_ICON_ENTRY (icon_entry)); - - /* release the previous stock-id */ - g_free (icon_entry->priv->stock_id); - - /* apply the new stock-id */ - icon_entry->priv->stock_id = g_strdup (stock_id); - - /* notify listeners */ - g_object_notify (G_OBJECT (icon_entry), "stock-id"); - - /* schedule a resize */ - gtk_widget_queue_resize (GTK_WIDGET (icon_entry)); -} - - diff --git a/panel/frap-icon-entry.h b/panel/frap-icon-entry.h deleted file mode 100644 index 15eb34d6..00000000 --- a/panel/frap-icon-entry.h +++ /dev/null @@ -1,64 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005-2006 Benedikt Meurer <benny@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 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 - */ - -#ifndef __FRAP_ICON_ENTRY_H__ -#define __FRAP_ICON_ENTRY_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS; - -typedef struct _FrapIconEntryPrivate FrapIconEntryPrivate; -typedef struct _FrapIconEntryClass FrapIconEntryClass; -typedef struct _FrapIconEntry FrapIconEntry; - -#define FRAP_TYPE_ICON_ENTRY (frap_icon_entry_get_type ()) -#define FRAP_ICON_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FRAP_TYPE_ICON_ENTRY, FrapIconEntry)) -#define FRAP_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FRAP_TYPE_ICON_ENTRY, FrapIconEntryClass)) -#define FRAP_IS_ICON_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FRAP_TYPE_ICON_ENTRY)) -#define FRAP_IS_ICON_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FRAP_TYPE_ICON_ENTRY)) -#define FRAP_ICON_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FRAP_TYPE_ICON_ENTRY, FrapIconEntryClass)) - -struct _FrapIconEntryClass -{ - GtkEntryClass __parent__; -}; - -struct _FrapIconEntry -{ - GtkEntry __parent__; - GdkWindow *icon_area; - FrapIconEntryPrivate *priv; -}; - -GType frap_icon_entry_get_type (void) G_GNUC_CONST; - -GtkWidget *frap_icon_entry_new (void) G_GNUC_MALLOC; - -GtkIconSize frap_icon_entry_get_size (FrapIconEntry *icon_entry); -void frap_icon_entry_set_size (FrapIconEntry *icon_entry, - GtkIconSize size); - -const gchar *frap_icon_entry_get_stock_id (FrapIconEntry *icon_entry); -void frap_icon_entry_set_stock_id (FrapIconEntry *icon_entry, - const gchar *stock_id); - -G_END_DECLS; - -#endif /* !__FRAP_ICON_ENTRY_H__ */ diff --git a/panel/main.c b/panel/main.c deleted file mode 100644 index b047de23..00000000 --- a/panel/main.c +++ /dev/null @@ -1,170 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_LOCALE_H -#include <locale.h> -#endif - -#include <gtk/gtk.h> -#include <libxfce4util/libxfce4util.h> - -#include "panel-app.h" -#include "panel-app-messages.h" - -#ifndef _ -#define _(x) x -#endif - -/* globals */ -static gboolean opt_version = FALSE; -static gboolean opt_customize = FALSE; -static gboolean opt_save = FALSE; -static gboolean opt_restart = FALSE; -static gboolean opt_quit = FALSE; -static gboolean opt_exit = FALSE; -static gboolean opt_add = FALSE; -static gchar *opt_client_id = NULL; - -/* command line options */ -static GOptionEntry option_entries[] = -{ - { "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_ ("Print version information and exit"), NULL }, - { "customize", 'c', 0, G_OPTION_ARG_NONE, &opt_customize, N_ ("Show 'Customize Panel' dialog"), NULL }, - { "save", 's', 0, G_OPTION_ARG_NONE, &opt_save, N_ ("Save the panel configuration"), NULL }, - { "restart", 'r', 0, G_OPTION_ARG_NONE, &opt_restart, N_ ("Restart the running instance of xfce4-panel"), NULL }, - { "quit", 'q', 0, G_OPTION_ARG_NONE, &opt_quit, N_ ("Log out the active session"), NULL }, - { "exit", 'x', 0, G_OPTION_ARG_NONE, &opt_exit, N_ ("Close all panels and end the program"), NULL }, - { "add", 'a', 0, G_OPTION_ARG_NONE, &opt_add, N_ ("Show 'Add New Items' dialog"), NULL }, - { "sm-client-id", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_client_id, NULL, NULL }, - { NULL } -}; - -/* main program */ -gint -main (gint argc, gchar **argv) -{ - gint msg = -1; - GError *error = NULL; - - /* translation domain */ - xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); - - /* application name */ - g_set_application_name (PACKAGE_NAME); - - MARK ("start gtk_init_with_args ()"); - - /* initialize gtk */ - if (!gtk_init_with_args (&argc, &argv, (gchar *) "", option_entries, (gchar *) GETTEXT_PACKAGE, &error)) - { - /* TRANSLATORS: Errors when gtk_init failed, probably the command - executed without xserver running */ - g_print ("%s: %s\n", PACKAGE_NAME, error ? error->message : _("Failed to open display")); - - if (error != NULL) - g_error_free (error); - - return EXIT_FAILURE; - } - - /* handle the options */ - if (G_UNLIKELY (opt_version)) - { - g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ()); - g_print ("%s\n", "Copyright (c) 2004-2009"); - g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved.")); - - /* TRANSLATORS: Bug report website, %s points to bugzilla.xfce.org */ - g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT); - g_print ("\n"); - - return EXIT_SUCCESS; - } - else if (G_UNLIKELY (opt_customize)) - msg = PANEL_APP_CUSTOMIZE; - else if (G_UNLIKELY (opt_save)) - msg = PANEL_APP_SAVE; - else if (G_UNLIKELY (opt_restart)) - msg = PANEL_APP_RESTART; - else if (G_UNLIKELY (opt_quit)) - msg = PANEL_APP_QUIT; - else if (G_UNLIKELY (opt_exit)) - msg = PANEL_APP_EXIT; - else if (G_UNLIKELY (opt_add)) - msg = PANEL_APP_ADD; - - /* handle the message, if there is any */ - if (G_UNLIKELY (msg >= 0)) - { - if (!panel_app_send (msg)) - { - if (msg != PANEL_APP_RESTART ) - { - return EXIT_FAILURE; - } - /* else: continue and start new panel */ - } - else - { - return EXIT_SUCCESS; - } - } - - MARK ("start panel_init()"); - msg = panel_app_init (); - - if (G_UNLIKELY (msg == INIT_FAILURE)) - { - return EXIT_FAILURE; - } - else if (G_UNLIKELY (msg == INIT_RUNNING)) - { - g_message (_("Xfce4-panel already running")); - - return EXIT_SUCCESS; - } - - MARK ("start panel_app_run()"); - msg = panel_app_run (opt_client_id); - MARK ("end panel_app_run()"); - - if (G_UNLIKELY (msg == RUN_RESTART)) - { - g_message (_("Restarting xfce4-panel...")); - - /* restart */ - execvp (argv[0], argv); - } - - return G_UNLIKELY (msg == RUN_FAILURE) ? EXIT_FAILURE : EXIT_SUCCESS; -} - diff --git a/panel/panel-app-messages.c b/panel/panel-app-messages.c deleted file mode 100644 index 5cf65306..00000000 --- a/panel/panel-app-messages.c +++ /dev/null @@ -1,140 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#ifdef HAVE_STRING_H -#include <string.h> -#endif - -#include <X11/Xlib.h> -#include <gtk/gtk.h> -#include <libxfce4util/libxfce4util.h> - -#include "panel-app.h" -#include "panel-app-messages.h" - -#ifndef _ -#define _(x) x -#endif - -#define PANEL_APP_ATOM "XFCE4_PANEL_APP" - -/* client messages */ - -static gboolean -client_event_received (GtkWidget *win, - GdkEventClient *ev) -{ - GdkAtom atom = gdk_atom_intern (PANEL_APP_ATOM, FALSE); - - if (ev->message_type == atom) - { - switch (ev->data.s[0]) - { - case PANEL_APP_CUSTOMIZE: - panel_app_customize (); - break; - case PANEL_APP_SAVE: - panel_app_save (); - break; - case PANEL_APP_RESTART: - panel_app_restart (); - break; - case PANEL_APP_QUIT: - panel_app_quit (); - break; - case PANEL_APP_EXIT: - panel_app_quit_noconfirm (); - break; - case PANEL_APP_ADD: - panel_app_customize_items (NULL); - break; - default: - return FALSE; - } - - return TRUE; - } - - return FALSE; -} - -/* public API */ - -/** - * panel_app_send - * @message: %PanelAppMesssage - * - * Send a message to a running instance of xfce4-panel. - * - * Return value: %FALSE if no panel instance is running, or %TRUE otherwise. - **/ -gboolean -panel_app_send (PanelAppMessage message) -{ - Window win; - GdkEventClient gev; - GtkWidget *invisible; - - if (panel_app_init () != 1) - { - g_warning ("xfce4-panel is not running"); - return FALSE; - } - - win = panel_app_get_ipc_window (); - - if (win) - { - invisible = gtk_invisible_new (); - gtk_widget_realize (invisible); - - gev.type = GDK_CLIENT_EVENT; - gev.window = invisible->window; - gev.send_event = TRUE; - gev.message_type = gdk_atom_intern (PANEL_APP_ATOM, FALSE); - gev.data_format = 16; - gev.data.s[0] = message; - gev.data.s[1] = 0; - - gdk_event_send_client_message ((GdkEvent *) & gev, - (GdkNativeWindow) win); - gdk_flush (); - - gtk_widget_destroy (invisible); - } - return TRUE; -} - -/** - * panel_app_listen - * @ipc_window: #GtkWidget that will receive messages. - * - * Set up listeners for messages to @ipc_window. - **/ -void -panel_app_listen (GtkWidget *ipc_window) -{ - g_signal_connect (G_OBJECT (ipc_window), "client-event", - G_CALLBACK (client_event_received), NULL); -} - diff --git a/panel/panel-app-messages.h b/panel/panel-app-messages.h deleted file mode 100644 index d1f32bba..00000000 --- a/panel/panel-app-messages.h +++ /dev/null @@ -1,44 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_APP_MESSAGES_H__ -#define __PANEL_APP_MESSAGES_H__ - -#include <gtk/gtkwidget.h> - -G_BEGIN_DECLS - -typedef enum -{ - PANEL_APP_CUSTOMIZE, - PANEL_APP_SAVE, - PANEL_APP_RESTART, - PANEL_APP_QUIT, - PANEL_APP_EXIT, - PANEL_APP_ADD -} -PanelAppMessage; - -gboolean panel_app_send (PanelAppMessage message); - -void panel_app_listen (GtkWidget *ipc_window); - -G_END_DECLS - -#endif /* !__PANEL_APP_MESSAGES_H__ */ diff --git a/panel/panel-app.c b/panel/panel-app.c deleted file mode 100644 index d02e1bff..00000000 --- a/panel/panel-app.c +++ /dev/null @@ -1,1089 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#ifdef HAVE_STDIO_H -#include <stdio.h> -#endif -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif -#ifdef HAVE_SIGNAL_H -#include <signal.h> -#endif -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif -#ifdef HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif - -#include <X11/Xlib.h> -#include <X11/Xatom.h> -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <libxfcegui4/libxfcegui4.h> -#include <libxfce4panel/xfce-panel-macros.h> -#include <libxfce4panel/xfce-panel-convenience.h> - -#include "panel-app.h" -#include "panel-app-messages.h" -#include "panel-item-manager.h" -#include "panel-config.h" -#include "panel-properties.h" -#include "panel-dialogs.h" -#include "panel.h" - -#ifndef _ -#define _(x) x -#endif - -#ifndef WAIT_ANY -#define WAIT_ANY (-1) -#endif - -#define SELECTION_NAME "XFCE4_PANEL" -#define PANEL_LAUNCHER "launcher" -#define SAVE_TIMEOUT 30000 -#define TEST_MULTIPLE_MONITORS FALSE - -#if defined(TIMER) && defined(G_HAVE_ISO_VARARGS) -void -xfce_panel_program_log (const gchar *file, - const gint line, - const gchar *format, - ...) -{ - va_list args; - gchar *formatted; - gchar *message; - - va_start (args, format); - formatted = g_strdup_vprintf (format, args); - va_end (args); - - message = g_strdup_printf ("MARK: %s: %s:%d: %s", - g_get_prgname(), file, line, formatted); - - access (message, F_OK); - - g_free (formatted); - g_free (message); -} -#endif - -/* types and global variables */ - -typedef enum -{ - PANEL_RUN_STATE_NORMAL, - PANEL_RUN_STATE_RESTART, - PANEL_RUN_STATE_QUIT, - PANEL_RUN_STATE_QUIT_NOCONFIRM, - PANEL_RUN_STATE_QUIT_NOSAVE -} -PanelRunState; - -typedef struct _PanelApp PanelApp; - -struct _PanelApp -{ - GtkWidget *gtk_ipc_window; - Window ipc_window; - - SessionClient *session_client; - PanelRunState runstate; - GPtrArray *panel_list; - GPtrArray *monitor_list; - - gint save_id; - gint current_panel; - - GList *dialogs; - - /* Initialization. Also unset before cleanup. */ - guint initialized : 1; - - /* Check whether monitors in Xinerama are aligned. */ - guint xinerama_and_equal_width : 1; - guint xinerama_and_equal_height : 1; -}; - -static PanelApp panel_app = {0}; -static gint signal_pipe[2]; - - -/* cleanup */ - -static void -cleanup_panels (void) -{ - guint i; - GList *l; - Panel *panel; - XfceMonitor *xmon; - - if (!panel_app.initialized) - return; - - panel_app.initialized = FALSE; - - l = panel_app.dialogs; - panel_app.dialogs = NULL; - - while (l) - { - gtk_dialog_response (GTK_DIALOG (l->data), GTK_RESPONSE_NONE); - l = g_list_delete_link (l, l); - } - - for (i = 0; i < panel_app.panel_list->len; ++i) - { - panel = g_ptr_array_index (panel_app.panel_list, i); - - gtk_widget_hide (GTK_WIDGET (panel)); - - panel_free_data (panel); - - gtk_widget_destroy (GTK_WIDGET (panel)); - - DBG ("Destroyed panel %d", i + 1); - } - - g_ptr_array_free (panel_app.panel_list, TRUE); - - for (i = 0; i < panel_app.monitor_list->len; ++i) - { - xmon = g_ptr_array_index (panel_app.monitor_list, i); - panel_slice_free (XfceMonitor, xmon); - } - g_ptr_array_free (panel_app.monitor_list, TRUE); -} - - -/* signal handling */ - -/** copied from glibc manual, does this prevent zombies? */ -static void -sigchld_handler (gint sig) -{ - gint pid, status, serrno; - - serrno = errno; - - while (1) - { - pid = waitpid (WAIT_ANY, &status, WNOHANG); - - if (pid < 0 || pid == 0) - break; - } - - errno = serrno; -} - -static void -sighandler (gint sig) -{ - /* Don't do any real stuff here. - * Only write the signal to a pipe. The value will be picked up by a - * g_io_channel watch. This will prevent problems with gtk main loop - * threads and stuff. - */ - if (write (signal_pipe[1], &sig, sizeof (int)) != sizeof (int)) - { - g_printerr ("unix signal %d lost\n", sig); - } -} - -static gboolean -evaluate_run_state (void) -{ - static gint recursive = 0; - gboolean quit = FALSE; - - /* micro-optimization */ - if (G_LIKELY (panel_app.runstate == PANEL_RUN_STATE_NORMAL)) - return TRUE; - - if (G_UNLIKELY (recursive)) - return TRUE; - - recursive++; - - switch (panel_app.runstate) - { - case PANEL_RUN_STATE_RESTART: - case PANEL_RUN_STATE_QUIT_NOCONFIRM: - panel_app_save (); - quit = TRUE; - break; - - case PANEL_RUN_STATE_QUIT_NOSAVE: - quit = TRUE; - break; - - default: - if (panel_app.session_client != NULL) - { - logout_session (panel_app.session_client); - } - else if (xfce_confirm (_("Exit Xfce Panel?"), - GTK_STOCK_QUIT, NULL)) - { - panel_app_save (); - quit = TRUE; - } - - /* don't forget to set back the run state */ - panel_app.runstate = PANEL_RUN_STATE_NORMAL; - break; - } - - if (quit) - { - /* we quit on purpose, update session manager so - * it does not restart the program immediately */ - if (panel_app.session_client != NULL) - client_session_set_restart_style (panel_app.session_client, - SESSION_RESTART_IF_RUNNING); - - if (panel_app.save_id) - { - g_source_remove (panel_app.save_id); - panel_app.save_id = 0; - } - - close (signal_pipe[0]); - close (signal_pipe[1]); - - gtk_main_quit (); - - return FALSE; - } - - recursive--; - - return TRUE; -} - -static gboolean -signal_pipe_io (GIOChannel *source, - GIOCondition cond, - gpointer data) -{ - gint signal_; - gsize bytes_read; - - if (G_IO_STATUS_NORMAL == g_io_channel_read_chars (source, (gchar *)&signal_, - sizeof (signal_), - &bytes_read, NULL) - && sizeof(signal_) == bytes_read) - { - switch (signal_) - { - case SIGUSR1: - DBG ("USR1 signal caught"); - panel_app.runstate = PANEL_RUN_STATE_RESTART; - break; - - case SIGUSR2: - DBG ("USR2 signal caught"); - panel_app.runstate = PANEL_RUN_STATE_QUIT; - break; - - case SIGINT: - case SIGABRT: - DBG ("INT or ABRT signal caught"); - panel_app.runstate = PANEL_RUN_STATE_QUIT_NOSAVE; - break; - - default: - DBG ("Signal caught: %d", buf.signal); - panel_app.runstate = PANEL_RUN_STATE_QUIT_NOSAVE; - } - } - - return evaluate_run_state (); -} - -static gboolean -init_signal_pipe ( void ) -{ - GIOChannel *g_signal_in; - glong fd_flags; - - /* create pipe and set writing end in non-blocking mode */ - if (pipe (signal_pipe)) - { - return FALSE; - } - - fd_flags = fcntl (signal_pipe[1], F_GETFL); - if (fd_flags == -1) - { - return FALSE; - } - - if (fcntl (signal_pipe[1], F_SETFL, fd_flags | O_NONBLOCK) == -1) - { - close (signal_pipe[0]); - close (signal_pipe[1]); - - return FALSE; - } - - /* convert the reading end of the pipe into a GIOChannel */ - g_signal_in = g_io_channel_unix_new (signal_pipe[0]); - g_io_channel_set_encoding (g_signal_in, NULL, NULL); - g_io_channel_set_close_on_unref (g_signal_in, FALSE); - - /* register the reading end with the event loop */ - g_io_add_watch (g_signal_in, G_IO_IN | G_IO_PRI, signal_pipe_io, NULL); - g_io_channel_unref (g_signal_in); - - return TRUE; -} - -static void -init_signal_handlers ( void ) -{ -#ifdef HAVE_SIGACTION - struct sigaction act; - - act.sa_handler = sighandler; - sigemptyset (&act.sa_mask); -# ifdef SA_RESTART - act.sa_flags = SA_RESTART; -# else - act.sa_flags = 0; -# endif - sigaction (SIGHUP, &act, NULL); - sigaction (SIGUSR1, &act, NULL); - sigaction (SIGUSR2, &act, NULL); - sigaction (SIGINT, &act, NULL); - sigaction (SIGABRT, &act, NULL); - sigaction (SIGTERM, &act, NULL); - act.sa_handler = sigchld_handler; - sigaction (SIGCHLD, &act, NULL); -#else - signal (SIGHUP, sighandler); - signal (SIGUSR1, sighandler); - signal (SIGUSR2, sighandler); - signal (SIGINT, sighandler); - signal (SIGABRT, sighandler); - signal (SIGTERM, sighandler); - signal (SIGCHLD, sigchld_handler); -#endif -} - -/* session */ - -static void -session_save_yourself (gpointer data, - gint save_style, - gboolean shutdown, - gint interact_style, - gboolean fast) -{ - panel_app_save (); -} - -static void -session_die (gpointer client_data) -{ - panel_app_quit_noconfirm (); -} - -/* screen layout */ -static void -monitor_size_changed (GdkScreen *screen) -{ - guint i; - XfceMonitor *monitor; - GtkWidget *panel; - - for (i = 0; i < panel_app.monitor_list->len; ++i) - { - monitor = g_ptr_array_index (panel_app.monitor_list, i); - - /* - * With xrandr 1.2, monitors can be added/removed, so need - * to double check the number of monitors (bug #3620)... - */ - if ((monitor->screen == screen) && (monitor->num < gdk_screen_get_n_monitors (screen))) - { - gdk_screen_get_monitor_geometry (screen, monitor->num, - &(monitor->geometry)); - } - } - - for (i = 0; i < panel_app.panel_list->len; ++i) - { - panel = g_ptr_array_index (panel_app.panel_list, i); - - if (screen == gtk_widget_get_screen (panel)) - panel_screen_size_changed (screen, PANEL (panel)); - } -} - -static void -create_monitor_list (void) -{ - GdkDisplay *display; - GdkScreen *screen; - XfceMonitor *monitor; - gint n_screens; - gint n_monitors = 0; - gint i, j; - guint k, m; - gint w = 0, h = 0; - gboolean equal_w, equal_h; - XfceMonitor *mon1, *mon2; - - panel_app.monitor_list = g_ptr_array_new (); - - display = gdk_display_get_default (); - - n_screens = gdk_display_get_n_screens (display); - - equal_w = equal_h = TRUE; - - for (i = 0; i < n_screens; ++i) - { - screen = gdk_display_get_screen (display, i); - - n_monitors = gdk_screen_get_n_monitors (screen); - - for (j = 0; j < n_monitors; ++j) - { - monitor = panel_slice_new0 (XfceMonitor); - - monitor->screen = screen; - monitor->num = j; - - gdk_screen_get_monitor_geometry (screen, j, &(monitor->geometry)); - - g_ptr_array_add (panel_app.monitor_list, monitor); - - if (j > 0) - { - if (w != monitor->geometry.width) - equal_w = FALSE; - if (h != monitor->geometry.height) - equal_h = FALSE; - } - - w = monitor->geometry.width; - h = monitor->geometry.height; - -#if TEST_MULTIPLE_MONITORS - monitor = panel_slice_new0 (XfceMonitor); - - monitor->screen = screen; - monitor->num = j; - - gdk_screen_get_monitor_geometry (screen, j, &(monitor->geometry)); - - g_ptr_array_add (panel_app.monitor_list, monitor); -#endif - } - - g_signal_connect (G_OBJECT (screen), "size-changed", - G_CALLBACK (monitor_size_changed), NULL); - } - - if (n_screens == 1 && n_monitors > 1) - { - panel_app.xinerama_and_equal_width = equal_w; - panel_app.xinerama_and_equal_height = equal_h; - } - - /* check layout */ - for (k = 0; k < panel_app.monitor_list->len; ++k) - { - mon1 = g_ptr_array_index (panel_app.monitor_list, k); - - for (m = 0; m < panel_app.monitor_list->len; ++m) - { - if (m == k) - continue; - - mon2 = g_ptr_array_index (panel_app.monitor_list, m); - - if (mon2->geometry.x < mon1->geometry.x - && mon2->geometry.y < mon1->geometry.y + mon1->geometry.height - && mon2->geometry.y + mon2->geometry.height > mon1->geometry.y - ) - { - mon1->has_neighbor_left = TRUE; - } - - if (mon2->geometry.x > mon1->geometry.x - && mon2->geometry.y < mon1->geometry.y + mon1->geometry.height - && mon2->geometry.y + mon2->geometry.height > mon1->geometry.y - ) - { - mon1->has_neighbor_right = TRUE; - } - - if (mon2->geometry.y < mon1->geometry.y - && mon2->geometry.x < mon1->geometry.x + mon1->geometry.width - && mon2->geometry.x + mon2->geometry.width > mon1->geometry.x - ) - { - mon1->has_neighbor_above = TRUE; - } - - if (mon2->geometry.y > mon1->geometry.y - && mon2->geometry.x < mon1->geometry.x + mon1->geometry.width - && mon2->geometry.x + mon2->geometry.width > mon1->geometry.x - ) - { - mon1->has_neighbor_below = TRUE; - } - } - } -} - -/* open dialogs */ -static void -unregister_dialog (GtkWidget *dialog) -{ - GList *l; - - for (l = panel_app.dialogs; l != NULL; l = l->next) - { - if (dialog == GTK_WIDGET (l->data)) - { - panel_app.dialogs = g_list_delete_link (panel_app.dialogs, l); - break; - } - } -} - -/* public API */ - -/** - * panel_app_init - * - * Initialize application. Creates ipc window if no other instance is - * running or sets the ipc window from the running instance. - * - * Returns: INIT_SUCCESS (0) on success, INIT_RUNNING (1) when an xfce4-panel - * instance already exists, and INIT_FAILURE (2) on failure. - **/ -int -panel_app_init (void) -{ - Atom selection_atom, manager_atom; - GtkWidget *invisible; - XClientMessageEvent xev; - - if (panel_app.initialized) - return INIT_SUCCESS; - - panel_app.initialized = TRUE; - - selection_atom = XInternAtom (GDK_DISPLAY (), SELECTION_NAME, False); - - panel_app.ipc_window = XGetSelectionOwner (GDK_DISPLAY (), selection_atom); - - if (panel_app.ipc_window) - return INIT_RUNNING; - - invisible = gtk_invisible_new (); - gtk_widget_realize (invisible); - - panel_app.gtk_ipc_window = invisible; - panel_app.ipc_window = GDK_WINDOW_XWINDOW (invisible->window); - - XSelectInput (GDK_DISPLAY (), panel_app.ipc_window, PropertyChangeMask); - - XSetSelectionOwner (GDK_DISPLAY (), selection_atom, panel_app.ipc_window, - GDK_CURRENT_TIME); - - if (XGetSelectionOwner (GDK_DISPLAY (), selection_atom) != - panel_app.ipc_window) - { - g_critical ("Could not set ownership of selection \"%s\"", - SELECTION_NAME); - return INIT_FAILURE; - } - - manager_atom = XInternAtom (GDK_DISPLAY (), "MANAGER", False); - - xev.type = ClientMessage; - xev.window = GDK_ROOT_WINDOW (); - xev.message_type = manager_atom; - xev.format = 32; - xev.data.l[0] = GDK_CURRENT_TIME; - xev.data.l[1] = selection_atom; - xev.data.l[2] = panel_app.ipc_window; - xev.data.l[3] = 0; /* manager specific data */ - xev.data.l[4] = 0; /* manager specific data */ - - XSendEvent (GDK_DISPLAY (), GDK_ROOT_WINDOW (), False, - StructureNotifyMask, (XEvent *) & xev); - - /* listen for client messages */ - panel_app_listen (invisible); - - return INIT_SUCCESS; -} - -/* fix position after showing panel for the first time */ -static gboolean -expose_timeout (GtkWidget *panel) -{ - gtk_widget_queue_resize (panel); - return FALSE; -} - -static void -panel_app_init_panel (GtkWidget *panel) -{ - MARK("start panel_app_init_panel: %p", panel); - panel_init_position (PANEL (panel)); - panel_init_signals (PANEL (panel)); - MARK(" + start show panel"); - gtk_widget_show (panel); - MARK(" + end show panel"); - g_idle_add ((GSourceFunc)expose_timeout, panel); - MARK("end panel_app_init_panel"); -} - -/** - * panel_app_run - * - * Run the panel application. Reads the configuration file(s) and sets up the - * panels, before turning over control to the main event loop. - * - * Returns: RUN_FAILURE (2) if something goes wrong, RUN_RESTART (1) to restart - * and RUN_SUCCESS (0) to quit. - **/ -gint -panel_app_run (gchar *client_id) -{ - gchar **restart_command; - - /* initialize signal handling */ - if (!init_signal_pipe ()) - { - g_critical ("Unable to create signal-watch pipe: %s.", - strerror(errno)); - return RUN_FAILURE; - } - init_signal_handlers (); - - /* environment */ - xfce_setenv ("DISPLAY", - gdk_display_get_name (gdk_display_get_default ()), - TRUE); - - /* session management */ - restart_command = g_new (gchar *, 2); - restart_command[0] = g_strdup ("xfce4-panel"); - restart_command[1] = NULL; - - panel_app.session_client = - client_session_new_full (NULL, - SESSION_RESTART_IMMEDIATELY, - 40, - client_id, - (gchar *) PACKAGE_NAME, - NULL, - restart_command, - g_strdupv (restart_command), - NULL, - NULL, - NULL); - panel_app.session_client->save_yourself = session_save_yourself; - panel_app.session_client->die = session_die; - - MARK("connect to session manager"); - if (!session_init (panel_app.session_client)) - { - /* no indeed we're not connected... */ - panel_app.session_client->current_state = SESSION_CLIENT_DISCONNECTED; - - /* cleanup */ - client_session_free (panel_app.session_client); - panel_app.session_client = NULL; - } - - /* screen layout and geometry */ - MARK("start monitor list creation"); - create_monitor_list (); - - /* configuration */ - MARK("start init item manager"); - xfce_panel_item_manager_init (); - - MARK("start panel creation"); - panel_app.panel_list = panel_config_create_panels (); - MARK("end panel creation"); - - g_ptr_array_foreach (panel_app.panel_list, (GFunc)panel_app_init_panel, - NULL); - - /* Run Forrest, Run! */ - panel_app.runstate = PANEL_RUN_STATE_NORMAL; - MARK("start main loop"); - gtk_main (); - MARK("end main loop"); - - /* cleanup */ - if (panel_app.session_client != NULL) - { - client_session_free (panel_app.session_client); - panel_app.session_client = NULL; - } - - cleanup_panels (); - xfce_panel_item_manager_cleanup (); - - if (panel_app.runstate == PANEL_RUN_STATE_RESTART) - return RUN_RESTART; - - return RUN_SUCCESS; -} - -static gboolean -save_timeout (void) -{ - DBG (" ++ save timeout"); - - if (panel_app.save_id) - g_source_remove (panel_app.save_id); - panel_app.save_id = 0; - - if (panel_app.runstate == PANEL_RUN_STATE_NORMAL) - { - DBG (" ++ really save"); - panel_app_save (); - } - - return FALSE; -} - -void -panel_app_queue_save (void) -{ - if (!panel_app.initialized) - return; - - if (panel_app.runstate == PANEL_RUN_STATE_NORMAL) - { - if (!panel_app.save_id) - panel_app.save_id = - g_timeout_add (SAVE_TIMEOUT, (GSourceFunc)save_timeout, NULL); - } -} - -void -panel_app_customize (void) -{ - if (xfce_allow_panel_customization()) - panel_manager_dialog (panel_app.panel_list); -} - -void -panel_app_customize_items (GtkWidget *active_item) -{ - if (xfce_allow_panel_customization()) - add_items_dialog (panel_app.panel_list, active_item); -} - -void -panel_app_save (void) -{ - if (!panel_app.initialized) - return; - - if (xfce_allow_panel_customization()) - panel_config_save_panels (panel_app.panel_list); -} - -void -panel_app_restart (void) -{ - panel_app.runstate = PANEL_RUN_STATE_RESTART; - evaluate_run_state (); -} - -void -panel_app_quit (void) -{ - panel_app.runstate = PANEL_RUN_STATE_QUIT; - evaluate_run_state (); -} - -void -panel_app_quit_noconfirm (void) -{ - panel_app.runstate = PANEL_RUN_STATE_QUIT_NOCONFIRM; - evaluate_run_state (); -} - -void -panel_app_quit_nosave (void) -{ - panel_app.runstate = PANEL_RUN_STATE_QUIT_NOSAVE; - evaluate_run_state (); -} - -void -panel_app_add_panel (void) -{ - Panel *panel; - - if (!xfce_allow_panel_customization()) - return; - - panel = panel_new (); - - if (G_UNLIKELY (panel_app.panel_list == NULL)) - panel_app.panel_list = g_ptr_array_sized_new (1); - - g_ptr_array_add (panel_app.panel_list, panel); - - panel_set_screen_position (panel, XFCE_SCREEN_POSITION_FLOATING_H); - panel_add_item (panel, PANEL_LAUNCHER); - - panel_center (panel); - panel_init_position (panel); - panel_init_signals (panel); - gtk_widget_show (GTK_WIDGET (panel)); - - panel_app.current_panel = panel_app.panel_list->len - 1; - panel_app_customize (); -} - -void -panel_app_remove_panel (GtkWidget *panel) -{ - gint response = GTK_RESPONSE_NONE; - guint n; - gchar *first; - - if (!xfce_allow_panel_customization()) - return; - - if (panel_app.panel_list->len == 1) - { - response = - xfce_message_dialog (NULL, _("Xfce Panel"), - GTK_STOCK_DIALOG_WARNING, - _("Exit Xfce Panel?"), - _("You can't remove the last panel. " - "Would you like to exit the program?"), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_QUIT, GTK_RESPONSE_ACCEPT, - NULL); - - if (response == GTK_RESPONSE_ACCEPT) - panel_app_quit_noconfirm (); - - return; - } - - for (n = 0; n < panel_app.panel_list->len; ++n) - { - if (panel == g_ptr_array_index (panel_app.panel_list, n)) - break; - } - - if (n == panel_app.panel_list->len) - return; - - panel_block_autohide (PANEL (panel)); - - panel_set_items_sensitive (PANEL (panel), FALSE); - gtk_widget_set_sensitive (panel, FALSE); - gtk_drag_highlight (panel); - - first = g_strdup_printf (_("Remove Panel \"%d\"?"), n + 1); - - response = xfce_message_dialog (GTK_WINDOW (panel), _("Xfce Panel"), - GTK_STOCK_DIALOG_WARNING, first, - _("The selected panel and all its items " - "will be removed."), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT, - NULL); - g_free (first); - - if (response != GTK_RESPONSE_ACCEPT) - { - gtk_drag_unhighlight (panel); - gtk_widget_set_sensitive (panel, TRUE); - panel_set_items_sensitive (PANEL (panel), TRUE); - panel_unblock_autohide (PANEL (panel)); - return; - } - - if (g_ptr_array_remove (panel_app.panel_list, (gpointer)panel)) - { - gtk_widget_hide (panel); - panel_free_data (PANEL (panel)); - gtk_widget_destroy (panel); - } -} - -void -panel_app_about (GtkWidget *panel) -{ - XfceAboutInfo *info; - GtkWidget *dlg; - GdkPixbuf *pb; - - info = xfce_about_info_new (_("Xfce Panel"), "", _("Xfce Panel"), - XFCE_COPYRIGHT_TEXT ("2009", "Jasper Huijsmans"), - XFCE_LICENSE_GPL); - - xfce_about_info_set_homepage (info, "http://www.xfce.org"); - - /* TRANSLATORS: Used in the credits tab in the panel's about dialog */ - xfce_about_info_add_credit (info, "Jasper Huijsmans", "jasper@xfce.org", _("Developer")); - xfce_about_info_add_credit (info, "Nick Schermer", "nick@xfce.org", _("Developer")); - - pb = xfce_themed_icon_load ("xfce4-panel", 48); - dlg = xfce_about_dialog_new_with_values (NULL, info, pb); - g_object_unref (G_OBJECT (pb)); - - gtk_window_set_screen (GTK_WINDOW (dlg), gtk_widget_get_screen (panel)); - - gtk_widget_set_size_request (dlg, 400, 300); - - gtk_dialog_run (GTK_DIALOG (dlg)); - - gtk_widget_destroy (dlg); - - xfce_about_info_free (info); -} - -Window -panel_app_get_ipc_window (void) -{ - panel_app_init (); - - return panel_app.ipc_window; -} - -XfceMonitor * -panel_app_get_monitor (guint n) -{ - return g_ptr_array_index (panel_app.monitor_list, - MIN (n, panel_app.monitor_list->len - 1)); -} - -guint -panel_app_get_n_monitors (void) -{ - return panel_app.monitor_list->len; -} - -/* open dialogs */ -void -panel_app_register_dialog (GtkWidget *dialog) -{ - g_return_if_fail (GTK_IS_WIDGET (dialog)); - - g_signal_connect (G_OBJECT (dialog), "destroy", - G_CALLBACK (unregister_dialog), NULL); - - panel_app.dialogs = g_list_prepend (panel_app.dialogs, dialog); -} - -/* current panel */ -void -panel_app_set_current_panel (gpointer *panel) -{ - guint i; - - panel_app.current_panel = 0; - - for (i = 0; i < panel_app.panel_list->len; ++i) - { - if (g_ptr_array_index (panel_app.panel_list, i) == panel) - { - panel_app.current_panel = i; - break; - } - } - - DBG ("Current panel: %d", panel_app.current_panel); -} - -void -panel_app_unset_current_panel (gpointer *panel) -{ - guint i; - - for (i = 0; i < panel_app.panel_list->len; ++i) - { - if (g_ptr_array_index (panel_app.panel_list, i) == panel) - { - if (i == (guint) panel_app.current_panel) - panel_app.current_panel = 0; - break; - } - } - - DBG ("Current panel: %d", panel_app.current_panel); -} - -gint -panel_app_get_current_panel (void) -{ - return panel_app.current_panel; -} - -const GPtrArray * -panel_app_get_panel_list (void) -{ - return panel_app.panel_list; -} - -/* check whether monitors in Xinerama are aligned */ -gboolean -panel_app_monitors_equal_height (void) -{ - return panel_app.xinerama_and_equal_height; -} - -gboolean -panel_app_monitors_equal_width (void) -{ - return panel_app.xinerama_and_equal_width; -} - diff --git a/panel/panel-app.h b/panel/panel-app.h deleted file mode 100644 index 93df5209..00000000 --- a/panel/panel-app.h +++ /dev/null @@ -1,127 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_APP_H__ -#define __PANEL_APP_H__ - -#include <X11/Xlib.h> -#include <gtk/gtkwidget.h> - -G_BEGIN_DECLS - -typedef struct _XfceMonitor XfceMonitor; - -#if defined(TIMER) && defined(G_HAVE_ISO_VARARGS) -void xfce_panel_program_log (const char *file, const int line, - const char *format, ...); - -#define MARK(...) \ - xfce_panel_program_log (__FILE__, __LINE__, __VA_ARGS__) - -#else - -#define MARK(fmt,args...) do {} while(0) - -#endif /* TIMER */ - - -struct _XfceMonitor -{ - GdkScreen *screen; - gint num; - GdkRectangle geometry; - guint has_neighbor_left : 1; - guint has_neighbor_right : 1; - guint has_neighbor_above : 1; - guint has_neighbor_below : 1; -}; - - -/* return status */ -enum { - INIT_SUCCESS, - INIT_RUNNING, - INIT_FAILURE -}; - -enum { - RUN_SUCCESS, - RUN_RESTART, - RUN_FAILURE, -}; - - -/* run control */ - -int panel_app_init (void); - -int panel_app_run (gchar *client_id); - -void panel_app_queue_save (void); - - -/* actions */ - -void panel_app_customize (void); - -void panel_app_customize_items (GtkWidget *active_item); - -void panel_app_save (void); - -void panel_app_restart (void); - -void panel_app_quit (void); - -void panel_app_quit_noconfirm (void); - -void panel_app_quit_nosave (void); - -void panel_app_add_panel (void); - -void panel_app_remove_panel (GtkWidget *panel); - -void panel_app_about (GtkWidget *panel); - -Window panel_app_get_ipc_window (void); - -XfceMonitor *panel_app_get_monitor (guint n); - -guint panel_app_get_n_monitors (void); - -gboolean panel_app_monitors_equal_height (void); - -gboolean panel_app_monitors_equal_width (void); - -/* keep track of open dialogs */ -void panel_app_register_dialog (GtkWidget *dialog); - -/* keep track of active panel */ -void panel_app_set_current_panel (gpointer *panel); - -void panel_app_unset_current_panel (gpointer *panel); - -int panel_app_get_current_panel (void); - -/* get panel list */ -const GPtrArray *panel_app_get_panel_list (void); - - -G_END_DECLS - -#endif /* !__PANEL_APP_H__ */ diff --git a/panel/panel-config.c b/panel/panel-config.c deleted file mode 100644 index 410cebcd..00000000 --- a/panel/panel-config.c +++ /dev/null @@ -1,737 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#ifdef HAVE_MEMORY_H -#include <memory.h> -#endif -#ifdef HAVE_SYS_MMAN_H -#include <sys/mman.h> -#endif -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif -#ifdef HAVE_STDIO_H -#include <stdio.h> -#endif -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif - -#include <gdk/gdkx.h> -#include <gtk/gtkenums.h> -#include <libxfce4util/libxfce4util.h> -#include <libxfce4panel/xfce-panel-macros.h> -#include <libxfce4panel/xfce-panel-convenience.h> -#include <libxfce4panel/xfce-panel-item-iface.h> - -#include "panel-config.h" -#include "panel-private.h" -#include "panel.h" -#include "panel-properties.h" -#include "panel-app.h" - -#ifndef _ -#define _(x) x -#endif - -#define PANEL_LAUNCHER "launcher" - -static GPtrArray *config_parse_file (const gchar *filename); - -static gboolean config_save_to_file (GPtrArray *panels, const gchar *filename); - - -/* fallback panel */ - -static GPtrArray * -create_fallback_panel_array (void) -{ - GPtrArray *array; - Panel *panel; - - DBG ("No suitable panel configuration was found."); - - panel = panel_new (); - g_object_ref (G_OBJECT (panel)); - gtk_object_sink (GTK_OBJECT (panel)); - - panel_add_item (panel, PANEL_LAUNCHER); - - array = g_ptr_array_new (); - - g_ptr_array_add (array, panel); - - return array; -} - -/* public API */ - -GPtrArray * -panel_config_create_panels (void) -{ - gchar *file; - GPtrArray *array = NULL; - const gchar *path = "xfce4" G_DIR_SEPARATOR_S - "panel" G_DIR_SEPARATOR_S - "panels.xml"; - - if (G_UNLIKELY (!xfce_allow_panel_customization ())) - { - file = g_build_filename (SYSCONFDIR, "xdg", path, NULL); - - if (!g_file_test (file, G_FILE_TEST_IS_REGULAR)) - { - g_free (file); - - file = NULL; - } - } - else - { - file = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, path); - - if (G_UNLIKELY (!file)) - { - file = g_build_filename (SYSCONFDIR, path, NULL); - - if (!g_file_test (file, G_FILE_TEST_IS_REGULAR)) - { - g_free (file); - - file = NULL; - } - } - } - - if (G_LIKELY (file)) - { - array = config_parse_file (file); - g_free (file); - } - - if (!array) - array = create_fallback_panel_array (); - - DBG ("Successfully configured %d panel(s).", array->len); - - return array; -} - -gboolean -panel_config_save_panels (GPtrArray * panels) -{ - gchar *file; - gboolean failed = FALSE; - guint i; - const gchar *path = "xfce4" G_DIR_SEPARATOR_S - "panel" G_DIR_SEPARATOR_S - "panels.xml"; - - if (xfce_allow_panel_customization ()) - { - file = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, path, TRUE); - - failed = !config_save_to_file (panels, file); - - g_free (file); - - for (i = 0; i < panels->len; ++i) - { - Panel *panel = g_ptr_array_index (panels, i); - - panel_save_items (panel); - } - } - - return !failed; -} - -/* GMarkup parsing */ - -typedef enum -{ - START, - PANELS, - PANEL, - PROPERTIES, - ITEMS, - UNKNOWN -} -ParserState; - -typedef struct _ConfigParser ConfigParser; -struct _ConfigParser -{ - GPtrArray *panels; - Panel *current_panel; - ParserState state; - - guint properties_set : 1; - guint monitor_set : 1; - - /* properties */ - gint size; - gint monitor; - gint screen_position; - gint full_width; - gint xoffset; - gint yoffset; - gint handle_style; - guint autohide : 1; - gint transparency; - guint activetrans : 1; -}; - -static void -init_properties (ConfigParser *parser) -{ - parser->properties_set = FALSE; - parser->monitor_set = FALSE; - - parser->size = DEFAULT_SIZE; - parser->monitor = 0; - parser->screen_position = DEFAULT_SCREEN_POSITION; - parser->full_width = XFCE_PANEL_NORMAL_WIDTH; - parser->xoffset = 0; - parser->yoffset = 0; - parser->handle_style = XFCE_HANDLE_STYLE_NONE; - parser->autohide = DEFAULT_AUTOHIDE; - parser->transparency = DEFAULT_TRANSPARENCY; - parser->activetrans = DEFAULT_ACTIVE_TRANS; -} - -static void -config_set_property (ConfigParser *parser, - const gchar *name, - const gchar *value) -{ - g_return_if_fail (name != NULL && value != NULL); - - parser->properties_set = TRUE; - - if (strcmp (name, "size") == 0) - { - parser->size = (gint) strtol (value, NULL, 0); - } - else if (strcmp (name, "monitor") == 0) - { - parser->monitor = (gint) strtol (value, NULL, 0); - parser->monitor_set = TRUE; - } - else if (strcmp (name, "screen-position") == 0) - { - parser->screen_position = (gint) strtol (value, NULL, 0); - } - else if (strcmp (name, "fullwidth") == 0) - { - parser->full_width = ((gint) strtol (value, NULL, 0)); - } - else if (strcmp (name, "xoffset") == 0) - { - parser->xoffset = (gint) strtol (value, NULL, 0); - } - else if (strcmp (name, "yoffset") == 0) - { - parser->yoffset = (gint) strtol (value, NULL, 0); - } - else if (strcmp (name, "handlestyle") == 0) - { - parser->handle_style = (gint) strtol (value, NULL, 0); - } - else if (strcmp (name, "autohide") == 0) - { - parser->autohide = ((gint) strtol (value, NULL, 0) == 1); - } - else if (strcmp (name, "transparency") == 0) - { - parser->transparency = (gint) strtol (value, NULL, 0); - } - else if (strcmp (name, "activetrans") == 0) - { - parser->activetrans = ((gint) strtol (value, NULL, 0) == 1); - } -} - -static void -start_element_handler (GMarkupParseContext *context, - const gchar *element_name, - const gchar **attribute_names, - const gchar **attribute_values, - gpointer user_data, - GError **error) -{ - ConfigParser *parser = user_data; - gchar *name = NULL; - gchar *value = NULL; - gint i = 0; - - switch (parser->state) - { - case START: - if (strcmp (element_name, "panels") == 0) - { - parser->state = PANELS; - } - break; - - case PANELS: - if (strcmp (element_name, "panel") == 0) - { - parser->state = PANEL; - parser->current_panel = panel_new (); - g_ptr_array_add (parser->panels, parser->current_panel); - init_properties (parser); - MARK(" + start config panel"); - } - break; - - case PANEL: - if (strcmp (element_name, "properties") == 0) - { - MARK(" ++ start properties"); - parser->state = PROPERTIES; - } - else if (strcmp (element_name, "items") == 0) - { - MARK(" ++ start items"); - parser->state = ITEMS; - } - break; - - case PROPERTIES: - if (strcmp (element_name, "property") == 0) - { - while (attribute_names[i] != NULL) - { - if (strcmp (attribute_names[i], "name") == 0) - { - name = (char *) attribute_values[i]; - } - else if (strcmp (attribute_names[i], "value") == 0) - { - value = (char *) attribute_values[i]; - } - ++i; - } - - if (name != NULL && value != NULL) - { - config_set_property (parser, name, value); - } - else - { - g_warning ("Property name or value not defined"); - } - } - break; - - case ITEMS: - if (strcmp (element_name, "item") == 0) - { - while (attribute_names[i] != NULL) - { - if (strcmp (attribute_names[i], "name") == 0) - { - name = (char *) attribute_values[i]; - } - else if (strcmp (attribute_names[i], "id") == 0) - { - value = (char *) attribute_values[i]; - } - ++i; - } - - if (name != NULL && value != NULL) - { - DBG ("Add item: name=\"%s\", id=\"%s\"", name, value); - - MARK(" +++ add item: %s", name); - panel_add_item_with_id (parser->current_panel, - name, value); - } - else - { - g_warning ("No item name found"); - } - } - break; - - default: - g_warning ("start unknown element \"%s\"", element_name); - break; - } -} - -static void -end_element_handler (GMarkupParseContext *context, - const gchar *element_name, - gpointer user_data, - GError **error) -{ - ConfigParser *parser = user_data; - - switch (parser->state) - { - case START: - g_warning ("end unexpected element: \"%s\"", element_name); - break; - - case PANELS: - if (strcmp ("panels", element_name) == 0) - parser->state = START; - break; - - case PANEL: - if (strcmp ("panel", element_name) == 0) - { - parser->state = PANELS; - parser->current_panel = NULL; - MARK(" + end config panel"); - } - break; - - case PROPERTIES: - if (strcmp ("properties", element_name) == 0) - { - parser->state = PANEL; - if (parser->properties_set) - { - if (parser->screen_position == XFCE_SCREEN_POSITION_NONE) - parser->screen_position = - XFCE_SCREEN_POSITION_FLOATING_H; - - if (!parser->monitor_set) - { - parser->monitor = DefaultScreen (GDK_DISPLAY()); - } - - - g_object_set (G_OBJECT (parser->current_panel), - "size", parser->size, - "monitor", parser->monitor, - "screen-position", parser->screen_position, - "fullwidth", parser->full_width, - "xoffset", parser->xoffset, - "yoffset", parser->yoffset, - "handle-style", parser->handle_style, - "autohide", parser->autohide, - "transparency", parser->transparency, - "activetrans", parser->activetrans, - NULL); - } - MARK(" ++ end properties"); - } - break; - - case ITEMS: - if (strcmp ("items", element_name) == 0) - { - parser->state = PANEL; - MARK(" ++ end items"); - } - break; - - default: - g_warning ("end unknown element \"%s\"", element_name); - break; - } -} - -static GMarkupParser markup_parser = { - start_element_handler, - end_element_handler, - NULL, - NULL, - NULL -}; - -static GPtrArray * -config_parse_file (const gchar *filename) -{ - GPtrArray *array = NULL; - gchar *contents; - GError *error; - GMarkupParseContext *context; - ConfigParser parser; - struct stat sb; - size_t bytes; - gint fd, rc; -#ifdef HAVE_MMAP - void *addr; -#endif - - g_return_val_if_fail (filename != NULL && strlen (filename) > 0, NULL); - - if (stat (filename, &sb) < 0) - return NULL; - - if ((fd = open (filename, O_RDONLY, 0)) < 0) - { - g_critical ("Unable to open file %s to load configuration: %s", - filename, g_strerror (errno)); - return NULL; - } - - contents = NULL; - -#ifdef HAVE_MMAP - /* Try to mmap(2) the config file, as this save us a lot of - * kernelspace -> userspace copying - */ - -#ifdef MAP_FILE - addr = mmap (NULL, sb.st_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0); -#else - addr = mmap (NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); -#endif - - if (addr != NULL) - { - /* nice, mmap did the job */ - contents = addr; - } - else - { - g_warning ("Failed to mmap file %s to load data: %s. " - "Using read fallback.", filename, g_strerror (errno)); - } -#endif /* HAVE_MMAP */ - - if (contents == NULL) - { - contents = panel_slice_alloc ((size_t) sb.st_size); - - if (contents == NULL) - { - g_critical ("Unable to allocate %lu bytes of memory to load " - "contents of file %s: %s", - (gulong) sb.st_size, filename, g_strerror (errno)); - goto finished; - } - - for (bytes = 0; bytes < (size_t) sb.st_size;) - { - errno = 0; - rc = read (fd, contents + bytes, sb.st_size - bytes); - - if (rc < 0) - { - if (errno == EINTR || errno == EAGAIN) - continue; - - g_critical ("Unable to read contents from file %s: %s", - filename, g_strerror (errno)); - goto finished; - } - else if (rc == 0) - { - g_critical ("Unexpected end of file reading contents from " - "file %s: %s", filename, g_strerror (errno)); - } - - bytes += rc; - } - } - - /* parse the file */ - error = NULL; - - parser.state = START; - parser.panels = array = g_ptr_array_new (); - parser.current_panel = NULL; - - context = g_markup_parse_context_new (&markup_parser, 0, &parser, NULL); - - if (!g_markup_parse_context_parse (context, contents, sb.st_size, &error) - || !g_markup_parse_context_end_parse (context, &error)) - { - g_critical ("Unable to parse file %s: %s", - filename, error->message); - g_error_free (error); - } - - g_markup_parse_context_free (context); - -finished: -#ifdef HAVE_MMAP - if (addr != NULL) - { - if (munmap (addr, sb.st_size)) - { - g_critical ("Unable to unmap file %s: %s. This should not happen!", - filename, g_strerror (errno)); - } - - contents = NULL; - } -#endif - - if (contents != NULL) - panel_slice_free1 ((size_t) sb.st_size, contents); - - if (close (fd) < 0) - { - g_critical ("Failed to close file %s: %s", filename, - g_strerror (errno)); - } - - if (array && array->len == 0) - { - g_ptr_array_free (array, TRUE); - array = NULL; - } - - return array; -} - -gboolean -config_save_to_file (GPtrArray *array, - const gchar *filename) -{ - guint i; - GString *contents; - GError *error = NULL; - gboolean result; - - g_return_val_if_fail (array != NULL, FALSE); - g_return_val_if_fail (filename != NULL || (strlen (filename) > 0), FALSE); - - DBG ("Save configuration of %d panels.", array->len); - - /* write header */ - contents = g_string_new ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - "<!DOCTYPE config SYSTEM \"config.dtd\">\n" - "<panels>\n"); - - for (i = 0; i < array->len; ++i) - { - gint size = 0; - gint monitor = 0; - gint screen_position = 0; - gint fullwidth = 0; - gint xoffset = 0; - gint yoffset = 0; - gint handle_style = 0; - gint transparency = 0; - gboolean autohide = FALSE; - gboolean activetrans = FALSE; - Panel *panel; - GList *configlist, *l; - - DBG ("Saving panel %d", i + 1); - - panel = g_ptr_array_index (array, i); - - g_object_get (G_OBJECT (panel), - "size", &size, - "monitor", &monitor, - "screen-position", &screen_position, - "fullwidth", &fullwidth, - "xoffset", &xoffset, - "yoffset", &yoffset, - "handle-style", &handle_style, - "autohide", &autohide, - "transparency", &transparency, - "activetrans", &activetrans, - NULL); - - /* write the panel config */ - g_string_append_printf (contents, - "\t<panel>\n" - "\t\t<properties>\n" - "\t\t\t<property name=\"size\" value=\"%d\"/>\n" - "\t\t\t<property name=\"monitor\" value=\"%d\"/>\n" - "\t\t\t<property name=\"screen-position\" value=\"%d\"/>\n" - "\t\t\t<property name=\"fullwidth\" value=\"%d\"/>\n" - "\t\t\t<property name=\"xoffset\" value=\"%d\"/>\n" - "\t\t\t<property name=\"yoffset\" value=\"%d\"/>\n" - "\t\t\t<property name=\"handlestyle\" value=\"%d\"/>\n" - "\t\t\t<property name=\"autohide\" value=\"%d\"/>\n" - "\t\t\t<property name=\"transparency\" value=\"%d\"/>\n" - "\t\t\t<property name=\"activetrans\" value=\"%d\"/>\n" - "\t\t</properties>\n" - "\t\t<items>\n", - size, - monitor, - screen_position, - fullwidth, - xoffset, - yoffset, - handle_style, - autohide, - transparency, - activetrans); - - /* panel items */ - configlist = panel_get_item_list (panel); - - for (l = configlist; l != NULL; l = l->next) - { - XfcePanelItem *item = l->data; - - /* write item name and id */ - g_string_append_printf (contents, - "\t\t\t<item name=\"%s\" id=\"%s\"/>\n", - xfce_panel_item_get_name (item), - xfce_panel_item_get_id (item)); - } - - g_list_free (configlist); - - /* close panel group */ - contents = g_string_append (contents, - "\t\t</items>\n" - "\t</panel>\n"); - } - - /* closing panels group */ - contents = g_string_append (contents, "</panels>\n"); - - /* try to write the content to the config file */ - result = g_file_set_contents (filename, contents->str, -1, &error); - if (G_UNLIKELY (result == FALSE)) - { - g_critical ("Unable to write config file: %s", error->message); - g_error_free (error); - } - - /* cleanup */ - g_string_free (contents, TRUE); - - return result; -} diff --git a/panel/panel-config.h b/panel/panel-config.h deleted file mode 100644 index e4a38f57..00000000 --- a/panel/panel-config.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_CONFIG_H__ -#define __PANEL_CONFIG_H__ - -#include <glib.h> - -G_BEGIN_DECLS - -GPtrArray *panel_config_create_panels (void); - -gboolean panel_config_save_panels (GPtrArray *panels); - -G_END_DECLS - -#endif /* !__PANEL_CONFIG_H__ */ diff --git a/panel/panel-dialogs.c b/panel/panel-dialogs.c deleted file mode 100644 index e1980109..00000000 --- a/panel/panel-dialogs.c +++ /dev/null @@ -1,1727 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005-2007 Jasper Huijsmans <jasper@xfce.org> - * Copyright (c) 2006 Benedikt Meurer <benny@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 - -#ifdef HAVE_STRING_H -#include <string.h> -#endif - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <libxfcegui4/libxfcegui4.h> - -#include <libxfce4panel/xfce-itembar.h> -#include <libxfce4panel/xfce-panel-macros.h> -#include <libxfce4panel/xfce-panel-item-iface.h> - -#include "frap-icon-entry.h" -#include "panel-properties.h" -#include "panel-private.h" -#include "panel-item-manager.h" -#include "panel-dnd.h" -#include "panel-dialogs.h" - -#define BORDER 6 - -typedef struct _PanelItemsDialog PanelItemsDialog; -typedef struct _PanelManagerDialog PanelManagerDialog; - -struct _PanelItemsDialog -{ - GtkWidget *dlg; - - GPtrArray *panels; - Panel *panel; - gint current; - - GtkWidget *active; - - GPtrArray *items; - GtkWidget *search_entry; - GtkWidget *tree; - GtkWidget *items_box; - - gint panel_destroy_id; -}; - -struct _PanelManagerDialog -{ - GtkWidget *dlg; - - GPtrArray *panels; - Panel *panel; - gint current; - - GtkTooltips *tips; - - guint updating : 1; - - /* add/remove/rename panel */ - GtkWidget *panel_selector; - GtkWidget *add_panel; - GtkWidget *rm_panel; - - /* appearance */ - GtkWidget *size; - GtkWidget *transparency; - GtkWidget *activetrans; -#if 0 - GtkWidget *position; -#endif - - /* monitors */ - GPtrArray *monitors; - - /* position */ - GtkWidget *fixed; - GtkWidget *floating; - - GtkWidget *fixed_box; - GtkWidget *screen_position[12]; - GtkWidget *fullwidth; - gint n_width_items; - GtkWidget *autohide; - - GtkWidget *floating_box; - GtkWidget *orientation; - GtkWidget *handle_style; -}; - - -static GtkWidget *panel_dialog_widget = NULL; -static GtkWidget *items_dialog_widget = NULL; - - -/* - * Common Code - * =========== - */ - -static void -present_dialog (GtkWidget *dialog, - GPtrArray *panels) -{ - gint n = panel_app_get_current_panel (); - GdkScreen *screen = gtk_widget_get_screen (g_ptr_array_index (panels, n)); - - if (screen != gtk_widget_get_screen (dialog)) - gtk_window_set_screen (GTK_WINDOW (dialog), screen); - - gtk_window_present (GTK_WINDOW (dialog)); -} - -/* - * Add Items Dialog - * ================ - */ - -static gboolean -item_configure_timeout (XfcePanelItem *item) -{ - xfce_panel_item_configure (item); - - return FALSE; -} - - -static XfcePanelItemInfo * -get_selected_tree_item (PanelItemsDialog *pid) -{ - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - XfcePanelItemInfo *info = NULL; - - /* get the tree selection */ - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (pid->tree)); - if (G_LIKELY (selection)) - { - /* get the selected item */ - if (gtk_tree_selection_get_selected (selection, &model, &iter)) - gtk_tree_model_get (model, &iter, 0, &info, -1); - } - - return info; -} - - -static gboolean -add_selected_item (PanelItemsDialog *pid) -{ - XfcePanelItemInfo *info; - GtkWidget *item = NULL; - - /* get the selected item */ - info = get_selected_tree_item (pid); - if (G_LIKELY (info && xfce_panel_item_manager_is_available (info->name))) - { - if (pid->active) - { - PanelPrivate *priv = PANEL_GET_PRIVATE (pid->panel); - gint n; - - n = xfce_itembar_get_item_index (XFCE_ITEMBAR (priv->itembar), pid->active); - - item = panel_insert_item (pid->panel, info->name, n + 1); - } - else - { - item = panel_add_item (pid->panel, info->name); - } - - if (item) - g_idle_add ((GSourceFunc)item_configure_timeout, item); - else - /* TRANSLATORS: Warning when adding an item to the panel failed. */ - xfce_err (_("Could not open \"%s\" module"), info->name); - - return TRUE; - } - - return FALSE; -} - -static gboolean -treeview_dblclick (GtkWidget *tv, - GdkEventButton *evt, - PanelItemsDialog *pid) -{ - if (evt->button == 1 && evt->type == GDK_2BUTTON_PRESS) - return add_selected_item (pid); - - return FALSE; -} - -static void -treeview_destroyed (GtkWidget *tv) -{ - GtkTreeModel *store; - - store = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (GTK_TREE_VIEW (tv)))); - gtk_list_store_clear (GTK_LIST_STORE (store)); -} - -static void -render_icon (GtkTreeViewColumn *col, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - XfcePanelItemInfo *info; - - gtk_tree_model_get (model, iter, 0, &info, -1); - - if (info) - { - g_object_set (G_OBJECT (cell), - "pixbuf", info->icon, - NULL); - } - else - { - g_object_set (G_OBJECT (cell), - "pixbuf", NULL, - NULL); - } -} - -static void -render_text (GtkTreeViewColumn *col, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - GtkWidget *treeview) -{ - XfcePanelItemInfo *info; - gboolean insensitive; - gchar text[512]; - - gtk_tree_model_get (model, iter, 0, &info, -1); - - if (info) - { - insensitive = !xfce_panel_item_manager_is_available (info->name); - - if (info->comment) - { - g_snprintf (text, sizeof(text), "<b>%s</b>\n%s", info->display_name, - info->comment); - } - else - { - g_snprintf (text, sizeof(text), "<b>%s</b>", info->display_name); - } - - g_object_set (G_OBJECT (cell), - "markup", text, - "foreground-set", insensitive, - NULL); - } - else - { - g_object_set (G_OBJECT (cell), - "markup", "", - "foreground-set", TRUE, - NULL); - } -} - -static void -treeview_data_received (GtkWidget *widget, GdkDragContext *context, - gint x, gint y, GtkSelectionData *data, - guint info, guint time_, PanelItemsDialog *pid) -{ - gboolean succeeded = FALSE; - GtkWidget *item; - - /* get the drag source */ - item = gtk_drag_get_source_widget (context); - - if (item && XFCE_IS_PANEL_ITEM (item)) - { - /* ask to remove the item */ - xfce_panel_item_remove (XFCE_PANEL_ITEM (item)); - - succeeded = TRUE; - } - - /* finish the drag */ - gtk_drag_finish (context, succeeded, FALSE, time_); -} - -static gboolean -treeview_drag_drop (GtkWidget *widget, GdkDragContext *context, - gint x, gint y, guint time_, PanelItemsDialog *pid) -{ - GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); - - /* we cannot handle the drag data */ - if (G_UNLIKELY (target == GDK_NONE)) - return FALSE; - - /* request the drag data */ - gtk_drag_get_data (widget, context, target, time_); - - /* we call gtk_drag_finish later */ - return TRUE; -} - -static void -treeview_drag_begin (GtkWidget *treeview, GdkDragContext *context, - PanelItemsDialog *pid) -{ - XfcePanelItemInfo *item_info; - - DBG (" + drag begin"); - - /* set nice drag icon */ - item_info = get_selected_tree_item (pid); - if (G_LIKELY (item_info && item_info->icon)) - gtk_drag_set_icon_pixbuf (context, item_info->icon, 0, 0); -} - -static void -treeview_data_get (GtkWidget *widget, GdkDragContext *drag_context, - GtkSelectionData *data, guint info, - guint time_, PanelItemsDialog *pid) -{ - XfcePanelItemInfo *item_info; - const gchar *item_name; - - DBG (" + drag data get: %d", info); - - if (G_LIKELY (info == TARGET_PLUGIN_NAME)) - { - /* get the selected item info */ - item_info = get_selected_tree_item (pid); - if (G_LIKELY (item_info)) - { - item_name = item_info->name; - - if (xfce_panel_item_manager_is_available (item_name)) - { - DBG (" + set selection data: %s", item_name); - - /* set the selection data */ - gtk_selection_data_set (data, data->target, 8, (guchar *) item_name, strlen (item_name)); - } - } - } -} - -static gboolean -item_visible_func (GtkTreeModel *model, - GtkTreeIter *iter, - gpointer user_data) -{ - XfcePanelItemInfo *info; - const gchar *text; - GtkWidget *entry = GTK_WIDGET (user_data); - gboolean visible; - gchar *text_casefolded; - gchar *info_casefolded; - gchar *normalized; - - text = gtk_entry_get_text (GTK_ENTRY (entry)); - if (G_UNLIKELY (*text == '\0')) - return TRUE; - - gtk_tree_model_get (model, iter, 0, &info, -1); - if (G_UNLIKELY (info == NULL)) - return TRUE; - - normalized = g_utf8_normalize (text, -1, G_NORMALIZE_ALL); - text_casefolded = g_utf8_casefold (normalized, -1); - g_free (normalized); - - normalized = g_utf8_normalize (info->display_name, -1, G_NORMALIZE_ALL); - info_casefolded = g_utf8_casefold (normalized, -1); - g_free (normalized); - - visible = (strstr (info_casefolded, text_casefolded) != NULL); - - g_free (info_casefolded); - - if (!visible && info->comment) - { - normalized = g_utf8_normalize (info->comment, -1, G_NORMALIZE_ALL); - info_casefolded = g_utf8_casefold (normalized, -1); - g_free (normalized); - - visible = (strstr (info_casefolded, text_casefolded) != NULL); - - g_free (info_casefolded); - } - - g_free (text_casefolded); - - return visible; -} - -static void -add_item_treeview (PanelItemsDialog *pid) -{ - GtkWidget *tv, *scroll; - GtkCellRenderer *cell; - GtkTreeViewColumn *col; - GtkListStore *store; - GtkTreeModel *filter; - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter iter; - guint i; - GdkColor *color; - GtkRequisition req; - - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (scroll); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_NEVER, - GTK_POLICY_NEVER); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), - GTK_SHADOW_IN); - gtk_box_pack_start (GTK_BOX (pid->items_box), scroll, TRUE, TRUE, 0); - - store = gtk_list_store_new (1, G_TYPE_POINTER); - model = GTK_TREE_MODEL (store); - - filter = gtk_tree_model_filter_new (model, NULL); - gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter), - item_visible_func, pid->search_entry, NULL); - g_signal_connect_swapped (G_OBJECT (pid->search_entry), "changed", - G_CALLBACK (gtk_tree_model_filter_refilter), filter); - - pid->tree = tv = gtk_tree_view_new_with_model (filter); - gtk_widget_show (tv); - gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tv), TRUE); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tv), FALSE); - gtk_container_add (GTK_CONTAINER (scroll), tv); - - g_signal_connect (G_OBJECT (tv), "destroy", - G_CALLBACK (treeview_destroyed), NULL); - - g_object_unref (G_OBJECT (filter)); - g_object_unref (G_OBJECT (store)); - - /* dnd */ - panel_dnd_set_source_name (tv); - panel_dnd_set_dest_name_and_widget (tv); - - g_signal_connect (tv, "drag-data-get", G_CALLBACK (treeview_data_get), pid); - g_signal_connect (tv, "drag-data-received", G_CALLBACK (treeview_data_received), pid); - g_signal_connect (tv, "drag-drop", G_CALLBACK (treeview_drag_drop), pid); - g_signal_connect (tv, "drag-begin", G_CALLBACK (treeview_drag_begin), pid); - - /* create the view */ - col = gtk_tree_view_column_new (); - gtk_tree_view_column_set_spacing (col, BORDER); - gtk_tree_view_append_column (GTK_TREE_VIEW (tv), col); - - cell = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (col, cell, FALSE); - gtk_tree_view_column_set_cell_data_func (col, cell, - (GtkTreeCellDataFunc) render_icon, - NULL, NULL); - - cell = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (col, cell, TRUE); - gtk_tree_view_column_set_cell_data_func (col, cell, - (GtkTreeCellDataFunc) render_text, - tv, NULL); - - color = &(tv->style->fg[GTK_STATE_INSENSITIVE]); - g_object_set (G_OBJECT (cell), "foreground-gdk", color, NULL); - - /* fill model */ - for (i = 0; i < pid->items->len; ++i) - { - if (i == 5) - { - gtk_widget_size_request (tv, &req); - gtk_widget_set_size_request (tv, -1, req.height); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_NEVER, - GTK_POLICY_ALWAYS); - } - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, - g_ptr_array_index (pid->items, i), -1); - } - - g_signal_connect (G_OBJECT (tv), "button-press-event", - G_CALLBACK (treeview_dblclick), pid); - - path = gtk_tree_path_new_from_string ("0"); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tv), path, NULL, FALSE); - gtk_tree_path_free (path); -} - -static void -item_dialog_opened (Panel *panel) -{ - PanelPrivate *priv = PANEL_GET_PRIVATE (panel); - - panel_block_autohide (panel); - xfce_itembar_raise_event_window (XFCE_ITEMBAR (priv->itembar)); - panel_set_items_sensitive (panel, FALSE); - - priv->edit_mode = TRUE; -} - -static void -item_dialog_closed (Panel *panel) -{ - PanelPrivate *priv = PANEL_GET_PRIVATE (panel); - - panel_unblock_autohide (panel); - xfce_itembar_lower_event_window (XFCE_ITEMBAR (priv->itembar)); - panel_set_items_sensitive (panel, TRUE); - - priv->edit_mode = FALSE; -} - -static void -item_dialog_response (GtkWidget *dlg, - gint response, - PanelItemsDialog *pid) -{ - if (response != GTK_RESPONSE_HELP) - { - if (response == GTK_RESPONSE_OK) - { - add_selected_item (pid); - } - - items_dialog_widget = NULL; - g_ptr_array_foreach (pid->panels, (GFunc)item_dialog_closed, NULL); - - xfce_panel_item_manager_free_item_info_list (pid->items); - - gtk_widget_destroy (dlg); - - g_signal_handler_disconnect (pid->panel, pid->panel_destroy_id); - panel_slice_free (PanelItemsDialog, pid); - - panel_app_save (); - } - else - { - xfce_exec_on_screen (gtk_widget_get_screen (dlg), - "xfhelp4 panel.html", FALSE, FALSE, NULL); - } -} - -static void -items_dialog_panel_destroyed (PanelItemsDialog *pid) -{ - gtk_dialog_response (GTK_DIALOG (pid->dlg), GTK_RESPONSE_CANCEL); -} - -void -add_items_dialog (GPtrArray *panels, - GtkWidget *active_item) -{ - PanelItemsDialog *pid; - Panel *panel; - GtkWidget *dlg, *vbox, *img, *hbox, *label; - - if (items_dialog_widget) - { - present_dialog (items_dialog_widget, panels); - return; - } - - pid = panel_slice_new0 (PanelItemsDialog); - - /* panels */ - pid->panels = panels; - pid->current = panel_app_get_current_panel(); - panel = pid->panel = g_ptr_array_index (panels, pid->current); - pid->active = active_item; - - /* available items */ - pid->items = xfce_panel_item_manager_get_item_info_list (); - - /* main dialog widget */ - items_dialog_widget = pid->dlg = dlg = - xfce_titled_dialog_new_with_buttons (_("Add New Items"), NULL, - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_HELP, GTK_RESPONSE_HELP, - GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, - GTK_STOCK_ADD, GTK_RESPONSE_OK, - NULL); - gtk_window_set_icon_name (GTK_WINDOW (dlg), GTK_STOCK_ADD); - - g_signal_connect (G_OBJECT (dlg), "response", - G_CALLBACK (item_dialog_response), pid); - - pid->panel_destroy_id = - g_signal_connect_swapped (G_OBJECT (panel), "destroy", - G_CALLBACK (items_dialog_panel_destroyed), pid); - - pid->items_box = vbox = gtk_vbox_new (FALSE, BORDER); - gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER); - gtk_widget_show (vbox); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox, TRUE, TRUE, 0); - - /* info */ - hbox = gtk_hbox_new (FALSE, BORDER * 2); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); - - img = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_LARGE_TOOLBAR); - gtk_widget_show (img); - gtk_box_pack_start (GTK_BOX (hbox), img, FALSE, FALSE, 0); - - /* TRANSLATORS: Make sure this string is equally spread in the add items dialog, - since gtk labels do not update text wrapping on a dialog resize. */ - label = gtk_label_new (_("Drag items from the list to a panel or remove\n" - "them by dragging them back to the list.")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - - /* treeview */ - hbox = gtk_hbox_new (FALSE, BORDER * 2); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - label = gtk_label_new_with_mnemonic (_("_Search:")); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - - /* the list filter entry (FIXME: Add tooltip? Jasper?) */ - pid->search_entry = frap_icon_entry_new (); - frap_icon_entry_set_stock_id (FRAP_ICON_ENTRY (pid->search_entry), GTK_STOCK_FIND); - gtk_widget_show (pid->search_entry); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), pid->search_entry); - gtk_box_pack_end (GTK_BOX (hbox), pid->search_entry, FALSE, FALSE, 0); - - add_item_treeview (pid); - - /* make panels insensitive and set up dnd */ - g_ptr_array_foreach (panels, (GFunc)item_dialog_opened, NULL); - - gtk_window_stick(GTK_WINDOW (dlg)); - xfce_gtk_window_center_on_monitor_with_pointer (GTK_WINDOW (dlg)); - - gtk_widget_show (dlg); - - panel_app_register_dialog (dlg); - - gtk_window_present (GTK_WINDOW (dlg)); -} - -/* - * Manage Panels Dialog - * ==================== - */ - -static gboolean -can_span_monitors (Panel *panel) -{ - return ( (panel_app_monitors_equal_height () && - panel_is_horizontal (panel)) - || (panel_app_monitors_equal_width () && - !panel_is_horizontal (panel)) ); -} - -/* Update widgets */ - -static void -update_widgets (PanelManagerDialog *pmd) -{ - PanelPrivate *priv = PANEL_GET_PRIVATE (pmd->panel); - guint i; - GtkToggleButton *tb; - XfceHandleStyle style; - - pmd->updating = TRUE; - - /* monitor */ - if (pmd->monitors) - { - for (i = 0; i < pmd->monitors->len; ++i) - { - tb = g_ptr_array_index (pmd->monitors, i); - - gtk_toggle_button_set_active (tb, i == (guint) priv->monitor); - } - } - - /* appearance */ - gtk_range_set_value (GTK_RANGE (pmd->size), priv->size); - - if (pmd->transparency) - { - gtk_range_set_value (GTK_RANGE (pmd->transparency), - priv->transparency); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pmd->activetrans), - !priv->activetrans); - } - - /* behavior */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pmd->autohide), - priv->autohide); - - /* position */ - if (!xfce_screen_position_is_floating (priv->screen_position)) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pmd->fixed), TRUE); - - gtk_widget_hide (pmd->floating_box); - gtk_widget_show (pmd->fixed_box); - - for (i = 0; i < 12; ++i) - { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (pmd->screen_position[i]), - priv->screen_position == i + 1); - } - - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->fullwidth), - priv->full_width); - } - else - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pmd->floating), TRUE); - - gtk_widget_hide (pmd->fixed_box); - gtk_widget_show (pmd->floating_box); - - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->orientation), - panel_is_horizontal (pmd->panel) ? 0 : 1); - - style = xfce_panel_window_get_handle_style ( - XFCE_PANEL_WINDOW (pmd->panel)); - if (style == XFCE_HANDLE_STYLE_NONE) - style = XFCE_HANDLE_STYLE_BOTH; - - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->handle_style), - style - 1); - } - - pmd->updating = FALSE; -} - - -/* position */ -static void -type_changed (GtkToggleButton *tb, - PanelManagerDialog *pmd) -{ - PanelPrivate *priv; - gint active; - - if (pmd->updating) - return; - - if (!gtk_toggle_button_get_active (tb)) - return; - - priv = PANEL_GET_PRIVATE (pmd->panel); - - /* 0 for fixed, 1 for floating */ - active = GTK_WIDGET (tb) == pmd->fixed ? 0 : 1; - - if ((active == 0) == - (priv->screen_position > XFCE_SCREEN_POSITION_NONE && - priv->screen_position < XFCE_SCREEN_POSITION_FLOATING_H)) - { - return; - } - - if (active == 1) - { - if (xfce_screen_position_is_horizontal (priv->screen_position)) - { - panel_set_screen_position (pmd->panel, - XFCE_SCREEN_POSITION_FLOATING_H); - } - else - { - panel_set_screen_position (pmd->panel, - XFCE_SCREEN_POSITION_FLOATING_V); - } - - xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (pmd->panel), - XFCE_HANDLE_STYLE_BOTH); - } - else - { - if (xfce_screen_position_is_horizontal (priv->screen_position)) - { - panel_set_screen_position (pmd->panel, - XFCE_SCREEN_POSITION_S); - } - else - { - panel_set_screen_position (pmd->panel, - XFCE_SCREEN_POSITION_E); - } - - xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (pmd->panel), - XFCE_HANDLE_STYLE_NONE); - } - - gtk_widget_queue_draw (GTK_WIDGET (pmd->panel)); - - update_widgets (pmd); -} - -static gboolean -screen_position_pressed (GtkToggleButton *tb, - GdkEvent *ev, - PanelManagerDialog *pmd) -{ - GtkToggleButton *button; - gint i, full_width; - - if (ev->type == GDK_KEY_PRESS && - ((GdkEventKey *)ev)->keyval == GDK_Tab) - { - return FALSE; - } - - if (!gtk_toggle_button_get_active (tb)) - { - if (ev->type == GDK_BUTTON_PRESS || - (ev->type == GDK_KEY_PRESS && - (((GdkEventKey *)ev)->keyval == GDK_space || - ((GdkEventKey *)ev)->keyval == GDK_Return))) - { - for (i = 0; i < 12; ++i) - { - button = GTK_TOGGLE_BUTTON (pmd->screen_position[i]); - - if (button == tb) - { - gtk_toggle_button_set_active (button, TRUE); - panel_set_screen_position (pmd->panel, i + 1); - - /* fix up full width setting */ - full_width = gtk_combo_box_get_active ( - GTK_COMBO_BOX (pmd->fullwidth)); - - for ( ; pmd->n_width_items > 0; pmd->n_width_items--) - { - gtk_combo_box_remove_text ( - GTK_COMBO_BOX (pmd->fullwidth), - pmd->n_width_items - 1); - } - - if (xfce_screen_position_is_horizontal (i+1)) - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Normal Width")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Full Width")); - } - else - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Normal Height")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Full Height")); - } - - pmd->n_width_items = 2; - if (can_span_monitors(pmd->panel)) - { - gtk_combo_box_append_text ( - GTK_COMBO_BOX (pmd->fullwidth), - _("Span Monitors")); - pmd->n_width_items = 3; - } - - full_width = MIN(pmd->n_width_items - 1, full_width); - panel_set_full_width (pmd->panel, full_width); - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->fullwidth), - full_width); - } - else - { - gtk_toggle_button_set_active (button, FALSE); - } - } - } - } - - return TRUE; -} - -static void -fullwidth_changed (GtkComboBox *box, - PanelManagerDialog *pmd) -{ - if (pmd->updating) - return; - - panel_set_full_width (pmd->panel, gtk_combo_box_get_active (box)); -} - -static void -autohide_changed (GtkToggleButton *tb, - PanelManagerDialog *pmd) -{ - if (pmd->updating) - return; - - panel_set_autohide (pmd->panel, gtk_toggle_button_get_active (tb)); -} - -static void -orientation_changed (GtkComboBox *box, - PanelManagerDialog *pmd) -{ - XfceScreenPosition position; - gint n; - gboolean tmp_updating; - - position = gtk_combo_box_get_active (box) == 0 ? - XFCE_SCREEN_POSITION_FLOATING_H : - XFCE_SCREEN_POSITION_FLOATING_V; - - tmp_updating = pmd->updating; - - pmd->updating = TRUE; - n = gtk_combo_box_get_active (GTK_COMBO_BOX (pmd->handle_style)); - - gtk_combo_box_remove_text (GTK_COMBO_BOX (pmd->handle_style), 2); - gtk_combo_box_remove_text (GTK_COMBO_BOX (pmd->handle_style), 1); - - if (position == XFCE_SCREEN_POSITION_FLOATING_H) - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Left")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Right")); - } - else - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Top")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Bottom")); - } - - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->handle_style), n); - pmd->updating = tmp_updating; - - if (!pmd->updating) - panel_set_screen_position (pmd->panel, position); -} - -static void -handle_style_changed (GtkComboBox *box, - PanelManagerDialog *pmd) -{ - if (pmd->updating) - return; - - xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (pmd->panel), - gtk_combo_box_get_active (box) + 1); -} - -static void -add_position_options (GtkBox *box, - PanelManagerDialog *pmd) -{ - GtkWidget *frame, *vbox, *vbox2, *hbox, *table, *align, *label, *sep; - GtkSizeGroup *sg; - gint i; - - /* position */ - frame = xfce_create_framebox (_("Position"), &align); - gtk_widget_show (frame); - gtk_box_pack_start (box, frame, FALSE, FALSE, 0); - - vbox2 = gtk_vbox_new (FALSE, BORDER); - gtk_widget_show (vbox2); - gtk_container_add (GTK_CONTAINER (align), vbox2); - - /* type */ - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, TRUE, 0); - - pmd->fixed = - gtk_radio_button_new_with_mnemonic (NULL, _("_Fixed position")); - gtk_widget_show (pmd->fixed); - gtk_box_pack_start (GTK_BOX (hbox), pmd->fixed, FALSE, FALSE, 0); - - pmd->floating = - gtk_radio_button_new_with_mnemonic_from_widget ( - GTK_RADIO_BUTTON (pmd->fixed), _("Freely _moveable")); - gtk_widget_show (pmd->floating); - gtk_box_pack_start (GTK_BOX (hbox), pmd->floating, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (pmd->fixed), "toggled", - G_CALLBACK (type_changed), pmd); - - g_signal_connect (G_OBJECT (pmd->floating), "toggled", - G_CALLBACK (type_changed), pmd); - - sep = gtk_hseparator_new (); - gtk_widget_show (sep); - gtk_box_pack_start (GTK_BOX (vbox2), sep, FALSE, FALSE, 0); - - /* fixed */ - pmd->fixed_box = hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, TRUE, 0); - - /* fixed: position */ - vbox = gtk_vbox_new (FALSE, 0); - gtk_widget_show (vbox); - gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); - - table = gtk_table_new (5, 5, FALSE); - gtk_widget_show (table); - gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); - - align = gtk_alignment_new (0, 0, 0, 0); - gtk_widget_show (align); - gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0); - - for (i = 0; i < 12; ++i) - { - pmd->screen_position[i] = gtk_toggle_button_new (); - gtk_widget_show (pmd->screen_position[i]); - - if (i <= 2 || i >= 9) - gtk_widget_set_size_request (pmd->screen_position[i], 30, 15); - else - gtk_widget_set_size_request (pmd->screen_position[i], 15, 25); - - g_signal_connect (G_OBJECT (pmd->screen_position[i]), "button-press-event", - G_CALLBACK (screen_position_pressed), pmd); - - g_signal_connect (G_OBJECT (pmd->screen_position[i]), "key-press-event", - G_CALLBACK (screen_position_pressed), pmd); - } - - /* fixed:postion:top */ - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[0], - 1, 2, 0, 1); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[1], - 2, 3, 0, 1); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[2], - 3, 4, 0, 1); - - /* fixed:postion:left */ - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[3], - 0, 1, 1, 2); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[4], - 0, 1, 2, 3); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[5], - 0, 1, 3, 4); - - /* fixed:postion:right */ - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[6], - 4, 5, 1, 2); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[7], - 4, 5, 2, 3); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[8], - 4, 5, 3, 4); - - /* fixed:postion:bottom */ - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[9], - 1, 2, 4, 5); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[10], - 2, 3, 4, 5); - - gtk_table_attach_defaults (GTK_TABLE (table), pmd->screen_position[11], - 3, 4, 4, 5); - - /* fixed:full width */ - vbox = gtk_vbox_new (FALSE, BORDER); - gtk_widget_show (vbox); - gtk_box_pack_start (GTK_BOX (pmd->fixed_box), vbox, TRUE, TRUE, 0); - - pmd->fullwidth = gtk_combo_box_new_text (); - gtk_widget_show (pmd->fullwidth); - gtk_box_pack_start (GTK_BOX (vbox), pmd->fullwidth, FALSE, FALSE, 0); - - if (panel_is_horizontal (pmd->panel)) - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Normal Width")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Full Width")); - } - else - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Normal Height")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), _("Full Height")); - } - - - pmd->n_width_items = 2; - if (can_span_monitors (pmd->panel)) - { - pmd->n_width_items = 3; - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->fullwidth), - _("Span Monitors")); - } - - g_signal_connect (G_OBJECT (pmd->fullwidth), "changed", - G_CALLBACK (fullwidth_changed), pmd); - - /* fixed:autohide */ - pmd->autohide = - gtk_check_button_new_with_mnemonic (_("Auto_hide")); - gtk_widget_show (pmd->autohide); - gtk_box_pack_start (GTK_BOX (vbox), pmd->autohide, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (pmd->autohide), "toggled", - G_CALLBACK (autohide_changed), pmd); - - /* floating */ - pmd->floating_box = vbox = gtk_vbox_new (FALSE, BORDER); - /* don't show by default */ - gtk_box_pack_start (GTK_BOX (vbox2), vbox, TRUE, TRUE, 0); - - sg = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - label = gtk_label_new (_("Orientation:")); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - gtk_size_group_add_widget (sg, label); - - pmd->orientation = gtk_combo_box_new_text (); - gtk_widget_show (pmd->orientation); - gtk_box_pack_start (GTK_BOX (hbox), pmd->orientation, TRUE, TRUE, 0); - - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->orientation), - _("Horizontal")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->orientation), - _("Vertical")); - - g_signal_connect (G_OBJECT (pmd->orientation), "changed", - G_CALLBACK (orientation_changed), pmd); - - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - label = gtk_label_new (_("Handle:")); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - gtk_size_group_add_widget (sg, label); - - pmd->handle_style = gtk_combo_box_new_text (); - gtk_widget_show (pmd->handle_style); - gtk_box_pack_start (GTK_BOX (hbox), pmd->handle_style, TRUE, TRUE, 0); - - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("At both sides")); - if (panel_is_horizontal (pmd->panel)) - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Left")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Right")); - } - else - { - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Top")); - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->handle_style), - _("Bottom")); - } - - g_signal_connect (G_OBJECT (pmd->handle_style), "changed", - G_CALLBACK (handle_style_changed), pmd); - - g_object_unref (G_OBJECT (sg)); -} - -/* monitors */ -static gboolean -monitor_pressed (GtkToggleButton *tb, - GdkEvent *ev, - PanelManagerDialog *pmd) -{ - guint i; - GtkToggleButton *mon; - - if (ev->type == GDK_KEY_PRESS && - ((GdkEventKey *)ev)->keyval == GDK_Tab) - { - return FALSE; - } - - if (!gtk_toggle_button_get_active (tb)) - { - if (ev->type == GDK_BUTTON_PRESS || - (ev->type == GDK_KEY_PRESS && - (((GdkEventKey *)ev)->keyval == GDK_space || - ((GdkEventKey *)ev)->keyval == GDK_Return))) - { - for (i = 0; i < pmd->monitors->len; ++i) - { - mon = g_ptr_array_index (pmd->monitors, i); - - if (mon == tb) - { - gtk_toggle_button_set_active (mon, TRUE); - panel_set_monitor (pmd->panel, i); - } - else - { - gtk_toggle_button_set_active (mon, FALSE); - } - } - } - } - - return TRUE; -} - -static void -add_monitor_selector (GtkBox *box, - PanelManagerDialog *pmd) -{ - gint n_monitors, i; - GtkWidget *frame, *align, *hbox; - GtkWidget *scroll = NULL; - GtkWidget *ebox, *ebox2, *b, *label; - GtkStyle *style; - gchar markup[10]; - GtkRequisition req; - - n_monitors = panel_app_get_n_monitors (); - - if (n_monitors > 1) - { - frame = xfce_create_framebox (_("Select Monitor"), &align); - gtk_widget_show (frame); - gtk_box_pack_start (box, frame, FALSE, FALSE, 0); - - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - /* don't add it to align yet */ - - pmd->monitors = g_ptr_array_sized_new (n_monitors); - - for (i = 0; i < n_monitors; ++i) - { - /* use a scroll window if more than 4 monitors */ - if (i == 5) - { - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (scroll); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_NEVER, - GTK_POLICY_NEVER); - gtk_scrolled_window_set_shadow_type ( - GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); - - gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); - - gtk_scrolled_window_add_with_viewport ( - GTK_SCROLLED_WINDOW (scroll), hbox); - - gtk_widget_size_request (scroll, &req); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_ALWAYS, - GTK_POLICY_NEVER); - - gtk_widget_set_size_request (scroll, req.width, -1); - } - - g_snprintf (markup, sizeof(markup), "<b>%d</b>", i + 1); - - ebox = gtk_event_box_new (); - style = gtk_widget_get_style (ebox); - gtk_widget_modify_bg (ebox, GTK_STATE_NORMAL, - &(style->bg[GTK_STATE_SELECTED])); - gtk_widget_show (ebox); - gtk_box_pack_start (GTK_BOX (hbox), ebox, FALSE, FALSE, 0); - - ebox2 = gtk_event_box_new (); - gtk_container_set_border_width (GTK_CONTAINER (ebox2), 3); - gtk_widget_show (ebox2); - gtk_container_add (GTK_CONTAINER (ebox), ebox2); - - b = gtk_toggle_button_new(); - gtk_button_set_relief (GTK_BUTTON (b), GTK_RELIEF_NONE); - gtk_widget_set_size_request (b, 40, 30); - gtk_widget_show (b); - gtk_container_add (GTK_CONTAINER (ebox2), b); - - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), markup); - gtk_widget_show (label); - gtk_container_add (GTK_CONTAINER (b), label); - - g_signal_connect (G_OBJECT (b), "button-press-event", - G_CALLBACK (monitor_pressed), pmd); - - g_signal_connect (G_OBJECT (b), "key-press-event", - G_CALLBACK (monitor_pressed), pmd); - - g_ptr_array_add (pmd->monitors, b); - } - - if (scroll) - gtk_container_add (GTK_CONTAINER (align), scroll); - else - gtk_container_add (GTK_CONTAINER (align), hbox); - } -} - -/* appearance */ -static void -size_changed (GtkRange *range, - PanelManagerDialog *pmd) -{ - if (pmd->updating) - return; - - panel_set_size (pmd->panel, (gint) gtk_range_get_value (range)); -} - -static void -transparency_changed (GtkRange *range, - PanelManagerDialog *pmd) -{ - if (pmd->updating) - return; - - panel_set_transparency (pmd->panel, (gint) gtk_range_get_value (range)); -} - -static void -activetrans_toggled (GtkToggleButton *tb, - PanelManagerDialog *pmd) -{ - if (pmd->updating) - return; - - panel_set_activetrans (pmd->panel, !gtk_toggle_button_get_active (tb)); -} -#if 0 -static void -popup_position_changed (GtkComboBox *box, - PanelManagerDialog *pmd) -{ - if (pmd->updating) - return; -} -#endif -static void -add_appearance_options (GtkBox *box, - PanelManagerDialog *pmd) -{ - static Atom composite_atom = 0; - GtkWidget *frame, *table, *hbox, *label, *align; - gchar text[16]; - GtkSizeGroup *size_group; - - size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - frame = xfce_create_framebox (_("Appearance"), &align); - gtk_widget_show (frame); - gtk_box_pack_start (box, frame, FALSE, FALSE, 0); - - table = gtk_vbox_new (FALSE, BORDER); - gtk_widget_show (table); - gtk_container_add (GTK_CONTAINER (align), table); - - /* size */ - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (table), hbox, FALSE, FALSE, 0); - - label = gtk_label_new_with_mnemonic (_("_Size (pixels):")); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - gtk_size_group_add_widget (size_group, label); - - pmd->size = gtk_hscale_new_with_range (MIN_SIZE, MAX_SIZE, 1); - gtk_scale_set_value_pos (GTK_SCALE (pmd->size), GTK_POS_LEFT); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), pmd->size); - gtk_range_set_update_policy (GTK_RANGE (pmd->size), GTK_UPDATE_DELAYED); - gtk_widget_show (pmd->size); - gtk_box_pack_start (GTK_BOX (hbox), pmd->size, TRUE, TRUE, 0); - - g_signal_connect (G_OBJECT (pmd->size), "value-changed", - G_CALLBACK (size_changed), pmd); - - /* transparency */ - if (G_UNLIKELY (!composite_atom)) - { - g_snprintf (text, sizeof(text), "_NET_WM_CM_S%d", - GDK_SCREEN_XNUMBER(gdk_screen_get_default())); - composite_atom = - XInternAtom (GDK_DISPLAY (), text, False); - } - - if (XGetSelectionOwner (GDK_DISPLAY (), composite_atom)) - { - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (table), hbox, FALSE, FALSE, 0); - - label = gtk_label_new_with_mnemonic (_("_Transparency (%):")); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - gtk_size_group_add_widget (size_group, label); - - pmd->transparency = gtk_hscale_new_with_range (0, 100, 5); - gtk_scale_set_value_pos (GTK_SCALE (pmd->transparency), GTK_POS_LEFT); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), pmd->transparency); - gtk_range_set_update_policy (GTK_RANGE (pmd->transparency), - GTK_UPDATE_DELAYED); - gtk_widget_show (pmd->transparency); - gtk_box_pack_start (GTK_BOX (hbox), pmd->transparency, TRUE, TRUE, 0); - - g_signal_connect (G_OBJECT (pmd->transparency), "value-changed", - G_CALLBACK (transparency_changed), pmd); - - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (table), hbox, FALSE, FALSE, 0); - - label = gtk_label_new (""); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - gtk_size_group_add_widget (size_group, label); - - pmd->activetrans = gtk_check_button_new_with_mnemonic (_("Make active panel _opaque")); - gtk_widget_show (pmd->activetrans); - gtk_box_pack_start (GTK_BOX (hbox), pmd->activetrans, TRUE, TRUE, 0); - - g_signal_connect (G_OBJECT (pmd->activetrans), "toggled", - G_CALLBACK (activetrans_toggled), pmd); - } - g_object_unref (G_OBJECT (size_group)); -} - -/* panel selector: add/remove/rename panel */ -static void -panel_selected (GtkComboBox *combo, - PanelManagerDialog *pmd) -{ - gint n = gtk_combo_box_get_active (combo); - - if (n == pmd->current || n < 0) - return; - - pmd->current = n; - pmd->panel = g_ptr_array_index (pmd->panels, n); - - update_widgets (pmd); -} - -static void -add_panel (GtkWidget *w, - PanelManagerDialog *pmd) -{ - gchar name[20]; - guint n; - gint x, y; - - n = pmd->panels->len; - - panel_app_add_panel (); - - if (n == pmd->panels->len) - return; - - panel_block_autohide (PANEL (g_ptr_array_index (pmd->panels, n))); - - g_snprintf (name, sizeof(name), _("Panel %d"), pmd->panels->len); - - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->panel_selector), name); - - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->panel_selector), n); - - gtk_window_get_position (GTK_WINDOW (pmd->dlg), &x, &y); - - x += (pmd->dlg->allocation.width - - GTK_WIDGET (pmd->panel)->allocation.width) / 2; - y += pmd->dlg->allocation.height + BORDER; - - gtk_window_move (GTK_WINDOW (pmd->panel), x, y); - gtk_widget_queue_resize (GTK_WIDGET (pmd->panel)); -} - -static void -remove_panel (GtkWidget *w, - PanelManagerDialog *pmd) -{ - GtkTreeModel *model; - guint n = pmd->panels->len; - guint i; - gchar name[20]; - - panel_app_remove_panel (GTK_WIDGET (pmd->panel)); - - if (pmd->panels->len == n) - return; - - - model = gtk_combo_box_get_model (GTK_COMBO_BOX (pmd->panel_selector)); - gtk_list_store_clear (GTK_LIST_STORE (model)); - - for (i = 0; i < pmd->panels->len; ++i) - { - g_snprintf (name, sizeof(name), _("Panel %d"), i + 1); - - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->panel_selector), name); - } - - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->panel_selector), 0); -} - -static GtkWidget * -create_panel_selector (PanelManagerDialog *pmd) -{ - GtkWidget *hbox, *img; - guint i; - gchar name[20]; - - hbox = gtk_hbox_new (FALSE, BORDER); - gtk_widget_show (hbox); - - pmd->panel_selector = gtk_combo_box_new_text (); - gtk_widget_show (pmd->panel_selector); - gtk_box_pack_start (GTK_BOX (hbox), pmd->panel_selector, TRUE, TRUE, 0); - - for (i = 0; i < pmd->panels->len; ++i) - { - g_snprintf (name, sizeof(name), _("Panel %d"), i + 1); - - gtk_combo_box_append_text (GTK_COMBO_BOX (pmd->panel_selector), name); - } - - gtk_combo_box_set_active (GTK_COMBO_BOX (pmd->panel_selector), - pmd->current); - - g_signal_connect (G_OBJECT (pmd->panel_selector), "changed", - G_CALLBACK (panel_selected), pmd); - - pmd->rm_panel = gtk_button_new (); - gtk_widget_show (pmd->rm_panel); - gtk_box_pack_start (GTK_BOX (hbox), pmd->rm_panel, FALSE, FALSE, 0); - - img = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON); - gtk_widget_show (img); - gtk_container_add (GTK_CONTAINER (pmd->rm_panel), img); - - /* TRANSLATORS: Tooltip for the add button in the customize panel dialog */ - gtk_tooltips_set_tip (pmd->tips, pmd->rm_panel, _("Remove the currently selected panel"), NULL); - - g_signal_connect (G_OBJECT (pmd->rm_panel), "clicked", - G_CALLBACK (remove_panel), pmd); - - pmd->add_panel = gtk_button_new (); - gtk_widget_show (pmd->add_panel); - gtk_box_pack_start (GTK_BOX (hbox), pmd->add_panel, FALSE, FALSE, 0); - - img = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); - gtk_widget_show (img); - gtk_container_add (GTK_CONTAINER (pmd->add_panel), img); - - /* TRANSLATORS: Tooltip for the add button in the customize panel dialog */ - gtk_tooltips_set_tip (pmd->tips, pmd->add_panel, _("Add a new panel"), NULL); - - g_signal_connect (G_OBJECT (pmd->add_panel), "clicked", - G_CALLBACK (add_panel), pmd); - - return hbox; -} - -/* main dialog */ -static void -panel_dialog_response (GtkWidget *dlg, - gint response, - PanelManagerDialog *pmd) -{ - if (response != GTK_RESPONSE_HELP) - { - panel_dialog_widget = NULL; - - if (pmd->monitors) - g_ptr_array_free (pmd->monitors, TRUE); - - g_ptr_array_foreach (pmd->panels, (GFunc)panel_unblock_autohide, NULL); - - gtk_widget_destroy (dlg); - - g_object_unref (G_OBJECT (pmd->tips)); - panel_slice_free (PanelManagerDialog, pmd); - - panel_app_save (); - } - else - { - xfce_exec_on_screen (gtk_widget_get_screen (dlg), - "xfhelp4 panel.html", FALSE, FALSE, NULL); - } -} - -void -panel_manager_dialog (GPtrArray *panels) -{ - PanelManagerDialog *pmd; - GtkWidget *vbox, *sel, *separator; - Panel *panel; - - if (panel_dialog_widget) - { - present_dialog (panel_dialog_widget, panels); - return; - } - - pmd = panel_slice_new0 (PanelManagerDialog); - - /* panels */ - pmd->panels = panels; - pmd->current = panel_app_get_current_panel(); - panel = pmd->panel = - g_ptr_array_index (panels, pmd->current); - - /* main dialog widget */ - panel_dialog_widget = pmd->dlg = - xfce_titled_dialog_new_with_buttons (_("Panel"), NULL, - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_HELP, GTK_RESPONSE_HELP, - GTK_STOCK_CLOSE, GTK_RESPONSE_OK, - NULL); - gtk_dialog_set_default_response (GTK_DIALOG (pmd->dlg), GTK_RESPONSE_OK); - gtk_window_set_icon_name (GTK_WINDOW (pmd->dlg), "xfce4-panel"); - xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (panel_dialog_widget), _("Customize the panel settings")); - - pmd->tips = gtk_tooltips_new (); - g_object_ref (G_OBJECT (pmd->tips)); - gtk_object_sink (GTK_OBJECT (pmd->tips)); - - /* main container */ - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (pmd->dlg)->vbox), vbox, - TRUE, TRUE, 0); - - pmd->updating = TRUE; - - /* add/remove/rename panel */ - sel = create_panel_selector (pmd); - gtk_widget_show (sel); - gtk_box_pack_start (GTK_BOX (vbox), sel, FALSE, FALSE, 0); - - separator = gtk_hseparator_new (); - gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); - gtk_widget_show (separator); - - /* appearance */ - add_appearance_options (GTK_BOX (vbox), pmd); - - /* position */ - add_position_options (GTK_BOX (vbox), pmd); - - /* monitors */ - add_monitor_selector (GTK_BOX (vbox), pmd); - - pmd->updating = FALSE; - - /* fill in values */ - update_widgets (pmd); - - /* setup panels */ - g_ptr_array_foreach (pmd->panels, (GFunc)panel_block_autohide, NULL); - - /* setup and show dialog */ - g_signal_connect (G_OBJECT (pmd->dlg), "response", - G_CALLBACK (panel_dialog_response), pmd); - - gtk_window_stick(GTK_WINDOW (pmd->dlg)); - xfce_gtk_window_center_on_monitor_with_pointer (GTK_WINDOW (pmd->dlg)); - - gtk_widget_show (pmd->dlg); - - panel_app_register_dialog (pmd->dlg); -} - diff --git a/panel/panel-dialogs.h b/panel/panel-dialogs.h deleted file mode 100644 index ceac4bf5..00000000 --- a/panel/panel-dialogs.h +++ /dev/null @@ -1,27 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_DIALOGS_H__ -#define __PANEL_DIALOGS_H__ - -void add_items_dialog (GPtrArray *panels, GtkWidget *active_item); - -void panel_manager_dialog (GPtrArray *panels); - -#endif /* !__PANEL_DIALOGS_H__ */ diff --git a/panel/panel-dnd.c b/panel/panel-dnd.c deleted file mode 100644 index afcd98be..00000000 --- a/panel/panel-dnd.c +++ /dev/null @@ -1,104 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#include <libxfce4util/libxfce4util.h> -#include "panel-dnd.h" - - -/* Partly based on the example on - * http://live.gnome.org/GnomeLove/DragNDropTutorial - * Copyright (c) 2005 Ryan McDougall - * Licensed under the GNU GPL - */ - -static const GtkTargetEntry dest_target_list[] = -{ - { (gchar *) "application/x-xfce-panel-plugin-name", 0, TARGET_PLUGIN_NAME }, - { (gchar *) "application/x-xfce-panel-plugin-widget", GTK_TARGET_SAME_APP, TARGET_PLUGIN_WIDGET } -}; - -static const GtkTargetEntry name_target_list[] = -{ - { (gchar *) "application/x-xfce-panel-plugin-name", 0, TARGET_PLUGIN_NAME } -}; - -static const GtkTargetEntry widget_target_list[] = -{ - { (gchar *) "application/x-xfce-panel-plugin-widget", GTK_TARGET_SAME_APP, TARGET_PLUGIN_WIDGET } -}; - -/* public API */ - -void -panel_dnd_set_dest_name_and_widget (GtkWidget *widget) -{ - gtk_drag_dest_set (widget, - GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_MOTION, - dest_target_list, G_N_ELEMENTS (dest_target_list), - GDK_ACTION_MOVE | GDK_ACTION_COPY); -} - -void -panel_dnd_set_dest_widget (GtkWidget *widget) -{ - gtk_drag_dest_set (widget, - GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_MOTION, - widget_target_list, G_N_ELEMENTS (widget_target_list), GDK_ACTION_MOVE); -} - -void -panel_dnd_set_source_name (GtkWidget *widget) -{ - gtk_drag_source_set (widget, GDK_BUTTON1_MASK, - name_target_list, G_N_ELEMENTS (name_target_list), GDK_ACTION_COPY); -} - -void -panel_dnd_set_source_widget (GtkWidget *widget) -{ - gtk_drag_source_set (widget, GDK_BUTTON1_MASK, - widget_target_list, G_N_ELEMENTS (widget_target_list), GDK_ACTION_COPY); -} - -void -panel_dnd_begin_drag (GtkWidget *widget) -{ - GtkTargetList *target_list ; - GdkEvent *event; - - event = gtk_get_current_event(); - if (G_LIKELY (event)) - { - /* create a new target list */ - target_list = gtk_target_list_new (widget_target_list, G_N_ELEMENTS (widget_target_list)); - - /* begin the drag */ - gtk_drag_begin (widget, target_list, GDK_ACTION_MOVE, 1, event); - - /* release the target list */ - gtk_target_list_unref (target_list); - - /* free the event */ - gdk_event_free (event); - } -} diff --git a/panel/panel-dnd.h b/panel/panel-dnd.h deleted file mode 100644 index 52449811..00000000 --- a/panel/panel-dnd.h +++ /dev/null @@ -1,41 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_DND_H__ -#define __PANEL_DND_H__ - -#include <gtk/gtk.h> - -enum -{ - TARGET_PLUGIN_NAME, - TARGET_PLUGIN_WIDGET -}; - -void panel_dnd_set_dest_name_and_widget (GtkWidget *widget); - -void panel_dnd_set_dest_widget (GtkWidget *widget); - -void panel_dnd_set_source_name (GtkWidget *widget); - -void panel_dnd_set_source_widget (GtkWidget *widget); - -void panel_dnd_begin_drag (GtkWidget *widget); - -#endif /* !__PANEL_DND_H__ */ diff --git a/panel/panel-item-manager.c b/panel/panel-item-manager.c deleted file mode 100644 index 014ae7ff..00000000 --- a/panel/panel-item-manager.c +++ /dev/null @@ -1,552 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#ifdef HAVE_STRING_H -#include <string.h> -#endif - -#include <gdk/gdkx.h> -#include <gtk/gtk.h> -#include <gmodule.h> -#include <libxfce4util/libxfce4util.h> -#include <libxfcegui4/libxfcegui4.h> -#include <libxfce4panel/xfce-panel-item-iface.h> -#include <libxfce4panel/xfce-panel-macros.h> -#include <libxfce4panel/xfce-panel-internal-plugin.h> -#include <libxfce4panel/xfce-panel-external-item.h> -#include <libxfce4panel/xfce-panel-enums.h> -#include <libxfce4panel/xfce-panel-convenience.h> - -#include "panel-item-manager.h" - -#ifndef _ -#define _(x) x -#endif - -typedef struct _XfcePanelItemClass XfcePanelItemClass; - -struct _XfcePanelItemClass -{ - /* info from .desktop file */ - gchar *plugin_name; - - gchar *name; - gchar *comment; - gchar *icon; - - guint unique : 1; - guint is_external : 1; - - /* either executable or loadable module */ - gchar *file; - - /* using the plugin */ - gint use_count; - - /* for loadable modules only */ - GModule *gmodule; - XfcePanelPluginFunc construct; - XfcePanelPluginCheck check; -}; - -static GHashTable *plugin_klasses = NULL; - -/* hash table */ - -static void -free_item_klass (XfcePanelItemClass *klass) -{ - DBG ("Free item klass: %s", klass->plugin_name); - - /* close the module if needed */ - if (klass->gmodule != NULL) - g_module_close (klass->gmodule); - - /* cleanup */ - g_free (klass->plugin_name); - g_free (klass->name); - g_free (klass->comment); - g_free (klass->icon); - g_free (klass->file); - - /* free the structure */ - panel_slice_free (XfcePanelItemClass, klass); -} - -static void -add_item_info_to_array (char *plugin_name, - XfcePanelItemClass *klass, - gpointer data) -{ - GPtrArray *array = data; - XfcePanelItemInfo *info; - - info = panel_slice_new0 (XfcePanelItemInfo); - - info->name = plugin_name; - info->display_name = klass->name; - info->comment = klass->comment; - - /* for the item list in the 'Add Items' dialog */ - if (klass->icon) - info->icon = xfce_themed_icon_load (klass->icon, 48); - - g_ptr_array_add (array, info); -} - -static gboolean -check_klass_removal (gpointer key, - XfcePanelItemClass *klass) -{ - if (!g_file_test (klass->file, G_FILE_TEST_EXISTS)) - { - if (klass->is_external || !klass->use_count) - return TRUE; - } - - return FALSE; -} - -static int -compare_klasses (gpointer *a, - gpointer *b) -{ - XfcePanelItemClass *klass_a, *klass_b; - - if (!a || !(*a)) - return 1; - - if (!b || !(*b)) - return -1; - - if (*a == *b) - return 0; - - klass_a = *a; - klass_b = *b; - - if (!strcmp (klass_a->plugin_name, "launcher")) - return -1; - - if (!strcmp (klass_b->plugin_name, "launcher")) - return 1; - - return strcmp (klass_a->name ? klass_a->name : "x", - klass_b->name ? klass_b->name : "x"); -} - -/* plugin desktop files */ - -static XfcePanelItemClass * -create_item_klass (const gchar *file, - gboolean is_external) - { - XfcePanelItemClass *klass; - - klass = panel_slice_new0 (XfcePanelItemClass); - klass->file = g_strdup (file); - klass->is_external = is_external; - - return klass; -} - -static XfcePanelItemClass * -new_plugin_klass_from_desktop_file (const gchar *directory, - const gchar *filename) -{ - XfcePanelItemClass *klass = NULL; - XfceRc *rc; - gchar *name, *file; - const gchar *value, *p; - const gchar *dir; - gchar *path; - - /* create the full desktop filename */ - file = g_build_filename (directory, filename, NULL); - - /* get the plugin (fallback) name */ - /* NOTE: this cannot fail since the filename passed the suffix test */ - p = strrchr (filename, '.'); - name = g_strndup (filename, p - filename); - - /* check if the plugin already exisits in the table */ - if (G_UNLIKELY (g_hash_table_lookup (plugin_klasses, name) != NULL)) - goto already_exists; - - /* open the desktop file */ - rc = xfce_rc_simple_open (file, TRUE); - - if (G_LIKELY (rc != NULL)) - { - if (G_LIKELY (xfce_rc_has_group (rc, "Xfce Panel"))) - { - /* set the xfce panel group */ - xfce_rc_set_group (rc, "Xfce Panel"); - - /* check if this is an external plugin and if it exists */ - if ((value = xfce_rc_read_entry (rc, "X-XFCE-Exec", NULL)) && - g_path_is_absolute (value) && - g_file_test (value, G_FILE_TEST_EXISTS)) - - { - klass = create_item_klass (value, TRUE); - - DBG ("External plugin: %s", value); - } - /* an internal plugin then ... ? */ - else if (G_LIKELY ((value = xfce_rc_read_entry (rc, "X-XFCE-Module", NULL)))) - { - /* read the module path */ - dir = xfce_rc_read_entry (rc, "X-XFCE-Module-Path", NULL); - - if (G_LIKELY (dir != NULL)) - { - /* build the module filename */ - path = g_module_build_path (dir, value); - - /* test if the module exists */ - if (G_LIKELY (g_file_test (path, G_FILE_TEST_EXISTS))) - { - klass = create_item_klass (path, FALSE); - - DBG ("Internal plugin: %s", path); - } - - /* cleanup */ - g_free (path); - } - else - { - g_warning ("Internal plugins need the \"X-XFCE-Module-Path\" entry to work properly."); - } - } - else - { - g_warning ("No X-XFCE-{Module,Exec} entry found in \"%s\".", file); - } - } - - if (G_LIKELY (klass != NULL)) - { - /* set the plugin name */ - klass->plugin_name = name; - - /* set the plugin name with our generated name as fallback */ - value = xfce_rc_read_entry (rc, "Name", name); - klass->name = g_strdup (value); - - /* reset the name since it is now pointed to klass->plugin_name */ - name = NULL; - - /* set a comment from the desktop file */ - value = xfce_rc_read_entry (rc, "Comment", NULL); - klass->comment = g_strdup (value); - - /* set the plugin icon */ - value = xfce_rc_read_entry (rc, "Icon", NULL); - klass->icon = g_strdup (value); - - /* whether this plugin can only be placed once on the panel(s) */ - klass->unique = xfce_rc_read_bool_entry (rc, "X-XFCE-Unique", FALSE); - } - else - { - g_warning ("Failed to create plugin \"%s\"", name); - } - - /* close the rc file */ - xfce_rc_close (rc); - } - - already_exists: - - /* cleanup */ - g_free (name); - g_free (file); - - return klass; -} - -static void -update_plugin_list (void) -{ - gchar **directories; - gint n; - GDir *gdir; - gchar *dirname; - const gchar *file; - XfcePanelItemClass *klass; - - if (G_LIKELY (xfce_allow_panel_customization() == TRUE)) - { - /* if panel customization is allowed, we search all resource dirs */ - directories = xfce_resource_dirs (XFCE_RESOURCE_DATA); - - /* check if the DATADIR is in the list */ - for (n = 0; directories[n] != NULL; ++n) - if (strcmp (directories[n], DATADIR) == 0) - break; - - if (G_UNLIKELY (directories[n] == NULL)) - { - /* append the datadir path */ - directories = g_realloc (directories, (n + 2) * sizeof (gchar*)); - directories[n] = g_strdup (DATADIR); - directories[n+1] = NULL; - } - } - else - { - /* only append the data directory */ - directories = g_new0 ( char*, 2 ); - directories[0] = g_strdup (DATADIR); - directories[1] = NULL; - } - - /* walk through the directories */ - for (n = 0; directories[n] != NULL; ++n) - { - /* build the plugins directory name */ - dirname = g_build_filename (directories[n], "xfce4", "panel-plugins", NULL); - - /* open the directory */ - gdir = g_dir_open (dirname, 0, NULL); - - DBG (" + directory: %s", dirname); - - if (G_LIKELY (gdir != NULL)) - { - /* walk though all the files in the directory */ - while ((file = g_dir_read_name (gdir)) != NULL) - { - /* continue if it's not a .desktop file */ - if (!g_str_has_suffix (file, ".desktop")) - continue; - - /* try to create a klass */ - klass = new_plugin_klass_from_desktop_file (dirname, file); - - if (G_LIKELY (klass)) - { - DBG (" + klass \"%s\": " - "name=%s, comment=%s, icon=%s, external=%d, path=%s", - klass->plugin_name ? klass->plugin_name : "(null)", - klass->name ? klass->name : "(null)", - klass->comment ? klass->comment : "(null)", - klass->icon ? klass->icon : "(null)", - klass->is_external, - klass->file ? klass->file : "(null)"); - - /* insert the class in the hash table */ - g_hash_table_insert (plugin_klasses, klass->plugin_name, klass); - } - } - - /* close the directory */ - g_dir_close (gdir); - } - - /* cleanup */ - g_free (dirname); - } - - /* cleanup */ - g_strfreev (directories); -} - -static gboolean -load_module (XfcePanelItemClass *klass) -{ - gpointer symbol; - XfcePanelPluginFunc (*get_construct) (void); - XfcePanelPluginCheck (*get_check) (void); - - /* try to open the module */ - klass->gmodule = g_module_open (klass->file, G_MODULE_BIND_LOCAL); - - /* check */ - if (G_UNLIKELY (klass->gmodule == NULL)) - { - /* show a warning */ - g_critical ("Could not open module \"%s\" (%s): %s", - klass->name, klass->file, g_module_error ()); - - return FALSE; - } - - /* check */ - if (G_UNLIKELY (!g_module_symbol (klass->gmodule, - "xfce_panel_plugin_get_construct", - &symbol))) - { - /* show a warning */ - g_critical ("Could not open symbol in module \"%s\" (%s): %s", - klass->name, klass->file, g_module_error ()); - - /* close the module */ - g_module_close (klass->gmodule); - klass->gmodule = NULL; - - return FALSE; - } - - get_construct = symbol; - klass->construct = get_construct (); - - /* check of the check function ^_^ */ - if (g_module_symbol (klass->gmodule, - "xfce_panel_plugin_get_check", &symbol)) - { - get_check = symbol; - klass->check = get_check (); - } - else - { - klass->check = NULL; - } - - return TRUE; -} - -static void -decrease_use_count (GtkWidget *item, - XfcePanelItemClass *klass) -{ - if (klass->use_count > 0) - klass->use_count--; -} - -/* public API */ - -void -xfce_panel_item_manager_init (void) -{ - plugin_klasses = g_hash_table_new_full ((GHashFunc) g_str_hash, - (GEqualFunc) g_str_equal, - NULL, - (GDestroyNotify) free_item_klass); - - update_plugin_list (); -} - -void -xfce_panel_item_manager_cleanup (void) -{ - g_hash_table_destroy (plugin_klasses); - - plugin_klasses = NULL; -} - -GtkWidget * -xfce_panel_item_manager_create_item (GdkScreen *screen, - const gchar *name, - const gchar *id, - gint size, - XfceScreenPosition position) -{ - XfcePanelItemClass *klass; - GtkWidget *item = NULL; - - if ((klass = g_hash_table_lookup (plugin_klasses, name)) == NULL) - return NULL; - - if (klass->is_external) - { - item = xfce_external_panel_item_new (klass->plugin_name, id, - klass->name, klass->file, - size, position); - } - else - { - if (!klass->gmodule && !load_module (klass)) - return NULL; - - if (klass->check == NULL || klass->check(screen) == TRUE ) - { - item = xfce_internal_panel_plugin_new (klass->plugin_name, - id, - klass->name, - size, - position, - klass->construct); - } - } - - if (item) - { - klass->use_count++; - g_signal_connect (G_OBJECT (item), "destroy", - G_CALLBACK (decrease_use_count), klass); - } - - return item; -} - -GPtrArray * -xfce_panel_item_manager_get_item_info_list (void) -{ - GPtrArray *array; - - update_plugin_list (); - - g_hash_table_foreach_remove (plugin_klasses, (GHRFunc)check_klass_removal, - NULL); - - array = g_ptr_array_sized_new (g_hash_table_size (plugin_klasses)); - - g_hash_table_foreach (plugin_klasses, (GHFunc)add_item_info_to_array, - array); - - g_ptr_array_sort (array, (GCompareFunc)compare_klasses); - - return array; -} - -void -xfce_panel_item_manager_free_item_info_list (GPtrArray *info_list) -{ - guint i; - - for (i = 0; i < info_list->len; ++i) - { - XfcePanelItemInfo *info = g_ptr_array_index (info_list, i); - - if (info->icon) - g_object_unref (G_OBJECT (info->icon)); - - panel_slice_free (XfcePanelItemInfo, info); - } - - g_ptr_array_free (info_list, TRUE); -} - -gboolean -xfce_panel_item_manager_is_available (const gchar *name) -{ - XfcePanelItemClass *klass; - - if ((klass = g_hash_table_lookup (plugin_klasses, name)) == NULL) - return FALSE; - - return (!(klass->unique && klass->use_count)); -} diff --git a/panel/panel-item-manager.h b/panel/panel-item-manager.h deleted file mode 100644 index d0fa9dba..00000000 --- a/panel/panel-item-manager.h +++ /dev/null @@ -1,56 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __XFCE_PANEL_ITEM_MANAGER_H__ -#define __XFCE_PANEL_ITEM_MANAGER_H__ - -#include <gtk/gtkwidget.h> -#include <libxfce4panel/xfce-panel-enums.h> - -G_BEGIN_DECLS - -typedef struct _XfcePanelItemInfo XfcePanelItemInfo; - -struct _XfcePanelItemInfo -{ - char *name; - char *display_name; - char *comment; - GdkPixbuf *icon; -}; - -void xfce_panel_item_manager_init (void); - -void xfce_panel_item_manager_cleanup (void); - -GtkWidget *xfce_panel_item_manager_create_item (GdkScreen *screen, - const char *name, - const char *id, - int size, - XfceScreenPosition position); - -/* for 'Add Item' dialog */ -GPtrArray *xfce_panel_item_manager_get_item_info_list (void); - -void xfce_panel_item_manager_free_item_info_list (GPtrArray *info_list); - -gboolean xfce_panel_item_manager_is_available (const char *name); - - -#endif /* !__XFCE_PANEL_ITEM_MANAGER_H__ */ diff --git a/panel/panel-private.h b/panel/panel-private.h deleted file mode 100644 index 8d3d0993..00000000 --- a/panel/panel-private.h +++ /dev/null @@ -1,81 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_PRIVATE_H__ -#define __PANEL_PRIVATE_H__ - -#include <gtk/gtkwidget.h> -#include <libxfce4panel/xfce-panel-enums.h> - -#include "panel-app.h" - -#define DEFAULT_SIZE 48 -#define MIN_SIZE 16 -#define MAX_SIZE 128 -#define DEFAULT_MONITOR 0 -#define DEFAULT_SCREEN_POSITION XFCE_SCREEN_POSITION_NONE -#define DEFAULT_XOFFSET 0 -#define DEFAULT_YOFFSET 0 -#define DEFAULT_AUTOHIDE FALSE -#define DEFAULT_FULL_WIDTH XFCE_PANEL_NORMAL_WIDTH -#define DEFAULT_TRANSPARENCY 20 -#define DEFAULT_ACTIVE_TRANS FALSE - -#define PANEL_GET_PRIVATE(o) (PANEL(o)->priv) - -typedef struct _PanelPrivate PanelPrivate; - -typedef enum -{ - XFCE_PANEL_NORMAL_WIDTH, - XFCE_PANEL_FULL_WIDTH, - XFCE_PANEL_SPAN_MONITORS, -} -XfcePanelWidthType; - -struct _PanelPrivate -{ - GtkWidget *itembar; - GtkWidget *menu; - - gint size; - gint monitor; - XfceScreenPosition screen_position; - gint xoffset; - gint yoffset; - XfcePanelWidthType full_width; - gint transparency; - - gulong opacity; - gulong saved_opacity; - - gint block_autohide; - gint hide_timeout; - gint unhide_timeout; - - /* booleans */ - guint autohide : 1; - guint activetrans : 1; - guint hidden : 1; - guint edit_mode : 1; - - gulong struts[12]; -}; - -#endif /* !__PANEL_PRIVATE_H__ */ diff --git a/panel/panel-properties.c b/panel/panel-properties.c deleted file mode 100644 index c8f4a64f..00000000 --- a/panel/panel-properties.c +++ /dev/null @@ -1,1562 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_TIME_H -#include <time.h> -#endif -#ifdef HAVE_MATH_H -#include <math.h> -#endif - -#include <gtk/gtk.h> -#include <libxfce4util/libxfce4util.h> -#include <libxfce4panel/xfce-panel-window.h> -#include <libxfce4panel/xfce-itembar.h> -#include <libxfce4panel/xfce-panel-item-iface.h> -#include <libxfce4panel/xfce-panel-enums.h> -#include <libxfce4panel/xfce-panel-macros.h> - -#include "panel-properties.h" -#include "panel-private.h" -#include "panel-dnd.h" - -#define HIDDEN_SIZE 2 -#define OPAQUE 0xffffffff -#define HIDE_TIMEOUT 350 -#define UNHIDE_TIMEOUT 200 - - - -/* prototypes */ -static void panel_move_end (XfcePanelWindow *window, - gint x, - gint y); -static void panel_move_function (XfcePanelWindow *window, - Panel *panel, - gint *x, - gint *y); -static void panel_resize_function (XfcePanelWindow *window, - Panel *panel, - GtkAllocation *alloc_old, - GtkAllocation *alloc_new, - gint *x, - gint *y); -static void panel_enter (Panel *p, - GdkEventCrossing *event); -static void panel_leave (Panel *p, - GdkEventCrossing *event); -static void panel_grabbed (Panel *p, - gboolean was_grabbed); - - - -/* moving and resizing */ -static void -_calculate_coordinates (XfceScreenPosition position, /* screen position */ - GdkRectangle *screen, /* monitor geometry */ - gint width, /* panel size */ - gint height, - gint *x, /* output coordinates */ - gint *y) -{ - switch (position) - { - /* floating */ - case XFCE_SCREEN_POSITION_NONE: - case XFCE_SCREEN_POSITION_FLOATING_H: - case XFCE_SCREEN_POSITION_FLOATING_V: - *x = CLAMP (*x, screen->x, - MAX (screen->x, screen->x + screen->width - width)); - *y = CLAMP (*y, screen->y, - MAX (screen->y, screen->y + screen->height - height)); - break; - - /* top */ - case XFCE_SCREEN_POSITION_NW_H: - *x = screen->x; - *y = screen->y; - break; - - case XFCE_SCREEN_POSITION_N: - *x = MAX (screen->x, screen->x + (screen->width - width) / 2); - *y = screen->y; - break; - - case XFCE_SCREEN_POSITION_NE_H: - *x = MAX (screen->x, screen->x + screen->width - width); - *y = screen->y; - break; - - /* left */ - case XFCE_SCREEN_POSITION_NW_V: - *x = screen->x; - *y = screen->y; - break; - - case XFCE_SCREEN_POSITION_W: - *x = screen->x; - *y = MAX (screen->y, screen->y + (screen->height - height) / 2); - break; - - case XFCE_SCREEN_POSITION_SW_V: - *x = screen->x; - *y = MAX (screen->y, screen->y + screen->height - height); - break; - - /* right */ - case XFCE_SCREEN_POSITION_NE_V: - *x = screen->x + screen->width - width; - *y = screen->y; - break; - - case XFCE_SCREEN_POSITION_E: - *x = screen->x + screen->width - width; - *y = MAX (screen->y, screen->y + (screen->height - height) / 2); - break; - - case XFCE_SCREEN_POSITION_SE_V: - *x = screen->x + screen->width - width; - *y = MAX (screen->y, screen->y + screen->height - height); - break; - - /* bottom */ - case XFCE_SCREEN_POSITION_SW_H: - *x = screen->x; - *y = screen->y + screen->height - height; - break; - - case XFCE_SCREEN_POSITION_S: - *x = MAX (screen->x, screen->x + (screen->width - width) / 2); - *y = screen->y + screen->height - height; - break; - - case XFCE_SCREEN_POSITION_SE_H: - *x = MAX (screen->x, screen->x + screen->width - width); - *y = screen->y + screen->height - height; - break; - } -} - - - -static void -_set_borders (Panel *panel) -{ - PanelPrivate *priv; - gboolean top, bottom, left, right; - - priv = panel->priv; - - top = bottom = left = right = TRUE; - - switch (priv->screen_position) - { - /* floating */ - case XFCE_SCREEN_POSITION_NONE: - case XFCE_SCREEN_POSITION_FLOATING_H: - case XFCE_SCREEN_POSITION_FLOATING_V: - break; - - /* top */ - case XFCE_SCREEN_POSITION_NW_H: - top = left = FALSE; - right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_N: - top = FALSE; - left = right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_NE_H: - top = right = FALSE; - left = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - /* left */ - case XFCE_SCREEN_POSITION_NW_V: - left = top = FALSE; - bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_W: - left = FALSE; - top = bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_SW_V: - left = bottom = FALSE; - top = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - /* right */ - case XFCE_SCREEN_POSITION_NE_V: - right = top = FALSE; - bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_E: - right = FALSE; - top = bottom = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_SE_V: - right = bottom = FALSE; - top = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - /* bottom */ - case XFCE_SCREEN_POSITION_SW_H: - bottom = left = FALSE; - right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_S: - bottom = FALSE; - left = right = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - - case XFCE_SCREEN_POSITION_SE_H: - bottom = right = FALSE; - left = (priv->full_width == XFCE_PANEL_NORMAL_WIDTH); - break; - } - - xfce_panel_window_set_show_border (XFCE_PANEL_WINDOW (panel), - top, bottom, left, right); -} - -/* fairly arbitrary maximum strut size */ -static gboolean -_validate_strut( gint width, - gint offset ) -{ - return ( offset < width / 4 ); -} - -static void -_set_struts (Panel *panel, - XfceMonitor *xmon, - gint x, - gint y, - gint w, - gint h) -{ - PanelPrivate *priv; - gulong data[12] = { 0, }; - gint i; - gboolean update = FALSE; - - /* _NET_WM_STRUT_PARTIAL: CARDINAL[12]/32 - * - * 0: left 1: right 2: top 3: bottom - * 4: left_start_y 5: left_end_y 6: right_start_y 7: right_end_y - * 8: top_start_x 9: top_end_x 10: bottom_start_x 11: bottom_end_x - * - * Note: In xinerama use struts relative to combined screen dimensions, - * not just the current monitor. - */ - - priv = panel->priv; - - /* use edit_mode property to test if we are changing position */ - if (G_UNLIKELY (priv->edit_mode)) - return; - - if (!priv->autohide && - !xfce_screen_position_is_floating (priv->screen_position)) - { - if (xfce_screen_position_is_left (priv->screen_position)) - { - /* no struts possible on Xinerama screens when this monitor - * has neighbors on the left (see fd.o spec). - */ - if (!xmon->has_neighbor_left - && _validate_strut (xmon->geometry.width, w)) - { - data[0] = xmon->geometry.x + w; /* left */ - data[4] = y; /* left_start_y */ - data[5] = y + h - 1; /* left_end_y */ - } - } - else if (xfce_screen_position_is_right (priv->screen_position)) - { - /* no struts possible on Xinerama screens when this monitor - * has neighbors on the right (see fd.o spec). - */ - if (!xmon->has_neighbor_right - && _validate_strut (xmon->geometry.width, w)) - { - data[1] = gdk_screen_get_width (xmon->screen) - - xmon->geometry.x - xmon->geometry.width - + w; /* right */ - data[6] = y; /* right_start_y */ - data[7] = y + h - 1; /* right_end_y */ - } - } - else if (xfce_screen_position_is_top (priv->screen_position)) - { - /* no struts possible on Xinerama screens when this monitor - * has neighbors on the top (see fd.o spec). - */ - if (!xmon->has_neighbor_above - && _validate_strut (xmon->geometry.height, h)) - { - data[2] = xmon->geometry.y - + h; /* top */ - data[8] = x; /* top_start_x */ - data[9] = x + w - 1; /* top_end_x */ - } - } - else - { - /* no struts possible on Xinerama screens when this monitor - * has neighbors on the bottom (see fd.o spec). - */ - if (!xmon->has_neighbor_below - && _validate_strut (xmon->geometry.height, h)) - { - data[3] = gdk_screen_get_height (xmon->screen) - - xmon->geometry.y - xmon->geometry.height - + h; /* bottom */ - data[10] = x; /* bottom_start_x */ - data[11] = x + w - 1; /* bottom_end_x */ - } - } - } - - DBG ("\nStruts\n" - "%ld\t%ld\t%ld\t%ld\n" - "%ld\t%ld\t%ld\t%ld\n" - "%ld\t%ld\t%ld\t%ld\n", - data[0], data[1], data[2], data[3], - data[4], data[5], data[6], data[7], - data[8], data[9], data[10], data[11]); - - /* Check if values have changed. */ - for (i = 0; i < 12; i++) - { - if (data[i] != priv->struts[i]) - { - update = TRUE; - priv->struts[i] = data[i]; - } - } - - if (update) - { - gdk_error_trap_push (); - gdk_property_change (GTK_WIDGET (panel)->window, - gdk_atom_intern ("_NET_WM_STRUT_PARTIAL", FALSE), - gdk_atom_intern ("CARDINAL", FALSE), 32, - GDK_PROP_MODE_REPLACE, (guchar *) & data, 12); - gdk_error_trap_pop (); - - gdk_error_trap_push (); - gdk_property_change (GTK_WIDGET (panel)->window, - gdk_atom_intern ("_NET_WM_STRUT", FALSE), - gdk_atom_intern ("CARDINAL", FALSE), 32, - GDK_PROP_MODE_REPLACE, (guchar *) & data, 4); - gdk_error_trap_pop (); - } - - DBG ("all struts are checked and updated"); -} - -static gboolean -unblock_struts (Panel *panel) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - gint x, y, w, h; - - priv = PANEL (panel)->priv; - priv->edit_mode = FALSE; - - gtk_window_get_position (GTK_WINDOW (panel), &x, &y); - gtk_window_get_size (GTK_WINDOW (panel), &w, &h); - - xmon = panel_app_get_monitor (priv->monitor); - - _set_struts (panel, xmon, x, y, w, h); - return FALSE; -} - -static void -panel_move_end (XfcePanelWindow *window, - gint x, - gint y) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - - priv = PANEL (window)->priv; - - if (xfce_screen_position_is_floating (priv->screen_position)) - { - /* Emit this signal to allow plugins to do something based on the - * new position. E.g. the launcher plugin adjusts the arrow type - * of the associated menu button. */ - gtk_container_foreach (GTK_CONTAINER (priv->itembar), - (GtkCallback)xfce_panel_item_set_screen_position, - GINT_TO_POINTER (priv->screen_position)); - } - - xmon = panel_app_get_monitor (priv->monitor); - - priv->xoffset = x - xmon->geometry.x; - priv->yoffset = y - xmon->geometry.y; - - DBG ("\n + Position: %d\n + Offset: (%d, %d)", - priv->screen_position, priv->xoffset, priv->yoffset); - - panel_app_queue_save (); -} - -static void -panel_move_function (XfcePanelWindow *window, - Panel *panel, - gint *x, - gint *y) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - GdkScreen *screen; - - priv = panel->priv; - - screen = gtk_widget_get_screen (GTK_WIDGET (window)); - priv->monitor = gdk_screen_get_monitor_at_point (screen, *x, *y); - - DBG (" + Monitor at (%d, %d) = %d\n", *x, *y, priv->monitor); - - xmon = panel_app_get_monitor (priv->monitor); - - _calculate_coordinates (priv->screen_position, - &(xmon->geometry), - GTK_WIDGET (window)->allocation.width, - GTK_WIDGET (window)->allocation.height, - x, y); -} - -static void -panel_resize_function (XfcePanelWindow *window, - Panel *panel, - GtkAllocation *alloc_old, - GtkAllocation *alloc_new, - gint *x, - gint *y) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - GdkRectangle rect; - - DBG ("old: %dx%d\tnew: %dx%d", - alloc_old ? alloc_old->width : 0, alloc_old ? alloc_old->height : 0, - alloc_new->width, alloc_new->height ); - - if (!GTK_WIDGET_VISIBLE (panel)) - return; - - priv = panel->priv; - xmon = panel_app_get_monitor (priv->monitor); - - if (priv->full_width < XFCE_PANEL_SPAN_MONITORS) - { - _calculate_coordinates (priv->screen_position, - &(xmon->geometry), - alloc_new->width, - alloc_new->height, - x, y); - - priv->xoffset = *x - xmon->geometry.x; - priv->yoffset = *y - xmon->geometry.y; - } - else - { - rect.x = 0; - rect.y = 0; - rect.width = gdk_screen_get_width (xmon->screen); - rect.height = gdk_screen_get_height (xmon->screen); - - _calculate_coordinates (priv->screen_position, - &rect, - alloc_new->width, - alloc_new->height, - x, y); - - priv->xoffset = *x; - priv->yoffset = *y; - } - - _set_struts (panel, xmon, *x, *y, alloc_new->width, alloc_new->height); -} - -static void -panel_set_position (Panel *panel, - XfceScreenPosition position, - gint xoffset, - gint yoffset) -{ - PanelPrivate *priv; - GtkRequisition req; - gint x, y; - XfceMonitor *xmon; - GdkRectangle rect; - - if (!GTK_WIDGET_VISIBLE (panel)) - return; - - priv = panel->priv; - xmon = panel_app_get_monitor (priv->monitor); - - priv->screen_position = position; - _set_borders (panel); - - gtk_widget_size_request (GTK_WIDGET (panel), &req); - - x = y = 0; - - /* NOTE: xoffset and yoffset are only used for floating panels */ - if (xfce_screen_position_is_floating (position)) - { - if (G_UNLIKELY (xoffset < 0 || yoffset < 0)) - { - /* This means we switched to being a floating panel; - * calculate the actual position here. */ - gtk_window_get_position (GTK_WINDOW (panel), &x, &y); - } - else - { - x = xmon->geometry.x + xoffset; - y = xmon->geometry.y + yoffset; - } - } - - if (priv->full_width < XFCE_PANEL_SPAN_MONITORS) - { - _calculate_coordinates (position, - &(xmon->geometry), - req.width, - req.height, - &x, &y); - - priv->xoffset = x - xmon->geometry.x; - priv->yoffset = y - xmon->geometry.y; - } - else - { - rect.x = 0; - rect.y = 0; - rect.width = gdk_screen_get_width (xmon->screen); - rect.height = gdk_screen_get_height (xmon->screen); - - _calculate_coordinates (position, - &rect, - req.width, - req.height, - &x, &y); - - priv->xoffset = x; - priv->yoffset = y; - } - - DBG ("\n + Position: %d\n + Offset: (%d, %d)", - priv->screen_position, priv->xoffset, priv->yoffset); - - DBG (" + coordinates: (%d, %d)\n", x, y); - - gtk_window_move (GTK_WINDOW (panel), x, y); - - _set_struts (panel, xmon, x, y, req.width, req.height); -} - -/* screen size */ -void -panel_screen_size_changed (GdkScreen *screen, - Panel *panel) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - XfcePanelWidthType width; - - priv = panel->priv; - - xmon = panel_app_get_monitor (priv->monitor); - - gdk_screen_get_monitor_geometry (screen, - xmon->num, - &(xmon->geometry)); - - /* new size constraints */ - if ((width = priv->full_width) != XFCE_PANEL_NORMAL_WIDTH) - { - priv->full_width = XFCE_PANEL_NORMAL_WIDTH; - panel_set_full_width (panel, width); - } - else - { - gtk_widget_queue_resize (GTK_WIDGET (panel)); - } -} - -/* transparency and autohide */ -static void -_set_transparent (Panel *panel, - gboolean transparent) -{ - PanelPrivate *priv; - gulong opacity; - - if (!GTK_WIDGET (panel)->window) - return; - - priv = panel->priv; - - if (G_UNLIKELY (priv->opacity == 0)) - { - if (priv->transparency != 0) - { - priv->opacity = - OPAQUE - rint ((gdouble)priv->transparency * OPAQUE / 100); - } - else - { - priv->opacity = OPAQUE; - } - } - - opacity = (transparent || priv->activetrans) ? priv->opacity : OPAQUE; - - if (opacity != priv->saved_opacity) - { - priv->saved_opacity = opacity; - - gdk_error_trap_push (); - - gdk_property_change (GTK_WIDGET (panel)->window, - gdk_atom_intern ("_NET_WM_WINDOW_OPACITY", FALSE), - gdk_atom_intern ("CARDINAL", FALSE), 32, - GDK_PROP_MODE_REPLACE, - (guchar *) & opacity, - 1L); - - gdk_error_trap_pop (); - - gtk_widget_queue_draw (GTK_WIDGET (panel)); - } -} - -void -panel_set_hidden (Panel *panel, - gboolean hide) -{ - PanelPrivate *priv; - gint w, h; - XfceMonitor *xmon; - - priv = panel->priv; - - priv->hidden = hide; - w = h = 0; - - if (hide) - { - if (xfce_screen_position_is_horizontal (priv->screen_position)) - { - w = GTK_WIDGET (panel)->allocation.width; - h = HIDDEN_SIZE; - } - else - { - w = HIDDEN_SIZE; - h = GTK_WIDGET (panel)->allocation.height; - } - - gtk_widget_hide (priv->itembar); - } - else - { - xmon = panel_app_get_monitor (priv->monitor); - - switch (priv->full_width) - { - case XFCE_PANEL_NORMAL_WIDTH: - w = h = -1; - break; - - case XFCE_PANEL_FULL_WIDTH: - case XFCE_PANEL_SPAN_MONITORS: - if (xfce_screen_position_is_horizontal (priv->screen_position)) - { - h = -1; - if (priv->full_width == XFCE_PANEL_FULL_WIDTH) - w = xmon->geometry.width; - else - w = gdk_screen_get_width (xmon->screen); - } - else - { - w = -1; - if (priv->full_width == XFCE_PANEL_FULL_WIDTH) - h = xmon->geometry.height; - else - h = gdk_screen_get_height (xmon->screen); - } - break; - } - - gtk_widget_show (priv->itembar); - } - - gtk_widget_set_size_request (GTK_WIDGET (panel), w, h); -} - -static gboolean -_hide_timeout (Panel *panel) -{ - PanelPrivate *priv; - - priv = panel->priv; - priv->hide_timeout = 0; - - if (!priv->hidden && !priv->block_autohide) - panel_set_hidden (panel, TRUE); - - return FALSE; -} - -static gboolean -_unhide_timeout (Panel *panel) -{ - PanelPrivate *priv; - - priv = panel->priv; - priv->unhide_timeout = 0; - - if (priv->hidden) - panel_set_hidden (panel, FALSE); - - return FALSE; -} - -static gboolean -drag_motion (Panel *panel, - GdkDragContext *context, - int x, - int y, - guint time_, - gpointer user_data) -{ - PanelPrivate *priv; - - priv = panel->priv; - - if (!priv->hidden || priv->block_autohide) - return TRUE; - - if (priv->hide_timeout) - { - g_source_remove (priv->hide_timeout); - priv->hide_timeout = 0; - } - - if (!priv->unhide_timeout) - { - priv->unhide_timeout = - g_timeout_add (UNHIDE_TIMEOUT, - (GSourceFunc) _unhide_timeout, panel); - } - - return TRUE; -} - - -static void -drag_leave (Panel *panel, - GdkDragContext *drag_context, - guint time_, - gpointer user_data) -{ - int x, y, w, h, px, py; - PanelPrivate *priv; - - priv = panel->priv; - - if (!priv->autohide || priv->hidden || priv->block_autohide) - return; - - /* check if pointer is inside the window */ - gdk_display_get_pointer (gdk_display_get_default (), NULL, &px, &py, NULL); - gtk_window_get_position (GTK_WINDOW (panel), &x, &y); - gtk_window_get_size (GTK_WINDOW (panel), &w, &h); - - if (px < x || px > x + w || py < y || py > y + h) - { - if (priv->unhide_timeout) - { - g_source_remove (priv->unhide_timeout); - priv->unhide_timeout = 0; - } - - if (!priv->hide_timeout) - { - priv->hide_timeout = - g_timeout_add (HIDE_TIMEOUT, - (GSourceFunc) _hide_timeout, panel); - } - } -} - - -static void -panel_enter (Panel *panel, - GdkEventCrossing *event) -{ - PanelPrivate *priv; - - if (event->detail != GDK_NOTIFY_INFERIOR) - { - panel_app_set_current_panel ((gpointer)panel); - - priv = panel->priv; - - if (priv->block_autohide) - return; - - _set_transparent (panel, FALSE); - - if (!priv->autohide) - return; - - if (priv->hide_timeout) - { - g_source_remove (priv->hide_timeout); - priv->hide_timeout = 0; - } - - if (priv->hidden) - priv->unhide_timeout = g_timeout_add (UNHIDE_TIMEOUT, - (GSourceFunc)_unhide_timeout, - panel); - } -} - - -static void -panel_leave (Panel *panel, - GdkEventCrossing *event) -{ - PanelPrivate *priv; - - if (event->detail != GDK_NOTIFY_INFERIOR) - { - priv = panel->priv; - - if (priv->block_autohide) - return; - - _set_transparent (panel, TRUE); - - if (!priv->autohide) - return; - - if (priv->unhide_timeout) - { - g_source_remove (priv->unhide_timeout); - priv->unhide_timeout = 0; - } - - if (!priv->hidden) - priv->hide_timeout = g_timeout_add (HIDE_TIMEOUT, - (GSourceFunc)_hide_timeout, - panel); - } -} - -static void -panel_grabbed (Panel *panel, - gboolean was_grabbed) -{ - PanelPrivate *priv = panel->priv; - - /* block the panel if the widget is grabbed */ - if (was_grabbed) - priv->block_autohide--; - else - priv->block_autohide++; -} - -static void -_window_mapped (Panel *panel) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - gint x, y; - - priv = panel->priv; - - panel_set_position (panel, - priv->screen_position, - priv->xoffset, - priv->yoffset); - - _set_transparent (panel, TRUE); - - gtk_window_get_position (GTK_WINDOW (panel), &x, &y); - - xmon = panel_app_get_monitor (priv->monitor); - priv->xoffset = x - xmon->geometry.x; - priv->yoffset = y - xmon->geometry.y; - - DBG (" + coordinates: (%d, %d)\n", x, y); - - DBG ("\n + Position: %d\n + Offset: (%d, %d)", - priv->screen_position, priv->xoffset, priv->yoffset); - - if (priv->autohide) - { - priv->hide_timeout = - g_timeout_add (2000, (GSourceFunc)_hide_timeout, panel); - } - -} - -/* public API */ -void panel_init_signals (Panel *panel) -{ - DBG (" + Connect signals for panel %p", panel); - - g_signal_connect (G_OBJECT (panel), "enter-notify-event", - G_CALLBACK (panel_enter), NULL); - - g_signal_connect (G_OBJECT (panel), "leave-notify-event", - G_CALLBACK (panel_leave), NULL); - - g_signal_connect (G_OBJECT (panel), "grab-notify", - G_CALLBACK (panel_grabbed), NULL); - - g_signal_connect (G_OBJECT (panel), "map", - G_CALLBACK (_window_mapped), NULL); - - g_signal_connect (G_OBJECT (panel), "move-end", - G_CALLBACK (panel_move_end), NULL); - - panel_dnd_set_dest_name_and_widget (GTK_WIDGET (panel)); - g_signal_connect (panel, "drag-motion", G_CALLBACK (drag_motion), NULL); - g_signal_connect (panel, "drag-leave", G_CALLBACK (drag_leave), NULL); -} - -void -panel_init_position (Panel *panel) -{ - PanelPrivate *priv; - GtkOrientation orientation; - XfceMonitor *xmon; - gint x, y, w, h, max; - GtkRequisition req; - GdkRectangle rect; - - priv = panel->priv; - - orientation = - xfce_screen_position_is_horizontal (priv->screen_position) ? - GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; - - xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (panel), orientation); - xfce_itembar_set_orientation (XFCE_ITEMBAR (priv->itembar), orientation); - - xmon = panel_app_get_monitor (priv->monitor); - - gtk_window_set_screen (GTK_WINDOW (panel), xmon->screen); - - w = h = -1; - - if (priv->full_width > XFCE_PANEL_NORMAL_WIDTH) - xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar), TRUE); - - if (xfce_screen_position_is_horizontal (priv->screen_position)) - { - if (priv->full_width < XFCE_PANEL_SPAN_MONITORS) - w = xmon->geometry.width; - else - w = gdk_screen_get_width (xmon->screen); - - max = w; - } - else - { - if (priv->full_width < XFCE_PANEL_SPAN_MONITORS) - h = xmon->geometry.height; - else - h = gdk_screen_get_height (xmon->screen); - - max = h; - } - - xfce_itembar_set_maximum_size (XFCE_ITEMBAR (priv->itembar), max); - - if (priv->full_width > XFCE_PANEL_NORMAL_WIDTH) - gtk_widget_set_size_request (GTK_WIDGET (panel), w, h); - - if (!xfce_screen_position_is_floating (priv->screen_position)) - { - xfce_panel_window_set_movable (XFCE_PANEL_WINDOW (panel), FALSE); - xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (panel), - XFCE_HANDLE_STYLE_NONE); - } - - x = xmon->geometry.x; - y = xmon->geometry.y; - - if (priv->xoffset > 0 || priv->yoffset > 0) - { - x += priv->xoffset; - y += priv->yoffset; - } - else - { - if (priv->full_width < XFCE_PANEL_SPAN_MONITORS) - { - gtk_widget_size_request (GTK_WIDGET (panel), &req); - _calculate_coordinates (priv->screen_position, - &(xmon->geometry), - req.width, - req.height, - &x, &y); - - priv->xoffset = x - xmon->geometry.x; - priv->yoffset = y - xmon->geometry.y; - } - else - { - rect.x = 0; - rect.y = 0; - rect.width = gdk_screen_get_width (xmon->screen); - rect.height = gdk_screen_get_height (xmon->screen); - - _calculate_coordinates (priv->screen_position, - &rect, - req.width, - req.height, - &x, &y); - - priv->xoffset = x; - priv->yoffset = y; - } - } - - DBG (" + offsets: (%d, %d)\n", - priv->xoffset, priv->yoffset); - - DBG (" + coordinates: (%d, %d)\n", x, y); - - gtk_window_move (GTK_WINDOW (panel), x, y); - - xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel), - (XfcePanelWindowMoveFunc)panel_move_function, panel); - - xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel), - (XfcePanelWindowResizeFunc)panel_resize_function, panel); -} - -void -panel_center (Panel *panel) -{ - PanelPrivate *priv; - GtkRequisition req; - XfceMonitor *xmon; - - priv = panel->priv; - - if (priv->screen_position < XFCE_SCREEN_POSITION_FLOATING_H) - return; - - xmon = panel_app_get_monitor (priv->monitor); - - gtk_widget_size_request (GTK_WIDGET (panel), &req); - - priv->xoffset = (xmon->geometry.width - req.width) / 2; - priv->yoffset = (xmon->geometry.height - req.height) / 2; - - DBG ("\n + Position: %d\n + Offset: (%d, %d)", - priv->screen_position, priv->xoffset, priv->yoffset); -} - -void panel_set_autohide (Panel *panel, - gboolean autohide) -{ - PanelPrivate *priv; - gint x, y, w, h; - XfceMonitor *xmon; - - priv = panel->priv; - - if (autohide == priv->autohide) - return; - - priv->autohide = autohide; - - if (!GTK_WIDGET_VISIBLE (panel)) - return; - - if (autohide) - { - panel_set_hidden (panel, TRUE); - - /* If autohide is blocked unhide again. - * We use the first panel_set_hidden() call to give the user - * some visual feedback. */ - if (priv->block_autohide) - { - while (gtk_events_pending ()) - gtk_main_iteration (); - - g_usleep (500000); /* 1/2 sec */ - panel_set_hidden (panel, FALSE); - } - } - else if (priv->hidden) - { - panel_set_hidden (panel, FALSE); - } - else - { - gtk_window_get_position (GTK_WINDOW (panel), &x, &y); - gtk_window_get_size (GTK_WINDOW (panel), &w, &h); - - xmon = panel_app_get_monitor (priv->monitor); - - _set_struts (panel, xmon, x, y, w, h); - } -} - -void panel_block_autohide (Panel *panel) -{ - PanelPrivate *priv; - - DBG ("block"); - - priv = panel->priv; - - priv->block_autohide++; - - if (priv->hidden) - panel_set_hidden (panel, FALSE); - - _set_transparent (panel, FALSE); -} - -void panel_unblock_autohide (Panel *panel) -{ - PanelPrivate *priv; - gint x, y, w, h, px, py; - - DBG ("unblock"); - - priv = panel->priv; - - if (priv->block_autohide > 0) - { - priv->block_autohide--; - - if (!priv->block_autohide) - { - gdk_display_get_pointer (gdk_display_get_default (), - NULL, &px, &py, NULL); - - gtk_window_get_position (GTK_WINDOW (panel), &x, &y); - gtk_window_get_size (GTK_WINDOW (panel), &w, &h); - - if (px < x || px > x + w || py < y || py > y + h) - { - if (priv->autohide && !priv->hidden) - panel_set_hidden (panel, TRUE); - - _set_transparent (panel, TRUE); - } - } - } -} - -void -panel_set_full_width (Panel *panel, - gint fullwidth) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - gint w = -1, h = -1, max = -1; - - priv = panel->priv; - - if ((XfcePanelWidthType) fullwidth != priv->full_width) - { - priv->full_width = (XfcePanelWidthType) fullwidth; - - if (GTK_WIDGET_VISIBLE (panel)) - { - xmon = panel_app_get_monitor (priv->monitor); - - switch (priv->full_width) - { - case XFCE_PANEL_NORMAL_WIDTH: - xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar), - FALSE); - - if (xfce_screen_position_is_horizontal (priv->screen_position)) - max = xmon->geometry.width; - else - max = xmon->geometry.height; - break; - - case XFCE_PANEL_FULL_WIDTH: - case XFCE_PANEL_SPAN_MONITORS: - xfce_itembar_set_allow_expand (XFCE_ITEMBAR (priv->itembar), - TRUE); - if (xfce_screen_position_is_horizontal ( - priv->screen_position)) - { - if (priv->full_width == XFCE_PANEL_FULL_WIDTH) - w = xmon->geometry.width; - else - w = gdk_screen_get_width (xmon->screen); - - max = w; - } - else - { - if (priv->full_width == XFCE_PANEL_FULL_WIDTH) - h = xmon->geometry.height; - else - h = gdk_screen_get_height (xmon->screen); - - max = h; - } - break; - } - - xfce_itembar_set_maximum_size (XFCE_ITEMBAR (priv->itembar), max); - - gtk_widget_set_size_request (GTK_WIDGET (panel), w, h); - - panel_set_position (panel, priv->screen_position, - priv->xoffset, priv->yoffset); - - gtk_widget_queue_resize (GTK_WIDGET (panel)); - } - } -} - -void -panel_set_transparency (Panel *panel, - gint transparency) -{ - PanelPrivate *priv; - - priv = panel->priv; - - if (transparency != priv->transparency) - { - DBG ("Transparency: %d", transparency); - - priv->transparency = transparency; - priv->opacity = 0; - - _set_transparent (panel, TRUE); - } -} - -void -panel_set_activetrans (Panel *panel, - gboolean activetrans) -{ - PanelPrivate *priv = panel->priv; - - if (activetrans != priv->activetrans) - { - priv->activetrans = activetrans; - - _set_transparent (panel, TRUE); - } -} - -/* properties */ - -gint -panel_get_size (Panel *panel) -{ - PanelPrivate *priv; - - g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_SIZE); - - priv = panel->priv; - - return priv->size; -} - -void -panel_set_size (Panel *panel, - gint size) -{ - PanelPrivate *priv; - - g_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - if (xfce_screen_position_is_horizontal (priv->screen_position)) - { - gtk_widget_set_size_request (priv->itembar, -1, size); - } - else - { - gtk_widget_set_size_request (priv->itembar, size, -1); - } - - if (size != priv->size) - { - priv->size = size; - - gtk_container_foreach (GTK_CONTAINER (priv->itembar), - (GtkCallback)xfce_panel_item_set_size, - GINT_TO_POINTER (size)); - } -} - -gint -panel_get_monitor (Panel *panel) -{ - PanelPrivate *priv; - - g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_MONITOR); - - priv = panel->priv; - - return priv->monitor; -} - -void -panel_set_monitor (Panel *panel, - gint monitor) -{ - PanelPrivate *priv; - XfceMonitor *xmon; - XfcePanelWidthType width; - - g_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - if (monitor != priv->monitor) - { - /* TODO: check range */ - priv->monitor = monitor; - - xmon = panel_app_get_monitor (monitor); - - if (xmon->screen != gtk_widget_get_screen (GTK_WIDGET (panel))) - { - gtk_widget_hide (GTK_WIDGET (panel)); - gtk_window_set_screen (GTK_WINDOW (panel), xmon->screen); - gtk_widget_show (GTK_WIDGET (panel)); - } - - /* new size constraints */ - if ((width = priv->full_width) != XFCE_PANEL_NORMAL_WIDTH) - { - priv->full_width = XFCE_PANEL_NORMAL_WIDTH; - panel_set_full_width (panel, width); - } - else - { - gtk_widget_queue_resize (GTK_WIDGET (panel)); - } - } -} - -XfceScreenPosition -panel_get_screen_position (Panel *panel) -{ - PanelPrivate *priv; - - g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_SCREEN_POSITION); - - priv = panel->priv; - - return priv->screen_position; -} - -void -panel_set_screen_position (Panel *panel, - XfceScreenPosition position) -{ - PanelPrivate *priv; - GtkOrientation orientation; - XfcePanelWidthType full_width; - - g_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - if (position != priv->screen_position) - { - full_width = priv->full_width; - - /* use edit_mode property to test if we are changing position */ - priv->edit_mode = TRUE; - - xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel), - NULL, NULL); - - xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel), - NULL, NULL); - - if (position == XFCE_SCREEN_POSITION_NONE) - position = XFCE_SCREEN_POSITION_FLOATING_H; - - orientation = xfce_screen_position_get_orientation (position); - - if (xfce_screen_position_get_orientation (priv->screen_position) != - orientation) - { - if (full_width > XFCE_PANEL_NORMAL_WIDTH) - panel_set_full_width (panel, XFCE_PANEL_NORMAL_WIDTH); - - xfce_panel_window_set_orientation (XFCE_PANEL_WINDOW (panel), - orientation); - - xfce_itembar_set_orientation (XFCE_ITEMBAR (priv->itembar), - orientation); - } - - gtk_container_foreach (GTK_CONTAINER (priv->itembar), - (GtkCallback)xfce_panel_item_set_screen_position, - GINT_TO_POINTER (position)); - - if (xfce_screen_position_is_floating (position)) - { - full_width = XFCE_PANEL_NORMAL_WIDTH; - panel_set_full_width (panel, full_width); - panel_set_autohide (panel, FALSE); - xfce_panel_window_set_movable (XFCE_PANEL_WINDOW (panel), TRUE); - - if (!xfce_screen_position_is_floating (priv->screen_position)) - xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (panel), - XFCE_HANDLE_STYLE_BOTH); - - priv->xoffset = priv->yoffset = -1; - } - else - { - xfce_panel_window_set_movable (XFCE_PANEL_WINDOW (panel), FALSE); - xfce_panel_window_set_handle_style (XFCE_PANEL_WINDOW (panel), - XFCE_HANDLE_STYLE_NONE); - priv->xoffset = priv->yoffset = 0; - } - - xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel), - (XfcePanelWindowMoveFunc)panel_move_function, panel); - - xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel), - (XfcePanelWindowResizeFunc)panel_resize_function, panel); - - priv->screen_position = position; - panel_set_position (panel, position, priv->xoffset, priv->yoffset); - - if (full_width > XFCE_PANEL_NORMAL_WIDTH) - { - panel_set_full_width (panel, full_width); - } - - /* update itembar size request */ - panel_set_size (panel, priv->size); - - gtk_widget_queue_resize (GTK_WIDGET (panel)); - - g_idle_add((GSourceFunc)unblock_struts, panel); - } -} - -gint -panel_get_xoffset (Panel *panel) -{ - PanelPrivate *priv; - - g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_XOFFSET); - - priv = panel->priv; - - return priv->xoffset; -} - -void -panel_set_xoffset (Panel *panel, - gint xoffset) -{ - PanelPrivate *priv; - - g_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - if (xoffset != priv->xoffset) - { - priv->xoffset = xoffset; - panel_set_position (panel, priv->screen_position, - xoffset, priv->yoffset); - } -} - -gint -panel_get_yoffset (Panel *panel) -{ - PanelPrivate *priv; - - g_return_val_if_fail (PANEL_IS_PANEL (panel), DEFAULT_YOFFSET); - - priv = panel->priv; - - return priv->yoffset; -} - -void -panel_set_yoffset (Panel *panel, - gint yoffset) -{ - PanelPrivate *priv; - - g_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - if (yoffset != priv->yoffset) - { - priv->yoffset = yoffset; - panel_set_position (panel, priv->screen_position, - priv->xoffset, yoffset); - } -} - diff --git a/panel/panel-properties.h b/panel/panel-properties.h deleted file mode 100644 index bee9e78c..00000000 --- a/panel/panel-properties.h +++ /dev/null @@ -1,90 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_POSITION_H__ -#define __PANEL_POSITION_H__ - -#include <libxfce4panel/xfce-panel-window.h> -#include <libxfce4panel/xfce-panel-enums.h> - -#include "panel.h" - -G_BEGIN_DECLS - -/* properties */ -gint panel_get_size (Panel *panel); - -void panel_set_size (Panel *panel, gint size); - - -gint panel_get_monitor (Panel *panel); - -void panel_set_monitor (Panel *panel, gint monitor); - - -XfceScreenPosition panel_get_screen_position (Panel *panel); - -void panel_set_screen_position (Panel *panel, XfceScreenPosition position); - - -gint panel_get_xoffset (Panel *panel); - -void panel_set_xoffset (Panel *panel, gint xoffset); - - -gint panel_get_yoffset (Panel *panel); - -void panel_set_yoffset (Panel *panel, gint yoffset); - - -/* initilization */ -void panel_init_position (Panel *panel); - -void panel_init_signals (Panel *panel); - - -/* positioning */ -void panel_center (Panel *panel); - -void panel_screen_size_changed (GdkScreen *screen, - Panel *panel); - -void panel_set_autohide (Panel *panel, - gboolean autohide); - -void panel_set_hidden (Panel *panel, - gboolean hide); - -void panel_block_autohide (Panel *panel); - -void panel_unblock_autohide (Panel *panel); - -void panel_set_full_width (Panel *panel, - gint fullwidth); - -void panel_set_transparency (Panel *panel, - gint transparency); - -void panel_set_activetrans (Panel *panel, - gboolean activetrans); - -G_END_DECLS - -#endif /* !__PANEL_POSITION_H__ */ - diff --git a/panel/panel.c b/panel/panel.c deleted file mode 100644 index fa0709b1..00000000 --- a/panel/panel.c +++ /dev/null @@ -1,1015 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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 - -#include <string.h> -#include <time.h> -#include <gtk/gtk.h> - -#include <libxfcegui4/libxfcegui4.h> -#include <libxfce4panel/xfce-panel-window.h> -#include <libxfce4panel/xfce-itembar.h> -#include <libxfce4panel/xfce-panel-item-iface.h> - -#include <libxfce4panel/libxfce4panel-enum-types.h> -#include <libxfce4panel/xfce-panel-convenience.h> -#include <libxfce4panel/xfce-panel-macros.h> - -#include "panel.h" -#include "panel-app.h" -#include "panel-properties.h" -#include "panel-item-manager.h" -#include "panel-dnd.h" - -/* PanelPrivate struct */ -#include "panel-private.h" - -#ifndef _ -#define _(x) x -#endif - -enum -{ - PROP_0, - PROP_SIZE, - PROP_MONITOR, - PROP_SCREEN_POSITION, - PROP_XOFFSET, - PROP_YOFFSET, - PROP_AUTOHIDE, - PROP_FULL_WIDTH, - PROP_TRANSPARENCY, - PROP_ACTIVE_TRANS -}; - - -/* GObject */ -static void panel_finalize (GObject * object); - -static void panel_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void panel_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -/* GtkWidget */ -static void panel_size_request (GtkWidget *widget, - GtkRequisition *requisition); - -static gboolean panel_button_pressed (GtkWidget *widget, - GdkEventButton *ev); - -/* plugin menu */ -static void panel_menu_deactivated (GtkWidget *item); - -static void panel_menu_opened (GtkWidget *item); -static void _item_start_move (GtkWidget *item, Panel *panel); - -/* DND dest */ -static void _panel_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time_, - Panel *panel); - -static gboolean _panel_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time_, - Panel *panel); - -/* DND source */ -static void _panel_drag_begin (GtkWidget *widget, - GdkDragContext *drag_context, - Panel *panel); - -/* pass through button press events */ -static gboolean _panel_itembar_button_pressed (GtkWidget *widget, - GdkEventButton *ev, - Panel *panel); - -/* menu */ -static GtkWidget *_panel_create_menu (Panel *panel); - - -/* this sets up a lot of stuff, see GObject API reference */ -G_DEFINE_TYPE (Panel, panel, XFCE_TYPE_PANEL_WINDOW); - -static void -panel_class_init (PanelClass * klass) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - GParamSpec *pspec; - - g_type_class_add_private (klass, sizeof (PanelPrivate)); - - object_class = (GObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - object_class->finalize = panel_finalize; - object_class->get_property = panel_get_property; - object_class->set_property = panel_set_property; - - widget_class->button_press_event = panel_button_pressed; - widget_class->size_request = panel_size_request; - - /* properties */ - - pspec = g_param_spec_int ("size", - "Size", - "The size of the panel", - MIN_SIZE, MAX_SIZE, - DEFAULT_SIZE, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_SIZE, pspec); - - pspec = g_param_spec_int ("monitor", - "Monitor", - "The monitor number of the panel", - 0, G_MAXINT, - DEFAULT_MONITOR, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_MONITOR, pspec); - - pspec = g_param_spec_enum ("screen-position", - "Screen position", - "The screen position of the panel", - XFCE_TYPE_SCREEN_POSITION, - DEFAULT_SCREEN_POSITION, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_SCREEN_POSITION, - pspec); - - pspec = g_param_spec_int ("xoffset", - "Offset in x direction", - "Offset in x direction", - 0, G_MAXINT, - DEFAULT_XOFFSET, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_XOFFSET, pspec); - - pspec = g_param_spec_int ("yoffset", - "Offset in y direction", - "Offset in y direction", - 0, G_MAXINT, - DEFAULT_YOFFSET, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_YOFFSET, pspec); - - pspec = g_param_spec_boolean ("autohide", - "panel_autohide", - "Automatically hide the panel", - DEFAULT_AUTOHIDE, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_AUTOHIDE, pspec); - - pspec = g_param_spec_int ("fullwidth", - "panel_fullwidth", - "Use the full screen width", - XFCE_PANEL_NORMAL_WIDTH, - XFCE_PANEL_SPAN_MONITORS, - DEFAULT_FULL_WIDTH, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_FULL_WIDTH, pspec); - - pspec = g_param_spec_int ("transparency", - "panel_transparency", - "Transparency of the panel", - 0, 100, - DEFAULT_TRANSPARENCY, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_TRANSPARENCY, pspec); - - pspec = g_param_spec_boolean ("activetrans", - "panel_activetrans", - "Keep the active panel transparent", - DEFAULT_ACTIVE_TRANS, G_PARAM_READWRITE); - - g_object_class_install_property (object_class, PROP_ACTIVE_TRANS, pspec); -} - -static void -panel_init (Panel * panel) -{ - PanelPrivate *priv; - - priv = panel->priv = G_TYPE_INSTANCE_GET_PRIVATE (panel, - PANEL_TYPE_PANEL, - PanelPrivate); - - priv->size = DEFAULT_SIZE; - priv->monitor = DEFAULT_MONITOR; - priv->screen_position = DEFAULT_SCREEN_POSITION; - priv->xoffset = DEFAULT_XOFFSET; - priv->yoffset = DEFAULT_YOFFSET; - priv->autohide = DEFAULT_AUTOHIDE; - priv->full_width = DEFAULT_FULL_WIDTH; - priv->transparency = DEFAULT_TRANSPARENCY; - priv->activetrans = DEFAULT_ACTIVE_TRANS; - - priv->itembar = xfce_itembar_new (GTK_ORIENTATION_HORIZONTAL); - gtk_widget_show (priv->itembar); - gtk_container_add (GTK_CONTAINER (panel), priv->itembar); - - panel_dnd_set_dest_name_and_widget (priv->itembar); - panel_dnd_set_source_widget (priv->itembar); - - /* don't allow the wm to close the panel window */ - g_signal_connect (panel, "delete-event", G_CALLBACK (gtk_true), NULL); - - /* DND */ - g_signal_connect (priv->itembar, "drag-data-received", - G_CALLBACK (_panel_drag_data_received), panel); - - g_signal_connect (priv->itembar, "drag-drop", - G_CALLBACK (_panel_drag_drop), panel); - - g_signal_connect (priv->itembar, "drag-begin", - G_CALLBACK (_panel_drag_begin), panel); - - /* mouse click */ - g_signal_connect (priv->itembar, "button-press-event", - G_CALLBACK (_panel_itembar_button_pressed), panel); - - /* menu */ - priv->menu = _panel_create_menu (PANEL (panel)); - - priv->opacity = priv->saved_opacity = 0; -} - -static void -panel_finalize (GObject * object) -{ - /* TODO: properly ref and unref private widgets */ - - G_OBJECT_CLASS (panel_parent_class)->finalize (object); -} - -static void -panel_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - PanelPrivate *priv = PANEL(object)->priv; - - switch (prop_id) - { - case PROP_SIZE: - g_value_set_int (value, priv->size); - break; - case PROP_MONITOR: - g_value_set_int (value, priv->monitor); - break; - case PROP_SCREEN_POSITION: - g_value_set_enum (value, priv->screen_position); - break; - case PROP_XOFFSET: - g_value_set_int (value, priv->xoffset); - break; - case PROP_YOFFSET: - g_value_set_int (value, priv->yoffset); - break; - case PROP_AUTOHIDE: - g_value_set_boolean (value, priv->autohide); - break; - case PROP_FULL_WIDTH: - g_value_set_int (value, priv->full_width); - break; - case PROP_TRANSPARENCY: - g_value_set_int (value, priv->transparency); - break; - case PROP_ACTIVE_TRANS: - g_value_set_boolean (value, priv->activetrans); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -panel_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - Panel *panel = PANEL (object); - - switch (prop_id) - { - case PROP_SIZE: - panel_set_size (panel, g_value_get_int (value)); - break; - case PROP_MONITOR: - panel_set_monitor (panel, g_value_get_int (value)); - break; - case PROP_SCREEN_POSITION: - panel_set_screen_position (panel, g_value_get_enum (value)); - break; - case PROP_XOFFSET: - panel_set_xoffset (panel, g_value_get_int (value)); - break; - case PROP_YOFFSET: - panel_set_yoffset (panel, g_value_get_int (value)); - break; - case PROP_AUTOHIDE: - panel_set_autohide (panel, g_value_get_boolean (value)); - break; - case PROP_FULL_WIDTH: - panel_set_full_width (panel, g_value_get_int (value)); - break; - case PROP_TRANSPARENCY: - panel_set_transparency (panel, g_value_get_int (value)); - break; - case PROP_ACTIVE_TRANS: - panel_set_activetrans (panel, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -panel_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - PanelPrivate *priv = PANEL(widget)->priv; - - GTK_WIDGET_CLASS (panel_parent_class)->size_request (widget, requisition); - - if (panel_is_horizontal (PANEL (widget))) - { - requisition->width = MAX (MIN_SIZE, requisition->width); - requisition->height = MAX (priv->size, requisition->height); - } - else - { - requisition->width = MAX (priv->size, requisition->width); - requisition->height = MAX (MIN_SIZE, requisition->height); - } -} - -static gboolean -panel_button_pressed (GtkWidget *widget, - GdkEventButton *ev) -{ - guint modifiers; - - modifiers = gtk_accelerator_get_default_mod_mask (); - - if (ev->button == 3 || (ev->button == 1 && - (ev->state & modifiers) == GDK_CONTROL_MASK)) - { - PanelPrivate *priv; - - priv = PANEL (widget)->priv; - - gtk_menu_set_screen (GTK_MENU (priv->menu), - gtk_widget_get_screen (widget)); - - gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL, NULL, NULL, - ev->button, ev->time); - - return TRUE; - } - - return - GTK_WIDGET_CLASS (panel_parent_class)->button_press_event (widget, ev); -} - -/* DND dest */ -static void -_panel_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time_, - Panel *panel) -{ - XfceItembar *itembar = XFCE_ITEMBAR (widget); - PanelPrivate *priv = panel->priv; - XfcePanelItem *item; - GtkWidget *plugin; - gint index_; - gint oldindex; - gboolean expand; - gboolean succeed = FALSE; - - DBG (" + drag data received: %d", info); - - /* get the drop index */ - index_ = xfce_itembar_get_drop_index (itembar, x, y); - - switch (info) - { - case TARGET_PLUGIN_NAME: - if (data->length > 0) - { - /* insert the new plugin */ - panel_insert_item (panel, (const gchar *) data->data, index_); - - /* succeeded */ - succeed = TRUE; - } - break; - - case TARGET_PLUGIN_WIDGET: - /* get the plugin from the drag context */ - plugin = gtk_drag_get_source_widget (context); - - /* try the drag_widget or leave */ - if (!plugin || !XFCE_IS_PANEL_ITEM (plugin)) - break; - - if (gtk_widget_get_parent (plugin) != widget) - { - /* get the plugin and information */ - item = XFCE_PANEL_ITEM (plugin); - expand = xfce_panel_item_get_expand (item); - - /* freeze plugin notifications */ - g_object_freeze_notify (G_OBJECT (widget)); - - /* move the plugin from the old panel to the new one */ - gtk_widget_reparent (GTK_WIDGET (plugin), widget); - - /* update the plugin */ - xfce_panel_item_set_size (item, priv->size); - xfce_panel_item_set_screen_position (item, priv->screen_position); - - /* update the itembar */ - xfce_itembar_reorder_child (itembar, plugin, index_); - xfce_itembar_set_child_expand (itembar, plugin, expand); - - /* thaw update notifications */ - g_object_thaw_notify (G_OBJECT (widget)); - } - else /* move on same panel */ - { - /* get the old index */ - oldindex = xfce_itembar_get_item_index (itembar, plugin); - - if (index_ > oldindex) - index_--; - - if (index_ != oldindex) - xfce_itembar_reorder_child (itembar, plugin, index_); - } - - /* properly handled */ - succeed = TRUE; - - break; - - default: - break; - } - - /* finish the drag */ - gtk_drag_finish (context, succeed, FALSE, time_); -} - -static gboolean -_panel_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time_, - Panel *panel) -{ - GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); - - /* we cannot handle the drag data */ - if (G_UNLIKELY (target == GDK_NONE)) - return FALSE; - - /* request the drag data */ - gtk_drag_get_data (widget, context, target, time_); - - /* we call gtk_drag_finish later */ - return TRUE; -} - -/* DND source */ -static void -_panel_drag_begin (GtkWidget *widget, - GdkDragContext *drag_context, - Panel *panel) -{ - gint x, y, rootx, rooty; - GtkWidget *plugin; - - DBG (" + drag begin"); - - /* get the pointer position */ - gdk_display_get_pointer (gtk_widget_get_display (widget), NULL, &x, &y, NULL); - - /* get the window root coordinates */ - gdk_window_get_root_origin (widget->window, &rootx, &rooty); - - /* calc the position inside the panel */ - x -= rootx; - y -= rooty; - - /* get the plugin on the itembar at this position */ - plugin = xfce_itembar_get_item_at_point (XFCE_ITEMBAR (widget), x, y); - - /* start an item move */ - if (G_LIKELY (plugin)) - _item_start_move (plugin, panel); -} - -/* pass through right-click events when the event window of itembar is raised - */ -static gboolean -_panel_itembar_button_pressed (GtkWidget *widget, - GdkEventButton *ev, - Panel *panel) -{ - GtkWidget *plugin; - guint modifiers; - - if (xfce_itembar_event_window_is_raised (XFCE_ITEMBAR (widget))) - { - modifiers = gtk_accelerator_get_default_mod_mask (); - - if (ev->button == 3 || (ev->button == 1 && - (ev->state & modifiers) == GDK_CONTROL_MASK)) - { - plugin = xfce_itembar_get_item_at_point (XFCE_ITEMBAR (widget), - ev->x, ev->y); - if (plugin) - { - gtk_widget_event (plugin, (GdkEvent *)ev); - return TRUE; - } - } - } - - return FALSE; -} - -/* menu */ - -static GtkWidget * -_panel_create_menu (Panel *panel) -{ - GtkWidget *menu, *mi, *img; - - menu = gtk_menu_new (); - - if (xfce_allow_panel_customization ()) - { - mi = gtk_image_menu_item_new_with_label (_("Customize Panel...")); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - - img = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); - gtk_widget_show (img); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img); - - g_signal_connect (mi, "activate", G_CALLBACK (panel_app_customize), - NULL); - - mi = gtk_image_menu_item_new_with_label (_("Add New Items...")); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - - img = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU); - gtk_widget_show (img); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img); - - g_signal_connect_swapped (mi, "activate", - G_CALLBACK (panel_app_customize_items), NULL); - - mi = gtk_separator_menu_item_new (); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - - mi = gtk_image_menu_item_new_with_label (_("Quit")); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - - img = gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU); - gtk_widget_show (img); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img); - - g_signal_connect (mi, "activate", G_CALLBACK (panel_app_quit), NULL); - - mi = gtk_image_menu_item_new_with_label (_("Restart")); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - - img = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_MENU); - gtk_widget_show (img); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img); - - g_signal_connect (mi, "activate", G_CALLBACK (panel_app_restart), NULL); - - mi = gtk_separator_menu_item_new (); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - } - - mi = gtk_image_menu_item_new_with_label (_("About the Xfce Panel")); - gtk_widget_show (mi); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); - - img = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_MENU); - gtk_widget_show (img); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img); - - g_signal_connect_swapped (mi, "activate", G_CALLBACK (panel_app_about), - panel); - - return menu; -} - -/* public API */ - -Panel * -panel_new (void) -{ - return PANEL (g_object_new (PANEL_TYPE_PANEL, NULL)); -} - -void -panel_free_data (Panel *panel) -{ - PanelPrivate *priv; - GList *l; - int i; - - _panel_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - /* try and prevent some race conditions */ - priv->block_autohide++; - xfce_panel_window_set_move_function (XFCE_PANEL_WINDOW (panel), - NULL, NULL); - xfce_panel_window_set_resize_function (XFCE_PANEL_WINDOW (panel), - NULL, NULL); - - for (l = gtk_container_get_children (GTK_CONTAINER (priv->itembar)); - l != NULL; - l = l->next) - { - XfcePanelItem *item = l->data; - - xfce_panel_item_free_data (item); - } - - g_list_free (l); - - /* give plugins the chance to quit */ - for (i = 0; i < 10 && - xfce_itembar_get_n_items (XFCE_ITEMBAR (priv->itembar)) != 0; ++i) - { - DBG (" + %d item(s) on the panel", - xfce_itembar_get_n_items (XFCE_ITEMBAR (priv->itembar))); - g_usleep (200000); /* 0.2 sec */ - - while (gtk_events_pending ()) - gtk_main_iteration (); - } - -} - -/* items */ - -static void -panel_menu_deactivated (GtkWidget *item) -{ - int x, y, w, h, px, py; - Panel *panel = PANEL (item->parent->parent); - - _panel_return_if_fail (PANEL_IS_PANEL (panel)); - - panel_unblock_autohide (panel); - - gdk_display_get_pointer (gdk_display_get_default (), NULL, &px, &py, NULL); - - gtk_window_get_position (GTK_WINDOW (panel), &x, &y); - gtk_window_get_size (GTK_WINDOW (panel), &w, &h); - - if (px < x || px > x + w || py < y || py > y + h) - { - GdkEvent *ev = gdk_event_new (GDK_LEAVE_NOTIFY); - - ((GdkEventCrossing *) ev)->time = GDK_CURRENT_TIME; - ((GdkEventCrossing *) ev)->detail = GDK_NOTIFY_NONLINEAR; - - gtk_widget_event (GTK_WIDGET (panel), ev); - - gdk_event_free (ev); - } -} - -static void -panel_menu_opened (GtkWidget *item) -{ - _panel_return_if_fail (PANEL_IS_PANEL (item->parent->parent)); - - panel_block_autohide (PANEL (item->parent->parent)); -} - -static void -_item_expand_changed (GtkWidget *item, - gboolean expand, - Panel *panel) -{ - PanelPrivate *priv; - - _panel_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - xfce_itembar_set_child_expand (XFCE_ITEMBAR (priv->itembar), item, expand); -} - - - -static void -_item_start_move_end (GtkWidget *item, - GdkDragContext *context, - Panel *panel) -{ - PanelPrivate *priv = panel->priv; - Panel *p; - - DBG ("+ finish item drag"); - - /* disconnect drag end signal */ - g_signal_handlers_disconnect_by_func (G_OBJECT (item), G_CALLBACK (_item_start_move_end), panel); - - if (!priv->edit_mode) - { - const GPtrArray *panels = panel_app_get_panel_list (); - guint i; - - for (i = 0; i < panels->len; ++i) - { - p = g_ptr_array_index (panels, i); - priv = p->priv; - - xfce_itembar_lower_event_window (XFCE_ITEMBAR (priv->itembar)); - panel_set_items_sensitive (p, TRUE); - - panel_unblock_autohide (p); - } - } -} - - - -static void -_item_start_move (GtkWidget *item, - Panel *panel) -{ - const GPtrArray *panels = panel_app_get_panel_list (); - PanelPrivate *priv; - Panel *p; - guint i; - - for (i = 0; i < panels->len; ++i) - { - p = g_ptr_array_index (panels, i); - priv = p->priv; - - if (!priv->edit_mode) - { - panel_set_items_sensitive (p, FALSE); - xfce_itembar_raise_event_window (XFCE_ITEMBAR (priv->itembar)); - panel_block_autohide (p); - } - } - - /* start the drag */ - panel_dnd_begin_drag (item); - - /* signal to make panels sensitive after a drop */ - g_signal_connect (G_OBJECT (item), "drag-end", G_CALLBACK (_item_start_move_end), panel); -} - - - -static void -_item_set_panel_hidden (GtkWidget *item, - gboolean hidden, - Panel *panel) -{ - PanelPrivate *priv; - - _panel_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - if (priv->autohide) - panel_set_hidden (panel, hidden); -} - -static void -panel_insert_widget (Panel *panel, - GtkWidget *item, - int position) -{ - PanelPrivate *priv = panel->priv; - - gtk_widget_show (item); - - if (position == -1) - xfce_itembar_append (XFCE_ITEMBAR (priv->itembar), item); - else - xfce_itembar_insert (XFCE_ITEMBAR (priv->itembar), item, position); - - xfce_itembar_set_child_expand (XFCE_ITEMBAR (priv->itembar), item, - xfce_panel_item_get_expand (XFCE_PANEL_ITEM (item))); - - if (xfce_itembar_event_window_is_raised (XFCE_ITEMBAR (priv->itembar))) - xfce_panel_item_set_sensitive (XFCE_PANEL_ITEM (item), FALSE); - - g_signal_connect (item, "destroy", G_CALLBACK (panel_app_queue_save), - NULL); -} - -static GtkWidget * -panel_create_item (Panel *panel, - const char *name, - const char *id) -{ - PanelPrivate *priv; - GtkWidget *item = NULL; - XfceMonitor *xmon; - - priv = panel->priv; - xmon = panel_app_get_monitor (priv->monitor); - - item = xfce_panel_item_manager_create_item (xmon->screen, - name, - id, - priv->size, - priv->screen_position); - - if (item != NULL) - { - g_signal_connect (item, "menu-deactivated", - G_CALLBACK (panel_menu_deactivated), panel); - - g_signal_connect (item, "menu-opened", - G_CALLBACK (panel_menu_opened), panel); - - g_signal_connect (item, "expand-changed", - G_CALLBACK (_item_expand_changed), panel); - - g_signal_connect (item, "customize-panel", - G_CALLBACK (panel_app_customize), NULL); - - g_signal_connect (item, "customize-items", - G_CALLBACK (panel_app_customize_items), NULL); - - g_signal_connect (item, "move", - G_CALLBACK (_item_start_move), panel); - - g_signal_connect (item, "set-hidden", - G_CALLBACK (_item_set_panel_hidden), panel); - } - - return item; -} - -static char * -_panel_get_new_id (void) -{ - static int counter = 0; - static char id[30]; - - /* unique number: pseudo-random time() + counter */ - g_snprintf (id, sizeof(id), "%ld%d", (glong) time (NULL), counter++); - - return id; -} - -GtkWidget * -panel_add_item_with_id (Panel *panel, - const char *name, - const char *id) -{ - GtkWidget *item; - - item = panel_create_item (panel, name, id); - - if (item != NULL) - { - panel_insert_widget (panel, item, -1); - } - - return item; -} - -GtkWidget * -panel_add_item (Panel *panel, - const char *name) -{ - return panel_add_item_with_id (panel, name, _panel_get_new_id ()); -} - -GtkWidget * -panel_insert_item (Panel *panel, - const char *name, - int position) -{ - GtkWidget *item; - - item = panel_create_item (panel, name, _panel_get_new_id ()); - - if (item != NULL) - { - panel_insert_widget (panel, item, position); - } - - return item; -} - -/* configuration */ - -GList * -panel_get_item_list (Panel * panel) -{ - PanelPrivate *priv; - - priv = panel->priv; - - return gtk_container_get_children (GTK_CONTAINER (priv->itembar)); -} - -void -panel_save_items (Panel *panel) -{ - PanelPrivate *priv; - - _panel_return_if_fail (PANEL_IS_PANEL (panel)); - - priv = panel->priv; - - gtk_container_foreach (GTK_CONTAINER (priv->itembar), - (GtkCallback)xfce_panel_item_save, NULL); -} - -/* convenience */ - -gboolean -panel_is_horizontal (Panel *panel) -{ - return (GTK_ORIENTATION_HORIZONTAL == - xfce_panel_window_get_orientation (XFCE_PANEL_WINDOW (panel))); -} - -void -panel_set_items_sensitive (Panel *panel, - gboolean sensitive) -{ - PanelPrivate *priv = panel->priv; - GList *l, *children; - - children = gtk_container_get_children (GTK_CONTAINER (priv->itembar)); - - for (l = children; l != NULL; l = l->next) - { - xfce_panel_item_set_sensitive (XFCE_PANEL_ITEM (l->data), sensitive); - } - - g_list_free (children); -} diff --git a/panel/panel.h b/panel/panel.h deleted file mode 100644 index 423de17d..00000000 --- a/panel/panel.h +++ /dev/null @@ -1,84 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2005 Jasper Huijsmans <jasper@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. - */ - -#ifndef __PANEL_H__ -#define __PANEL_H__ - -#include <glib-object.h> -#include <gtk/gtkwidget.h> - -#include <libxfce4panel/xfce-panel-window.h> -#include <libxfce4panel/xfce-panel-enums.h> - -#define PANEL_TYPE_PANEL (panel_get_type ()) -#define PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_PANEL, Panel)) -#define PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_PANEL, PanelClass)) -#define PANEL_IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_PANEL)) -#define PANEL_IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_PANEL)) -#define PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANEL_TYPE_PANEL, PanelClass)) - - -G_BEGIN_DECLS - -typedef struct _Panel Panel; -typedef struct _PanelClass PanelClass; - -struct _Panel -{ - XfcePanelWindow parent; - /*< private >*/ - gpointer priv; -}; - -struct _PanelClass -{ - XfcePanelWindowClass parent_class; -}; - -GType panel_get_type (void) G_GNUC_CONST; - -Panel *panel_new (void); - -void panel_free_data (Panel *panel); - - -/* adding items */ -GtkWidget *panel_add_item (Panel *panel, const char *name); - -GtkWidget *panel_insert_item (Panel *panel, const char *name, int position); - -GtkWidget *panel_add_item_with_id (Panel *panel, const char *name, - const char *id); - -/* configuration */ -GList *panel_get_item_list (Panel *panel); - -void panel_save_items (Panel *panel); - - -/* convenience */ - -gboolean panel_is_horizontal (Panel *panel); - -void panel_set_items_sensitive (Panel *panel, gboolean sensitive); - - -G_END_DECLS - -#endif /* !__PANEL_H__ */ |