From 9d1f7899374585c47a3c4272b7767f55be59ab0b Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Wed, 11 Sep 2013 17:44:24 +0200 Subject: [PATCH] ShellGlobal: repurpose the stage_gdk_window as the IBus window And use it directly in the IBus event handling (by pushing it down to StIMText) https://bugzilla.gnome.org/show_bug.cgi?id=707467 --- src/shell-global.c | 19 ++++++++----------- src/st/st-im-text.c | 30 ++++++++++-------------------- src/st/st-im-text.h | 2 ++ 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/shell-global.c b/src/shell-global.c index 1d0dadc1b..65994ec95 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -52,7 +52,7 @@ struct _ShellGlobal { ClutterStage *stage; Window stage_xwindow; - GdkWindow *stage_gdk_window; + GdkWindow *ibus_window; MetaDisplay *meta_display; GdkDisplay *gdk_display; @@ -793,13 +793,9 @@ gnome_shell_gdk_event_handler (GdkEvent *event_gdk, { if (event_gdk->type == GDK_KEY_PRESS || event_gdk->type == GDK_KEY_RELEASE) { - ClutterActor *stage; - Window stage_xwindow; + ShellGlobal *global = data; - stage = CLUTTER_ACTOR (data); - stage_xwindow = clutter_x11_get_stage_window (CLUTTER_STAGE (stage)); - - if (GDK_WINDOW_XID (event_gdk->key.window) == stage_xwindow) + if (event_gdk->key.window == global->ibus_window) { ClutterDeviceManager *device_manager = clutter_device_manager_get_default (); ClutterInputDevice *keyboard = clutter_device_manager_get_core_device (device_manager, @@ -809,7 +805,7 @@ gnome_shell_gdk_event_handler (GdkEvent *event_gdk, CLUTTER_KEY_PRESS : CLUTTER_KEY_RELEASE); event_clutter->key.time = event_gdk->key.time; event_clutter->key.flags = CLUTTER_EVENT_NONE; - event_clutter->key.stage = CLUTTER_STAGE (stage); + event_clutter->key.stage = CLUTTER_STAGE (global->stage); event_clutter->key.source = NULL; /* This depends on ClutterModifierType and GdkModifierType being @@ -852,8 +848,9 @@ _shell_global_set_plugin (ShellGlobal *global, global->stage = CLUTTER_STAGE (meta_get_stage_for_screen (global->meta_screen)); global->stage_xwindow = clutter_x11_get_stage_window (global->stage); - global->stage_gdk_window = gdk_x11_window_foreign_new_for_display (global->gdk_display, - global->stage_xwindow); + global->ibus_window = gdk_x11_window_foreign_new_for_display (global->gdk_display, + global->stage_xwindow); + st_im_text_set_event_window (global->ibus_window); g_signal_connect (global->stage, "notify::width", G_CALLBACK (global_stage_notify_width), global); @@ -882,7 +879,7 @@ _shell_global_set_plugin (ShellGlobal *global, g_signal_connect (global->meta_display, "notify::focus-window", G_CALLBACK (focus_window_changed), global); - gdk_event_handler_set (gnome_shell_gdk_event_handler, global->stage, NULL); + gdk_event_handler_set (gnome_shell_gdk_event_handler, global, NULL); global->focus_manager = st_focus_manager_get_for_stage (global->stage); } diff --git a/src/st/st-im-text.c b/src/st/st-im-text.c index 624a0674c..5666e7acd 100644 --- a/src/st/st-im-text.c +++ b/src/st/st-im-text.c @@ -41,7 +41,6 @@ #endif #include -#include #include #include #include @@ -203,25 +202,14 @@ st_im_text_get_paint_volume (ClutterActor *self, return clutter_paint_volume_set_from_allocation (volume, self); } -/* Returns a new reference to window */ -static GdkWindow * -window_for_actor (ClutterActor *actor) +static GdkWindow *event_window; + +void +st_im_text_set_event_window (GdkWindow *window) { - GdkDisplay *display = gdk_display_get_default (); - ClutterActor *stage; - Window xwindow; - GdkWindow *window; + g_assert (event_window == NULL); - stage = clutter_actor_get_stage (actor); - xwindow = clutter_x11_get_stage_window ((ClutterStage *)stage); - - window = gdk_x11_window_lookup_for_display (display, xwindow); - if (window) - g_object_ref (window); - else - window = gdk_x11_window_foreign_new_for_display (display, xwindow); - - return window; + event_window = window; } static void @@ -229,7 +217,8 @@ st_im_text_realize (ClutterActor *actor) { StIMTextPrivate *priv = ST_IM_TEXT (actor)->priv; - priv->window = window_for_actor (actor); + g_assert (event_window != NULL); + priv->window = g_object_ref (event_window); gtk_im_context_set_client_window (priv->im_context, priv->window); } @@ -291,7 +280,8 @@ key_event_to_gdk (ClutterKeyEvent *event_clutter) event_gdk = (GdkEventKey *)gdk_event_new ((event_clutter->type == CLUTTER_KEY_PRESS) ? GDK_KEY_PRESS : GDK_KEY_RELEASE); - event_gdk->window = window_for_actor ((ClutterActor *)event_clutter->stage); + g_assert (event_window != NULL); + event_gdk->window = g_object_ref (event_window); event_gdk->send_event = FALSE; event_gdk->time = event_clutter->time; /* This depends on ClutterModifierType and GdkModifierType being diff --git a/src/st/st-im-text.h b/src/st/st-im-text.h index e675c3403..c97975ae9 100644 --- a/src/st/st-im-text.h +++ b/src/st/st-im-text.h @@ -68,6 +68,8 @@ void st_im_text_set_input_hints (StIMText *imtext, GtkInputHints hints); GtkInputHints st_im_text_get_input_hints (StIMText *imtext); +void st_im_text_set_event_window (GdkWindow *window); + G_END_DECLS #endif /* __ST_IM_TEXT_H__ */