[gnome-panel] wncklet: port to libgnome-panel
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] wncklet: port to libgnome-panel
- Date: Tue, 1 Nov 2016 17:41:14 +0000 (UTC)
commit a36828c8679e318d2745230efb7ed644941405b6
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Oct 31 23:44:43 2016 +0200
wncklet: port to libgnome-panel
applets/wncklet/Makefile.am | 33 +---
.../org.gnome.panel.Wncklet.panel-applet.in.in | 42 -----
applets/wncklet/showdesktop.c | 140 +++++++---------
applets/wncklet/showdesktop.h | 7 +-
applets/wncklet/window-list-menu.ui | 16 ++-
applets/wncklet/window-list.c | 170 +++++++++-----------
applets/wncklet/window-list.h | 7 +-
applets/wncklet/window-menu.c | 82 ++++++----
applets/wncklet/window-menu.h | 7 +-
applets/wncklet/wncklet-module.c | 134 +++++++++++++++
applets/wncklet/wncklet.c | 40 -----
applets/wncklet/workspace-switcher-menu.ui | 16 ++-
applets/wncklet/workspace-switcher.c | 156 ++++++++----------
applets/wncklet/workspace-switcher.h | 7 +-
po/POTFILES.in | 2 +-
15 files changed, 436 insertions(+), 423 deletions(-)
---
diff --git a/applets/wncklet/Makefile.am b/applets/wncklet/Makefile.am
index 93d7b2a..558447d 100644
--- a/applets/wncklet/Makefile.am
+++ b/applets/wncklet/Makefile.am
@@ -1,20 +1,17 @@
NULL =
-wncklet_libdir = $(pkglibdir)
+wncklet_libdir = $(libdir)/gnome-panel/applets
wncklet_lib_LTLIBRARIES = wncklet.la
wncklet_la_CPPFLAGS = \
- -DGNOMELOCALEDIR=\""$(localedir)"\" \
+ -DLOCALEDIR=\""$(localedir)"\" \
-DWNCK_I_KNOW_THIS_IS_UNSTABLE \
- -I$(top_builddir) \
- -I$(top_builddir)/applets/wncklet \
- -I$(top_srcdir)/libpanel-applet \
- -I$(top_builddir)/libpanel-applet \
+ -I$(top_srcdir) \
$(AM_CPPFLAGS) \
$(NULL)
wncklet_la_CFLAGS = \
- $(LIBPANEL_APPLET_CFLAGS) \
+ $(LIBGNOME_PANEL_CFLAGS) \
$(WNCKLET_CFLAGS) \
$(WARN_CFLAGS) \
$(AM_CFLAGS) \
@@ -23,6 +20,7 @@ wncklet_la_CFLAGS = \
wncklet_la_SOURCES = \
wncklet.c \
wncklet.h \
+ wncklet-module.c \
window-menu.c \
window-menu.h \
window-list.c \
@@ -35,8 +33,8 @@ wncklet_la_SOURCES = \
$(NULL)
wncklet_la_LIBADD = \
- $(top_builddir)/libpanel-applet/libpanel-applet.la \
- $(LIBPANEL_APPLET_LIBS) \
+ $(top_builddir)/libgnome-panel/libgnome-panel.la \
+ $(LIBGNOME_PANEL_LIBS) \
$(WNCKLET_LIBS) \
$(NULL)
@@ -46,20 +44,6 @@ wncklet_la_LDFLAGS = \
$(AM_LDFLAGS) \
$(NULL)
-APPLET_LOCATION = $(pkglibdir)/wncklet.so
-
-appletdir = $(appletsdir)
-applet_in_files = org.gnome.panel.Wncklet.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@
-
ui_FILES = \
window-list-menu.ui \
window-list.ui \
@@ -79,14 +63,11 @@ BUILT_SOURCES = \
$(NULL)
EXTRA_DIST = \
- org.gnome.panel.Wncklet.panel-applet.in.in \
wncklet.gresource.xml \
$(ui_FILES) \
$(NULL)
CLEANFILES = \
- $(applet_DATA) \
- $(applet_DATA).in \
$(BUILT_SOURCES) \
$(NULL)
diff --git a/applets/wncklet/showdesktop.c b/applets/wncklet/showdesktop.c
index 8616678..267054d 100644
--- a/applets/wncklet/showdesktop.c
+++ b/applets/wncklet/showdesktop.c
@@ -30,8 +30,10 @@
#define TIMEOUT_ACTIVATE_SECONDS 1
#define SHOW_DESKTOP_ICON "user-desktop"
-typedef struct {
- GtkWidget *applet;
+struct _ShowDesktopApplet
+{
+ GpApplet parent;
+
GtkWidget *button;
GtkWidget *image;
@@ -44,7 +46,9 @@ typedef struct {
guint button_activate;
GtkIconTheme *icon_theme;
-} ShowDesktopApplet;
+};
+
+G_DEFINE_TYPE (ShowDesktopApplet, show_desktop_applet, GP_TYPE_APPLET)
static void
update_icon (ShowDesktopApplet *sdd)
@@ -140,34 +144,6 @@ update_icon (ShowDesktopApplet *sdd)
}
static void
-applet_change_orient (PanelApplet *applet,
- PanelAppletOrient orient,
- ShowDesktopApplet *sdd)
-{
- GtkOrientation new_orient;
-
- switch (orient)
- {
- case PANEL_APPLET_ORIENT_LEFT:
- case PANEL_APPLET_ORIENT_RIGHT:
- new_orient = GTK_ORIENTATION_VERTICAL;
- break;
- case PANEL_APPLET_ORIENT_UP:
- case PANEL_APPLET_ORIENT_DOWN:
- default:
- new_orient = GTK_ORIENTATION_HORIZONTAL;
- break;
- }
-
- if (new_orient == sdd->orient)
- return;
-
- sdd->orient = new_orient;
-
- update_icon (sdd);
-}
-
-static void
button_size_allocated (GtkWidget *button,
GtkAllocation *allocation,
ShowDesktopApplet *sdd)
@@ -320,8 +296,6 @@ applet_destroyed (GtkWidget *applet,
sdd);
sdd->icon_theme = NULL;
}
-
- g_free (sdd);
}
static gboolean
@@ -378,13 +352,9 @@ button_drag_motion (GtkWidget *widget,
}
static void
-show_desktop_applet_realized (PanelApplet *applet,
- gpointer data)
+show_desktop_applet_realized (GtkWidget *widget,
+ ShowDesktopApplet *sdd)
{
- ShowDesktopApplet *sdd;
-
- sdd = (ShowDesktopApplet *) data;
-
if (sdd->wnck_screen != NULL)
g_signal_handlers_disconnect_by_func (sdd->wnck_screen,
show_desktop_changed_callback,
@@ -401,8 +371,7 @@ show_desktop_applet_realized (PanelApplet *applet,
wncklet_connect_while_alive (sdd->wnck_screen,
"showing_desktop_changed",
G_CALLBACK (show_desktop_changed_callback),
- sdd,
- sdd->applet);
+ sdd, sdd);
else
g_warning ("Could not get WnckScreen!");
@@ -411,39 +380,23 @@ show_desktop_applet_realized (PanelApplet *applet,
sdd->icon_theme = gtk_icon_theme_get_default ();
wncklet_connect_while_alive (sdd->icon_theme, "changed",
G_CALLBACK (theme_changed_callback),
- sdd,
- sdd->applet);
+ sdd, sdd);
update_icon (sdd);
}
-gboolean
-show_desktop_applet_fill (PanelApplet *applet)
+static void
+show_desktop_applet_fill (GpApplet *applet)
{
ShowDesktopApplet *sdd;
AtkObject *atk_obj;
- panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
-
- sdd = g_new0 (ShowDesktopApplet, 1);
-
- sdd->applet = GTK_WIDGET (applet);
+ sdd = SHOW_DESKTOP_APPLET (applet);
sdd->image = gtk_image_new ();
+ sdd->orient = gp_applet_get_orientation (applet);
- switch (panel_applet_get_orient (applet)) {
- case PANEL_APPLET_ORIENT_LEFT:
- case PANEL_APPLET_ORIENT_RIGHT:
- sdd->orient = GTK_ORIENTATION_VERTICAL;
- break;
- case PANEL_APPLET_ORIENT_UP:
- case PANEL_APPLET_ORIENT_DOWN:
- default:
- sdd->orient = GTK_ORIENTATION_HORIZONTAL;
- break;
- }
-
- g_signal_connect (G_OBJECT (sdd->applet), "realize",
+ g_signal_connect (sdd, "realize",
G_CALLBACK (show_desktop_applet_realized), sdd);
sdd->button = gtk_toggle_button_new ();
@@ -460,24 +413,14 @@ show_desktop_applet_fill (PanelApplet *applet)
gtk_container_set_border_width (GTK_CONTAINER (sdd->button), 0);
gtk_container_add (GTK_CONTAINER (sdd->button), sdd->image);
- gtk_container_add (GTK_CONTAINER (sdd->applet), sdd->button);
+ gtk_container_add (GTK_CONTAINER (sdd), sdd->button);
g_signal_connect (G_OBJECT (sdd->button),
"size_allocate",
G_CALLBACK (button_size_allocated),
sdd);
- /* FIXME: Update this comment. */
- /* we have to bind change_orient before we do applet_widget_add
- since we need to get an initial change_orient signal to set our
- initial oriantation, and we get that during the _add call */
- g_signal_connect (G_OBJECT (sdd->applet),
- "change_orient",
- G_CALLBACK (applet_change_orient),
- sdd);
-
- g_signal_connect (G_OBJECT (sdd->applet),
- "destroy",
+ g_signal_connect (sdd, "destroy",
G_CALLBACK (applet_destroyed),
sdd);
@@ -490,7 +433,50 @@ show_desktop_applet_fill (PanelApplet *applet)
G_CALLBACK (button_drag_leave),
sdd);
- gtk_widget_show_all (sdd->applet);
+ gtk_widget_show_all (GTK_WIDGET (sdd));
+}
+
+static void
+show_desktop_applet_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (show_desktop_applet_parent_class)->constructed (object);
+
+ show_desktop_applet_fill (GP_APPLET (object));
+}
+
+static void
+show_desktop_applet_placement_changed (GpApplet *applet,
+ GtkOrientation orientation,
+ GtkPositionType position)
+{
+ ShowDesktopApplet *sdd;
+
+ sdd = SHOW_DESKTOP_APPLET (applet);
+
+ if (orientation == sdd->orient)
+ return;
+
+ sdd->orient = orientation;
+
+ update_icon (sdd);
+}
+
+static void
+show_desktop_applet_class_init (ShowDesktopAppletClass *sdd_class)
+{
+ GObjectClass *object_class;
+ GpAppletClass *applet_class;
+
+ object_class = G_OBJECT_CLASS (sdd_class);
+ applet_class = GP_APPLET_CLASS (sdd_class);
- return TRUE;
+ object_class->constructed = show_desktop_applet_constructed;
+
+ applet_class->placement_changed = show_desktop_applet_placement_changed;
+}
+
+static void
+show_desktop_applet_init (ShowDesktopApplet *sdd)
+{
+ gp_applet_set_flags (GP_APPLET (sdd), GP_APPLET_FLAGS_EXPAND_MINOR);
}
diff --git a/applets/wncklet/showdesktop.h b/applets/wncklet/showdesktop.h
index 1694ae7..754d29c 100644
--- a/applets/wncklet/showdesktop.h
+++ b/applets/wncklet/showdesktop.h
@@ -19,12 +19,13 @@
#ifndef SHOW_DESKTOP_APPLET_H
#define SHOW_DESKTOP_APPLET_H
-#include <glib.h>
-#include <panel-applet.h>
+#include <libgnome-panel/gp-applet.h>
G_BEGIN_DECLS
-gboolean show_desktop_applet_fill (PanelApplet *applet);
+#define SHOW_DESKTOP_TYPE_APPLET show_desktop_applet_get_type ()
+G_DECLARE_FINAL_TYPE (ShowDesktopApplet, show_desktop_applet,
+ SHOW_DESKTOP, APPLET, GpApplet)
G_END_DECLS
diff --git a/applets/wncklet/window-list-menu.ui b/applets/wncklet/window-list-menu.ui
index f6c04b6..6c71567 100644
--- a/applets/wncklet/window-list-menu.ui
+++ b/applets/wncklet/window-list-menu.ui
@@ -1,6 +1,10 @@
-<section>
- <item>
- <attribute name="label" translatable="yes">_Preferences</attribute>
- <attribute name="action">tasklist.preferences</attribute>
- </item>
-</section>
+<interface>
+ <menu id="window-list-menu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="action">window-list.preferences</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/applets/wncklet/window-list.c b/applets/wncklet/window-list.c
index afe8dd3..593749b 100644
--- a/applets/wncklet/window-list.c
+++ b/applets/wncklet/window-list.c
@@ -23,7 +23,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libwnck/libwnck.h>
-#include <panel-applet.h>
#include <string.h>
#include "wncklet.h"
@@ -31,19 +30,21 @@
#define WINDOW_LIST_ICON "gnome-panel-window-list"
-typedef struct {
- GtkWidget *applet;
+struct _WindowListApplet
+{
+ GpApplet parent;
+
GtkWidget *tasklist;
-
+
gboolean include_all_workspaces;
WnckTasklistGroupingType grouping;
gboolean move_unminimized_windows;
-
+
GtkOrientation orientation;
int size;
GtkIconTheme *icon_theme;
-
+
/* Properties: */
GtkWidget *properties_dialog;
GtkWidget *show_current_radio;
@@ -56,7 +57,9 @@ typedef struct {
GtkWidget *change_workspace_radio;
GSettings *settings;
-} WindowListApplet;
+};
+
+G_DEFINE_TYPE (WindowListApplet, window_list_applet, GP_TYPE_APPLET)
static void
tasklist_update (WindowListApplet *tasklist)
@@ -86,35 +89,6 @@ response_cb (GtkWidget *widget,
}
static void
-applet_change_orient (PanelApplet *applet,
- PanelAppletOrient orient,
- WindowListApplet *tasklist)
-{
- GtkOrientation new_orient;
-
- switch (orient) {
- case PANEL_APPLET_ORIENT_LEFT:
- case PANEL_APPLET_ORIENT_RIGHT:
- new_orient = GTK_ORIENTATION_VERTICAL;
- break;
- case PANEL_APPLET_ORIENT_UP:
- case PANEL_APPLET_ORIENT_DOWN:
- default:
- new_orient = GTK_ORIENTATION_HORIZONTAL;
- break;
- }
-
- if (new_orient == tasklist->orientation)
- return;
-
- tasklist->orientation = new_orient;
-
- wnck_tasklist_set_orientation (WNCK_TASKLIST (tasklist->tasklist), new_orient);
-
- tasklist_update (tasklist);
-}
-
-static void
destroy_tasklist (GtkWidget *widget,
WindowListApplet *tasklist)
{
@@ -123,8 +97,6 @@ destroy_tasklist (GtkWidget *widget,
if (tasklist->properties_dialog)
gtk_widget_destroy (tasklist->properties_dialog);
-
- g_free (tasklist);
}
static void
@@ -240,7 +212,7 @@ static void
setup_gsettings (WindowListApplet *tasklist)
{
tasklist->settings =
- panel_applet_settings_new (PANEL_APPLET (tasklist->applet),
+ gp_applet_settings_new (GP_APPLET (tasklist),
"org.gnome.gnome-panel.applet.window-list");
g_signal_connect (tasklist->settings, "changed::display-all-workspaces",
@@ -260,15 +232,14 @@ applet_size_allocate (GtkWidget *widget,
{
gint len, size;
const int *size_hints;
- PanelAppletOrient orient = panel_applet_get_orient (PANEL_APPLET (tasklist->applet));
+ GtkOrientation orient = gp_applet_get_orientation (GP_APPLET (tasklist));
size_hints = wnck_tasklist_get_size_hint_list (WNCK_TASKLIST (tasklist->tasklist), &len);
g_assert (len % 2 == 0);
- panel_applet_set_size_hints (PANEL_APPLET (tasklist->applet),
- size_hints, len, 0);
+ gp_applet_set_size_hints (GP_APPLET (tasklist), size_hints, len, 0);
- if (orient == PANEL_APPLET_ORIENT_UP || orient == PANEL_APPLET_ORIENT_DOWN) {
+ if (orient == GTK_ORIENTATION_HORIZONTAL) {
size = allocation->height;
} else {
size = allocation->width;
@@ -490,30 +461,21 @@ display_properties_dialog (GSimpleAction *action,
WINDOW_LIST_ICON);
gtk_window_set_resizable (GTK_WINDOW (tasklist->properties_dialog), FALSE);
- gtk_window_set_screen (GTK_WINDOW (tasklist->properties_dialog),
- gtk_widget_get_screen (tasklist->applet));
gtk_window_present (GTK_WINDOW (tasklist->properties_dialog));
}
static const GActionEntry tasklist_menu_actions [] = {
{ "preferences", display_properties_dialog, NULL, NULL, NULL },
+ { NULL }
};
-gboolean
-window_list_applet_fill (PanelApplet *applet)
+static void
+window_list_applet_fill (GpApplet *applet)
{
WindowListApplet *tasklist;
- GSimpleActionGroup *action_group;
GAction *action;
- tasklist = g_new0 (WindowListApplet, 1);
-
- tasklist->applet = GTK_WIDGET (applet);
-
- panel_applet_set_flags (PANEL_APPLET (tasklist->applet),
- PANEL_APPLET_EXPAND_MAJOR |
- PANEL_APPLET_EXPAND_MINOR |
- PANEL_APPLET_HAS_HANDLE);
+ tasklist = WINDOW_LIST_APPLET (applet);
setup_gsettings (tasklist);
@@ -521,17 +483,7 @@ window_list_applet_fill (PanelApplet *applet)
tasklist->grouping = g_settings_get_enum (tasklist->settings, "group-windows");
tasklist->move_unminimized_windows = g_settings_get_boolean (tasklist->settings,
"move-unminimized-windows");
- switch (panel_applet_get_orient (applet)) {
- case PANEL_APPLET_ORIENT_LEFT:
- case PANEL_APPLET_ORIENT_RIGHT:
- tasklist->orientation = GTK_ORIENTATION_VERTICAL;
- break;
- case PANEL_APPLET_ORIENT_UP:
- case PANEL_APPLET_ORIENT_DOWN:
- default:
- tasklist->orientation = GTK_ORIENTATION_HORIZONTAL;
- break;
- }
+ tasklist->orientation = gp_applet_get_orientation (applet);
tasklist->tasklist = wnck_tasklist_new ();
tasklist->icon_theme = gtk_icon_theme_get_default ();
@@ -543,40 +495,74 @@ window_list_applet_fill (PanelApplet *applet)
g_signal_connect (G_OBJECT (tasklist->tasklist), "destroy",
G_CALLBACK (destroy_tasklist),
tasklist);
- g_signal_connect (G_OBJECT (tasklist->applet), "size_allocate",
+ g_signal_connect (G_OBJECT (tasklist), "size-allocate",
G_CALLBACK (applet_size_allocate),
tasklist);
tasklist_update (tasklist);
gtk_widget_show (tasklist->tasklist);
- gtk_container_add (GTK_CONTAINER (tasklist->applet), tasklist->tasklist);
+ gtk_container_add (GTK_CONTAINER (tasklist), tasklist->tasklist);
- g_signal_connect (G_OBJECT (tasklist->applet),
- "change_orient",
- G_CALLBACK (applet_change_orient),
- tasklist);
+ gp_applet_setup_menu_from_resource (applet,
+ WNCKLET_RESOURCE_PATH "window-list-menu.ui",
+ tasklist_menu_actions);
- action_group = g_simple_action_group_new ();
- g_action_map_add_action_entries (G_ACTION_MAP (action_group),
- tasklist_menu_actions,
- G_N_ELEMENTS (tasklist_menu_actions),
- tasklist);
- panel_applet_setup_menu_from_resource (PANEL_APPLET (tasklist->applet),
- WNCKLET_RESOURCE_PATH "window-list-menu.ui",
- action_group,
- GETTEXT_PACKAGE);
-
- gtk_widget_insert_action_group (GTK_WIDGET (applet), "tasklist",
- G_ACTION_GROUP (action_group));
-
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
- g_object_bind_property (tasklist->applet, "locked-down",
- action, "enabled",
+ action = gp_applet_menu_lookup_action (applet, "preferences");
+ g_object_bind_property (tasklist, "locked-down", action, "enabled",
G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
- g_object_unref (action_group);
+ gtk_widget_show (GTK_WIDGET (tasklist));
+}
+
+static void
+window_list_applet_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (window_list_applet_parent_class)->constructed (object);
+
+ window_list_applet_fill (GP_APPLET (object));
+}
+
+static void
+window_list_applet_placement_changed (GpApplet *applet,
+ GtkOrientation orientation,
+ GtkPositionType position)
+{
+ WindowListApplet *tasklist;
+
+ tasklist = WINDOW_LIST_APPLET (applet);
+
+ if (orientation == tasklist->orientation)
+ return;
+
+ tasklist->orientation = orientation;
+
+ wnck_tasklist_set_orientation (WNCK_TASKLIST (tasklist->tasklist), orientation);
+
+ tasklist_update (tasklist);
+}
+
+static void
+window_list_applet_class_init (WindowListAppletClass *tasklist_class)
+{
+ GObjectClass *object_class;
+ GpAppletClass *applet_class;
+
+ object_class = G_OBJECT_CLASS (tasklist_class);
+ applet_class = GP_APPLET_CLASS (tasklist_class);
+
+ object_class->constructed = window_list_applet_constructed;
+
+ applet_class->placement_changed = window_list_applet_placement_changed;
+}
+
+static void
+window_list_applet_init (WindowListApplet *tasklist)
+{
+ GpAppletFlags flags;
- gtk_widget_show (tasklist->applet);
+ flags = GP_APPLET_FLAGS_EXPAND_MAJOR |
+ GP_APPLET_FLAGS_EXPAND_MINOR |
+ GP_APPLET_FLAGS_HAS_HANDLE;
- return TRUE;
+ gp_applet_set_flags (GP_APPLET (tasklist), flags);
}
diff --git a/applets/wncklet/window-list.h b/applets/wncklet/window-list.h
index 3122762..2d285d6 100644
--- a/applets/wncklet/window-list.h
+++ b/applets/wncklet/window-list.h
@@ -20,12 +20,13 @@
#ifndef WINDOW_LIST_APPLET_H
#define WINDOW_LIST_APPLET_H
-#include <glib.h>
-#include <panel-applet.h>
+#include <libgnome-panel/gp-applet.h>
G_BEGIN_DECLS
-gboolean window_list_applet_fill (PanelApplet *applet);
+#define WINDOW_LIST_TYPE_APPLET window_list_applet_get_type ()
+G_DECLARE_FINAL_TYPE (WindowListApplet, window_list_applet,
+ WINDOW_LIST, APPLET, GpApplet)
G_END_DECLS
diff --git a/applets/wncklet/window-menu.c b/applets/wncklet/window-menu.c
index 40d172c..301677e 100644
--- a/applets/wncklet/window-menu.c
+++ b/applets/wncklet/window-menu.c
@@ -27,7 +27,6 @@
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <libwnck/libwnck.h>
-#include <panel-applet.h>
#include <string.h>
#include "wncklet.h"
@@ -35,19 +34,16 @@
#define WINDOW_MENU_ICON "gnome-panel-window-menu"
-typedef struct {
- GtkWidget *applet;
+struct _WindowMenuApplet
+{
+ GpApplet parent;
+
GtkWidget *selector;
int size;
- PanelAppletOrient orient;
-} WindowMenuApplet;
+ GtkOrientation orient;
+};
-static void
-window_menu_destroy (GtkWidget *widget,
- WindowMenuApplet *window_menu)
-{
- g_free (window_menu);
-}
+G_DEFINE_TYPE (WindowMenuApplet, window_menu_applet, GP_TYPE_APPLET)
static gboolean
window_menu_on_draw (GtkWidget *widget,
@@ -58,7 +54,7 @@ window_menu_on_draw (GtkWidget *widget,
GtkStateFlags state;
WindowMenuApplet *window_menu = data;
- if (!gtk_widget_has_focus (window_menu->applet))
+ if (!gtk_widget_has_focus (GTK_WIDGET (window_menu)))
return FALSE;
state = gtk_widget_get_state_flags (widget);
@@ -79,22 +75,21 @@ window_menu_on_draw (GtkWidget *widget,
}
static void
-window_menu_size_allocate (PanelApplet *applet,
+window_menu_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
WindowMenuApplet *window_menu)
{
- PanelAppletOrient orient;
+ GtkOrientation orient;
GList *children;
GtkWidget *child;
- orient = panel_applet_get_orient (applet);
+ orient = gp_applet_get_orientation (GP_APPLET (widget));
children = gtk_container_get_children (GTK_CONTAINER (window_menu->selector));
child = GTK_WIDGET (children->data);
g_list_free (children);
- if (orient == PANEL_APPLET_ORIENT_LEFT ||
- orient == PANEL_APPLET_ORIENT_RIGHT) {
+ if (orient == GTK_ORIENTATION_VERTICAL) {
if (window_menu->size == allocation->width &&
orient == window_menu->orient)
return;
@@ -164,35 +159,30 @@ filter_button_press (GtkWidget *widget,
return FALSE;
}
-gboolean
-window_menu_applet_fill (PanelApplet *applet)
+static void
+window_menu_applet_fill (GpApplet *applet)
{
WindowMenuApplet *window_menu;
- window_menu = g_new0 (WindowMenuApplet, 1);
+ window_menu = WINDOW_MENU_APPLET (applet);
- window_menu->applet = GTK_WIDGET (applet);
- gtk_widget_set_name (window_menu->applet, "window-menu-applet-button");
- gtk_widget_set_tooltip_text (window_menu->applet, _("Window Selector"));
-
- panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
- window_menu->orient = panel_applet_get_orient (applet);
+ gtk_widget_set_name (GTK_WIDGET (window_menu), "window-menu-applet-button");
+ gtk_widget_set_tooltip_text (GTK_WIDGET (window_menu), _("Window Selector"));
- g_signal_connect (window_menu->applet, "destroy",
- G_CALLBACK (window_menu_destroy), window_menu);
+ window_menu->orient = gp_applet_get_orientation (applet);
window_menu->selector = wnck_selector_new ();
- gtk_container_add (GTK_CONTAINER (window_menu->applet),
+ gtk_container_add (GTK_CONTAINER (window_menu),
window_menu->selector);
- g_signal_connect (window_menu->applet, "key_press_event",
+ g_signal_connect (window_menu, "key_press_event",
G_CALLBACK (window_menu_key_press_event), window_menu);
- g_signal_connect (window_menu->applet, "size-allocate",
+ g_signal_connect (window_menu, "size-allocate",
G_CALLBACK (window_menu_size_allocate), window_menu);
- g_signal_connect_after (G_OBJECT (window_menu->applet), "focus-in-event",
+ g_signal_connect_after (window_menu, "focus-in-event",
G_CALLBACK (gtk_widget_queue_draw), window_menu);
- g_signal_connect_after (G_OBJECT (window_menu->applet), "focus-out-event",
+ g_signal_connect_after (window_menu, "focus-out-event",
G_CALLBACK (gtk_widget_queue_draw), window_menu);
g_signal_connect_after (G_OBJECT (window_menu->selector), "draw",
G_CALLBACK (window_menu_on_draw), window_menu);
@@ -200,7 +190,29 @@ window_menu_applet_fill (PanelApplet *applet)
g_signal_connect (G_OBJECT (window_menu->selector), "button_press_event",
G_CALLBACK (filter_button_press), window_menu);
- gtk_widget_show_all (GTK_WIDGET (window_menu->applet));
+ gtk_widget_show_all (GTK_WIDGET (window_menu));
+}
+
+static void
+window_menu_applet_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (window_menu_applet_parent_class)->constructed (object);
+
+ window_menu_applet_fill (GP_APPLET (object));
+}
+
+static void
+window_menu_applet_class_init (WindowMenuAppletClass *window_menu_class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (window_menu_class);
+
+ object_class->constructed = window_menu_applet_constructed;
+}
- return TRUE;
+static void
+window_menu_applet_init (WindowMenuApplet *window_menu)
+{
+ gp_applet_set_flags (GP_APPLET (window_menu), GP_APPLET_FLAGS_EXPAND_MINOR);
}
diff --git a/applets/wncklet/window-menu.h b/applets/wncklet/window-menu.h
index 313b11a..7f1c132 100644
--- a/applets/wncklet/window-menu.h
+++ b/applets/wncklet/window-menu.h
@@ -26,12 +26,13 @@
#ifndef WINDOW_MENU_APPLET_H
#define WINDOW_MENU_APPLET_H
-#include <glib.h>
-#include <panel-applet.h>
+#include <libgnome-panel/gp-applet.h>
G_BEGIN_DECLS
-gboolean window_menu_applet_fill (PanelApplet *applet);
+#define WINDOW_MENU_TYPE_APPLET window_menu_applet_get_type ()
+G_DECLARE_FINAL_TYPE (WindowMenuApplet, window_menu_applet,
+ WINDOW_MENU, APPLET, GpApplet)
G_END_DECLS
diff --git a/applets/wncklet/wncklet-module.c b/applets/wncklet/wncklet-module.c
new file mode 100644
index 0000000..7f67565
--- /dev/null
+++ b/applets/wncklet/wncklet-module.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * 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/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <libgnome-panel/gp-module.h>
+#include <libwnck/libwnck.h>
+
+#include "showdesktop.h"
+#include "window-list.h"
+#include "window-menu.h"
+#include "workspace-switcher.h"
+
+static GpModuleInfo *
+wncklet_get_module_info (void)
+{
+ GpModuleInfo *info;
+
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
+ wnck_set_client_type (WNCK_CLIENT_TYPE_PAGER);
+
+ info = gp_module_info_new ("wncklet", PACKAGE_VERSION);
+
+ gp_module_info_set_applets (info, "show-desktop", "window-list",
+ "window-menu", "workspace-switcher",
+ NULL);
+
+ gp_module_info_set_translation_domain (info, GETTEXT_PACKAGE);
+
+ return info;
+}
+
+static GpAppletInfo *
+wncklet_get_applet_info (const gchar *applet)
+{
+ const gchar *name;
+ const gchar *description;
+ const gchar *icon;
+ GpAppletInfo *info;
+
+ if (g_strcmp0 (applet, "show-desktop") == 0)
+ {
+ name = _("Show Desktop");
+ description = _("Hide application windows and show the desktop");
+ icon = "user-desktop";
+ }
+ else if (g_strcmp0 (applet, "window-list") == 0)
+ {
+ name = _("Window List");
+ description = _("Switch between open windows using buttons");
+ icon = "gnome-panel-window-list";
+ }
+ else if (g_strcmp0 (applet, "window-menu") == 0)
+ {
+ name = _("Window Selector");
+ description = _("Switch between open windows using a menu");
+ icon = "gnome-panel-window-menu";
+ }
+ else if (g_strcmp0 (applet, "workspace-switcher") == 0)
+ {
+ name = _("Workspace Switcher");
+ description = _("Switch between workspaces");
+ icon = "gnome-panel-workspace-switcher";
+ }
+ else
+ {
+ g_assert_not_reached ();
+ return NULL;
+ }
+
+ info = gp_applet_info_new (name, description, icon);
+
+ gp_applet_info_set_backends (info, "x11");
+
+ return info;
+}
+
+static GType
+wncklet_get_applet_type (const gchar *applet)
+{
+ if (g_strcmp0 (applet, "show-desktop") == 0)
+ {
+ return SHOW_DESKTOP_TYPE_APPLET;
+ }
+ else if (g_strcmp0 (applet, "window-list") == 0)
+ {
+ return WINDOW_LIST_TYPE_APPLET;
+ }
+ else if (g_strcmp0 (applet, "window-menu") == 0)
+ {
+ return WINDOW_MENU_TYPE_APPLET;
+ }
+ else if (g_strcmp0 (applet, "workspace-switcher") == 0)
+ {
+ return WORKSPACE_SWITCHER_TYPE_APPLET;
+ }
+
+ g_assert_not_reached ();
+ return G_TYPE_NONE;
+}
+
+guint32
+gp_module_get_abi_version (void)
+{
+ return GP_MODULE_ABI_VERSION;
+}
+
+void
+gp_module_get_vtable (GpModuleVTable *vtable)
+{
+ *vtable = (GpModuleVTable) {
+ wncklet_get_module_info,
+ wncklet_get_applet_info,
+ wncklet_get_applet_type,
+ NULL
+ };
+}
diff --git a/applets/wncklet/wncklet.c b/applets/wncklet/wncklet.c
index 1a47f6e..201196d 100644
--- a/applets/wncklet/wncklet.c
+++ b/applets/wncklet/wncklet.c
@@ -22,14 +22,9 @@
#include <gtk/gtk.h>
#include <libwnck/libwnck.h>
-#include <panel-applet.h>
#include <string.h>
#include "wncklet.h"
-#include "window-menu.h"
-#include "workspace-switcher.h"
-#include "window-list.h"
-#include "showdesktop.h"
void
wncklet_connect_while_alive (gpointer object,
@@ -48,38 +43,3 @@ wncklet_connect_while_alive (gpointer object,
closure,
FALSE);
}
-
-static gboolean
-wncklet_factory (PanelApplet *applet,
- const char *iid,
- gpointer data)
-{
- gboolean retval = FALSE;
- static gboolean type_registered = FALSE;
-
- if (!type_registered) {
- wnck_set_client_type (WNCK_CLIENT_TYPE_PAGER);
- type_registered = TRUE;
- }
-
- if (!strcmp (iid, "WindowMenuApplet"))
- retval = window_menu_applet_fill (applet);
-
- else if (!strcmp (iid, "WorkspaceSwitcherApplet")||
- !strcmp (iid, "PagerApplet"))
- retval = workspace_switcher_applet_fill (applet);
-
- else if (!strcmp (iid, "WindowListApplet") ||
- !strcmp (iid, "TasklistApplet"))
- retval = window_list_applet_fill (applet);
-
- else if (!strcmp (iid, "ShowDesktopApplet"))
- retval = show_desktop_applet_fill (applet);
-
- return retval;
-}
-
-PANEL_APPLET_IN_PROCESS_FACTORY ("WnckletFactory",
- PANEL_TYPE_APPLET,
- wncklet_factory,
- NULL)
diff --git a/applets/wncklet/workspace-switcher-menu.ui b/applets/wncklet/workspace-switcher-menu.ui
index 090f25a..1c76a62 100644
--- a/applets/wncklet/workspace-switcher-menu.ui
+++ b/applets/wncklet/workspace-switcher-menu.ui
@@ -1,6 +1,10 @@
-<section>
- <item>
- <attribute name="label" translatable="yes">_Preferences</attribute>
- <attribute name="action">ws.preferences</attribute>
- </item>
-</section>
+<interface>
+ <menu id="workspace-switcher-menu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Preferences</attribute>
+ <attribute name="action">workspace-switcher.preferences</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/applets/wncklet/workspace-switcher.c b/applets/wncklet/workspace-switcher.c
index 2b247a0..054278d 100644
--- a/applets/wncklet/workspace-switcher.c
+++ b/applets/wncklet/workspace-switcher.c
@@ -23,7 +23,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libwnck/libwnck.h>
-#include <panel-applet.h>
#include <stdlib.h>
#include <string.h>
@@ -39,11 +38,12 @@ typedef enum {
PAGER_WM_UNKNOWN
} PagerWM;
-typedef struct {
- GtkWidget *applet;
+struct _WorkspaceSwitcherApplet
+{
+ GpApplet parent;
GtkWidget *pager;
-
+
WnckScreen *screen;
PagerWM wm;
@@ -67,7 +67,9 @@ typedef struct {
gboolean display_all;
GSettings *settings;
-} WorkspaceSwitcherApplet;
+};
+
+G_DEFINE_TYPE (WorkspaceSwitcherApplet, workspace_switcher_applet, GP_TYPE_APPLET)
static void
pager_update (WorkspaceSwitcherApplet *pager)
@@ -148,7 +150,7 @@ window_manager_changed (WnckScreen *screen,
}
static void
-applet_realized (PanelApplet *applet,
+applet_realized (GtkWidget *widget,
WorkspaceSwitcherApplet *pager)
{
pager->screen = wnck_screen_get_default ();
@@ -156,12 +158,11 @@ applet_realized (PanelApplet *applet,
window_manager_changed (pager->screen, pager);
wncklet_connect_while_alive (pager->screen, "window_manager_changed",
G_CALLBACK (window_manager_changed),
- pager,
- pager->applet);
+ pager, pager);
}
static void
-applet_unrealized (PanelApplet *applet,
+applet_unrealized (GtkWidget *widget,
WorkspaceSwitcherApplet *pager)
{
pager->screen = NULL;
@@ -169,34 +170,6 @@ applet_unrealized (PanelApplet *applet,
}
static void
-applet_change_orient (PanelApplet *applet,
- PanelAppletOrient orient,
- WorkspaceSwitcherApplet *pager)
-{
- GtkOrientation new_orient;
-
- switch (orient) {
- case PANEL_APPLET_ORIENT_LEFT:
- case PANEL_APPLET_ORIENT_RIGHT:
- new_orient = GTK_ORIENTATION_VERTICAL;
- break;
- case PANEL_APPLET_ORIENT_UP:
- case PANEL_APPLET_ORIENT_DOWN:
- default:
- new_orient = GTK_ORIENTATION_HORIZONTAL;
- break;
- }
-
- if (new_orient == pager->orientation)
- return;
-
- pager->orientation = new_orient;
- pager_update (pager);
- if (pager->label_row_col)
- gtk_label_set_text (GTK_LABEL (pager->label_row_col), pager->orientation ==
GTK_ORIENTATION_HORIZONTAL ? _("rows") : _("columns"));
-}
-
-static void
destroy_pager (GtkWidget *widget,
WorkspaceSwitcherApplet *pager)
{
@@ -204,8 +177,6 @@ destroy_pager (GtkWidget *widget,
if (pager->properties_dialog)
gtk_widget_destroy (pager->properties_dialog);
-
- g_free (pager);
}
static void
@@ -277,7 +248,7 @@ static void
setup_gsettings (WorkspaceSwitcherApplet *pager)
{
pager->settings =
- panel_applet_settings_new (PANEL_APPLET (pager->applet),
+ gp_applet_settings_new (GP_APPLET (pager),
"org.gnome.gnome-panel.applet.workspace-switcher");
g_signal_connect (pager->settings, "changed::num-rows",
@@ -691,28 +662,22 @@ display_properties_dialog (GSimpleAction *action,
gtk_window_set_icon_name (GTK_WINDOW (pager->properties_dialog),
WORKSPACE_SWITCHER_ICON);
- gtk_window_set_screen (GTK_WINDOW (pager->properties_dialog),
- gtk_widget_get_screen (pager->applet));
gtk_window_present (GTK_WINDOW (pager->properties_dialog));
}
static const GActionEntry pager_menu_actions [] = {
{ "preferences", display_properties_dialog, NULL, NULL, NULL },
+ { NULL }
};
-gboolean
-workspace_switcher_applet_fill (PanelApplet *applet)
+static void
+workspace_switcher_applet_fill (GpApplet *applet)
{
WorkspaceSwitcherApplet *pager;
- GSimpleActionGroup *action_group;
GAction *action;
gboolean display_names;
- pager = g_new0 (WorkspaceSwitcherApplet, 1);
-
- pager->applet = GTK_WIDGET (applet);
-
- panel_applet_set_flags (PANEL_APPLET (pager->applet), PANEL_APPLET_EXPAND_MINOR);
+ pager = WORKSPACE_SWITCHER_APPLET (applet);
setup_gsettings (pager);
@@ -728,17 +693,7 @@ workspace_switcher_applet_fill (PanelApplet *applet)
pager->display_all = g_settings_get_boolean (pager->settings, "display-all-workspaces");
- switch (panel_applet_get_orient (applet)) {
- case PANEL_APPLET_ORIENT_LEFT:
- case PANEL_APPLET_ORIENT_RIGHT:
- pager->orientation = GTK_ORIENTATION_VERTICAL;
- break;
- case PANEL_APPLET_ORIENT_UP:
- case PANEL_APPLET_ORIENT_DOWN:
- default:
- pager->orientation = GTK_ORIENTATION_HORIZONTAL;
- break;
- }
+ pager->orientation = gp_applet_get_orientation (applet);
pager->pager = wnck_pager_new ();
pager->screen = NULL;
@@ -749,43 +704,72 @@ workspace_switcher_applet_fill (PanelApplet *applet)
G_CALLBACK (destroy_pager),
pager);
- gtk_container_add (GTK_CONTAINER (pager->applet), pager->pager);
+ gtk_container_add (GTK_CONTAINER (pager), pager->pager);
gtk_widget_show (pager->pager);
- g_signal_connect (G_OBJECT (pager->applet),
+ g_signal_connect (G_OBJECT (pager),
"realize",
G_CALLBACK (applet_realized),
pager);
- g_signal_connect (G_OBJECT (pager->applet),
+ g_signal_connect (G_OBJECT (pager),
"unrealize",
G_CALLBACK (applet_unrealized),
pager);
- g_signal_connect (G_OBJECT (pager->applet),
- "change_orient",
- G_CALLBACK (applet_change_orient),
- pager);
- gtk_widget_show (pager->applet);
+ gp_applet_setup_menu_from_resource (applet,
+ WNCKLET_RESOURCE_PATH "workspace-switcher-menu.ui",
+ pager_menu_actions);
+
+ action = gp_applet_menu_lookup_action (applet, "preferences");
+ g_object_bind_property (pager, "locked-down", action, "enabled",
+ G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
- action_group = g_simple_action_group_new ();
- g_action_map_add_action_entries (G_ACTION_MAP (action_group),
- pager_menu_actions,
- G_N_ELEMENTS (pager_menu_actions),
- pager);
- panel_applet_setup_menu_from_resource (PANEL_APPLET (pager->applet),
- WNCKLET_RESOURCE_PATH "workspace-switcher-menu.ui",
- action_group,
- GETTEXT_PACKAGE);
+ gtk_widget_show (GTK_WIDGET (pager));
+}
- gtk_widget_insert_action_group (GTK_WIDGET (applet), "ws",
- G_ACTION_GROUP (action_group));
+static void
+workspace_switcher_applet_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (workspace_switcher_applet_parent_class)->constructed (object);
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
- g_object_bind_property (pager->applet, "locked-down",
- action, "enabled",
- G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
+ workspace_switcher_applet_fill (GP_APPLET (object));
+}
- g_object_unref (action_group);
+static void
+workspace_switcher_applet_placement_changed (GpApplet *applet,
+ GtkOrientation orientation,
+ GtkPositionType position)
+{
+ WorkspaceSwitcherApplet *pager;
- return TRUE;
+ pager = WORKSPACE_SWITCHER_APPLET (applet);
+
+ if (orientation == pager->orientation)
+ return;
+
+ pager->orientation = orientation;
+ pager_update (pager);
+
+ if (pager->label_row_col)
+ gtk_label_set_text (GTK_LABEL (pager->label_row_col), orientation ==
GTK_ORIENTATION_HORIZONTAL ? _("rows") : _("columns"));
+}
+
+static void
+workspace_switcher_applet_class_init (WorkspaceSwitcherAppletClass *pager_class)
+{
+ GObjectClass *object_class;
+ GpAppletClass *applet_class;
+
+ object_class = G_OBJECT_CLASS (pager_class);
+ applet_class = GP_APPLET_CLASS (pager_class);
+
+ object_class->constructed = workspace_switcher_applet_constructed;
+
+ applet_class->placement_changed = workspace_switcher_applet_placement_changed;
+}
+
+static void
+workspace_switcher_applet_init (WorkspaceSwitcherApplet *pager)
+{
+ gp_applet_set_flags (GP_APPLET (pager), GP_APPLET_FLAGS_EXPAND_MINOR);
}
diff --git a/applets/wncklet/workspace-switcher.h b/applets/wncklet/workspace-switcher.h
index daf06a7..cd4644f 100644
--- a/applets/wncklet/workspace-switcher.h
+++ b/applets/wncklet/workspace-switcher.h
@@ -20,12 +20,13 @@
#ifndef WORKSPACE_SWITCHER_APPLET_H
#define WORKSPACE_SWITCHER_APPLET_H
-#include <glib.h>
-#include <panel-applet.h>
+#include <libgnome-panel/gp-applet.h>
G_BEGIN_DECLS
-gboolean workspace_switcher_applet_fill (PanelApplet *applet);
+#define WORKSPACE_SWITCHER_TYPE_APPLET workspace_switcher_applet_get_type ()
+G_DECLARE_FINAL_TYPE (WorkspaceSwitcherApplet, workspace_switcher_applet,
+ WORKSPACE_SWITCHER, APPLET, GpApplet)
G_END_DECLS
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5dcb64d..593a9f6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -18,13 +18,13 @@ applets/notification-area/na-applet.c
applets/notification-area/na-module.c
applets/notification-area/na-tray-manager.c
applets/status-notifier/sn-module.c
-[type: gettext/ini]applets/wncklet/org.gnome.panel.Wncklet.panel-applet.in.in
applets/wncklet/showdesktop.c
applets/wncklet/window-list.c
[type: gettext/glade]applets/wncklet/window-list-menu.ui
[type: gettext/glade]applets/wncklet/window-list.ui
applets/wncklet/window-menu.c
applets/wncklet/wncklet.c
+applets/wncklet/wncklet-module.c
applets/wncklet/workspace-switcher.c
[type: gettext/glade]applets/wncklet/workspace-switcher-menu.ui
[type: gettext/glade]applets/wncklet/workspace-switcher.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]