[gnome-panel/wip/segeiger/separator] applets/separator/separator-applet.c: rewrite of gnome-panel/panel-separator.c
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/segeiger/separator] applets/separator/separator-applet.c: rewrite of gnome-panel/panel-separator.c
- Date: Sat, 22 Aug 2015 22:08:51 +0000 (UTC)
commit b371dcc505c0d13930114c846a523f512ecdd38e
Author: Sebastian Geiger <sbastig gmx net>
Date: Sun Aug 23 00:07:54 2015 +0200
applets/separator/separator-applet.c: rewrite of gnome-panel/panel-separator.c
applets/Makefile.am | 3 +-
applets/separator/Makefile.am | 43 +++
.../org.gnome.panel.Separator.panel-applet.in.in | 16 +
applets/separator/separator-applet.c | 286 +++++++++++++++++++
configure.ac | 5 +
gnome-panel/Makefile.am | 2 -
gnome-panel/applet.c | 3 -
gnome-panel/panel-addto-dialog.c | 17 --
gnome-panel/panel-object-loader.c | 7 -
gnome-panel/panel-separator.c | 296 --------------------
gnome-panel/panel-separator.h | 64 -----
gnome-panel/panel.c | 15 -
12 files changed, 352 insertions(+), 405 deletions(-)
---
diff --git a/applets/Makefile.am b/applets/Makefile.am
index e1e952d..691161c 100644
--- a/applets/Makefile.am
+++ b/applets/Makefile.am
@@ -2,6 +2,7 @@ SUBDIRS = \
clock \
fish \
notification_area \
- wncklet
+ wncklet \
+ separator
-include $(top_srcdir)/git.mk
diff --git a/applets/separator/Makefile.am b/applets/separator/Makefile.am
new file mode 100644
index 0000000..771cca8
--- /dev/null
+++ b/applets/separator/Makefile.am
@@ -0,0 +1,43 @@
+AM_CPPFLAGS = \
+ $(LIBPANEL_APPLET_CFLAGS) \
+ $(SEPARATOR_CFLAGS) \
+ -I$(top_builddir) \
+ -I$(top_builddir)/applets/separator \
+ -I$(top_srcdir)/libpanel-applet \
+ -I$(top_builddir)/libpanel-applet \
+ -DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+
+AM_CFLAGS = $(WARN_CFLAGS)
+
+SEPARATOR_SOURCES = \
+ separator-applet.c
+
+SEPARATOR_LDADD = \
+ ../../libpanel-applet/libpanel-applet.la \
+ $(SEPARATOR_LIBS) \
+ $(LIBPANEL_APPLET_LIBS)
+
+APPLET_LOCATION = $(pkglibdir)/$(LIBPANEL_APPLET_API_VERSION)/libseparator-applet.so
+
+separator_appletlibdir = $(pkglibdir)/$(LIBPANEL_APPLET_API_VERSION)
+separator_appletlib_LTLIBRARIES = libseparator-applet.la
+libseparator_applet_la_SOURCES = $(SEPARATOR_SOURCES)
+libseparator_applet_la_LIBADD = $(SEPARATOR_LDADD)
+libseparator_applet_la_LDFLAGS = -module -avoid-version
+libseparator_applet_la_CFLAGS = $(AM_CFLAGS)
+
+appletdir = $(appletsdir)
+applet_in_files = org.gnome.panel.Separator.panel-applet.in
+applet_DATA = $(applet_in_files:.panel-applet.in=.panel-applet)
+
+$(applet_in_files): $(applet_in_files).in Makefile
+ $(AM_V_GEN)sed \
+ -e "s|\ LOCATION\@|$(APPLET_LOCATION)|" \
+ -e "s|\ VERSION\@|$(PACKAGE_VERSION)|" \
+ $< > $@
+
+ PANEL_INTLTOOL_PANEL_APPLET_RULE@
+
+CLEANFILES = $(applet_DATA) $(applet_DATA).in
+
+-include $(top_srcdir)/git.mk
diff --git a/applets/separator/org.gnome.panel.Separator.panel-applet.in.in
b/applets/separator/org.gnome.panel.Separator.panel-applet.in.in
new file mode 100644
index 0000000..aea7bb5
--- /dev/null
+++ b/applets/separator/org.gnome.panel.Separator.panel-applet.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=PanelSeparator
+InProcess=true
+Location= LOCATION@
+_Name=Window Navigation Applet Factory
+_Description=Factory for the window navigation related applets
+
+[PanelSeparator]
+_Name=Separator
+_Description=A separator applet
+Icon=gnome-panel-window-menu
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-panel
+X-GNOME-Bugzilla-Component=separator
+X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=separator-applet.la
diff --git a/applets/separator/separator-applet.c b/applets/separator/separator-applet.c
new file mode 100644
index 0000000..fb096cc
--- /dev/null
+++ b/applets/separator/separator-applet.c
@@ -0,0 +1,286 @@
+/*
+ * panel-separator.c: "Separator" applet for the panel
+ *
+ * Copyright (C) 2005 Carlos Garcia Campos <carlosgc gnome 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Carlos Garcia Campos <carlosgc gnome org>
+ */
+
+#include <gtk/gtk.h>
+#include <panel-applet.h>
+
+G_BEGIN_DECLS
+GType panel_separator_get_type (void);
+#define PANEL_TYPE_SEPARATOR panel_separator_get_type()
+#define PANEL_SEPARATOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_TYPE_SEPARATOR, PanelSeparator))
+#define PANEL_IS_SEPARATOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_TYPE_SEPARATOR))
+#define PANEL_SEPARATOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PANEL_TYPE_SEPARATOR,
PanelSeparatorClass))
+#define PANEL_IS_SEPARATOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PANEL_TYPE_SEPARATOR))
+#define PANEL_SEPARATOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PANEL_TYPE_SEPARATOR,
PanelSeparatorClass))
+
+typedef struct _PanelSeparator PanelSeparator;
+typedef struct _PanelSeparatorPrivate PanelSeparatorPrivate;
+typedef struct { PanelAppletClass parent_class; } PanelSeparatorClass;
+
+struct _PanelSeparator {
+ PanelApplet parent;
+ PanelSeparatorPrivate *priv;
+};
+
+struct _PanelSeparatorPrivate
+{
+ GtkOrientation orientation;
+ GtkWidget *separator;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (PanelSeparator, panel_separator, PANEL_TYPE_APPLET)
+
+static void
+panel_separator_get_preferred_width (GtkWidget *widget,
+ gint *minimal_width,
+ gint *natural_width)
+{
+ PanelSeparator *separator;
+ int size;
+
+ separator = PANEL_SEPARATOR (widget);
+
+ if (separator->priv->orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ size = gtk_widget_get_allocated_height (widget);
+ *minimal_width = *natural_width = size;
+ } else {
+ /* set width based on css styling & width of GtkSeparator */
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkWidget *child;
+ GtkBorder padding;
+ GtkBorder border;
+ gint width;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ child = gtk_bin_get_child (GTK_BIN (widget));
+
+ if (child && gtk_widget_get_visible (child))
+ gtk_widget_get_preferred_width (child,
+ minimal_width,
+ natural_width);
+ else
+ *minimal_width = *natural_width = 0;
+
+ gtk_style_context_get_border (context, state, &border);
+ gtk_style_context_get_padding (context, state, &padding);
+
+ width = border.left + border.right + padding.left + padding.right;
+ *minimal_width += width;
+ *natural_width += width;
+ }
+}
+
+static void
+panel_separator_get_preferred_height (GtkWidget *widget,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ PanelSeparator *separator;
+ int size;
+
+ separator = PANEL_SEPARATOR (widget);
+
+ if (separator->priv->orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ /* set height based on css styling & height of GtkSeparator */
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkWidget *child;
+ GtkBorder padding;
+ GtkBorder border;
+ gint height;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ child = gtk_bin_get_child (GTK_BIN (widget));
+
+ if (child && gtk_widget_get_visible (child))
+ gtk_widget_get_preferred_height (child,
+ minimal_height,
+ natural_height);
+ else
+ *minimal_height = *natural_height = 0;
+
+ gtk_style_context_get_border (context, state, &border);
+ gtk_style_context_get_padding (context, state, &padding);
+
+ height = border.top + border.bottom + padding.top + padding.bottom;
+ *minimal_height += height;
+ *natural_height += height;
+ } else
+ size = gtk_widget_get_allocated_height (widget);
+ *minimal_height = *natural_height = size;
+}
+
+static void
+panel_separator_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding;
+ GtkBorder border;
+ GtkAllocation new_allocation;
+ GtkWidget *child;
+
+ GTK_WIDGET_CLASS (panel_separator_parent_class)->size_allocate (widget,
+ allocation);
+
+ /* We cannot return early here if allocation == old_allocation because
+ * the event_box base class just sized the child and we need to
+ * recalculate and resize the child (the actual GtkSeparator).
+ *
+ * Preferably, the event_box base class would offer a method of moving
+ * the private event window, in which case, calling its size_allocate
+ * would not be necessary. But, alas, no. */
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ gtk_style_context_get_border (context, state, &border);
+ gtk_style_context_get_padding (context, state, &padding);
+
+ new_allocation.x = border.left + padding.left;
+ new_allocation.y = border.top + padding.top;
+ new_allocation.width = allocation->width -
+ (border.left + border.right + padding.left +
+ padding.right);
+ new_allocation.height = allocation->height -
+ (border.top + border.bottom + padding.top +
+ padding.bottom);
+ new_allocation.width = MAX (1, new_allocation.width);
+ new_allocation.height = MAX (1, new_allocation.height);
+
+ child = gtk_bin_get_child (GTK_BIN (widget));
+ if (child && gtk_widget_get_visible (child))
+ gtk_widget_size_allocate (child, &new_allocation);
+}
+
+static void
+panel_separator_orientation_changed (PanelApplet *applet,
+ PanelAppletOrient orientation,
+ gpointer user_data)
+{
+ GtkOrientation orient = GTK_ORIENTATION_HORIZONTAL;
+ GtkOrientation orient_separator = GTK_ORIENTATION_VERTICAL;
+ GtkStyleContext *context;
+
+ g_return_if_fail (PANEL_IS_SEPARATOR (applet));
+ PanelSeparator *separator = PANEL_SEPARATOR (applet);
+
+ switch (orientation)
+ {
+ case PANEL_APPLET_ORIENT_UP:
+ case PANEL_APPLET_ORIENT_DOWN:
+ orient = GTK_ORIENTATION_HORIZONTAL;
+ orient_separator = GTK_ORIENTATION_VERTICAL;
+ break;
+ case PANEL_APPLET_ORIENT_LEFT:
+ case PANEL_APPLET_ORIENT_RIGHT:
+ orient = GTK_ORIENTATION_VERTICAL;
+ orient_separator = GTK_ORIENTATION_HORIZONTAL;
+ break;
+ }
+
+ if (orient == separator->priv->orientation)
+ return;
+
+ /* Use css class "horizontal"/"vertical" for theming */
+ context = gtk_widget_get_style_context (GTK_WIDGET (separator));
+ if (orient == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_VERTICAL);
+ } else
+ {
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_VERTICAL);
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+ }
+
+ separator->priv->orientation = orient;
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (separator->priv->separator),
+ orient_separator);
+
+ gtk_widget_queue_resize (GTK_WIDGET (separator));
+}
+
+static void
+panel_separator_class_init (PanelSeparatorClass *applet_class)
+{
+ GObjectClass *obj_class = G_OBJECT_CLASS (applet_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (applet_class);
+
+ widget_class->get_preferred_width = panel_separator_get_preferred_width;
+ widget_class->get_preferred_height = panel_separator_get_preferred_height;
+ widget_class->size_allocate = panel_separator_size_allocate;
+}
+
+static void
+panel_separator_init (PanelSeparator *separator)
+{
+ GtkStyleContext *context;
+
+ separator->priv = panel_separator_get_instance_private (separator);
+ separator->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+ separator->priv->separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
+
+ gtk_container_add (GTK_CONTAINER (separator),
+ separator->priv->separator);
+ gtk_widget_show_all (separator);
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (separator));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+
+ g_signal_connect (separator, "change-orient",
+ G_CALLBACK (panel_separator_orientation_changed), NULL);
+}
+
+static void
+panel_separator_load (PanelApplet *panel)
+{
+ panel_applet_set_flags (panel, PANEL_APPLET_EXPAND_MINOR);
+}
+
+static gboolean
+panel_separator_factory (PanelApplet *applet,
+ const gchar *iid,
+ gpointer user_data)
+{
+ if (g_strcmp0 (iid, "PanelSeparator") != 0) {
+ fflush (stdout);
+ return FALSE;
+ }
+
+ panel_separator_load (applet);
+
+ return TRUE;
+}
+
+PANEL_APPLET_IN_PROCESS_FACTORY ("PanelSeparator",
+ PANEL_TYPE_SEPARATOR,
+ panel_separator_factory,
+ NULL);
\ No newline at end of file
diff --git a/configure.ac b/configure.ac
index 4dca8b9..b2455c8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -111,6 +111,10 @@ PKG_CHECK_MODULES(WNCKLET, gtk+-3.0 >= $GTK_REQUIRED libwnck-3.0 >= $LIBWNCK_REQ
AC_SUBST(WNCKLET_CFLAGS)
AC_SUBST(WNCKLET_LIBS)
+PKG_CHECK_MODULES(SEPARATOR, gtk+-3.0 >= $GTK_REQUIRED)
+AC_SUBST(SEPARATOR_CFLAGS)
+AC_SUBST(SEPARATOR_LIBS)
+
AC_CHECK_HEADERS(langinfo.h)
AC_CHECK_FUNCS(nl_langinfo)
@@ -238,6 +242,7 @@ applets/clock/pixmaps/Makefile
applets/fish/Makefile
applets/notification_area/Makefile
applets/wncklet/Makefile
+applets/separator/Makefile
doc/Makefile
doc/reference/Makefile
doc/reference/panel-applet/Makefile
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index 5b23f09..23d094f 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -45,7 +45,6 @@ panel_sources = \
panel-menu-bar-object.c \
panel-menu-button.c \
panel-menu-items.c \
- panel-separator.c \
panel-recent.c \
panel-action-protocol.c \
panel-toplevel.c \
@@ -93,7 +92,6 @@ panel_headers = \
panel-menu-bar-object.h \
panel-menu-button.h \
panel-menu-items.h \
- panel-separator.h \
panel-recent.h \
panel-action-protocol.h \
panel-toplevel.h \
diff --git a/gnome-panel/applet.c b/gnome-panel/applet.c
index 440ccf5..4efb777 100644
--- a/gnome-panel/applet.c
+++ b/gnome-panel/applet.c
@@ -24,7 +24,6 @@
#include "panel-applet-frame.h"
#include "panel-action-button.h"
#include "panel-menu-bar.h"
-#include "panel-separator.h"
#include "panel-toplevel.h"
#include "panel-util.h"
#include "panel-menu-button.h"
@@ -67,7 +66,6 @@ panel_applet_set_dnd_enabled (AppletInfo *info,
dnd_enabled);
break;
case PANEL_OBJECT_MENU_BAR:
- case PANEL_OBJECT_SEPARATOR:
case PANEL_OBJECT_USER_MENU:
break;
default:
@@ -193,7 +191,6 @@ applet_callback_callback (GtkWidget *widget,
* Applet's menu's are handled differently
*/
break;
- case PANEL_OBJECT_SEPARATOR:
case PANEL_OBJECT_USER_MENU:
break;
default:
diff --git a/gnome-panel/panel-addto-dialog.c b/gnome-panel/panel-addto-dialog.c
index 765a2ba..7eb1d7e 100644
--- a/gnome-panel/panel-addto-dialog.c
+++ b/gnome-panel/panel-addto-dialog.c
@@ -36,7 +36,6 @@
#include "panel-applet-frame.h"
#include "panel-action-button.h"
#include "panel-menu-bar.h"
-#include "panel-separator.h"
#include "panel-toplevel.h"
#include "panel-menu-button.h"
#include "panel-globals.h"
@@ -90,7 +89,6 @@ typedef enum {
PANEL_ADDTO_LAUNCHER_NEW,
PANEL_ADDTO_MENU,
PANEL_ADDTO_MENUBAR,
- PANEL_ADDTO_SEPARATOR,
PANEL_ADDTO_USER_MENU
} PanelAddtoItemType;
@@ -159,16 +157,6 @@ prepend_internal_applets (GSList *list)
list = g_slist_prepend (list, internal);
internal = g_new0 (PanelAddtoItemInfo, 1);
- internal->type = PANEL_ADDTO_SEPARATOR;
- internal->name = _("Separator");
- internal->description = _("A separator to organize the panel items");
- internal->icon = g_themed_icon_new (PANEL_ICON_SEPARATOR);
- internal->action_type = PANEL_ACTION_NONE;
- internal->iid = "SEPARATOR:NEW";
- internal->static_strings = TRUE;
- list = g_slist_prepend (list, internal);
-
- internal = g_new0 (PanelAddtoItemInfo, 1);
internal->type = PANEL_ADDTO_USER_MENU;
internal->name = _("User menu");
internal->description = _("Menu to change your settings and log out");
@@ -791,11 +779,6 @@ panel_addto_add_item (PanelAddtoDialog *dialog,
dialog->insert_pack_type,
pack_index);
break;
- case PANEL_ADDTO_SEPARATOR:
- panel_separator_create (dialog->panel_widget->toplevel,
- dialog->insert_pack_type,
- pack_index);
- break;
case PANEL_ADDTO_USER_MENU:
panel_user_menu_create (dialog->panel_widget->toplevel,
dialog->insert_pack_type,
diff --git a/gnome-panel/panel-object-loader.c b/gnome-panel/panel-object-loader.c
index c085806..eda33ca 100644
--- a/gnome-panel/panel-object-loader.c
+++ b/gnome-panel/panel-object-loader.c
@@ -41,7 +41,6 @@
#include "panel-applet-frame.h"
#include "panel-menu-bar.h"
#include "panel-menu-button.h"
-#include "panel-separator.h"
#include "panel-user-menu.h"
#include "panel-object-loader.h"
@@ -225,11 +224,6 @@ panel_object_loader_idle_handler (gpointer dummy)
object->id,
object->settings);
break;
- case PANEL_OBJECT_SEPARATOR:
- panel_separator_load (panel_widget,
- object->id,
- object->settings);
- break;
case PANEL_OBJECT_USER_MENU:
panel_user_menu_load (panel_widget,
object->id,
@@ -373,7 +367,6 @@ static struct {
{ PANEL_OBJECT_MENU_BAR, "MenuBar" , FALSE },
{ PANEL_OBJECT_MENU, "MenuButton" , FALSE },
{ PANEL_OBJECT_LAUNCHER, "Launcher" , FALSE },
- { PANEL_OBJECT_SEPARATOR, "Separator" , FALSE },
{ PANEL_OBJECT_USER_MENU, "UserMenu" , FALSE }
};
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index 26b5322..b306e23 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -33,7 +33,6 @@
#include "panel-applet-frame.h"
#include "panel-action-button.h"
#include "panel-menu-bar.h"
-#include "panel-separator.h"
#include "panel-multiscreen.h"
#include "panel-toplevel.h"
#include "panel-menu-button.h"
@@ -81,10 +80,6 @@ orientation_change (AppletInfo *info,
case PANEL_OBJECT_USER_MENU:
panel_menu_bar_object_set_orientation (PANEL_MENU_BAR_OBJECT (info->widget), orientation);
break;
- case PANEL_OBJECT_SEPARATOR:
- panel_separator_set_orientation (PANEL_SEPARATOR (info->widget),
- orientation);
- break;
default:
break;
}
@@ -124,7 +119,6 @@ back_change (AppletInfo *info,
break;
case PANEL_OBJECT_MENU_BAR:
case PANEL_OBJECT_USER_MENU:
- case PANEL_OBJECT_SEPARATOR:
break;
default:
break;
@@ -925,15 +919,6 @@ drop_internal_applet (PanelWidget *panel,
success = FALSE;
}
- } else if (!strcmp(applet_type,"SEPARATOR:NEW")) {
- if (panel_layout_is_writable ()) {
- panel_separator_create (panel->toplevel,
- pack_type, pack_index);
- success = TRUE;
- } else {
- success = FALSE;
- }
-
} else if (!strcmp (applet_type, "USERMENU:NEW")) {
if (panel_layout_is_writable ()) {
panel_user_menu_create (panel->toplevel,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]