[Xfce4-commits] [panel-plugins/xfce4-xkb-plugin] 10/17: Merge xfce4-xkb-plugin and xkb-callbacks
noreply at xfce.org
noreply at xfce.org
Sat Jun 10 14:31:43 CEST 2017
This is an automated email from the git hooks/post-receive script.
n i n e t l s p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-xkb-plugin.
commit 7de49ae2612fe9e13d26064d539e3082ebf40893
Author: Viktor Odintsev <zakhams at gmail.com>
Date: Tue Mar 28 15:27:43 2017 +0300
Merge xfce4-xkb-plugin and xkb-callbacks
XkbPlugin extends XfcePanelPlugin now.
Callbacks shouldn't be placed separately with object
so they were merged into single file.
---
panel-plugin/Makefile.am | 6 +-
panel-plugin/xfce4-xkb-plugin.c | 431 --------------
panel-plugin/xkb-cairo.c | 2 +-
panel-plugin/xkb-callbacks.c | 241 --------
panel-plugin/xkb-callbacks.h | 70 ---
panel-plugin/xkb-plugin.c | 693 ++++++++++++++++++++++
panel-plugin/{xfce4-xkb-plugin.h => xkb-plugin.h} | 35 +-
panel-plugin/xkb-settings-dialog.c | 31 +-
panel-plugin/xkb-settings-dialog.h | 6 +-
po/POTFILES.in | 2 +-
10 files changed, 734 insertions(+), 783 deletions(-)
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index e2fead7..177c945 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -7,8 +7,8 @@ plugin_LTLIBRARIES = \
libxkb.la
libxkb_la_SOURCES = \
- xfce4-xkb-plugin.h \
- xfce4-xkb-plugin.c \
+ xkb-plugin.h \
+ xkb-plugin.c \
xkb-settings-dialog.h \
xkb-settings-dialog.c \
xkb-keyboard.h \
@@ -17,8 +17,6 @@ libxkb_la_SOURCES = \
xkb-util.c \
xkb-cairo.h \
xkb-cairo.c \
- xkb-callbacks.h \
- xkb-callbacks.c \
xkb-properties.h \
xkb-xfconf.h \
xkb-xfconf.c
diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
deleted file mode 100644
index c08189f..0000000
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ /dev/null
@@ -1,431 +0,0 @@
-/* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
-/* xfce4-xkb-plugin.c
- * Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
- *
- * Parts of this program comes from the XfKC tool:
- * Copyright (C) 2006 Gauvain Pocentek <gauvainpocentek at gmail.com>
- *
- * A part of this file comes from the gnome keyboard capplet (control-center):
- * Copyright (C) 2003 Sergey V. Oudaltsov <svu at users.sourceforge.net>
- *
- * 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, 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 St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <ctype.h>
-
-#include <libwnck/libwnck.h>
-
-#include <librsvg/rsvg.h>
-#include <garcon/garcon.h>
-
-#include "xfce4-xkb-plugin.h"
-#include "xkb-settings-dialog.h"
-#include "xkb-util.h"
-#include "xkb-cairo.h"
-#include "xkb-callbacks.h"
-#include "xkb-properties.h"
-
-/* ------------------------------------------------------------------ *
- * Panel Plugin Interface *
- * ------------------------------------------------------------------ */
-
-static void xfce_xkb_construct (XfcePanelPlugin *plugin);
-
-static void xfce_xkb_orientation_changed (XfcePanelPlugin *plugin,
- GtkOrientation orientation,
- t_xkb *xkb);
-
-static gboolean xfce_xkb_set_size (XfcePanelPlugin *plugin,
- gint size,
- t_xkb *xkb);
-
-static void xfce_xkb_free_data (XfcePanelPlugin *plugin,
- t_xkb *xkb);
-
-/* ----------------------------------------------------------------- *
- * XKB Stuff *
- * ----------------------------------------------------------------- */
-
-static t_xkb * xkb_new (XfcePanelPlugin *plugin);
-
-static void xkb_free (t_xkb *xkb);
-
-static gboolean xkb_calculate_sizes (t_xkb *xkb,
- GtkOrientation orientation,
- gint panel_size);
-
-static void xkb_populate_popup_menu (t_xkb *xkb);
-
-static void xkb_destroy_popup_menu (t_xkb *xkb);
-
-static void xkb_refresh_gui (t_xkb *xkb);
-
-static void xfce_xkb_configure_layout (GtkWidget *widget,
- gpointer user_data);
-
-static void xkb_plugin_display_type_changed (t_xkb *xkb);
-
-static void xkb_plugin_display_scale_changed (t_xkb *xkb);
-
-static void xkb_plugin_group_policy_changed (t_xkb *xkb);
-
-/* ================================================================== *
- * Implementation *
- * ================================================================== */
-
-XFCE_PANEL_PLUGIN_REGISTER (xfce_xkb_construct);
-
-static void
-xfce_xkb_construct (XfcePanelPlugin *plugin)
-{
- GtkWidget *configure_layouts;
-
- t_xkb *xkb = xkb_new (plugin);
-
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
-
- xfce_panel_plugin_set_small (plugin, TRUE);
-
- g_signal_connect (plugin, "orientation-changed",
- G_CALLBACK (xfce_xkb_orientation_changed), xkb);
-
- g_signal_connect (plugin, "size-changed",
- G_CALLBACK (xfce_xkb_set_size), xkb);
-
- g_signal_connect (plugin, "free-data",
- G_CALLBACK (xfce_xkb_free_data), xkb);
-
- xfce_panel_plugin_menu_show_configure (plugin);
- g_signal_connect (plugin, "configure-plugin",
- G_CALLBACK (xfce_xkb_configure), xkb);
-
- xfce_panel_plugin_menu_show_about (plugin);
- g_signal_connect (plugin, "about",
- G_CALLBACK (xfce_xkb_about), xkb);
-
- configure_layouts = gtk_menu_item_new_with_label (_("Keyboard settings"));
- gtk_widget_show (configure_layouts);
- xfce_panel_plugin_menu_insert_item (plugin, GTK_MENU_ITEM (configure_layouts));
-
- g_signal_connect (G_OBJECT (configure_layouts), "activate",
- G_CALLBACK (xfce_xkb_configure_layout), NULL);
-}
-
-static void
-xfce_xkb_orientation_changed (XfcePanelPlugin *plugin,
- GtkOrientation orientation,
- t_xkb *xkb)
-{
- xkb_calculate_sizes (xkb, orientation, xfce_panel_plugin_get_size (plugin));
-}
-
-static gboolean
-xfce_xkb_set_size (XfcePanelPlugin *plugin, gint size,
- t_xkb *xkb)
-{
- return xkb_calculate_sizes (xkb, xfce_panel_plugin_get_orientation (plugin), size);
-}
-
-static void
-xfce_xkb_free_data (XfcePanelPlugin *plugin, t_xkb *xkb)
-{
- xkb_free (xkb);
-}
-
-/* ----------------- xkb plugin stuff -----------------------*/
-
-static void
-xkb_state_changed (gint current_group, gboolean config_changed,
- gpointer user_data)
-{
- t_xkb *xkb = (t_xkb*) user_data;
-
- xkb_refresh_gui (xkb);
-
- if (config_changed)
- {
- xkb_populate_popup_menu (xkb);
- }
-}
-
-static void
-xkb_plugin_set_group (GtkMenuItem *item,
- gpointer data)
-{
- MenuItemData *item_data = data;
- xkb_keyboard_set_group (item_data->xkb->keyboard, item_data->group);
-}
-
-static t_xkb *
-xkb_new (XfcePanelPlugin *plugin)
-{
- t_xkb *xkb;
- WnckScreen *wnck_screen;
- GtkCssProvider *css_provider;
-
- xkb = panel_slice_new0 (t_xkb);
- xkb->plugin = plugin;
-
- xkb->config = xkb_xfconf_new (xfce_panel_plugin_get_property_base (plugin));
- g_signal_connect_swapped (G_OBJECT (xkb->config), "notify::" DISPLAY_TYPE,
- G_CALLBACK (xkb_plugin_display_type_changed), xkb);
- g_signal_connect_swapped (G_OBJECT (xkb->config), "notify::" DISPLAY_SCALE,
- G_CALLBACK (xkb_plugin_display_scale_changed), xkb);
- g_signal_connect_swapped (G_OBJECT (xkb->config), "notify::" GROUP_POLICY,
- G_CALLBACK (xkb_plugin_group_policy_changed), xkb);
-
- xkb->btn = gtk_button_new ();
- gtk_button_set_relief (GTK_BUTTON (xkb->btn), GTK_RELIEF_NONE);
- gtk_container_add (GTK_CONTAINER (xkb->plugin), xkb->btn);
- xfce_panel_plugin_add_action_widget (xkb->plugin, xkb->btn);
- gtk_widget_add_events (xkb->btn, GDK_SCROLL_MASK);
-
- /* remove padding inside button */
- css_provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_data (css_provider, ".xfce4-panel button {padding: 0;}", -1, NULL);
- gtk_style_context_add_provider (GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (xkb->btn))),
- GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- g_object_unref (css_provider);
-
- gtk_widget_show (xkb->btn);
- g_signal_connect (xkb->btn, "button-press-event",
- G_CALLBACK (xkb_plugin_button_clicked), xkb);
- g_signal_connect (xkb->btn, "button-release-event",
- G_CALLBACK (xkb_plugin_button_clicked), xkb);
- g_signal_connect (xkb->btn, "scroll-event",
- G_CALLBACK (xkb_plugin_button_scrolled), xkb);
-
- g_object_set (G_OBJECT (xkb->btn), "has-tooltip", TRUE, NULL);
- g_signal_connect (xkb->btn, "query-tooltip",
- G_CALLBACK (xkb_plugin_set_tooltip), xkb);
-
- xkb->layout_image = gtk_image_new ();
- gtk_container_add (GTK_CONTAINER (xkb->btn), xkb->layout_image);
- g_signal_connect (G_OBJECT (xkb->layout_image), "draw",
- G_CALLBACK (xkb_plugin_layout_image_draw), xkb);
- gtk_widget_show (GTK_WIDGET (xkb->layout_image));
-
- xkb->keyboard = xkb_keyboard_new (xkb_xfconf_get_group_policy (xkb->config),
- xkb_state_changed, xkb);
- if (xkb_keyboard_get_initialized (xkb->keyboard))
- {
- xkb_refresh_gui (xkb);
- xkb_populate_popup_menu (xkb);
- }
-
- wnck_screen = wnck_screen_get_default ();
- g_signal_connect (G_OBJECT (wnck_screen), "active-window-changed",
- G_CALLBACK (xkb_plugin_active_window_changed), xkb);
- g_signal_connect (G_OBJECT (wnck_screen), "window-closed",
- G_CALLBACK (xkb_plugin_window_closed), xkb);
- g_signal_connect (G_OBJECT (wnck_screen), "application-closed",
- G_CALLBACK (xkb_plugin_application_closed), xkb);
-
- return xkb;
-}
-
-static void
-xkb_free (t_xkb *xkb)
-{
- xkb_destroy_popup_menu (xkb);
- gtk_widget_destroy (xkb->layout_image);
- gtk_widget_destroy (xkb->btn);
-
- g_object_unref (G_OBJECT (xkb->keyboard));
- g_object_unref (G_OBJECT (xkb->config));
-
- panel_slice_free (t_xkb, xkb);
-}
-
-static gboolean
-xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
-{
- guint nrows;
- gint hsize, vsize;
- gboolean proportional;
- guint display_type;
-
- display_type = xkb_xfconf_get_display_type (xkb->config);
- nrows = xfce_panel_plugin_get_nrows (xkb->plugin);
- panel_size /= nrows;
- proportional = nrows > 1 || display_type == DISPLAY_TYPE_SYSTEM;
- TRACE ("calculate_sizes(%p: %d,%d)", xkb, panel_size, nrows);
-
- switch (orientation)
- {
- case GTK_ORIENTATION_HORIZONTAL:
- vsize = panel_size;
- if (proportional)
- {
- hsize = panel_size;
- }
- else
- {
- hsize = (int) (1.33 * panel_size);
- }
-
- gtk_widget_set_size_request (xkb->btn, hsize, vsize);
- break;
- case GTK_ORIENTATION_VERTICAL:
- hsize = panel_size;
- if (proportional)
- {
- vsize = panel_size;
- }
- else
- {
- vsize = (int) (0.75 * panel_size);
- }
- if (vsize < 10) vsize = 10;
-
- gtk_widget_set_size_request (xkb->btn, hsize, vsize);
- break;
- default:
- break;
- }
-
- DBG ("size requested: h/v (%p: %d/%d), proportional: %d",
- xkb, hsize, vsize, proportional);
-
- xkb_refresh_gui (xkb);
- return TRUE;
-}
-
-static void
-xkb_destroy_popup_menu (t_xkb *xkb)
-{
- if (xkb->popup != NULL)
- {
- gtk_menu_popdown (GTK_MENU (xkb->popup));
- gtk_menu_detach (GTK_MENU (xkb->popup));
- g_free (xkb->popup_user_data);
- xkb->popup_user_data = NULL;
- xkb->popup = NULL;
- }
-}
-
-static void
-xkb_populate_popup_menu (t_xkb *xkb)
-{
- gint i, group_count;
- gchar *layout_string;
- GtkWidget *menu_item;
- MenuItemData *popup_user_data;
-
- if (G_UNLIKELY (xkb == NULL)) return;
-
- group_count = xkb_keyboard_get_group_count (xkb->keyboard);
-
- xkb_destroy_popup_menu (xkb);
- xkb->popup = gtk_menu_new ();
- xkb->popup_user_data = g_new0 (MenuItemData, group_count);
-
- popup_user_data = xkb->popup_user_data;
-
- for (i = 0; i < group_count; i++)
- {
- layout_string = xkb_keyboard_get_pretty_layout_name (xkb->keyboard, i);
-
- menu_item = gtk_menu_item_new_with_label (layout_string);
-
- popup_user_data[i].xkb = xkb;
- popup_user_data[i].group = i;
-
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (xkb_plugin_set_group), &popup_user_data[i]);
-
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (xkb->popup), menu_item);
- }
-
- g_signal_connect_swapped (GTK_MENU_SHELL (xkb->popup), "deactivate",
- G_CALLBACK (xkb_plugin_popup_menu_deactivate), xkb);
-
- gtk_menu_attach_to_widget (GTK_MENU (xkb->popup), xkb->btn, NULL);
-}
-
-static void
-xkb_refresh_gui (t_xkb *xkb)
-{
- GdkDisplay * display;
- GtkAllocation allocation;
-
- gtk_widget_get_allocation (GTK_WIDGET (xkb->btn), &allocation);
-
- /* Part of the image may remain visible after display type change */
- gtk_widget_queue_draw_area (xkb->btn, 0, 0,
- allocation.width, allocation.height);
-
- display = gdk_display_get_default();
- if (display)
- {
- gtk_tooltip_trigger_tooltip_query(display);
- }
-}
-
-static void
-xfce_xkb_configure_layout (GtkWidget *widget,
- gpointer user_data)
-{
- gchar *desktop_file = xfce_resource_lookup (XFCE_RESOURCE_DATA,
- "applications/xfce-keyboard-settings.desktop");
-
- GarconMenuItem *item = garcon_menu_item_new_for_path (desktop_file);
- if (item)
- {
- GError *error = NULL;
- gchar **argv;
- gboolean succeed;
- g_shell_parse_argv (garcon_menu_item_get_command (item), NULL, &argv, &error);
- succeed = xfce_spawn_on_screen (gtk_widget_get_screen (GTK_WIDGET (widget)),
- garcon_menu_item_get_path (item),
- argv, NULL, G_SPAWN_SEARCH_PATH,
- garcon_menu_item_supports_startup_notification (item),
- gtk_get_current_event_time (),
- garcon_menu_item_get_icon_name (item),
- &error);
- g_strfreev (argv);
- garcon_menu_item_unref (item);
- g_assert (succeed);
-
- }
- g_free (desktop_file);
-}
-
-static void
-xkb_plugin_display_type_changed (t_xkb *xkb)
-{
- xkb_calculate_sizes (xkb,
- xfce_panel_plugin_get_orientation (xkb->plugin),
- xfce_panel_plugin_get_size (xkb->plugin));
-}
-
-static void
-xkb_plugin_display_scale_changed (t_xkb *xkb)
-{
- xkb_refresh_gui (xkb);
-}
-
-static void
-xkb_plugin_group_policy_changed (t_xkb *xkb)
-{
- xkb_keyboard_set_group_policy (xkb->keyboard,
- xkb_xfconf_get_group_policy (xkb->config));
-}
diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c
index c0b8387..e04f125 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -25,7 +25,7 @@
#include "xkb-cairo.h"
#include "xkb-util.h"
-#include "xfce4-xkb-plugin.h"
+#include "xkb-plugin.h"
#include <librsvg/rsvg.h>
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
deleted file mode 100644
index 8f08114..0000000
--- a/panel-plugin/xkb-callbacks.c
+++ /dev/null
@@ -1,241 +0,0 @@
-/* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
-/* xkb-callbacks.c
- * Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
- *
- * Parts of this program comes from the XfKC tool:
- * Copyright (C) 2006 Gauvain Pocentek <gauvainpocentek at gmail.com>
- *
- * A part of this file comes from the gnome keyboard capplet (control-center):
- * Copyright (C) 2003 Sergey V. Oudaltsov <svu at users.sourceforge.net>
- *
- * 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, 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 St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "xkb-callbacks.h"
-#include "xkb-cairo.h"
-#include "xkb-util.h"
-
-static void xkb_plugin_popup_menu (GtkButton *btn,
- GdkEventButton *event,
- t_xkb *xkb);
-
-void
-xkb_plugin_active_window_changed (WnckScreen *screen,
- WnckWindow *previously_active_window,
- t_xkb *xkb)
-{
- WnckWindow *window;
- guint window_id, application_id;
-
- window = wnck_screen_get_active_window (screen);
- if (!WNCK_IS_WINDOW (window)) return;
- window_id = wnck_window_get_xid (window);
- application_id = wnck_window_get_pid (window);
-
- xkb_keyboard_window_changed (xkb->keyboard, window_id, application_id);
-}
-
-void
-xkb_plugin_application_closed (WnckScreen *screen,
- WnckApplication *app,
- t_xkb *xkb)
-{
- guint application_id;
-
- application_id = wnck_application_get_pid (app);
-
- xkb_keyboard_application_closed (xkb->keyboard, application_id);
-}
-
-void
-xkb_plugin_window_closed (WnckScreen *screen,
- WnckWindow *window,
- t_xkb *xkb)
-{
- guint window_id;
-
- window_id = wnck_window_get_xid (window);
-
- xkb_keyboard_window_closed (xkb->keyboard, window_id);
-}
-
-gboolean
-xkb_plugin_layout_image_draw (GtkWidget *widget,
- cairo_t *cr,
- t_xkb *xkb)
-{
- const gchar *group_name;
- GtkAllocation allocation;
- GtkStyleContext *style_ctx;
- GtkStateFlags state;
- PangoFontDescription *desc;
- GdkRGBA rgba;
- gint actual_hsize, actual_vsize;
- gint display_type, display_scale;
-
- display_type = xkb_xfconf_get_display_type (xkb->config);
- display_scale = xkb_xfconf_get_display_scale (xkb->config);
-
- gtk_widget_get_allocation (GTK_WIDGET (widget), &allocation);
- actual_hsize = allocation.width;
- actual_vsize = allocation.height;
-
- state = gtk_widget_get_state_flags (GTK_WIDGET (xkb->btn));
- style_ctx = gtk_widget_get_style_context (GTK_WIDGET (xkb->btn));
- gtk_style_context_get_color (style_ctx, state, &rgba);
- group_name = xkb_keyboard_get_group_name (xkb->keyboard, -1);
-
- DBG ("img_exposed: actual h/v (%d/%d)",
- actual_hsize, actual_vsize);
-
- if (display_type == DISPLAY_TYPE_IMAGE)
- {
- xkb_cairo_draw_flag (cr, group_name,
- actual_hsize, actual_vsize,
- xkb_keyboard_variant_index_for_group (xkb->keyboard, -1),
- xkb_keyboard_get_max_group_count (xkb->keyboard),
- display_scale,
- rgba
- );
- }
- else if (display_type == DISPLAY_TYPE_TEXT)
- {
- xkb_cairo_draw_label (cr, group_name,
- actual_hsize, actual_vsize,
- xkb_keyboard_variant_index_for_group (xkb->keyboard, -1),
- display_scale,
- rgba
- );
- }
- else
- {
- gtk_style_context_get (style_ctx, state, "font", &desc, NULL);
- xkb_cairo_draw_label_system (cr, group_name,
- actual_hsize, actual_vsize,
- xkb_keyboard_variant_index_for_group (xkb->keyboard, -1),
- desc, rgba
- );
- }
-
- return FALSE;
-}
-
-gboolean
-xkb_plugin_button_clicked (GtkButton *btn,
- GdkEventButton *event,
- gpointer data)
-{
- t_xkb *xkb;
- gboolean released, display_popup;
-
- if (event->button == 1)
- {
- xkb = data;
- released = event->type == GDK_BUTTON_RELEASE;
- display_popup = xkb_keyboard_get_group_count (xkb->keyboard) > 2;
-
- if (display_popup && !released)
- {
- xkb_plugin_popup_menu (btn, event, data);
- return TRUE;
- }
-
- if (!display_popup && released)
- {
- xkb_keyboard_next_group (xkb->keyboard);
- return FALSE;
- }
- }
- return FALSE;
-}
-
-gboolean
-xkb_plugin_button_scrolled (GtkWidget *btn,
- GdkEventScroll *event,
- gpointer data)
-{
- t_xkb *xkb = data;
-
- switch (event->direction)
- {
- case GDK_SCROLL_UP:
- case GDK_SCROLL_RIGHT:
- xkb_keyboard_next_group (xkb->keyboard);
- return TRUE;
- case GDK_SCROLL_DOWN:
- case GDK_SCROLL_LEFT:
- xkb_keyboard_prev_group (xkb->keyboard);
- return TRUE;
- default:
- return FALSE;
- }
-
- return FALSE;
-}
-
-static void
-xkb_plugin_popup_menu (GtkButton *btn,
- GdkEventButton *event,
- t_xkb *xkb)
-{
- gtk_widget_set_state_flags (GTK_WIDGET (xkb->btn), GTK_STATE_FLAG_CHECKED, FALSE);
-#if GTK_CHECK_VERSION(3, 22, 0)
- gtk_menu_popup_at_widget (GTK_MENU (xkb->popup), GTK_WIDGET (btn),
- GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, (GdkEvent *) event);
-#else
- gtk_menu_popup (GTK_MENU (xkb->popup), NULL, NULL,
- xfce_panel_plugin_position_menu, xkb->plugin,
- 0, event->time);
-#endif
-}
-
-void
-xkb_plugin_popup_menu_deactivate (gpointer data,
- GtkMenuShell *menu_shell)
-{
- t_xkb *xkb = (t_xkb *) data;
-
- g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
-
- gtk_widget_unset_state_flags (GTK_WIDGET (xkb->btn), GTK_STATE_FLAG_CHECKED);
-}
-
-gboolean
-xkb_plugin_set_tooltip (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip,
- t_xkb *xkb)
-{
- gint group;
- gchar *layout_name;
- GdkPixbuf *pixbuf;
-
- group = xkb_keyboard_get_current_group (xkb->keyboard);
-
- if (xkb_xfconf_get_display_tooltip_icon (xkb->config))
- {
- pixbuf = xkb_keyboard_get_tooltip_pixbuf (xkb->keyboard, group);
- gtk_tooltip_set_icon (tooltip, pixbuf);
- }
-
- layout_name = xkb_keyboard_get_pretty_layout_name (xkb->keyboard, group);
-
- gtk_tooltip_set_text (tooltip, layout_name);
-
- return TRUE;
-}
-
diff --git a/panel-plugin/xkb-callbacks.h b/panel-plugin/xkb-callbacks.h
deleted file mode 100644
index 8268a39..0000000
--- a/panel-plugin/xkb-callbacks.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
-/* xkb-callbacks.h
- * Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
- *
- * Parts of this program comes from the XfKC tool:
- * Copyright (C) 2006 Gauvain Pocentek <gauvainpocentek at gmail.com>
- *
- * A part of this file comes from the gnome keyboard capplet (control-center):
- * Copyright (C) 2003 Sergey V. Oudaltsov <svu at users.sourceforge.net>
- *
- * 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, 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 St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef _XKB_CALLBACKS_H_
-#define _XKB_CALLBACKS_H_
-
-#include <gtk/gtk.h>
-#include <gdk/gdk.h>
-#include <libwnck/libwnck.h>
-
-#include "xfce4-xkb-plugin.h"
-
-gboolean xkb_plugin_layout_image_draw (GtkWidget *widget,
- cairo_t *cr,
- t_xkb *xkb);
-
-void xkb_plugin_active_window_changed (WnckScreen *screen,
- WnckWindow *previously_active_window,
- t_xkb *xkb);
-
-void xkb_plugin_application_closed (WnckScreen *screen,
- WnckApplication *app,
- t_xkb *xkb);
-
-void xkb_plugin_window_closed (WnckScreen *screen,
- WnckWindow *window,
- t_xkb *xkb);
-
-gboolean xkb_plugin_button_clicked (GtkButton *btn,
- GdkEventButton *event,
- gpointer data);
-
-gboolean xkb_plugin_button_scrolled (GtkWidget *btn,
- GdkEventScroll *event,
- gpointer data);
-
-void xkb_plugin_popup_menu_deactivate (gpointer data,
- GtkMenuShell *menu_shell);
-
-gboolean xkb_plugin_set_tooltip (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip,
- t_xkb *xkb);
-
-#endif
-
diff --git a/panel-plugin/xkb-plugin.c b/panel-plugin/xkb-plugin.c
new file mode 100644
index 0000000..69b887b
--- /dev/null
+++ b/panel-plugin/xkb-plugin.c
@@ -0,0 +1,693 @@
+/* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
+/* xkb-plugin.c
+ * Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
+ *
+ * Parts of this program comes from the XfKC tool:
+ * Copyright (C) 2006 Gauvain Pocentek <gauvainpocentek at gmail.com>
+ *
+ * A part of this file comes from the gnome keyboard capplet (control-center):
+ * Copyright (C) 2003 Sergey V. Oudaltsov <svu at users.sourceforge.net>
+ *
+ * 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, 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+
+#include <libwnck/libwnck.h>
+
+#include <librsvg/rsvg.h>
+#include <garcon/garcon.h>
+
+#include "xkb-plugin.h"
+#include "xkb-settings-dialog.h"
+#include "xkb-util.h"
+#include "xkb-cairo.h"
+#include "xkb-properties.h"
+
+typedef struct
+{
+ XkbPlugin *plugin;
+ gint group;
+} MenuItemData;
+
+struct _XkbPluginClass
+{
+ XfcePanelPluginClass __parent__;
+};
+
+struct _XkbPlugin
+{
+ XfcePanelPlugin __parent__;
+
+ XkbXfconf *config;
+ XkbKeyboard *keyboard;
+
+ /* widgets */
+ GtkWidget *btn;
+ GtkWidget *layout_image;
+ GtkWidget *popup;
+ MenuItemData *popup_user_data;
+};
+
+/* ------------------------------------------------------------------ *
+ * Panel Plugin Interface *
+ * ------------------------------------------------------------------ */
+
+static void xkb_plugin_construct (XfcePanelPlugin *plugin);
+static void xkb_plugin_orientation_changed (XfcePanelPlugin *plugin,
+ GtkOrientation orientation);
+static gboolean xkb_plugin_size_changed (XfcePanelPlugin *plugin,
+ gint size);
+static void xkb_plugin_free_data (XfcePanelPlugin *plugin);
+
+/* ----------------------------------------------------------------- *
+ * XKB Stuff *
+ * ----------------------------------------------------------------- */
+
+static void xkb_plugin_state_changed (gint current_group,
+ gboolean config_changed,
+ gpointer user_data);
+
+static gboolean xkb_plugin_calculate_sizes (XkbPlugin *plugin,
+ GtkOrientation orientation,
+ gint panel_size);
+
+static void xkb_plugin_popup_menu_populate (XkbPlugin *plugin);
+static void xkb_plugin_popup_menu_destroy (XkbPlugin *plugin);
+static void xkb_plugin_popup_menu_show (GtkButton *btn,
+ GdkEventButton *event,
+ XkbPlugin *plugin);
+static void xkb_plugin_popup_menu_deactivate (gpointer data,
+ GtkMenuShell *menu_shell);
+
+static void xkb_plugin_refresh_gui (XkbPlugin *plugin);
+
+static void xkb_plugin_configure_layout (GtkWidget *widget,
+ gpointer user_data);
+
+static gboolean xkb_plugin_button_clicked (GtkButton *btn,
+ GdkEventButton *event,
+ gpointer data);
+static gboolean xkb_plugin_button_scrolled (GtkWidget *btn,
+ GdkEventScroll *event,
+ gpointer data);
+
+static gboolean xkb_plugin_set_tooltip (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip,
+ XkbPlugin *plugin);
+
+static gboolean xkb_plugin_layout_image_draw (GtkWidget *widget,
+ cairo_t *cr,
+ XkbPlugin *plugin);
+
+static void xkb_plugin_active_window_changed (WnckScreen *screen,
+ WnckWindow *previously_active_window,
+ XkbPlugin *plugin);
+static void xkb_plugin_application_closed (WnckScreen *screen,
+ WnckApplication *app,
+ XkbPlugin *plugin);
+static void xkb_plugin_window_closed (WnckScreen *screen,
+ WnckWindow *window,
+ XkbPlugin *plugin);
+
+static void xkb_plugin_display_type_changed (XkbPlugin *plugin);
+static void xkb_plugin_display_scale_changed (XkbPlugin *plugin);
+static void xkb_plugin_group_policy_changed (XkbPlugin *plugin);
+
+/* ================================================================== *
+ * Implementation *
+ * ================================================================== */
+
+XFCE_PANEL_DEFINE_PLUGIN (XkbPlugin, xkb_plugin)
+
+static void
+xkb_plugin_class_init (XkbPluginClass *klass)
+{
+ XfcePanelPluginClass *plugin_class;
+
+ plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
+ plugin_class->construct = xkb_plugin_construct;
+ plugin_class->free_data = xkb_plugin_free_data;
+ plugin_class->about = xkb_plugin_show_about;
+ plugin_class->configure_plugin = xkb_plugin_configure_plugin;
+ plugin_class->orientation_changed = xkb_plugin_orientation_changed;
+ plugin_class->size_changed = xkb_plugin_size_changed;
+}
+
+static void
+xkb_plugin_init (XkbPlugin *plugin)
+{
+ plugin->config = NULL;
+ plugin->keyboard = NULL;
+
+ plugin->btn = NULL;
+ plugin->layout_image = NULL;
+ plugin->popup = NULL;
+ plugin->popup_user_data = NULL;
+}
+
+static void
+xkb_plugin_construct (XfcePanelPlugin *plugin)
+{
+ XkbPlugin *xkb_plugin;
+ GtkWidget *configure_layouts;
+ WnckScreen *wnck_screen;
+ GtkCssProvider *css_provider;
+
+ xkb_plugin = XKB_PLUGIN (plugin);
+
+ xkb_plugin->config = xkb_xfconf_new (xfce_panel_plugin_get_property_base (plugin));
+ g_signal_connect_swapped (G_OBJECT (xkb_plugin->config), "notify::" DISPLAY_TYPE,
+ G_CALLBACK (xkb_plugin_display_type_changed), xkb_plugin);
+ g_signal_connect_swapped (G_OBJECT (xkb_plugin->config), "notify::" DISPLAY_SCALE,
+ G_CALLBACK (xkb_plugin_display_scale_changed), xkb_plugin);
+ g_signal_connect_swapped (G_OBJECT (xkb_plugin->config), "notify::" GROUP_POLICY,
+ G_CALLBACK (xkb_plugin_group_policy_changed), xkb_plugin);
+
+ xkb_plugin->btn = gtk_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (xkb_plugin->btn), GTK_RELIEF_NONE);
+ gtk_container_add (GTK_CONTAINER (plugin), xkb_plugin->btn);
+ xfce_panel_plugin_add_action_widget (plugin, xkb_plugin->btn);
+ gtk_widget_add_events (xkb_plugin->btn, GDK_SCROLL_MASK);
+
+ /* remove padding inside button */
+ css_provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (css_provider, ".xfce4-panel button {padding: 0;}", -1, NULL);
+ gtk_style_context_add_provider (GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (xkb_plugin->btn))),
+ GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref (css_provider);
+
+ gtk_widget_show (xkb_plugin->btn);
+ g_signal_connect (xkb_plugin->btn, "button-press-event",
+ G_CALLBACK (xkb_plugin_button_clicked), xkb_plugin);
+ g_signal_connect (xkb_plugin->btn, "button-release-event",
+ G_CALLBACK (xkb_plugin_button_clicked), xkb_plugin);
+ g_signal_connect (xkb_plugin->btn, "scroll-event",
+ G_CALLBACK (xkb_plugin_button_scrolled), xkb_plugin);
+
+ g_object_set (G_OBJECT (xkb_plugin->btn), "has-tooltip", TRUE, NULL);
+ g_signal_connect (xkb_plugin->btn, "query-tooltip",
+ G_CALLBACK (xkb_plugin_set_tooltip), xkb_plugin);
+
+ xkb_plugin->layout_image = gtk_image_new ();
+ gtk_container_add (GTK_CONTAINER (xkb_plugin->btn), xkb_plugin->layout_image);
+ g_signal_connect (G_OBJECT (xkb_plugin->layout_image), "draw",
+ G_CALLBACK (xkb_plugin_layout_image_draw), xkb_plugin);
+ gtk_widget_show (GTK_WIDGET (xkb_plugin->layout_image));
+
+ xkb_plugin->keyboard = xkb_keyboard_new (xkb_xfconf_get_group_policy (xkb_plugin->config),
+ xkb_plugin_state_changed, xkb_plugin);
+
+ if (xkb_keyboard_get_initialized (xkb_plugin->keyboard))
+ {
+ xkb_plugin_refresh_gui (xkb_plugin);
+ xkb_plugin_popup_menu_populate (xkb_plugin);
+ }
+
+ wnck_screen = wnck_screen_get_default ();
+ g_signal_connect (G_OBJECT (wnck_screen), "active-window-changed",
+ G_CALLBACK (xkb_plugin_active_window_changed), xkb_plugin);
+ g_signal_connect (G_OBJECT (wnck_screen), "window-closed",
+ G_CALLBACK (xkb_plugin_window_closed), xkb_plugin);
+ g_signal_connect (G_OBJECT (wnck_screen), "application-closed",
+ G_CALLBACK (xkb_plugin_application_closed), xkb_plugin);
+
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+ xfce_panel_plugin_menu_show_configure (plugin);
+ xfce_panel_plugin_menu_show_about (plugin);
+
+ xfce_panel_plugin_set_small (plugin, TRUE);
+
+ configure_layouts = gtk_menu_item_new_with_label (_("Keyboard settings"));
+ gtk_widget_show (configure_layouts);
+ xfce_panel_plugin_menu_insert_item (plugin, GTK_MENU_ITEM (configure_layouts));
+
+ g_signal_connect (G_OBJECT (configure_layouts), "activate",
+ G_CALLBACK (xkb_plugin_configure_layout), NULL);
+}
+
+static void
+xkb_plugin_orientation_changed (XfcePanelPlugin *plugin,
+ GtkOrientation orientation)
+{
+ xkb_plugin_calculate_sizes (XKB_PLUGIN (plugin),
+ orientation, xfce_panel_plugin_get_size (plugin));
+}
+
+static gboolean
+xkb_plugin_size_changed (XfcePanelPlugin *plugin,
+ gint size)
+{
+ return xkb_plugin_calculate_sizes (XKB_PLUGIN (plugin),
+ xfce_panel_plugin_get_orientation (plugin), size);
+}
+
+static void
+xkb_plugin_free_data (XfcePanelPlugin *plugin)
+{
+ XkbPlugin *xkb_plugin = XKB_PLUGIN (plugin);
+
+ xkb_plugin_popup_menu_destroy (xkb_plugin);
+ gtk_widget_destroy (xkb_plugin->layout_image);
+ gtk_widget_destroy (xkb_plugin->btn);
+
+ g_object_unref (G_OBJECT (xkb_plugin->keyboard));
+ g_object_unref (G_OBJECT (xkb_plugin->config));
+}
+
+/* ----------------- xkb plugin stuff -----------------------*/
+
+static void
+xkb_plugin_state_changed (gint current_group,
+ gboolean config_changed,
+ gpointer user_data)
+{
+ XkbPlugin *plugin = user_data;
+
+ xkb_plugin_refresh_gui (plugin);
+
+ if (config_changed)
+ {
+ xkb_plugin_popup_menu_populate (plugin);
+ }
+}
+
+static void
+xkb_plugin_set_group (GtkMenuItem *item,
+ gpointer data)
+{
+ MenuItemData *item_data = data;
+ xkb_keyboard_set_group (item_data->plugin->keyboard, item_data->group);
+}
+
+static gboolean
+xkb_plugin_calculate_sizes (XkbPlugin *plugin,
+ GtkOrientation orientation,
+ gint panel_size)
+{
+ guint nrows;
+ gint hsize, vsize;
+ gboolean proportional;
+ guint display_type;
+
+ display_type = xkb_xfconf_get_display_type (plugin->config);
+ nrows = xfce_panel_plugin_get_nrows (XFCE_PANEL_PLUGIN (plugin));
+ panel_size /= nrows;
+ proportional = nrows > 1 || display_type == DISPLAY_TYPE_SYSTEM;
+ TRACE ("calculate_sizes(%p: %d,%d)", plugin, panel_size, nrows);
+
+ switch (orientation)
+ {
+ case GTK_ORIENTATION_HORIZONTAL:
+ vsize = panel_size;
+ if (proportional)
+ {
+ hsize = panel_size;
+ }
+ else
+ {
+ hsize = (int) (1.33 * panel_size);
+ }
+
+ gtk_widget_set_size_request (plugin->btn, hsize, vsize);
+ break;
+ case GTK_ORIENTATION_VERTICAL:
+ hsize = panel_size;
+ if (proportional)
+ {
+ vsize = panel_size;
+ }
+ else
+ {
+ vsize = (int) (0.75 * panel_size);
+ }
+ if (vsize < 10) vsize = 10;
+
+ gtk_widget_set_size_request (plugin->btn, hsize, vsize);
+ break;
+ default:
+ break;
+ }
+
+ DBG ("size requested: h/v (%p: %d/%d), proportional: %d",
+ plugin, hsize, vsize, proportional);
+
+ xkb_plugin_refresh_gui (plugin);
+ return TRUE;
+}
+
+static void
+xkb_plugin_popup_menu_destroy (XkbPlugin *plugin)
+{
+ if (plugin->popup != NULL)
+ {
+ gtk_menu_popdown (GTK_MENU (plugin->popup));
+ gtk_menu_detach (GTK_MENU (plugin->popup));
+ g_free (plugin->popup_user_data);
+ plugin->popup_user_data = NULL;
+ plugin->popup = NULL;
+ }
+}
+
+static void
+xkb_plugin_popup_menu_populate (XkbPlugin *plugin)
+{
+ gint i, group_count;
+ gchar *layout_string;
+ GtkWidget *menu_item;
+
+ if (G_UNLIKELY (plugin == NULL)) return;
+
+ group_count = xkb_keyboard_get_group_count (plugin->keyboard);
+
+ xkb_plugin_popup_menu_destroy (plugin);
+ plugin->popup = gtk_menu_new ();
+ plugin->popup_user_data = g_new0 (MenuItemData, group_count);
+
+ for (i = 0; i < group_count; i++)
+ {
+ layout_string = xkb_keyboard_get_pretty_layout_name (plugin->keyboard, i);
+
+ menu_item = gtk_menu_item_new_with_label (layout_string);
+
+ plugin->popup_user_data[i].plugin = plugin;
+ plugin->popup_user_data[i].group = i;
+
+ g_signal_connect (G_OBJECT (menu_item), "activate",
+ G_CALLBACK (xkb_plugin_set_group), &plugin->popup_user_data[i]);
+
+ gtk_widget_show (menu_item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (plugin->popup), menu_item);
+ }
+
+ g_signal_connect_swapped (GTK_MENU_SHELL (plugin->popup), "deactivate",
+ G_CALLBACK (xkb_plugin_popup_menu_deactivate), plugin);
+
+ gtk_menu_attach_to_widget (GTK_MENU (plugin->popup), plugin->btn, NULL);
+}
+
+static void
+xkb_plugin_popup_menu_show (GtkButton *btn,
+ GdkEventButton *event,
+ XkbPlugin *plugin)
+{
+ gtk_widget_set_state_flags (GTK_WIDGET (btn), GTK_STATE_FLAG_CHECKED, FALSE);
+#if GTK_CHECK_VERSION(3, 22, 0)
+ gtk_menu_popup_at_widget (GTK_MENU (plugin->popup), GTK_WIDGET (btn),
+ GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, (GdkEvent *) event);
+#else
+ gtk_menu_popup (GTK_MENU (plugin->popup), NULL, NULL,
+ xfce_panel_plugin_position_menu, xkb_plugin_get_plugin (plugin),
+ 0, event->time);
+#endif
+}
+
+static void
+xkb_plugin_popup_menu_deactivate (gpointer data,
+ GtkMenuShell *menu_shell)
+{
+ XkbPlugin *plugin = data;
+
+ g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
+
+ gtk_widget_unset_state_flags (GTK_WIDGET (plugin->btn), GTK_STATE_FLAG_CHECKED);
+}
+
+static void
+xkb_plugin_refresh_gui (XkbPlugin *plugin)
+{
+ GdkDisplay * display;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (plugin->btn), &allocation);
+
+ /* Part of the image may remain visible after display type change */
+ gtk_widget_queue_draw_area (plugin->btn, 0, 0,
+ allocation.width, allocation.height);
+
+ display = gdk_display_get_default();
+ if (display)
+ {
+ gtk_tooltip_trigger_tooltip_query(display);
+ }
+}
+
+static void
+xkb_plugin_configure_layout (GtkWidget *widget,
+ gpointer user_data)
+{
+ gchar *desktop_file = xfce_resource_lookup (XFCE_RESOURCE_DATA,
+ "applications/xfce-keyboard-settings.desktop");
+
+ GarconMenuItem *item = garcon_menu_item_new_for_path (desktop_file);
+ if (item)
+ {
+ GError *error = NULL;
+ gchar **argv;
+ gboolean succeed;
+ g_shell_parse_argv (garcon_menu_item_get_command (item), NULL, &argv, &error);
+ succeed = xfce_spawn_on_screen (gtk_widget_get_screen (GTK_WIDGET (widget)),
+ garcon_menu_item_get_path (item),
+ argv, NULL, G_SPAWN_SEARCH_PATH,
+ garcon_menu_item_supports_startup_notification (item),
+ gtk_get_current_event_time (),
+ garcon_menu_item_get_icon_name (item),
+ &error);
+ g_strfreev (argv);
+ garcon_menu_item_unref (item);
+ g_assert (succeed);
+
+ }
+ g_free (desktop_file);
+}
+
+static gboolean
+xkb_plugin_button_clicked (GtkButton *btn,
+ GdkEventButton *event,
+ gpointer data)
+{
+ XkbPlugin *plugin;
+ gboolean released, display_popup;
+
+ if (event->button == 1)
+ {
+ plugin = data;
+
+ released = event->type == GDK_BUTTON_RELEASE;
+ display_popup = xkb_keyboard_get_group_count (plugin->keyboard) > 2;
+
+ if (display_popup && !released)
+ {
+ xkb_plugin_popup_menu_show (btn, event, data);
+ return TRUE;
+ }
+
+ if (!display_popup && released)
+ {
+ xkb_keyboard_next_group (plugin->keyboard);
+ return FALSE;
+ }
+ }
+ return FALSE;
+}
+
+static gboolean
+xkb_plugin_button_scrolled (GtkWidget *btn,
+ GdkEventScroll *event,
+ gpointer data)
+{
+ XkbPlugin *plugin = data;
+
+ switch (event->direction)
+ {
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_RIGHT:
+ xkb_keyboard_next_group (plugin->keyboard);
+ return TRUE;
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_LEFT:
+ xkb_keyboard_prev_group (plugin->keyboard);
+ return TRUE;
+ default:
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+xkb_plugin_set_tooltip (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip,
+ XkbPlugin *plugin)
+{
+ gint group;
+ gchar *layout_name;
+ GdkPixbuf *pixbuf;
+
+ group = xkb_keyboard_get_current_group (plugin->keyboard);
+
+ if (xkb_xfconf_get_display_tooltip_icon (plugin->config))
+ {
+ pixbuf = xkb_keyboard_get_tooltip_pixbuf (plugin->keyboard, group);
+ gtk_tooltip_set_icon (tooltip, pixbuf);
+ }
+
+ layout_name = xkb_keyboard_get_pretty_layout_name (plugin->keyboard, group);
+
+ gtk_tooltip_set_text (tooltip, layout_name);
+
+ return TRUE;
+}
+
+static gboolean
+xkb_plugin_layout_image_draw (GtkWidget *widget,
+ cairo_t *cr,
+ XkbPlugin *plugin)
+{
+ const gchar *group_name;
+ GtkAllocation allocation;
+ GtkStyleContext *style_ctx;
+ GtkStateFlags state;
+ PangoFontDescription *desc;
+ GdkRGBA rgba;
+ gint actual_hsize, actual_vsize;
+ gint display_type, display_scale;
+
+ display_type = xkb_xfconf_get_display_type (plugin->config);
+ display_scale = xkb_xfconf_get_display_scale (plugin->config);
+
+ gtk_widget_get_allocation (GTK_WIDGET (widget), &allocation);
+ actual_hsize = allocation.width;
+ actual_vsize = allocation.height;
+
+ state = gtk_widget_get_state_flags (GTK_WIDGET (plugin->btn));
+ style_ctx = gtk_widget_get_style_context (GTK_WIDGET (plugin->btn));
+ gtk_style_context_get_color (style_ctx, state, &rgba);
+ group_name = xkb_keyboard_get_group_name (plugin->keyboard, -1);
+
+ DBG ("img_exposed: actual h/v (%d/%d)",
+ actual_hsize, actual_vsize);
+
+ if (display_type == DISPLAY_TYPE_IMAGE)
+ {
+ xkb_cairo_draw_flag (cr, group_name,
+ actual_hsize, actual_vsize,
+ xkb_keyboard_variant_index_for_group (plugin->keyboard, -1),
+ xkb_keyboard_get_max_group_count (plugin->keyboard),
+ display_scale,
+ rgba
+ );
+ }
+ else if (display_type == DISPLAY_TYPE_TEXT)
+ {
+ xkb_cairo_draw_label (cr, group_name,
+ actual_hsize, actual_vsize,
+ xkb_keyboard_variant_index_for_group (plugin->keyboard, -1),
+ display_scale,
+ rgba
+ );
+ }
+ else
+ {
+ gtk_style_context_get (style_ctx, state, "font", &desc, NULL);
+ xkb_cairo_draw_label_system (cr, group_name,
+ actual_hsize, actual_vsize,
+ xkb_keyboard_variant_index_for_group (plugin->keyboard, -1),
+ desc, rgba
+ );
+ }
+
+ return FALSE;
+}
+
+static void
+xkb_plugin_active_window_changed (WnckScreen *screen,
+ WnckWindow *previously_active_window,
+ XkbPlugin *plugin)
+{
+ WnckWindow *window;
+ guint window_id, application_id;
+
+ window = wnck_screen_get_active_window (screen);
+ if (!WNCK_IS_WINDOW (window)) return;
+ window_id = wnck_window_get_xid (window);
+ application_id = wnck_window_get_pid (window);
+
+ xkb_keyboard_window_changed (plugin->keyboard, window_id, application_id);
+}
+
+static void
+xkb_plugin_application_closed (WnckScreen *screen,
+ WnckApplication *app,
+ XkbPlugin *plugin)
+{
+ guint application_id;
+
+ application_id = wnck_application_get_pid (app);
+
+ xkb_keyboard_application_closed (plugin->keyboard, application_id);
+}
+
+static void
+xkb_plugin_window_closed (WnckScreen *screen,
+ WnckWindow *window,
+ XkbPlugin *plugin)
+{
+ guint window_id;
+
+ window_id = wnck_window_get_xid (window);
+
+ xkb_keyboard_window_closed (plugin->keyboard, window_id);
+}
+
+static void
+xkb_plugin_display_type_changed (XkbPlugin *plugin)
+{
+ xkb_plugin_calculate_sizes (plugin,
+ xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin)),
+ xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin)));
+}
+
+static void
+xkb_plugin_display_scale_changed (XkbPlugin *plugin)
+{
+ xkb_plugin_refresh_gui (plugin);
+}
+
+static void
+xkb_plugin_group_policy_changed (XkbPlugin *plugin)
+{
+ xkb_keyboard_set_group_policy (plugin->keyboard,
+ xkb_xfconf_get_group_policy (plugin->config));
+}
+
+XkbXfconf *
+xkb_plugin_get_config (XkbPlugin *plugin)
+{
+ g_return_val_if_fail (IS_XKB_PLUGIN (plugin), NULL);
+ return plugin->config;
+}
diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xkb-plugin.h
similarity index 59%
rename from panel-plugin/xfce4-xkb-plugin.h
rename to panel-plugin/xkb-plugin.h
index a869bde..71ca460 100644
--- a/panel-plugin/xfce4-xkb-plugin.h
+++ b/panel-plugin/xkb-plugin.h
@@ -1,5 +1,5 @@
/* vim: set backspace=2 ts=4 softtabstop=4 sw=4 cinoptions=>4 expandtab autoindent smartindent: */
-/* xfce4-xkb-plugin.h
+/* xkb-plugin.h
* Copyright (C) 2008 Alexander Iliev <sasoiliev at mamul.org>
*
* Parts of this program comes from the XfKC tool:
@@ -37,25 +37,24 @@
#include <gtk/gtk.h>
#include <glib.h>
-typedef struct
-{
- XfcePanelPlugin *plugin;
+G_BEGIN_DECLS
- XkbXfconf *config;
- XkbKeyboard *keyboard;
+typedef struct _XkbPluginClass XkbPluginClass;
+typedef struct _XkbPlugin XkbPlugin;
- /* widgets */
- GtkWidget *btn;
- GtkWidget *layout_image;
- GtkWidget *popup;
- void *popup_user_data;
-} t_xkb;
+#define TYPE_XKB_PLUGIN (xkb_plugin_get_type ())
+#define XKB_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_XKB_PLUGIN, XkbPlugin))
+#define XKB_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_XKB_PLUGIN, XkbPluginClass))
+#define IS_XKB_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_XKB_PLUGIN))
+#define IS_XKB_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_XKB_PLUGIN))
+#define XKB_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_XKB_PLUGIN, XkbPlugin))
-typedef struct
-{
- t_xkb *xkb;
- gint group;
-} MenuItemData;
+GType xkb_plugin_get_type (void) G_GNUC_CONST;
-#endif
+void xkb_plugin_register_type (XfcePanelTypeModule *type_module);
+
+XkbXfconf *xkb_plugin_get_config (XkbPlugin *plugin);
+G_END_DECLS
+
+#endif
diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c
index 04429d4..4b2ca15 100644
--- a/panel-plugin/xkb-settings-dialog.c
+++ b/panel-plugin/xkb-settings-dialog.c
@@ -34,7 +34,7 @@
#include <libxfce4panel/xfce-panel-plugin.h>
#include <libxfce4ui/libxfce4ui.h>
-#include "xfce4-xkb-plugin.h"
+#include "xkb-plugin.h"
#include "xkb-settings-dialog.h"
#include "xkb-util.h"
@@ -44,7 +44,7 @@ GtkWidget *default_layout_menu;
typedef struct
{
- t_xkb *xkb;
+ XfcePanelPlugin *plugin;
GtkWidget *display_scale_range;
} DialogInstance;
@@ -74,15 +74,18 @@ enum enumeration
/**************************************************************/
static void
-on_settings_close (GtkDialog *dialog, gint response, DialogInstance *instance)
+on_settings_close (GtkDialog *dialog,
+ gint response,
+ DialogInstance *instance)
{
- xfce_panel_plugin_unblock_menu (instance->xkb->plugin);
+ xfce_panel_plugin_unblock_menu (instance->plugin);
gtk_widget_destroy (GTK_WIDGET (dialog));
g_free (instance);
}
static void
-on_display_type_changed (GtkComboBox *cb, DialogInstance *instance)
+on_display_type_changed (GtkComboBox *cb,
+ DialogInstance *instance)
{
gint active = gtk_combo_box_get_active (cb);
gtk_widget_set_sensitive (instance->display_scale_range,
@@ -90,20 +93,22 @@ on_display_type_changed (GtkComboBox *cb, DialogInstance *instance)
}
void
-xfce_xkb_configure (XfcePanelPlugin *plugin,
- t_xkb *xkb)
+xkb_plugin_configure_plugin (XfcePanelPlugin *plugin)
{
GtkWidget *display_type_combo;
GtkWidget *display_scale_range;
GtkWidget *display_tooltip_icon_switch;
GtkWidget *group_policy_combo;
GtkWidget *vbox, *frame, *bin, *grid, *label;
+ XkbXfconf *config;
DialogInstance *instance;
xfce_panel_plugin_block_menu (plugin);
+ config = xkb_plugin_get_config (XKB_PLUGIN (plugin));
+
instance = g_new0 (DialogInstance, 1);
- instance->xkb = xkb;
+ instance->plugin = plugin;
settings_dialog = xfce_titled_dialog_new_with_buttons (_("Keyboard Layouts"),
NULL, 0, "gtk-close", GTK_RESPONSE_OK, NULL);
@@ -193,19 +198,19 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
G_CALLBACK (on_display_type_changed), instance);
on_display_type_changed (GTK_COMBO_BOX (display_type_combo), instance);
- g_object_bind_property (G_OBJECT (xkb->config), DISPLAY_TYPE,
+ g_object_bind_property (G_OBJECT (config), DISPLAY_TYPE,
G_OBJECT (display_type_combo),
"active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (G_OBJECT (xkb->config), DISPLAY_SCALE,
+ g_object_bind_property (G_OBJECT (config), DISPLAY_SCALE,
G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (display_scale_range))),
"value", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (G_OBJECT (xkb->config), DISPLAY_TOOLTIP_ICON,
+ g_object_bind_property (G_OBJECT (config), DISPLAY_TOOLTIP_ICON,
G_OBJECT (display_tooltip_icon_switch),
"active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (G_OBJECT (xkb->config), GROUP_POLICY,
+ g_object_bind_property (G_OBJECT (config), GROUP_POLICY,
G_OBJECT (group_policy_combo),
"active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
@@ -213,7 +218,7 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
}
void
-xfce_xkb_about (XfcePanelPlugin *plugin)
+xkb_plugin_show_about (XfcePanelPlugin *plugin)
{
GtkWidget *about;
GdkPixbuf *icon;
diff --git a/panel-plugin/xkb-settings-dialog.h b/panel-plugin/xkb-settings-dialog.h
index a94b563..ae810d4 100644
--- a/panel-plugin/xkb-settings-dialog.h
+++ b/panel-plugin/xkb-settings-dialog.h
@@ -26,10 +26,8 @@
#ifndef __XKB_SETTINGS_DIALOG_H__
#define __XKB_SETTINGS_DIALOG_H__
-void xfce_xkb_configure (XfcePanelPlugin *plugin,
- t_xkb *xkb);
-
-void xfce_xkb_about (XfcePanelPlugin *plugin);
+void xkb_plugin_configure_plugin (XfcePanelPlugin *plugin);
+void xkb_plugin_show_about (XfcePanelPlugin *plugin);
#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b658aef..20b1f0a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,7 +1,7 @@
# List of source files containing translatable strings.
panel-plugin/xkb-settings-dialog.c
-panel-plugin/xfce4-xkb-plugin.c
+panel-plugin/xkb-plugin.c
# files added by intltool-prepare.
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list