[Xfce4-commits] [panel-plugins/xfce4-xkb-plugin] 02/06: Move wnck-related code to XkbKeyboard
noreply at xfce.org
noreply at xfce.org
Thu Jun 22 09:54:40 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 3c7064a36792eab9108af5acbdabd01768ad624e
Author: Viktor Odintsev <zakhams at gmail.com>
Date: Wed Jun 21 15:31:00 2017 +0300
Move wnck-related code to XkbKeyboard
---
panel-plugin/xkb-keyboard.c | 99 ++++++++++++++++++++++++++++++++++++---------
panel-plugin/xkb-keyboard.h | 7 ----
panel-plugin/xkb-plugin.c | 60 ---------------------------
3 files changed, 79 insertions(+), 87 deletions(-)
diff --git a/panel-plugin/xkb-keyboard.c b/panel-plugin/xkb-keyboard.c
index 218c124..42295e3 100644
--- a/panel-plugin/xkb-keyboard.c
+++ b/panel-plugin/xkb-keyboard.c
@@ -28,6 +28,7 @@
#include <gdk/gdkx.h>
#include <libxklavier/xklavier.h>
+#include <libwnck/libwnck.h>
#include <librsvg/rsvg.h>
typedef struct
@@ -54,6 +55,8 @@ struct _XkbKeyboard
XklEngine *engine;
XklConfigRec *last_config_rec;
+ WnckScreen *wnck_screen;
+
guint config_timeout_id;
XkbGroupData *group_data;
@@ -68,8 +71,22 @@ struct _XkbKeyboard
gint group_count;
gint current_group;
+
+ gulong active_window_changed_handler_id;
+ gulong application_closed_handler_id;
+ gulong window_closed_handler_id;
};
+static void xkb_keyboard_active_window_changed (WnckScreen *screen,
+ WnckWindow *previously_active_window,
+ XkbKeyboard *keyboard);
+static void xkb_keyboard_application_closed (WnckScreen *screen,
+ WnckApplication *application,
+ XkbKeyboard *keyboard);
+static void xkb_keyboard_window_closed (WnckScreen *screen,
+ WnckWindow *window,
+ XkbKeyboard *keyboard);
+
static void xkb_keyboard_xkl_state_changed (XklEngine *engine,
XklEngineStateChange change,
gint group,
@@ -135,17 +152,25 @@ xkb_keyboard_init (XkbKeyboard *keyboard)
keyboard->group_count = 0;
keyboard->current_group = 0;
+
+ keyboard->active_window_changed_handler_id = 0;
+ keyboard->application_closed_handler_id = 0;
+ keyboard->window_closed_handler_id = 0;
}
XkbKeyboard *
xkb_keyboard_new (XkbGroupPolicy group_policy)
{
- XkbKeyboard *keyboard = g_object_new (TYPE_XKB_KEYBOARD, NULL);
+ XkbKeyboard *keyboard;
+
+ keyboard = g_object_new (TYPE_XKB_KEYBOARD, NULL);
keyboard->group_policy = group_policy;
keyboard->engine = xkl_engine_get_instance (gdk_x11_get_default_xdisplay ());
+ keyboard->wnck_screen = wnck_screen_get_default ();
+
if (keyboard->engine)
{
xkb_keyboard_update_from_xkl (keyboard);
@@ -163,6 +188,16 @@ xkb_keyboard_new (XkbGroupPolicy group_policy)
G_CALLBACK (xkb_keyboard_xkl_config_changed),
keyboard);
gdk_window_add_filter (NULL, xkb_keyboard_handle_xevent, keyboard);
+
+ keyboard->active_window_changed_handler_id =
+ g_signal_connect (G_OBJECT (keyboard->wnck_screen), "active-window-changed",
+ G_CALLBACK (xkb_keyboard_active_window_changed), keyboard);
+ keyboard->application_closed_handler_id =
+ g_signal_connect (G_OBJECT (keyboard->wnck_screen), "application-closed",
+ G_CALLBACK (xkb_keyboard_application_closed), keyboard);
+ keyboard->window_closed_handler_id =
+ g_signal_connect (G_OBJECT (keyboard->wnck_screen), "window-closed",
+ G_CALLBACK (xkb_keyboard_window_closed), keyboard);
}
return keyboard;
@@ -376,7 +411,16 @@ xkb_keyboard_finalize (GObject *object)
if (keyboard->config_timeout_id != 0)
g_source_remove (keyboard->config_timeout_id);
-
+
+ if (keyboard->active_window_changed_handler_id > 0)
+ g_signal_handler_disconnect (keyboard->wnck_screen, keyboard->active_window_changed_handler_id);
+
+ if (keyboard->application_closed_handler_id > 0)
+ g_signal_handler_disconnect (keyboard->wnck_screen, keyboard->application_closed_handler_id);
+
+ if (keyboard->window_closed_handler_id > 0)
+ g_signal_handler_disconnect (keyboard->wnck_screen, keyboard->window_closed_handler_id);
+
G_OBJECT_CLASS (xkb_keyboard_parent_class)->finalize (object);
}
@@ -491,20 +535,27 @@ xkb_keyboard_update_from_xkl (XkbKeyboard *keyboard)
}
}
-void
-xkb_keyboard_window_changed (XkbKeyboard *keyboard,
- guint new_window_id,
- guint application_id)
+static void
+xkb_keyboard_active_window_changed (WnckScreen *screen,
+ WnckWindow *previously_active_window,
+ XkbKeyboard *keyboard)
{
- gint group;
+ gint group = 0;
gpointer key, value;
- GHashTable *hashtable;
- guint id;
+ GHashTable *hashtable = NULL;
+ guint id = 0;
+ WnckWindow *window;
+ guint window_id, application_id;
g_return_if_fail (IS_XKB_KEYBOARD (keyboard));
- id = 0;
- hashtable = NULL;
+ 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);
switch (keyboard->group_policy)
{
@@ -513,7 +564,7 @@ xkb_keyboard_window_changed (XkbKeyboard *keyboard,
case GROUP_POLICY_PER_WINDOW:
hashtable = keyboard->window_map;
- id = new_window_id;
+ id = window_id;
keyboard->current_window_id = id;
break;
@@ -524,8 +575,6 @@ xkb_keyboard_window_changed (XkbKeyboard *keyboard,
break;
}
- group = 0;
-
if (g_hash_table_lookup_extended (hashtable, GINT_TO_POINTER (id), &key, &value))
{
group = GPOINTER_TO_INT (value);
@@ -540,12 +589,17 @@ xkb_keyboard_window_changed (XkbKeyboard *keyboard,
xkb_keyboard_set_group (keyboard, group);
}
-void
-xkb_keyboard_application_closed (XkbKeyboard *keyboard,
- guint application_id)
+static void
+xkb_keyboard_application_closed (WnckScreen *screen,
+ WnckApplication *application,
+ XkbKeyboard *keyboard)
{
+ guint application_id;
+
g_return_if_fail (IS_XKB_KEYBOARD (keyboard));
+ application_id = wnck_application_get_pid (application);
+
switch (keyboard->group_policy)
{
case GROUP_POLICY_GLOBAL:
@@ -562,12 +616,17 @@ xkb_keyboard_application_closed (XkbKeyboard *keyboard,
}
}
-void
-xkb_keyboard_window_closed (XkbKeyboard *keyboard,
- guint window_id)
+static void
+xkb_keyboard_window_closed (WnckScreen *screen,
+ WnckWindow *window,
+ XkbKeyboard *keyboard)
{
+ guint window_id;
+
g_return_if_fail (IS_XKB_KEYBOARD (keyboard));
+ window_id = wnck_window_get_xid (window);
+
switch (keyboard->group_policy)
{
case GROUP_POLICY_GLOBAL:
diff --git a/panel-plugin/xkb-keyboard.h b/panel-plugin/xkb-keyboard.h
index 14dc76a..26aee84 100644
--- a/panel-plugin/xkb-keyboard.h
+++ b/panel-plugin/xkb-keyboard.h
@@ -62,13 +62,6 @@ gboolean xkb_keyboard_set_group (XkbKeyboard *ke
gboolean xkb_keyboard_next_group (XkbKeyboard *keyboard);
gboolean xkb_keyboard_prev_group (XkbKeyboard *keyboard);
-void xkb_keyboard_window_changed (XkbKeyboard *keyboard,
- guint new_window_id,
- guint application_id);
-void xkb_keyboard_application_closed (XkbKeyboard *keyboard,
- guint application_id);
-void xkb_keyboard_window_closed (XkbKeyboard *keyboard,
- guint window_id);
GdkPixbuf* xkb_keyboard_get_pixbuf (XkbKeyboard *keyboard,
gboolean tooltip,
gint group);
diff --git a/panel-plugin/xkb-plugin.c b/panel-plugin/xkb-plugin.c
index 3c6b98f..a807564 100644
--- a/panel-plugin/xkb-plugin.c
+++ b/panel-plugin/xkb-plugin.c
@@ -28,7 +28,6 @@
#endif
#include <libxfce4ui/libxfce4ui.h>
-#include <libwnck/libwnck.h>
#include <librsvg/rsvg.h>
#include <garcon/garcon.h>
@@ -119,16 +118,6 @@ 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_name_changed (XkbPlugin *plugin);
static void xkb_plugin_display_scale_changed (XkbPlugin *plugin);
@@ -171,7 +160,6 @@ xkb_plugin_construct (XfcePanelPlugin *plugin)
{
XkbPlugin *xkb_plugin;
GtkWidget *configure_layouts;
- WnckScreen *wnck_screen;
GtkCssProvider *css_provider;
xkb_plugin = XKB_PLUGIN (plugin);
@@ -228,14 +216,6 @@ xkb_plugin_construct (XfcePanelPlugin *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, LOCALEDIR, "UTF-8");
xfce_panel_plugin_menu_show_configure (plugin);
@@ -650,46 +630,6 @@ xkb_plugin_layout_image_draw (GtkWidget *widget,
}
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,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list