diff options
| -rw-r--r-- | .gitignore | 29 | ||||
| -rw-r--r-- | Makefile.am | 24 | ||||
| -rw-r--r-- | README | 1 | ||||
| -rwxr-xr-x | autogen.sh | 35 | ||||
| -rw-r--r-- | configure.ac.in | 111 | ||||
| -rw-r--r-- | panel-plugin/Makefile.am | 49 | ||||
| -rw-r--r-- | panel-plugin/title.c | 230 | ||||
| -rw-r--r-- | panel-plugin/title.desktop | 10 |
8 files changed, 489 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27bdee9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +*.gmo +*.la +*.lo +*.swp +*.tar.* +.deps +.libs +ChangeLog +INSTALL +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +compile +config* +depcomp +install-sh +intltool* +libtool +ltmain.sh +missing +mkinstalldirs +panel-plugin/*.desktop +panel-plugin/*.desktop.in +po/.intltool-merge-cache +po/Makefile.in.in +po/POTFILES +stamp-* +m4 diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..cd4ae16 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,24 @@ +@SET_MAKE@ + +AUTOMAKE_OPTIONS = subdir-objects +ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} + +SUBDIRS = panel-plugin + +distclean-local: + rm -rf *.cache *~ + +rpm: dist + rpmbuild -ta $(PACKAGE)-$(VERSION).tar.gz + @rm -f $(PACKAGE)-$(VERSION).tar.gz + +.PHONY: ChangeLog + +ChangeLog: Makefile + (GIT_DIR=$(top_srcdir)/.git git log > .changelog.tmp \ + && mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) \ + || (touch ChangeLog; echo 'Git directory not found: installing possibly empty changelog.' >&2) + +dist-hook: ChangeLog + +# vi:set ts=8 sw=8 noet ai nocindent syntax=automake: @@ -0,0 +1 @@ +Xfce4 Title Plugin diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..a600069 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# +# Copyright (c) 2002-2017 The Xfce development team. All rights reserved. +# +# This library 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 library 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 Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Written for Xfce by Benedikt Meurer <benny@xfce.org>. +# + +(type xdt-autogen) >/dev/null 2>&1 || { + cat >&2 <<EOF +autogen.sh: You don't seem to have the Xfce development tools installed on + your system, which are required to build this software. + Please install the xfce4-dev-tools package first, it is available + from https://www.xfce.org/. +EOF + exit 1 +} + +test -d m4 || mkdir m4 + +XDT_AUTOGEN_REQUIRED_VERSION="4.9.1" \ +exec xdt-autogen $@ diff --git a/configure.ac.in b/configure.ac.in new file mode 100644 index 0000000..6ebe17d --- /dev/null +++ b/configure.ac.in @@ -0,0 +1,111 @@ +dnl +dnl xfce4-title-plugin - A title plugin for the Xfce panel +dnl +dnl 2020 Mikhail Osipov <mike.osipov@gmail.com> +dnl + +dnl *************************** +dnl *** Version information *** +dnl *************************** +m4_define([title_version_major], [0]) +m4_define([title_version_minor], [0]) +m4_define([title_version_micro], [3]) +m4_define([title_version_nano], []) dnl leave this empty to have no nano version +m4_define([title_version_build], [@REVISION@]) +m4_define([title_version_tag], [git]) +m4_define([title_version], [title_version_major().title_version_minor().title_version_micro()ifelse(title_version_nano(), [], [], [.title_version_nano()])ifelse(title_version_tag(), [git], [title_version_tag()-title_version_build()], [title_version_tag()])]) +m4_define([title_default_debug], [ifelse(title_version_tag(), [git], [yes], [minimum])]) + +AC_CONFIG_MACRO_DIR([m4]) +dnl *************************** +dnl *** Initialize autoconf *** +dnl *************************** +AC_COPYRIGHT([Copyright (C) 2020 + The Xfce development team. All rights reserved.]) +AC_INIT([xfce4-title-plugin], [title_version], [https://gitlab.xfce.org/panel-plugins/xfce4-title-plugin], [xfce4-title-plugin]) +AC_PREREQ([2.50]) +AC_REVISION([xfce4_panel_version_build]) + +dnl *************************** +dnl *** Initialize automake *** +dnl *************************** +AM_INIT_AUTOMAKE([1.15 no-dist-gzip dist-bzip2 tar-ustar foreign]) +AC_CONFIG_HEADER([config.h]) +AM_MAINTAINER_MODE() +AM_SILENT_RULES([yes]) + +dnl ************************** +dnl *** Initialize libtool *** +dnl ************************** +LT_PREREQ([2.2.6]) +LT_INIT([disable-static]) + +dnl ******************************** +dnl *** Check for basic programs *** +dnl ******************************** +AC_PROG_CC() +AC_PROG_CC_C_O() +AC_PROG_LD() +AC_PROG_INSTALL() + +dnl ********************************** +dnl *** Check for standard headers *** +dnl ********************************** +AC_HEADER_STDC() +AC_CHECK_HEADERS([stdlib.h unistd.h locale.h stdio.h errno.h time.h string.h \ + math.h sys/types.h sys/wait.h memory.h signal.h sys/prctl.h \ + libintl.h]) +AC_CHECK_FUNCS([bind_textdomain_codeset]) + +dnl ****************************** +dnl *** Check for i18n support *** +dnl ****************************** +XDT_I18N([@LINGUAS@]) + +dnl ******************************* +dnl *** Check for X11 installed *** +dnl ******************************* +XDT_CHECK_LIBX11_REQUIRE() + +dnl *********************************** +dnl *** Check for required packages *** +dnl *********************************** +XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-2], [4.14.0]) +XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-2.0], [4.14.0]) +XDT_CHECK_PACKAGE([LIBWNCK], [libwnck-3.0], [3.0]) + +dnl *********************************** +dnl *** Check for debugging support *** +dnl *********************************** +XDT_FEATURE_DEBUG([title_default_debug]) + +dnl ********************************* +dnl *** Substitute platform flags *** +dnl ********************************* +AC_MSG_CHECKING([PLATFORM_CPPFLAGS]) +AC_MSG_RESULT([$PLATFORM_CPPFLAGS]) +AC_SUBST([PLATFORM_CPPFLAGS]) +AC_MSG_CHECKING([PLATFORM_CFLAGS]) +AC_MSG_RESULT([$PLATFORM_CFLAGS]) +AC_SUBST([PLATFORM_CFLAGS]) +AC_MSG_CHECKING([PLATFORM_LDFLAGS]) +AC_MSG_RESULT([$PLATFORM_LDFLAGS]) +AC_SUBST([PLATFORM_LDFLAGS]) + +AC_CONFIG_FILES([ +Makefile +icons/Makefile +icons/48x48/Makefile +icons/scalable/Makefile +panel-plugin/Makefile +]) +AC_OUTPUT + +dnl *************************** +dnl *** Print configuration *** +dnl *************************** +echo +echo "Build Configuration:" +echo +echo "* Debug Support: $enable_debug" +echo diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am new file mode 100644 index 0000000..fe8fc8a --- /dev/null +++ b/panel-plugin/Makefile.am @@ -0,0 +1,49 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"xfce4-title-plugin\" \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + -DWNCK_I_KNOW_THIS_IS_UNSTABLE \ + $(PLATFORM_CPPFLAGS) + +# +# Title plugin +# +plugin_LTLIBRARIES = \ + libtitle.la + +plugindir = \ + $(libdir)/xfce4/panel/plugins + +libtitle_la_SOURCES = \ + title.c + +libtitle_la_CFLAGS = \ + $(LIBXFCE4UTIL_CFLAGS) \ + $(LIBXFCE4UI_CFLAGS) \ + $(LIBXFCE4PANEL_CFLAGS) \ + $(LIBWNCK_CFLAGS) \ + $(PLATFORM_CFLAGS) + +libtitle_la_LDFLAGS = \ + -avoid-version \ + -module \ + -no-undefined \ + -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \ + $(PLATFORM_LDFLAGS) + +libtitle_la_LIBADD = \ + $(LIBXFCE4UTIL_LIBS) \ + $(LIBXFCE4UI_LIBS) \ + $(LIBWNCK_LIBS) \ + $(LIBXFCE4PANEL_LIBS) + +# +# Desktop file +# +desktopdir = \ + $(datadir)/xfce4/panel/plugins + +desktop_DATA = \ + title.desktop + +# vi:set ts=8 sw=8 noet ai nocindent syntax=automake: diff --git a/panel-plugin/title.c b/panel-plugin/title.c new file mode 100644 index 0000000..2252271 --- /dev/null +++ b/panel-plugin/title.c @@ -0,0 +1,230 @@ +#include <gtk/gtk.h> + +#include <libxfce4panel/xfce-panel-plugin.h> +#include <libxfce4panel/libxfce4panel.h> + +#include <libwnck/libwnck.h> + +#include <glib.h> +#include <glib-object.h> + +typedef struct { + XfcePanelPlugin *plugin; + + GtkWidget *button; + GtkWidget *label; + GtkWidget *menu; + + WnckScreen *screen; + WnckWindow *window; + + gint screen_id; + gint wnck_screen_id; + gint wnck_window_id; +} TitlePlugin; + +static void title_construct(XfcePanelPlugin *plugin); + +XFCE_PANEL_PLUGIN_REGISTER(title_construct); + +static void title_free(XfcePanelPlugin *plugin, TitlePlugin *title) +{ + if (title->screen_id != 0) + g_signal_handler_disconnect(plugin, title->screen_id); + + if (title->wnck_screen_id != 0) + g_signal_handler_disconnect(title->screen, title->wnck_screen_id); + + if (title->wnck_window_id != 0) + g_signal_handler_disconnect(title->window, title->wnck_window_id); + + if (title->menu != NULL) + gtk_widget_destroy(title->menu); + + title->screen_id = 0; + title->wnck_screen_id = 0; + title->wnck_window_id = 0; + + gtk_widget_destroy(title->button); + panel_slice_free(TitlePlugin, title); +} + +static gboolean title_size_changed(XfcePanelPlugin *plugin, + gint size, + G_GNUC_UNUSED TitlePlugin *title) +{ + GtkOrientation orientation; + + orientation = xfce_panel_plugin_get_orientation(plugin); + + if (orientation == GTK_ORIENTATION_HORIZONTAL) + gtk_widget_set_size_request(GTK_WIDGET(plugin), -1, size); + else + gtk_widget_set_size_request(GTK_WIDGET(plugin), size, -1); + + return TRUE; +} + +static void title_update_label(TitlePlugin *title, const char *label) +{ + gtk_label_set_label(GTK_LABEL(title->label), label); + gtk_widget_set_tooltip_text(title->button, label); +} + +static void title_window_name_changed(WnckWindow *window, + TitlePlugin *title) +{ + const gchar *name = wnck_window_get_name(window); + title_update_label(title, name); +} + +static int title_check_type(WnckWindow *window) +{ + WnckWindowType type = wnck_window_get_window_type(window); + + switch (type) { + case WNCK_WINDOW_NORMAL: + case WNCK_WINDOW_DIALOG: + return 0; + + default: + break; + } + + return 1; +} + +static void title_window_changed(WnckScreen *screen, + G_GNUC_UNUSED WnckWindow *window_, + TitlePlugin *title) +{ + WnckWindow *window; + const gchar *name = NULL; + + if (title->wnck_window_id != 0) { + g_signal_handler_disconnect(title->window, title->wnck_window_id); + title->wnck_window_id = 0; + title->window = NULL; + } + + window = wnck_screen_get_active_window(screen); + + if (window == NULL || title_check_type(window)) + gtk_widget_hide(title->button); + else { + title->window = window; + + name = wnck_window_get_name(window); + + title->wnck_window_id = g_signal_connect( + window, "name-changed", + G_CALLBACK(title_window_name_changed), title + ); + + gtk_widget_show(title->button); + } + + title_update_label(title, name); +} + +static void title_screen_changed(XfcePanelPlugin *plugin, + GdkScreen *screen, + TitlePlugin *title) +{ + if (title->wnck_screen_id != 0) { + g_signal_handler_disconnect(title->screen, title->wnck_screen_id); + title->wnck_screen_id = 0; + } + + if (title->wnck_window_id != 0) { + g_signal_handler_disconnect(title->window, title->wnck_window_id); + title->wnck_window_id = 0; + title->window = NULL; + } + + screen = gtk_widget_get_screen(GTK_WIDGET(plugin)); + if (screen != NULL) { + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + title->screen = wnck_screen_get(gdk_screen_get_number(screen)); + G_GNUC_END_IGNORE_DEPRECATIONS + + title->wnck_screen_id = g_signal_connect( + title->screen, "active-window-changed", + G_CALLBACK(title_window_changed), title + ); + + title_window_changed(title->screen, NULL, title); + } +} + +static void title_menu_destroy(GtkWidget *menu, TitlePlugin *title) +{ + gtk_widget_destroy(menu); + title->menu = NULL; +} + +static void title_pressed(GtkButton *button, TitlePlugin *title) +{ + if (title->menu != NULL) + gtk_widget_destroy(title->menu); + + if (title->window != NULL) { + GtkWidget *menu = wnck_action_menu_new(title->window); + + title->menu = menu; + + g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(title_menu_destroy), title); + gtk_menu_attach_to_widget(GTK_MENU(menu), GTK_WIDGET(button), NULL); + gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL); + } +} + +static TitlePlugin *title_new(XfcePanelPlugin *plugin) +{ + TitlePlugin *title; + + title = g_slice_new0(TitlePlugin); + + title->plugin = plugin; + + title->button = xfce_create_panel_button(); + gtk_widget_show(title->button); + + title->label = gtk_label_new(NULL); + gtk_label_set_ellipsize(GTK_LABEL(title->label), PANGO_ELLIPSIZE_END); + gtk_widget_show(title->label); + + gtk_container_add(GTK_CONTAINER(title->button), title->label); + + return title; +} + +static void title_construct(XfcePanelPlugin *plugin) +{ + TitlePlugin *title; + + title = title_new(plugin); + + gtk_container_add(GTK_CONTAINER(plugin), title->button); + + xfce_panel_plugin_add_action_widget(plugin, title->button); + xfce_panel_plugin_set_expand(plugin, TRUE); + + g_signal_connect(plugin, "free-data", + G_CALLBACK(title_free), title); + + g_signal_connect(plugin, "size-changed", + G_CALLBACK(title_size_changed), NULL); + + g_signal_connect(title->button, "pressed", + G_CALLBACK(title_pressed), title); + + title_screen_changed(plugin, gtk_widget_get_screen(title->button), + title); + + title->screen_id = g_signal_connect( + plugin, "screen-changed", + G_CALLBACK(title_screen_changed), title + ); +} + diff --git a/panel-plugin/title.desktop b/panel-plugin/title.desktop new file mode 100644 index 0000000..eeaf6dc --- /dev/null +++ b/panel-plugin/title.desktop @@ -0,0 +1,10 @@ +[Xfce Panel] +Type=X-XFCE-PanelPlugin +Encoding=UTF-8 +Name=Title Plugin +Comment=Show title of active window +Icon=xfce4-title-plugin +X-XFCE-Module=title +X-XFCE-Internal=false +X-XFCE-Unique=false +X-XFCE-API=2.0 |
