From 06e525f797cc8104c77a59d5d9c62e27d7de9efc Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sun, 7 Sep 2014 17:46:59 +0300 Subject: [PATCH] Add support for lxpanel 0.7+ (Bug 11108) The LXPanel plugin API was completely changed in version 0.7.0 without any module versioning or backwards compatibility. This patch make the plugin work with the new version while retaining the ability to still build for the old version (based on checking the package version at compile time). --- configure.ac.in | 10 ++- panel-plugins/power-manager-plugin/Makefile.am | 17 ++-- .../power-manager-plugin/lxde-0.7/Makefile.am | 56 +++++++++++++ .../lxde-0.7/lxde-power-manager-plugin.c | 93 ++++++++++++++++++++++ .../lxde/lxde-power-manager-plugin.c | 2 +- .../power-manager-plugin/power-manager-button.c | 13 ++- .../power-manager-plugin/power-manager-button.h | 2 +- po/POTFILES.in | 1 + 8 files changed, 177 insertions(+), 17 deletions(-) create mode 100644 panel-plugins/power-manager-plugin/lxde-0.7/Makefile.am create mode 100644 panel-plugins/power-manager-plugin/lxde-0.7/lxde-power-manager-plugin.c diff --git a/configure.ac.in b/configure.ac.in index 1eb0b71..86d5331 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -67,6 +67,7 @@ m4_define([xfconf_minimum_version], [4.10.0]) m4_define([libxfce4ui_minimum_version],[4.11.1]) m4_define([libxfce4util_minimum_version],[4.10.0]) m4_define([libxfce4panel_minimum_version],[4.10.0]) +m4_define([lxdepanel_new_minimum_version],[0.7.0]) m4_define([lxdepanel_minimum_version],[0.5.6]) m4_define([libnotify_minimum_version], [0.4.1]) @@ -153,12 +154,16 @@ fi XDT_CHECK_OPTIONAL_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [libxfce4panel_minimum_version], [xfce4panel], [To build plugin support for Xfce's panel]) +XDT_CHECK_OPTIONAL_PACKAGE([LXDEPANEL_NEW], [lxpanel], [lxdepanel_new_minimum_version], +[lxdepanel],[To build plugin support for LXDE's panel]) + XDT_CHECK_OPTIONAL_PACKAGE([LXDEPANEL], [lxpanel], [lxdepanel_minimum_version], [lxdepanel],[To build plugin support for LXDE's panel]) AM_CONDITIONAL([BUILD_PANEL_PLUGINS], [test "x$build_panel_plugins" = "xyes"]) -AM_CONDITIONAL([BUILD_XFCE_PLUGINS], [test "x$LIBXFCE4PANEL_FOUND" = "xyes" && test "x$build_panel_plugins" = "xyes"]) -AM_CONDITIONAL([BUILD_LXDE_PLUGINS], [test "x$LXDEPANEL_FOUND" = "xyes" && test "x$build_panel_plugins" = "xyes"]) +AM_CONDITIONAL([BUILD_XFCE_PLUGIN], [test "x$LIBXFCE4PANEL_FOUND" = "xyes" && test "x$build_panel_plugins" = "xyes"]) +AM_CONDITIONAL([BUILD_LXDE_NEW_PLUGIN], [test "x$LXDEPANEL_NEW_FOUND" = "xyes" && test "x$build_panel_plugins" = "xyes"]) +AM_CONDITIONAL([BUILD_LXDE_OLD_PLUGIN], [test "x$LXDEPANEL_NEW_FOUND" != "xyes" && test "x$LXDEPANEL_FOUND" = "xyes" && test "x$build_panel_plugins" = "xyes"]) #=======================================================# @@ -225,6 +230,7 @@ src/Makefile settings/Makefile panel-plugins/Makefile panel-plugins/power-manager-plugin/Makefile +panel-plugins/power-manager-plugin/lxde-0.7/Makefile panel-plugins/power-manager-plugin/lxde/Makefile panel-plugins/power-manager-plugin/xfce/Makefile data/Makefile diff --git a/panel-plugins/power-manager-plugin/Makefile.am b/panel-plugins/power-manager-plugin/Makefile.am index f6094da..e737a38 100644 --- a/panel-plugins/power-manager-plugin/Makefile.am +++ b/panel-plugins/power-manager-plugin/Makefile.am @@ -1,12 +1,17 @@ -if BUILD_XFCE_PLUGINS +if BUILD_XFCE_PLUGIN xfce_dir = xfce endif -if BUILD_LXDE_PLUGINS -lxde_dir = lxde +if BUILD_LXDE_OLD_PLUGIN +lxde_old_dir = lxde endif -SUBDIRS = \ - $(xfce_dir) \ - $(lxde_dir) +if BUILD_LXDE_NEW_PLUGIN +lxde_new_dir = lxde-0.7 +endif + +SUBDIRS = \ + $(xfce_dir) \ + $(lxde_old_dir) \ + $(lxde_new_dir) diff --git a/panel-plugins/power-manager-plugin/lxde-0.7/Makefile.am b/panel-plugins/power-manager-plugin/lxde-0.7/Makefile.am new file mode 100644 index 0000000..0d5faaa --- /dev/null +++ b/panel-plugins/power-manager-plugin/lxde-0.7/Makefile.am @@ -0,0 +1,56 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"lxde-power-manager-plugin\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + $(PLATFORM_CPPFLAGS) + + +# +# lxde power manager plugin +# + +plugin_LTLIBRARIES = \ + lxde_power_manager.la + +plugindir = \ + $(libdir)/lxpanel/plugins + +lxde_power_manager_la_SOURCES = \ + lxde-power-manager-plugin.c \ + ../power-manager-button.c \ + ../power-manager-button.h \ + ../scalemenuitem.c \ + ../scalemenuitem.h + +lxde_power_manager_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) + +lxde_power_manager_la_LDFLAGS = \ + -avoid-version \ + -module \ + -no-undefined \ + $(PLATFORM_LDFLAGS) + +lxde_power_manager_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/power-manager-plugin/lxde-0.7/lxde-power-manager-plugin.c b/panel-plugins/power-manager-plugin/lxde-0.7/lxde-power-manager-plugin.c new file mode 100644 index 0000000..80868f0 --- /dev/null +++ b/panel-plugins/power-manager-plugin/lxde-0.7/lxde-power-manager-plugin.c @@ -0,0 +1,93 @@ +/* + * * Copyright (C) 2014 Eric Koegel + * + * 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 +#endif + +#include +#include +#include + +#include +#include +#include + + +#include "../power-manager-button.h" + +/* plugin structure */ +typedef struct +{ + LXPanel *panel; + + /* panel widgets */ + GtkWidget *ebox; + GtkWidget *power_manager_button; +} +PowerManagerPlugin; + + +/* prototypes */ +static GtkWidget * power_manager_plugin_construct (LXPanel *panel, config_setting_t *settings); + +/* register the plugin */ +FM_DEFINE_MODULE(lxpanel_gtk, power_manager_plugin); + +/* Plugin descriptor. */ +LXPanelPluginInit fm_module_init_lxpanel_gtk = { + .name = N_("Power Manager Plugin"), + .description = N_("Display the battery levels of your devices and control the brightness of your display"), + .new_instance = power_manager_plugin_construct +}; + +static GtkWidget * +power_manager_plugin_new (LXPanel *panel) +{ + PowerManagerPlugin *power_manager_plugin; + + /* allocate memory for the plugin structure */ + power_manager_plugin = g_new0 (PowerManagerPlugin, 1); + + /* pointer to panel */ + power_manager_plugin->panel = panel; + + /* create a panel ebox */ + power_manager_plugin->ebox = gtk_event_box_new (); + gtk_widget_show (power_manager_plugin->ebox); + gtk_event_box_set_visible_window (GTK_EVENT_BOX(power_manager_plugin->ebox), FALSE); + + power_manager_plugin->power_manager_button = power_manager_button_new (); + power_manager_button_show(POWER_MANAGER_BUTTON(power_manager_plugin->power_manager_button)); + gtk_container_add (GTK_CONTAINER (power_manager_plugin->ebox), power_manager_plugin->power_manager_button); + + /* bind the plugin structure to the widget */ + lxpanel_plugin_set_data(power_manager_plugin->ebox, power_manager_plugin, g_free); + + return power_manager_plugin->ebox; +} + + +static GtkWidget * +power_manager_plugin_construct (LXPanel *panel, config_setting_t *settings) +{ + /* create the plugin */ + return power_manager_plugin_new (panel); +} diff --git a/panel-plugins/power-manager-plugin/lxde/lxde-power-manager-plugin.c b/panel-plugins/power-manager-plugin/lxde/lxde-power-manager-plugin.c index d668333..eda2d62 100644 --- a/panel-plugins/power-manager-plugin/lxde/lxde-power-manager-plugin.c +++ b/panel-plugins/power-manager-plugin/lxde/lxde-power-manager-plugin.c @@ -80,7 +80,7 @@ lxde_power_manager_plugin_new (Plugin *plugin) gtk_widget_show (power_manager_plugin->ebox); gtk_event_box_set_visible_window (GTK_EVENT_BOX(power_manager_plugin->ebox), FALSE); - power_manager_plugin->power_manager_button = power_manager_button_new (plugin); + power_manager_plugin->power_manager_button = power_manager_button_new (); power_manager_button_show(POWER_MANAGER_BUTTON(power_manager_plugin->power_manager_button)); gtk_container_add (GTK_CONTAINER (power_manager_plugin->ebox), power_manager_plugin->power_manager_button); diff --git a/panel-plugins/power-manager-plugin/power-manager-button.c b/panel-plugins/power-manager-plugin/power-manager-button.c index 42ba3f8..6087701 100644 --- a/panel-plugins/power-manager-plugin/power-manager-button.c +++ b/panel-plugins/power-manager-plugin/power-manager-button.c @@ -54,9 +54,7 @@ struct PowerManagerButtonPrivate #ifdef XFCE_PLUGIN XfcePanelPlugin *plugin; #endif -#ifdef LXDE_PLUGIN - Plugin *plugin; -#endif + XfconfChannel *channel; UpClient *upower; @@ -797,7 +795,7 @@ GtkWidget * power_manager_button_new (XfcePanelPlugin *plugin) #endif #ifdef LXDE_PLUGIN -power_manager_button_new (Plugin *plugin) +power_manager_button_new (void) #endif { PowerManagerButton *button = NULL; @@ -806,9 +804,6 @@ power_manager_button_new (Plugin *plugin) #ifdef XFCE_PLUGIN button->priv->plugin = XFCE_PANEL_PLUGIN (g_object_ref (plugin)); #endif -#ifdef LXDE_PLUGIN - button->priv->plugin = plugin; -#endif xfconf_g_property_bind(button->priv->channel, PROPERTIES_PREFIX BRIGHTNESS_SLIDER_MIN_LEVEL, G_TYPE_INT, @@ -1261,7 +1256,11 @@ power_manager_button_show_menu (PowerManagerButton *button) #else NULL, #endif +#ifdef XFCE_PLUGIN button->priv->plugin, +#else + NULL, +#endif 0, gtk_get_current_event_time ()); } diff --git a/panel-plugins/power-manager-plugin/power-manager-button.h b/panel-plugins/power-manager-plugin/power-manager-button.h index 8ba10c7..0ae1368 100644 --- a/panel-plugins/power-manager-plugin/power-manager-button.h +++ b/panel-plugins/power-manager-plugin/power-manager-button.h @@ -57,7 +57,7 @@ GType power_manager_button_get_type (void) G_GNUC_CONST; GtkWidget *power_manager_button_new (XfcePanelPlugin *plugin); #endif #ifdef LXDE_PLUGIN -GtkWidget *power_manager_button_new (Plugin *plugin); +GtkWidget *power_manager_button_new (void); #endif void power_manager_button_show (PowerManagerButton *button); diff --git a/po/POTFILES.in b/po/POTFILES.in index 785b872..8c8a68d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -22,6 +22,7 @@ src/org.xfce.power.policy.in2 panel-plugins/power-manager-plugin/power-manager-button.c panel-plugins/power-manager-plugin/scalemenuitem.c panel-plugins/power-manager-plugin/lxde/lxde-power-manager-plugin.c +panel-plugins/power-manager-plugin/lxde-0.7/lxde-power-manager-plugin.c panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c panel-plugins/power-manager-plugin/xfce/power-manager-plugin.desktop.in.in data/appdata/xfce4-power-manager.appdata.xml.in -- 2.1.0