diff options
author | Eric Koegel <eric.koegel@gmail.com> | 2014-06-16 11:06:24 +0300 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2014-06-23 16:50:47 +0300 |
commit | 5fc8c54b92843e692f43565abc7109c0c51ab24f (patch) | |
tree | d9a660f5ddc5b0c56d55fbeadf493a7a043d9937 /panel-plugins | |
parent | c865b4455ac3916847ff1abc1fd3a12811ef7ce4 (diff) | |
download | ixfce4-power-manager-5fc8c54b92843e692f43565abc7109c0c51ab24f.tar.gz |
LXDE battery plugin support (Bug 10929)
Adds support for the battery plugin to be built and used in LXDE
as the system tray icon was removed. Thanks to
https://github.com/nandhp/multiload-nandhp as it was used as a
complete example on how to easily do this. There may be a couple
things that need to be added to make this have the same
functionality as the Xfce plugin.
Diffstat (limited to 'panel-plugins')
-rw-r--r-- | panel-plugins/Makefile.am | 10 | ||||
-rw-r--r-- | panel-plugins/battery/Makefile.am | 77 | ||||
-rw-r--r-- | panel-plugins/battery/battery-button.c | 83 | ||||
-rw-r--r-- | panel-plugins/battery/battery-button.h | 10 | ||||
-rw-r--r-- | panel-plugins/battery/lxde/Makefile.am | 54 | ||||
-rw-r--r-- | panel-plugins/battery/lxde/battery-plugin.c | 102 | ||||
-rw-r--r-- | panel-plugins/battery/xfce/Makefile.am | 72 | ||||
-rw-r--r-- | panel-plugins/battery/xfce/battery-plugin.c (renamed from panel-plugins/battery/battery-plugin.c) | 11 | ||||
-rw-r--r-- | panel-plugins/battery/xfce/xfce4-battery-plugin.desktop.in.in (renamed from panel-plugins/battery/xfce4-battery-plugin.desktop.in.in) | 0 |
9 files changed, 299 insertions, 120 deletions
diff --git a/panel-plugins/Makefile.am b/panel-plugins/Makefile.am index 6376cbf0..82edd1a9 100644 --- a/panel-plugins/Makefile.am +++ b/panel-plugins/Makefile.am @@ -1,3 +1,7 @@ -SUBDIRS = \ - battery \ - brightness +if BUILD_XFCE_PLUGINS +brightness_dir = brightness +endif + +SUBDIRS = \ + battery \ + $(brightness_dir) diff --git a/panel-plugins/battery/Makefile.am b/panel-plugins/battery/Makefile.am index 47bf91fd..f6094dac 100644 --- a/panel-plugins/battery/Makefile.am +++ b/panel-plugins/battery/Makefile.am @@ -1,71 +1,12 @@ -AM_CPPFLAGS = \ - -I$(top_srcdir) \ - -DG_LOG_DOMAIN=\"xfce4-battery-plugin\" \ - -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ - $(PLATFORM_CPPFLAGS) -# -# xfce4 battery plugin -# -plugin_LTLIBRARIES = \ - libxfce4battery.la +if BUILD_XFCE_PLUGINS +xfce_dir = xfce +endif -plugindir = \ - $(libdir)/xfce4/panel/plugins +if BUILD_LXDE_PLUGINS +lxde_dir = lxde +endif -libxfce4battery_la_SOURCES = \ - battery-plugin.c \ - battery-button.c \ - battery-button.h - -libxfce4battery_la_CFLAGS = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/src \ - -DLOCALEDIR=\"$(localedir)\" \ - $(LIBXFCE4PANEL_CFLAGS) \ - $(LIBXFCE4UTIL_CFLAGS) \ - $(LIBXFCE4UI_CFLAGS) \ - $(XFCONF_CFLAGS) \ - $(GTK_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(PLATFORM_CPPFLAGS) \ - $(PLATFORM_CFLAGS) \ - $(DBUS_GLIB_CFLAGS) \ - $(UPOWER_CFLAGS) - -libxfce4battery_la_LDFLAGS = \ - -avoid-version \ - -module \ - -no-undefined \ - -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \ - $(PLATFORM_LDFLAGS) - -libxfce4battery_la_LIBADD = \ - $(top_builddir)/common/libxfpmcommon.la \ - $(LIBXFCE4PANEL_LIBS) \ - $(LIBXFCE4UI_LIBS) \ - $(LIBXFCE4UTIL_LIBS) \ - $(XFCONF_LIBS) \ - $(GTK_LIBS) \ - $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) \ - $(UPOWER_LIBS) - -# -# Desktop file -# -desktopdir = $(datadir)/xfce4/panel-plugins -desktop_in_in_files = xfce4-battery-plugin.desktop.in.in -desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in) -desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) -@INTLTOOL_DESKTOP_RULE@ - -EXTRA_DIST = \ - $(desktop_in_in_files) - -CLEANFILES = \ - $(desktop_in_files) \ - $(desktop_DATA) - -%.desktop.in: %.desktop.in.in - sed -e "s,\@libdir\@,$(libdir),g" < $< > $@ +SUBDIRS = \ + $(xfce_dir) \ + $(lxde_dir) diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c index 8d267a99..4713900b 100644 --- a/panel-plugins/battery/battery-button.c +++ b/panel-plugins/battery/battery-button.c @@ -44,7 +44,12 @@ struct BatteryButtonPrivate { +#ifdef XFCE_PLUGIN XfcePanelPlugin *plugin; +#endif +#ifdef LXDE_PLUGIN + Plugin *plugin; +#endif XfconfChannel *channel; UpClient *upower; @@ -67,12 +72,6 @@ struct BatteryButtonPrivate UpDevice *display_device; }; -enum -{ - PROP_0, - PROP_PLUGIN -}; - typedef struct { GdkPixbuf *pix; /* Icon */ @@ -93,24 +92,6 @@ static void battery_button_show_menu (BatteryButton *button); static void battery_button_menu_add_device (BatteryButton *button, BatteryDevice *battery_device, gboolean append); -static void -battery_button_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - BatteryButton *button = BATTERY_BUTTON (object); - switch (prop_id) - { - case PROP_PLUGIN: - button->priv->plugin = XFCE_PANEL_PLUGIN (g_object_ref (g_value_get_object (value))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - static BatteryDevice* get_display_device (BatteryButton *button) { @@ -407,19 +388,9 @@ battery_button_class_init (BatteryButtonClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->finalize = battery_button_finalize; - object_class->set_property = battery_button_set_property; widget_class->button_press_event = battery_button_press_event; - g_object_class_install_property (object_class, - PROP_PLUGIN, - g_param_spec_object ("plugin", - NULL, - NULL, - XFCE_TYPE_PANEL_PLUGIN, - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_WRITABLE)); - g_type_class_add_private (klass, sizeof (BatteryButtonPrivate)); } @@ -440,7 +411,7 @@ battery_button_init (BatteryButton *button) } else { - button->priv->channel = xfconf_channel_get ("xfce4-power-manager"); + button->priv->channel = xfconf_channel_get ("xfce4-power-manager"); } /* Sane defaults for the panel icon */ @@ -462,16 +433,31 @@ battery_button_finalize (GObject *object) g_signal_handlers_disconnect_by_data (button->priv->upower, button); +#ifdef XFCE_PLUGIN g_object_unref (button->priv->plugin); +#endif G_OBJECT_CLASS (battery_button_parent_class)->finalize (object); } GtkWidget * +#ifdef XFCE_PLUGIN battery_button_new (XfcePanelPlugin *plugin) +#endif +#ifdef LXDE_PLUGIN +battery_button_new (Plugin *plugin) +#endif { BatteryButton *button = NULL; - button = g_object_new (BATTERY_TYPE_BUTTON, "plugin", plugin, NULL); + button = g_object_new (BATTERY_TYPE_BUTTON, NULL, NULL); + +#ifdef XFCE_PLUGIN + button->priv->plugin = XFCE_PANEL_PLUGIN (g_object_ref (plugin)); +#endif +#ifdef LXDE_PLUGIN + button->priv->plugin = plugin; +#endif + return GTK_WIDGET (button); } @@ -508,6 +494,7 @@ battery_button_press_event (GtkWidget *widget, GdkEventButton *event) return TRUE; } +#ifdef XFCE_PLUGIN static gboolean battery_button_size_changed_cb (XfcePanelPlugin *plugin, gint size, BatteryButton *button) { @@ -516,6 +503,7 @@ battery_button_size_changed_cb (XfcePanelPlugin *plugin, gint size, BatteryButto g_return_val_if_fail (BATTERY_IS_BUTTON (button), FALSE); g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), FALSE); + size /= xfce_panel_plugin_get_nrows (plugin); width = size -2 - 2* MAX(gtk_widget_get_style(GTK_WIDGET(button))->xthickness, gtk_widget_get_style(GTK_WIDGET(button))->ythickness); @@ -531,6 +519,7 @@ battery_button_free_data_cb (XfcePanelPlugin *plugin, BatteryButton *button) { gtk_widget_destroy (GTK_WIDGET (button)); } +#endif static void help_cb (GtkMenuItem *menuitem, gpointer user_data) @@ -545,8 +534,10 @@ battery_button_show (BatteryButton *button) g_return_if_fail (BATTERY_IS_BUTTON (button)); +#ifdef XFCE_PLUGIN xfce_panel_plugin_add_action_widget (button->priv->plugin, GTK_WIDGET (button)); xfce_panel_plugin_set_small (button->priv->plugin, TRUE); +#endif button->priv->panel_icon_image = gtk_image_new (); gtk_container_add (GTK_CONTAINER (button), button->priv->panel_icon_image); @@ -557,13 +548,15 @@ battery_button_show (BatteryButton *button) gtk_widget_show (mi); g_signal_connect (mi, "activate", G_CALLBACK (help_cb), button); +#ifdef XFCE_PLUGIN xfce_panel_plugin_menu_insert_item (button->priv->plugin, GTK_MENU_ITEM (mi)); g_signal_connect (button->priv->plugin, "size-changed", - G_CALLBACK (battery_button_size_changed_cb), button); + G_CALLBACK (battery_button_size_changed_cb), button); g_signal_connect (button->priv->plugin, "free-data", - G_CALLBACK (battery_button_free_data_cb), button); + G_CALLBACK (battery_button_free_data_cb), button); +#endif gtk_widget_show_all (GTK_WIDGET(button)); battery_button_set_tooltip (button); @@ -686,9 +679,13 @@ battery_button_show_menu (BatteryButton *button) gtk_menu_popup (GTK_MENU (menu), NULL, - NULL, - xfce_panel_plugin_position_menu, - button->priv->plugin, - 0, - gtk_get_current_event_time ()); + NULL, +#ifdef XFCE_PLUGIN + xfce_panel_plugin_position_menu, +#else + NULL, +#endif + button->priv->plugin, + 0, + gtk_get_current_event_time ()); } diff --git a/panel-plugins/battery/battery-button.h b/panel-plugins/battery/battery-button.h index d2be8b6d..5e35ef4e 100644 --- a/panel-plugins/battery/battery-button.h +++ b/panel-plugins/battery/battery-button.h @@ -23,7 +23,12 @@ #include <glib-object.h> #include <gtk/gtk.h> +#ifdef XFCE_PLUGIN #include <libxfce4panel/xfce-panel-plugin.h> +#endif +#ifdef LXDE_PLUGIN +#include <lxpanel/plugin.h> +#endif G_BEGIN_DECLS @@ -48,7 +53,12 @@ typedef struct GType battery_button_get_type (void) G_GNUC_CONST; +#ifdef XFCE_PLUGIN GtkWidget *battery_button_new (XfcePanelPlugin *plugin); +#endif +#ifdef LXDE_PLUGIN +GtkWidget *battery_button_new (Plugin *plugin); +#endif void battery_button_show (BatteryButton *button); diff --git a/panel-plugins/battery/lxde/Makefile.am b/panel-plugins/battery/lxde/Makefile.am new file mode 100644 index 00000000..fbb80508 --- /dev/null +++ b/panel-plugins/battery/lxde/Makefile.am @@ -0,0 +1,54 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"lxde-battery-plugin\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + $(PLATFORM_CPPFLAGS) + + +# +# lxde battery plugin +# + +plugin_LTLIBRARIES = \ + lxdebattery.la + +plugindir = \ + $(libdir)/lxpanel/plugins + +lxdebattery_la_SOURCES = \ + battery-plugin.c \ + ../battery-button.c \ + ../battery-button.h + +lxdebattery_la_CFLAGS = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src \ + -DLOCALEDIR=\"$(localedir)\" \ + -DLXDE_PLUGIN \ + $(LXDEPANEL_CFLAGS) \ + $(LIBXFCE4UTIL_CFLAGS) \ + $(LIBXFCE4UI_CFLAGS) \ + $(XFCONF_CFLAGS) \ + $(GTK_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(PLATFORM_CPPFLAGS) \ + $(PLATFORM_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ + $(UPOWER_CFLAGS) + +lxdebattery_la_LDFLAGS = \ + -avoid-version \ + -module \ + -no-undefined \ + $(PLATFORM_LDFLAGS) + +lxdebattery_la_LIBADD = \ + $(top_builddir)/common/libxfpmcommon.la \ + $(LXDEPANEL_LIBS) \ + $(LIBXFCE4UI_LIBS) \ + $(LIBXFCE4UTIL_LIBS) \ + $(XFCONF_LIBS) \ + $(GTK_LIBS) \ + $(GLIB_LIBS) \ + $(DBUS_GLIB_LIBS) \ + $(UPOWER_LIBS) diff --git a/panel-plugins/battery/lxde/battery-plugin.c b/panel-plugins/battery/lxde/battery-plugin.c new file mode 100644 index 00000000..d1f96444 --- /dev/null +++ b/panel-plugins/battery/lxde/battery-plugin.c @@ -0,0 +1,102 @@ +/* + * * Copyright (C) 2014 Eric Koegel <eric@xfce.org> + * + * Licensed under the GNU General Public License Version 2 + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <gtk/gtk.h> +#include <glib.h> +#include <glib/gi18n-lib.h> + +#include "../battery-button.h" + +/* plugin structure */ +typedef struct +{ + Plugin *plugin; + + /* panel widgets */ + GtkWidget *ebox; + GtkWidget *battery_button; +} +BatteryPlugin; + + +/* prototypes */ +static int battery_plugin_construct (Plugin *p, char **fp); + +PluginClass lxdebattery_plugin_class = { + PLUGINCLASS_VERSIONING, + type : "lxdebattery", + name : N_("Battery indicator plugin"), + version: PACKAGE_VERSION, + description : N_("Display the battery levels of your devices"), + one_per_system : FALSE, + expand_available : FALSE, + constructor : battery_plugin_construct, + destructor : NULL, + config : NULL, + save : NULL, + panel_configuration_changed : NULL +}; + + +static BatteryPlugin * +battery_plugin_new (Plugin *plugin) +{ + BatteryPlugin *battery_plugin; + + /* allocate memory for the plugin structure */ + battery_plugin = g_new0 (BatteryPlugin, 1); + + /* pointer to plugin */ + battery_plugin->plugin = plugin; + + /* create some panel ebox */ + battery_plugin->ebox = gtk_event_box_new (); + gtk_widget_show (battery_plugin->ebox); + gtk_event_box_set_visible_window (GTK_EVENT_BOX(battery_plugin->ebox), FALSE); + + battery_plugin->battery_button = battery_button_new (plugin); + battery_button_show(BATTERY_BUTTON(battery_plugin->battery_button)); + gtk_container_add (GTK_CONTAINER (battery_plugin->ebox), battery_plugin->battery_button); + + return battery_plugin; +} + + +static int +battery_plugin_construct (Plugin *plugin, char **fp) +{ + BatteryPlugin *battery_plugin; + + /* create the plugin */ + battery_plugin = battery_plugin_new (plugin); + + /* add the ebox to the panel */ + plugin->pwid = battery_plugin->ebox; + + return 1; +} diff --git a/panel-plugins/battery/xfce/Makefile.am b/panel-plugins/battery/xfce/Makefile.am new file mode 100644 index 00000000..0b191914 --- /dev/null +++ b/panel-plugins/battery/xfce/Makefile.am @@ -0,0 +1,72 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"xfce4-battery-plugin\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + $(PLATFORM_CPPFLAGS) + +# +# xfce4 battery plugin +# +plugin_LTLIBRARIES = \ + libxfce4battery.la + +plugindir = \ + $(libdir)/xfce4/panel/plugins + +libxfce4battery_la_SOURCES = \ + battery-plugin.c \ + ../battery-button.c \ + ../battery-button.h + +libxfce4battery_la_CFLAGS = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src \ + -DLOCALEDIR=\"$(localedir)\" \ + -DXFCE_PLUGIN \ + $(LIBXFCE4PANEL_CFLAGS) \ + $(LIBXFCE4UTIL_CFLAGS) \ + $(LIBXFCE4UI_CFLAGS) \ + $(XFCONF_CFLAGS) \ + $(GTK_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(PLATFORM_CPPFLAGS) \ + $(PLATFORM_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ + $(UPOWER_CFLAGS) + +libxfce4battery_la_LDFLAGS = \ + -avoid-version \ + -module \ + -no-undefined \ + -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \ + $(PLATFORM_LDFLAGS) + +libxfce4battery_la_LIBADD = \ + $(top_builddir)/common/libxfpmcommon.la \ + $(LIBXFCE4PANEL_LIBS) \ + $(LIBXFCE4UI_LIBS) \ + $(LIBXFCE4UTIL_LIBS) \ + $(XFCONF_LIBS) \ + $(GTK_LIBS) \ + $(GLIB_LIBS) \ + $(DBUS_GLIB_LIBS) \ + $(UPOWER_LIBS) + +# +# Desktop file +# +desktopdir = $(datadir)/xfce4/panel-plugins +desktop_in_in_files = xfce4-battery-plugin.desktop.in.in +desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in) +desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) +@INTLTOOL_DESKTOP_RULE@ + +EXTRA_DIST = \ + $(desktop_in_in_files) + +CLEANFILES = \ + $(desktop_in_files) \ + $(desktop_DATA) + +%.desktop.in: %.desktop.in.in + sed -e "s,\@libdir\@,$(libdir),g" < $< > $@ diff --git a/panel-plugins/battery/battery-plugin.c b/panel-plugins/battery/xfce/battery-plugin.c index 1cec1962..84cc5de7 100644 --- a/panel-plugins/battery/battery-plugin.c +++ b/panel-plugins/battery/xfce/battery-plugin.c @@ -28,11 +28,14 @@ #include <gtk/gtk.h> #include <glib.h> +#include <glib/gi18n-lib.h> +#ifdef XFCE_PLUGIN #include <libxfce4panel/libxfce4panel.h> #include <libxfce4panel/xfce-panel-plugin.h> +#endif -#include "battery-button.h" +#include "../battery-button.h" /* plugin structure */ typedef struct @@ -45,10 +48,9 @@ typedef struct } BatteryPlugin; + /* prototypes */ static void battery_plugin_construct (XfcePanelPlugin *plugin); - - /* register the plugin */ XFCE_PANEL_PLUGIN_REGISTER (battery_plugin_construct); @@ -64,9 +66,6 @@ battery_plugin_new (XfcePanelPlugin *plugin) /* pointer to plugin */ battery_plugin->plugin = plugin; - /* pointer to plugin */ - battery_plugin->plugin = plugin; - /* create some panel ebox */ battery_plugin->ebox = gtk_event_box_new (); gtk_widget_show (battery_plugin->ebox); diff --git a/panel-plugins/battery/xfce4-battery-plugin.desktop.in.in b/panel-plugins/battery/xfce/xfce4-battery-plugin.desktop.in.in index 48b7ba2c..48b7ba2c 100644 --- a/panel-plugins/battery/xfce4-battery-plugin.desktop.in.in +++ b/panel-plugins/battery/xfce/xfce4-battery-plugin.desktop.in.in |