From 93c74d707fb50f24834dc316e5075ec4f06d34b1 Mon Sep 17 00:00:00 2001 From: Vadim Ushakov Date: Fri, 3 May 2013 01:35:34 +0800 Subject: [PATCH 1/3] Add support of lxpanelx --- lxpanelx/Makefile.am | 42 ++++ lxpanelx/lxpanelx-multiload-plugin.c | 318 +++++++++++++++++++++++++++ 2 files changed, 360 insertions(+) create mode 100644 lxpanelx/Makefile.am create mode 100644 lxpanelx/lxpanelx-multiload-plugin.c diff --git a/lxpanelx/Makefile.am b/lxpanelx/Makefile.am new file mode 100644 index 0000000..72cbfc2 --- /dev/null +++ b/lxpanelx/Makefile.am @@ -0,0 +1,42 @@ +# INCLUDES = +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/multiload \ + -DG_LOG_DOMAIN=\"lxpanelx-multiload-plugin\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + $(PLATFORM_CPPFLAGS) + +# +# multiload plugin +# +plugin_LTLIBRARIES = \ + multiload.la + +plugindir = \ + $(libdir)/lxpanelx/plugins + +multiload_la_SOURCES = \ + ../about-data.h \ + lxpanelx-multiload-plugin.c +# xfce4-multiload-plugin.h +# xfce4-multiload-dialogs.c xfce4-multiload-dialogs.h +# xfce4-multiload-settings.c xfce4-multiload-settings.h + +multiload_la_CFLAGS = \ + $(GTK_CFLAGS) \ + $(LXPANELX_CFLAGS) + +multiload_la_LDFLAGS = \ + -avoid-version \ + -module \ + -no-undefined \ + $(PLATFORM_LDFLAGS) + +# export-symbols-regex '^multiload_(constructor|destructor|configure|save_configuration|configuration_changed)' + +multiload_la_LIBADD = \ + $(GTK_LIBS) \ + $(LXPANELXX_LIBS) \ + ../multiload/multiload-core.la + +# vi:set ts=8 sw=8 noet ai nocindent syntax=automake: diff --git a/lxpanelx/lxpanelx-multiload-plugin.c b/lxpanelx/lxpanelx-multiload-plugin.c new file mode 100644 index 0000000..3a86d21 --- /dev/null +++ b/lxpanelx/lxpanelx-multiload-plugin.c @@ -0,0 +1,318 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#define PLUGIN_PRIV_TYPE MultiloadLxpanelPlugin + +#include +#include +#include + +#include +#include +#include + +#include "multiload/multiload.h" +#include "multiload/properties.h" + +/** BEGIN H **/ +typedef struct _MultiloadLxpanelPlugin MultiloadLxpanelPlugin; + +/* an instance of this struct is what will be assigned to 'priv' */ +struct _MultiloadLxpanelPlugin +{ + MultiloadPlugin ma; + GtkWidget *dlg; +}; +/** END H **/ + +static void +multiload_read(char **fp, MultiloadPlugin *ma) +{ + guint i, found = 0; + + /* Initial settings */ + ma->speed = 0; + ma->size = 0; + for ( i = 0; i < NGRAPHS; i++ ) + { + /* Default visibility and colors */ + ma->graph_config[i].visible = FALSE; + multiload_colorconfig_default(ma, i); + } + + if ( fp != NULL ) + { + line s; + while ( lxpanel_get_line(fp, &s) != LINE_BLOCK_END ) + { + if ( s.type == LINE_VAR ) + { + if ( g_ascii_strcasecmp(s.t[0], "speed") == 0 ) + ma->speed = atoi(s.t[1]); + else if ( g_ascii_strcasecmp(s.t[0], "size") == 0 ) + ma->size = atoi(s.t[1]); + else + { + const char *suffix; /* Set by multiload_find_graph_by_name */ + int i = multiload_find_graph_by_name(s.t[0], &suffix); + + if ( suffix == NULL || i < 0 || i >= NGRAPHS ) + continue; + else if ( g_ascii_strcasecmp(suffix, "Visible") == 0 ) + ma->graph_config[i].visible = atoi(s.t[1]) ? TRUE : FALSE; + else if ( g_ascii_strcasecmp(suffix, "Colors") == 0 ) + multiload_colorconfig_unstringify(ma, i, s.t[1]); + } + } + else + { + ERR ("Failed to parse config token %s\n", s.str); + break; + } + } + } + + /* Handle errors from atoi */ + if ( ma->speed == 0 ) + ma->speed = DEFAULT_SPEED; + if ( ma->size == 0 ) + ma->size = DEFAULT_SIZE; + /* Ensure at lease one graph is visible */ + for ( i = 0; i < NGRAPHS; i++ ) + if ( ma->graph_config[i].visible == TRUE ) + found++; + if ( found == 0 ) + ma->graph_config[0].visible = TRUE; +} + +static void multiload_save_configuration(Plugin * p, FILE * fp) +{ + MultiloadLxpanelPlugin *multiload = PRIV(p); + MultiloadPlugin *ma = &multiload->ma; + guint i; + + /* Write size and speed */ + lxpanel_put_int (fp, "speed", ma->speed); + lxpanel_put_int (fp, "size", ma->size); + + for ( i = 0; i < NGRAPHS; i++ ) + { + char *key, list[8*MAX_COLORS]; + + /* Visibility */ + key = g_strdup_printf("%sVisible", graph_types[i].name); + lxpanel_put_int (fp, key, ma->graph_config[i].visible); + g_free (key); + + /* Save colors */ + multiload_colorconfig_stringify (ma, i, list); + key = g_strdup_printf("%sColors", graph_types[i].name); + lxpanel_put_str(fp, key, list); + g_free (key); + } +} + +static void multiload_panel_configuration_changed(Plugin *p) +{ + MultiloadLxpanelPlugin *multiload = PRIV(p); + + /* Determine orientation and size */ + GtkOrientation orientation = + (plugin_get_orientation(p) == GTK_ORIENTATION_VERTICAL) ? + GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; +/* int size = (orientation == GTK_ORIENTATION_VERTICAL) ? + p->panel->width : p->panel->height; +*/ + int size = panel_get_oriented_height_pixels(plugin_panel(p)); + if ( orientation == GTK_ORIENTATION_HORIZONTAL ) + gtk_widget_set_size_request (plugin_widget(p), -1, size); + else + gtk_widget_set_size_request (plugin_widget(p), size, -1); + + /* Refresh the panel applet */ + multiload_refresh(&(multiload->ma), orientation); +} + +static gboolean +multiload_press_event(GtkWidget *pwid, GdkEventButton *event, Plugin *p) +{ + /* Standard right-click handling. */ + if (plugin_button_press_event(pwid, event, p)) + return TRUE; + + if (event->button == 1) /* left button */ + { + /* Launch system monitor */ + } + return TRUE; +} + +static int +multiload_constructor(Plugin *p, char **fp) +{ + /* allocate our private structure instance */ + MultiloadLxpanelPlugin *multiload = g_new0(MultiloadLxpanelPlugin, 1); + plugin_set_priv(p, multiload); + + /* Initialize multiload */ + multiload_init (); + multiload->dlg = NULL; + + /* read the user settings */ + multiload_read (fp, &multiload->ma); + + /* create a container widget */ + plugin_set_widget(p, gtk_event_box_new()); + gtk_widget_show (plugin_widget(p)); + + /* Initialize the applet */ + multiload->ma.container = GTK_CONTAINER(plugin_widget(p)); + /* Set size request and update orientation */ + multiload_panel_configuration_changed(p); + + g_signal_connect(plugin_widget(p), "button-press-event", + G_CALLBACK(multiload_press_event), p); + /* FIXME: No way to add system monitor item to menu? */ + + return 1; +} + +static void +multiload_destructor(Plugin * p) +{ + /* find our private structure instance */ + MultiloadLxpanelPlugin *multiload = PRIV(p); + + /* Destroy dialog */ + if ( multiload->dlg ) + { + gtk_widget_destroy (multiload->dlg); + multiload->dlg = NULL; + } + + /* free private data. Panel will free pwid for us. */ + g_free(multiload); +} + +static void +multiload_configure_response (GtkWidget *dialog, + gint response, + MultiloadLxpanelPlugin *multiload) +{ + gboolean result; + + if (response == GTK_RESPONSE_HELP) + { + /* show help */ + /* FIXME: Not all common versions of xdg-open support lxde -2012-06-25 */ + result = g_spawn_command_line_async ("xdg-open --launch WebBrowser " + PLUGIN_WEBSITE, NULL); + + if (G_UNLIKELY (result == FALSE)) + g_warning (_("Unable to open the following url: %s"), PLUGIN_WEBSITE); + } + else + { + /* destroy the properties dialog */ + gtk_widget_destroy (multiload->dlg); + multiload->dlg = NULL; + } +} + +/* Lookup the MultiloadPlugin object from the preferences dialog. */ +/* Called from multiload/properties.c */ +MultiloadPlugin * +multiload_configure_get_plugin (GtkWidget *widget) +{ + GtkWidget *toplevel = gtk_widget_get_toplevel (widget); + MultiloadPlugin *ma = NULL; + if ( G_LIKELY (gtk_widget_is_toplevel (toplevel)) ) + ma = g_object_get_data(G_OBJECT(toplevel), "MultiloadPlugin"); + else + g_assert_not_reached (); + g_assert( ma != NULL); + return ma; +} + +static void multiload_configure(Plugin * p, GtkWindow * parent) +{ + GtkWidget *dialog; + MultiloadLxpanelPlugin *multiload = PRIV(p); + if ( multiload->dlg != NULL ) + { + gtk_widget_show_all (multiload->dlg); + gtk_window_present (GTK_WINDOW (multiload->dlg)); + return; + } + + /* create the dialog */ + multiload->dlg = gtk_dialog_new_with_buttons + (_("Multiload"), + parent, + GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_HELP, GTK_RESPONSE_HELP, + GTK_STOCK_CLOSE, GTK_RESPONSE_OK, + NULL); + dialog = multiload->dlg; + + /* center dialog on the screen */ + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); + + /* set dialog icon */ + gtk_window_set_icon_name (GTK_WINDOW (dialog), + "utilities-system-monitor"); + + /* link the dialog to the plugin, so we can destroy it when the plugin + * is closed, but the dialog is still open */ + g_object_set_data (G_OBJECT (dialog), + "MultiloadPlugin", &multiload->ma); + + /* Initialize dialog widgets */ + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + multiload_init_preferences(dialog, &multiload->ma); + + /* connect the reponse signal to the dialog */ + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK(multiload_configure_response), multiload); + + /* Magic incantation from lxpanel/src/plugins/launchbar.c */ + /* Establish a callback when the dialog completes. */ + g_object_weak_ref(G_OBJECT(dialog), (GWeakNotify) plugin_save_configuration, p); + + /* show the entire dialog */ + gtk_widget_show_all (dialog); +} + +/* Plugin descriptor. */ +PluginClass multiload_plugin_class = { + + // this is a #define taking care of the size/version variables + PLUGINCLASS_VERSIONING, + + // type of this plugin + type : "multiload", + name : N_("Multiload"), + version: PACKAGE_VERSION, + description : N_("A system load monitor that graphs processor, memory, " + "and swap space use, plus network and disk activity."), + + // we can have many running at the same time + one_per_system : FALSE, + + // can't expand this plugin + expand_available : FALSE, + + // assigning our functions to provided pointers. + constructor : multiload_constructor, + destructor : multiload_destructor, + config : multiload_configure, + save : multiload_save_configuration, + panel_configuration_changed : multiload_panel_configuration_changed +}; + From e5cb88a11a30dfc86c8e15c189177cc58735b04a Mon Sep 17 00:00:00 2001 From: Vadim Ushakov Date: Fri, 3 May 2013 02:08:18 +0800 Subject: [PATCH 2/3] fix prev commit --- Makefile.am | 4 ++++ configure.ac | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 8b9cb7c..dae0766 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,10 +4,14 @@ endif if HAVE_LXPANEL LXPANEL_DIRS = lxpanel endif +if HAVE_LXPANELX +LXPANELX_DIRS = lxpanelx +endif SUBDIRS = \ multiload \ $(XFCE4_DIRS) \ $(LXPANEL_DIRS) \ + $(LXPANELX_DIRS) \ po distclean-local: diff --git a/configure.ac b/configure.ac index ac35b5c..a3db8bb 100644 --- a/configure.ac +++ b/configure.ac @@ -121,7 +121,30 @@ AM_CONDITIONAL(HAVE_LXPANEL, test x$with_lxpanel = xyes) AC_SUBST(LXPANEL_CFLAGS) AC_SUBST(LXPANEL_LIBS) -if test x$with_xfce4 != xyes && test x$with_lxpanel != xyes; then +# lxpanelx +AC_ARG_WITH([lxpanelx], AS_HELP_STRING([--with-lxpanelx], [Build plugin for lxpanelx]), + [], [with_lxpanelx=check]) +AS_IF([test "x$with_lxpanelx" != "xno"], [ + pkg_modules="lxpanelx" + # libmenu-cache is implicitly required; we will fail if it's not present. + PKG_CHECK_MODULES(LXPANELX, [$pkg_modules], + [ + AC_DEFINE([HAVE_LXPANELX], [1], [Support for lxpanelx]) + with_lxpanelx=yes + ],[ + if test "x$with_lxpanelx" != xcheck; then + AC_MSG_FAILURE( + [--with-lxpanelx was given, but test failed]) + fi + with_lxpanelx=no + ]) +]) +AM_CONDITIONAL(HAVE_LXPANELX, test x$with_lxpanelx = xyes) +AC_SUBST(LXPANELX_CFLAGS) +AC_SUBST(LXPANELX_LIBS) + + +if test x$with_xfce4 != xyes && test x$with_lxpanel != xyes && test x$with_lxpanelx != xyes; then AC_MSG_FAILURE([No supported panels are installed and available.]) fi @@ -146,6 +169,7 @@ AC_CONFIG_FILES([ xfce4/Makefile xfce4/multiload.desktop.in lxpanel/Makefile + lxpanelx/Makefile po/Makefile.in ]) AC_OUTPUT @@ -157,3 +181,6 @@ echo "* xfce4-panel : $with_xfce4" echo echo "* lxpanel : $with_lxpanel" echo +echo "* lxpanelx : $with_lxpanelx" +echo +#echo "LXPANELX_CFLAGS $LXPANELX_CFLAGS" \ No newline at end of file From dabd363b1b72ab68b2c7af129f9643b60fd9b9fc Mon Sep 17 00:00:00 2001 From: Vadim Ushakov Date: Fri, 3 May 2013 02:14:26 +0800 Subject: [PATCH 3/3] fix "ERROR: end of file in comment" in configure.ac --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a3db8bb..ed5e230 100644 --- a/configure.ac +++ b/configure.ac @@ -183,4 +183,4 @@ echo "* lxpanel : $with_lxpanel" echo echo "* lxpanelx : $with_lxpanelx" echo -#echo "LXPANELX_CFLAGS $LXPANELX_CFLAGS" \ No newline at end of file +#echo "LXPANELX_CFLAGS $LXPANELX_CFLAGS"