This is an automated email from the git hooks/post-receive script. nomad pushed a commit to branch master in repository apps/xfdashboard.
commit aed3c5498ed73b8978d4fbd72fb705aaf31051c6 Author: Stephan Haller <no...@froevel.de> Date: Tue Jun 21 14:14:36 2016 +0200 Add new plugin 'middle-click-window-close' which (when enabled) allows the user to close windows in windows view with a middle click. This plugin is not configurable. This commit addresses GH #128 --- configure.ac.in | 1 + plugins/Makefile.am | 3 +- plugins/middle-click-window-close/Makefile.am | 52 ++++ .../middle-click-window-close.c | 316 +++++++++++++++++++++ .../middle-click-window-close.h | 67 +++++ plugins/middle-click-window-close/plugin.c | 82 ++++++ 6 files changed, 520 insertions(+), 1 deletion(-) diff --git a/configure.ac.in b/configure.ac.in index 79ff2c3..f12dd36 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -277,6 +277,7 @@ plugins/Makefile plugins/clock-view/Makefile plugins/gnome-shell-search-provider/Makefile plugins/hot-corner/Makefile +plugins/middle-click-window-close/Makefile po/Makefile.in settings/Makefile xfdashboard/Makefile diff --git a/plugins/Makefile.am b/plugins/Makefile.am index c2d91ab..fdde9a5 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,4 +1,5 @@ SUBDIRS = \ clock-view \ gnome-shell-search-provider \ - hot-corner \ No newline at end of file + hot-corner \ + middle-click-window-close diff --git a/plugins/middle-click-window-close/Makefile.am b/plugins/middle-click-window-close/Makefile.am new file mode 100644 index 0000000..f85fb11 --- /dev/null +++ b/plugins/middle-click-window-close/Makefile.am @@ -0,0 +1,52 @@ +plugindir = $(libdir)/xfdashboard/plugins +PLUGIN_ID = middle-click-window-close + +AM_CPPFLAGS = \ + -I$(top_builddir) \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"xfdashboard-plugin-middle_click_window_close\" \ + -DLIBEXECDIR=\"$(libexecdir)\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + -DPLUGIN_ID=\"$(PLUGIN_ID)\" + +plugin_LTLIBRARIES = \ + middle-click-window-close.la + +middle_click_window_close_la_SOURCES = \ + middle-click-window-close.c \ + middle-click-window-close.h \ + plugin.c + +middle_click_window_close_la_CFLAGS = \ + $(LIBXFCE4UTIL_CFLAGS) \ + $(GTK_CFLAGS) \ + $(CLUTTER_CFLAGS) \ + $(LIBXFCONF_CFLAGS) \ + $(GARCON_CFLAGS) \ + $(PLATFORM_CFLAGS) + +middle_click_window_close_la_LDFLAGS = \ + -avoid-version \ + -export-dynamic \ + -export-symbols-regex '^plugin_init$$' \ + -no-undefined \ + -module \ + -shared \ + $(PLATFORM_LDFLAGS) + +middle_click_window_close_la_LIBADD = \ + $(LIBXFCE4UTIL_LIBS) \ + $(GTK_LIBS) \ + $(CLUTTER_LIBS) \ + $(LIBXFCONF_LIBS) \ + $(GARCON_CLIBS) \ + $(top_builddir)/libxfdashboard/libxfdashboard.la + +CLEANFILES = \ + $(plugin_DATA) + +EXTRA_DIST = \ + $(plugin_DATA) + +DISTCLEANFILES = \ + $(plugin_DATA) diff --git a/plugins/middle-click-window-close/middle-click-window-close.c b/plugins/middle-click-window-close/middle-click-window-close.c new file mode 100644 index 0000000..ce89510 --- /dev/null +++ b/plugins/middle-click-window-close/middle-click-window-close.c @@ -0,0 +1,316 @@ +/* + * middle-click-window-close: Closes windows in window by middle-click + * + * Copyright 2012-2016 Stephan Haller <no...@froevel.de> + * + * 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 "middle-click-window-close.h" + +#include <libxfdashboard/libxfdashboard.h> +#include <glib/gi18n-lib.h> +#include <gtk/gtk.h> +#include <math.h> + + +/* Define this class in GObject system */ +G_DEFINE_DYNAMIC_TYPE(XfdashboardMiddleClickWindowClose, + xfdashboard_middle_click_window_close, + G_TYPE_OBJECT) + +/* Define this class in this plugin */ +XFDASHBOARD_DEFINE_PLUGIN_TYPE(xfdashboard_middle_click_window_close); + +/* Private structure - access only by public API if needed */ +#define XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE, XfdashboardMiddleClickWindowClosePrivate)) + +struct _XfdashboardMiddleClickWindowClosePrivate +{ + /* Instance related */ + XfdashboardStage *stage; + guint stageActorCreatedSignalID; + guint stageDestroySignalID; + + XfdashboardCssSelector *liveWindowSelector; +}; + + +/* IMPLEMENTATION: Private variables and methods */ +#define DEFAULT_WINDOW_CLOSE_BUTTON XFDASHBOARD_CLICK_ACTION_MIDDLE_BUTTON +#define XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_ACTION_NAME "middle-click-window-close-action" + +/* A configured live window actor was clicked */ +static void _xfdashboard_middle_click_window_close_on_clicked(XfdashboardMiddleClickWindowClose *self, + ClutterActor *inActor, + gpointer inUserData) +{ + XfdashboardLiveWindow *liveWindow; + XfdashboardClickAction *action; + guint button; + XfdashboardWindowTrackerWindow *window; + + g_return_if_fail(XFDASHBOARD_IS_MIDDLE_CLICK_WINDOW_CLOSE(self)); + g_return_if_fail(XFDASHBOARD_IS_LIVE_WINDOW(inActor)); + g_return_if_fail(XFDASHBOARD_IS_CLICK_ACTION(inUserData)); + + liveWindow=XFDASHBOARD_LIVE_WINDOW(inActor); + action=XFDASHBOARD_CLICK_ACTION(inUserData); + + /* Get button used for click action */ + button=xfdashboard_click_action_get_button(action); + if(button==DEFAULT_WINDOW_CLOSE_BUTTON) + { + window=xfdashboard_live_window_get_window(liveWindow); + xfdashboard_window_tracker_window_close(window); + } +} + +/* An actor was created so check if we are interested at this one */ +static void _xfdashboard_middle_click_window_close_on_actor_created(XfdashboardMiddleClickWindowClose *self, + ClutterActor *inActor, + gpointer inUserData) +{ + XfdashboardMiddleClickWindowClosePrivate *priv; + gint score; + ClutterAction *action; + + g_return_if_fail(XFDASHBOARD_IS_MIDDLE_CLICK_WINDOW_CLOSE(self)); + g_return_if_fail(CLUTTER_IS_ACTOR(inActor)); + + priv=self->priv; + + /* Check if we are interested in this newly created actor and set it up */ + if(XFDASHBOARD_IS_STYLABLE(inActor)) + { + score=xfdashboard_css_selector_score_matching_stylable_node(priv->liveWindowSelector, XFDASHBOARD_STYLABLE(inActor)); + if(score>0) + { + action=xfdashboard_click_action_new(); + clutter_actor_add_action_with_name(inActor, XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_ACTION_NAME, action); + g_signal_connect_swapped(action, "clicked", G_CALLBACK(_xfdashboard_middle_click_window_close_on_clicked), self); + } + } +} + +/* Callback for traversal to setup live window for use with this plugin */ +static gboolean _xfdashboard_middle_click_window_close_traverse_acquire(ClutterActor *inActor, + gpointer inUserData) +{ + XfdashboardMiddleClickWindowClose *self; + ClutterAction *action; + + g_return_val_if_fail(XFDASHBOARD_IS_LIVE_WINDOW(inActor), XFDASHBOARD_TRAVERSAL_CONTINUE); + g_return_val_if_fail(XFDASHBOARD_IS_MIDDLE_CLICK_WINDOW_CLOSE(inUserData), XFDASHBOARD_TRAVERSAL_CONTINUE); + + self=XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE(inUserData); + + /* Set up live window */ + action=xfdashboard_click_action_new(); + clutter_actor_add_action_with_name(inActor, XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_ACTION_NAME, action); + g_signal_connect_swapped(action, "clicked", G_CALLBACK(_xfdashboard_middle_click_window_close_on_clicked), self); + + /* All done continue with traversal */ + return(XFDASHBOARD_TRAVERSAL_CONTINUE); +} + +/* Callback for traversal to deconfigure live window from use at this plugin */ +static gboolean _xfdashboard_middle_click_window_close_traverse_release(ClutterActor *inActor, + gpointer inUserData) +{ + g_return_val_if_fail(XFDASHBOARD_IS_LIVE_WINDOW(inActor), XFDASHBOARD_TRAVERSAL_CONTINUE); + g_return_val_if_fail(XFDASHBOARD_IS_MIDDLE_CLICK_WINDOW_CLOSE(inUserData), XFDASHBOARD_TRAVERSAL_CONTINUE); + + /* Set up live window */ + clutter_actor_remove_action_by_name(inActor, XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_ACTION_NAME); + + /* All done continue with traversal */ + return(XFDASHBOARD_TRAVERSAL_CONTINUE); +} + +/* Stage is going to be destroyed */ +static void _xfdashboard_middle_click_window_close_on_stage_destroyed(XfdashboardMiddleClickWindowClose *self, + gpointer inUserData) +{ + XfdashboardMiddleClickWindowClosePrivate *priv; + XfdashboardStage *stage; + + g_return_if_fail(XFDASHBOARD_IS_MIDDLE_CLICK_WINDOW_CLOSE(self)); + g_return_if_fail(XFDASHBOARD_IS_STAGE(inUserData)); + + priv=self->priv; + stage=XFDASHBOARD_STAGE(inUserData); + + /* Iterate through all existing live window actors that may still exist + * and deconfigure them from use at this plugin. We traverse the stage + * which is going to be destroyed and provided as function parameter + * regardless if it the stage we have set up initially or if it is any other. + */ + xfdashboard_traverse_actor(CLUTTER_ACTOR(stage), + priv->liveWindowSelector, + _xfdashboard_middle_click_window_close_traverse_release, + self); + + /* Disconnect signals from stage as it will be destroyed and reset variables + * but only if it the stage we are handling right now (this should always be + * the case!) + */ + if(priv->stage==stage) + { + /* Disconnect signals */ + if(priv->stageActorCreatedSignalID) + { + g_signal_handler_disconnect(priv->stage, priv->stageActorCreatedSignalID); + priv->stageActorCreatedSignalID=0; + } + + if(priv->stageDestroySignalID) + { + g_signal_handler_disconnect(priv->stage, priv->stageDestroySignalID); + priv->stageDestroySignalID=0; + } + + /* Release stage */ + priv->stage=NULL; + } +} + +/* IMPLEMENTATION: GObject */ + +/* Dispose this object */ +static void _xfdashboard_middle_click_window_close_dispose(GObject *inObject) +{ + XfdashboardMiddleClickWindowClose *self=XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE(inObject); + XfdashboardMiddleClickWindowClosePrivate *priv=self->priv; + + /* Release allocated resources */ + if(priv->stage) + { + /* Iterate through all existing live window actors that may still exist + * and deconfigure them from use at this plugin. + */ + xfdashboard_traverse_actor(CLUTTER_ACTOR(priv->stage), + priv->liveWindowSelector, + _xfdashboard_middle_click_window_close_traverse_release, + self); + + /* Disconnect signals from stage */ + if(priv->stageActorCreatedSignalID) + { + g_signal_handler_disconnect(priv->stage, priv->stageActorCreatedSignalID); + priv->stageActorCreatedSignalID=0; + } + + if(priv->stageDestroySignalID) + { + g_signal_handler_disconnect(priv->stage, priv->stageDestroySignalID); + priv->stageDestroySignalID=0; + } + + /* Release stage */ + priv->stage=NULL; + } + + if(priv->liveWindowSelector) + { + g_object_unref(priv->liveWindowSelector); + priv->liveWindowSelector=NULL; + } + + /* Call parent's class dispose method */ + G_OBJECT_CLASS(xfdashboard_middle_click_window_close_parent_class)->dispose(inObject); +} + +/* Class initialization + * Override functions in parent classes and define properties + * and signals + */ +void xfdashboard_middle_click_window_close_class_init(XfdashboardMiddleClickWindowCloseClass *klass) +{ + GObjectClass *gobjectClass=G_OBJECT_CLASS(klass); + + /* Override functions */ + gobjectClass->dispose=_xfdashboard_middle_click_window_close_dispose; + + /* Set up private structure */ + g_type_class_add_private(klass, sizeof(XfdashboardMiddleClickWindowClosePrivate)); +} + +/* Class finalization */ +void xfdashboard_middle_click_window_close_class_finalize(XfdashboardMiddleClickWindowCloseClass *klass) +{ +} + +/* Object initialization + * Create private structure and set up default values + */ +void xfdashboard_middle_click_window_close_init(XfdashboardMiddleClickWindowClose *self) +{ + XfdashboardMiddleClickWindowClosePrivate *priv; + + self->priv=priv=XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_GET_PRIVATE(self); + + /* Set up default values */ + priv->stage=xfdashboard_application_get_stage(NULL); + priv->stageActorCreatedSignalID=0; + priv->stageDestroySignalID=0; + priv->liveWindowSelector=xfdashboard_css_selector_new_from_string("XfdashboardWindowsView XfdashboardLiveWindow"); + + /* Iterate through all already existing live window actors and configure + * them for use with this plugin. + */ + xfdashboard_traverse_actor(CLUTTER_ACTOR(priv->stage), + priv->liveWindowSelector, + _xfdashboard_middle_click_window_close_traverse_acquire, + self); + + /* Connect signal to get notified about actor creations and filter out + * and set up the ones we are interested in. + */ + priv->stageActorCreatedSignalID= + g_signal_connect_swapped(priv->stage, + "actor-created", + G_CALLBACK(_xfdashboard_middle_click_window_close_on_actor_created), + self); + + /* Connect signal to get notified when stage is getting destoyed */ + priv->stageDestroySignalID= + g_signal_connect_swapped(priv->stage, + "destroy", + G_CALLBACK(_xfdashboard_middle_click_window_close_on_stage_destroyed), + self); +} + + +/* IMPLEMENTATION: Public API */ + +/* Create new instance */ +XfdashboardMiddleClickWindowClose* xfdashboard_middle_click_window_close_new(void) +{ + GObject *middleClickWindowClose; + + middleClickWindowClose=g_object_new(XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE, NULL); + if(!middleClickWindowClose) return(NULL); + + return(XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE(middleClickWindowClose)); +} diff --git a/plugins/middle-click-window-close/middle-click-window-close.h b/plugins/middle-click-window-close/middle-click-window-close.h new file mode 100644 index 0000000..ab20653 --- /dev/null +++ b/plugins/middle-click-window-close/middle-click-window-close.h @@ -0,0 +1,67 @@ +/* + * middle-click-window-close: Closes windows in window by middle-click + * + * Copyright 2012-2016 Stephan Haller <no...@froevel.de> + * + * 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. + * + * + */ + +#ifndef __XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE__ +#define __XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE__ + +#include <libxfdashboard/libxfdashboard.h> + +G_BEGIN_DECLS + +#define XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE (xfdashboard_middle_click_window_close_get_type()) +#define XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE, XfdashboardMiddleClickWindowClose)) +#define XFDASHBOARD_IS_MIDDLE_CLICK_WINDOW_CLOSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE)) +#define XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE, XfdashboardMiddleClickWindowCloseClass)) +#define XFDASHBOARD_IS_MIDDLE_CLICK_WINDOW_CLOSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE)) +#define XFDASHBOARD_MIDDLE_CLICK_WINDOW_CLOSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XFDASHBOARD_TYPE_MIDDLE_CLICK_WINDOW_CLOSE, XfdashboardMiddleClickWindowCloseClass)) + +typedef struct _XfdashboardMiddleClickWindowClose XfdashboardMiddleClickWindowClose; +typedef struct _XfdashboardMiddleClickWindowClosePrivate XfdashboardMiddleClickWindowClosePrivate; +typedef struct _XfdashboardMiddleClickWindowCloseClass XfdashboardMiddleClickWindowCloseClass; + +struct _XfdashboardMiddleClickWindowClose +{ + /* Parent instance */ + GObject parent_instance; + + /* Private structure */ + XfdashboardMiddleClickWindowClosePrivate *priv; +}; + +struct _XfdashboardMiddleClickWindowCloseClass +{ + /*< private >*/ + /* Parent class */ + GObjectClass parent_class; +}; + +/* Public API */ +GType xfdashboard_middle_click_window_close_get_type(void) G_GNUC_CONST; + +XFDASHBOARD_DECLARE_PLUGIN_TYPE(xfdashboard_middle_click_window_close); + +XfdashboardMiddleClickWindowClose* xfdashboard_middle_click_window_close_new(void); + +G_END_DECLS + +#endif diff --git a/plugins/middle-click-window-close/plugin.c b/plugins/middle-click-window-close/plugin.c new file mode 100644 index 0000000..2c7a298 --- /dev/null +++ b/plugins/middle-click-window-close/plugin.c @@ -0,0 +1,82 @@ +/* + * plugin: Plugin functions for 'middle-click-window-close' + * + * Copyright 2012-2016 Stephan Haller <no...@froevel.de> + * + * 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 <libxfce4util/libxfce4util.h> +#include <gtk/gtk.h> + +#include "middle-click-window-close.h" + + +/* Forward declarations */ +G_MODULE_EXPORT void plugin_init(XfdashboardPlugin *self); + + +/* IMPLEMENTATION: XfdashboardPlugin */ + +static XfdashboardMiddleClickWindowClose *middleClickWindowClose=NULL; + +/* Plugin enable function */ +static void plugin_enable(XfdashboardPlugin *self, gpointer inUserData) +{ + /* Create instance of hot corner */ + if(!middleClickWindowClose) + { + middleClickWindowClose=xfdashboard_middle_click_window_close_new(); + } +} + +/* Plugin disable function */ +static void plugin_disable(XfdashboardPlugin *self, gpointer inUserData) +{ + /* Destroy instance of hot corner */ + if(middleClickWindowClose) + { + g_object_unref(middleClickWindowClose); + middleClickWindowClose=NULL; + } +} + +/* Plugin initialization function */ +G_MODULE_EXPORT void plugin_init(XfdashboardPlugin *self) +{ + /* Set up localization */ + xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); + + /* Set plugin info */ + xfdashboard_plugin_set_info(self, + "name", _("Middle-click window close"), + "description", _("Closes windows in windows view by middle-click"), + "author", "Stephan Haller <no...@froevel.de>", + NULL); + + /* Register GObject types of this plugin */ + XFDASHBOARD_REGISTER_PLUGIN_TYPE(self, xfdashboard_middle_click_window_close); + + /* Connect plugin action handlers */ + g_signal_connect(self, "enable", G_CALLBACK(plugin_enable), NULL); + g_signal_connect(self, "disable", G_CALLBACK(plugin_disable), NULL); +} -- To stop receiving notification emails like this one, please contact the administrator of this repository. _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits