[uim-commit] r3014 - trunk/gtk
ekato at freedesktop.org
ekato at freedesktop.org
Sun Jan 29 02:58:08 PST 2006
Author: ekato
Date: 2006-01-29 02:58:04 -0800 (Sun, 29 Jan 2006)
New Revision: 3014
Modified:
trunk/gtk/gtk-im-uim.c
Log:
* (_IMUIMContext) : Remove in_toplevel and event_rec member.
(grab_widget) : New static variable.
(remove_cur_toplevel) : New. Remove toplevel key handler.
(update_in_toplevel) : Rename to update_cur_toplevel.
(update_cur_toplevel) : Update toplevel key handler.
(on_client_widget_hierarchy_changed) : Follow the rename.
(on_client_widget_grab_notify) : New.
(update_client_widget) : Set grab_notify handler. Follow the
rename.
(im_uim_filter_keypress) : Check grab instead of event time.
(im_uim_focus_in) : Use update_cur_toplevel().
(im_uim_focus_out) : Use remove_cur_toplevel().
(im_uim_init) : Update.
(handle_key_on_toplevel) : Don't store event time.
Modified: trunk/gtk/gtk-im-uim.c
===================================================================
--- trunk/gtk/gtk-im-uim.c 2006-01-28 04:55:29 UTC (rev 3013)
+++ trunk/gtk/gtk-im-uim.c 2006-01-29 10:58:04 UTC (rev 3014)
@@ -99,8 +99,6 @@
#if IM_UIM_USE_TOPLEVEL
GtkWidget *widget;
- gboolean in_toplevel;
- GdkEventKey event_rec;
#endif
struct _IMUIMContext *prev, *next;
@@ -113,6 +111,7 @@
static gboolean snooper_installed = FALSE;
#elif IM_UIM_USE_TOPLEVEL
static GtkWidget *cur_toplevel;
+static GtkWidget *grab_widget;
static gulong cur_key_press_handler_id;
static gulong cur_key_release_handler_id;
#endif
@@ -331,14 +330,37 @@
#if IM_UIM_USE_TOPLEVEL
static void
-update_in_toplevel(IMUIMContext *uic)
+remove_cur_toplevel()
{
+ if (cur_toplevel && GTK_WIDGET_TOPLEVEL(cur_toplevel)) {
+ if (cur_key_press_handler_id)
+ g_signal_handler_disconnect(cur_toplevel, cur_key_press_handler_id);
+ if (cur_key_release_handler_id)
+ g_signal_handler_disconnect(cur_toplevel, cur_key_release_handler_id);
+ cur_toplevel = NULL;
+ }
+}
+
+static void
+update_cur_toplevel(IMUIMContext *uic)
+{
if (uic->widget) {
GtkWidget *toplevel = gtk_widget_get_toplevel(uic->widget);
- uic->in_toplevel = (toplevel && GTK_WIDGET_TOPLEVEL(toplevel));
- } else {
- uic->in_toplevel = FALSE;
- }
+ if (toplevel && GTK_WIDGET_TOPLEVEL(toplevel)) {
+ if (cur_toplevel != toplevel) {
+ remove_cur_toplevel();
+ cur_toplevel = toplevel;
+ cur_key_press_handler_id = g_signal_connect(cur_toplevel,
+ "key-press-event",
+ G_CALLBACK(handle_key_on_toplevel), uic);
+ cur_key_release_handler_id = g_signal_connect(cur_toplevel,
+ "key-release-event",
+ G_CALLBACK(handle_key_on_toplevel), uic);
+ }
+ } else
+ remove_cur_toplevel();
+ } else
+ remove_cur_toplevel();
}
static GtkWidget *
@@ -359,28 +381,59 @@
static void
on_client_widget_hierarchy_changed(GtkWidget *widget, GtkWidget *old_toplevel, IMUIMContext *uic)
{
- update_in_toplevel(uic);
+ update_cur_toplevel(uic);
}
+static gboolean
+on_client_widget_grab_notify(GtkWidget *widget, gboolean was_grabbed, IMUIMContext *uic)
+{
+ if (was_grabbed)
+ grab_widget = NULL;
+ else {
+ grab_widget = gtk_grab_get_current();
+ if (!grab_widget) {
+ if (cur_toplevel && GTK_IS_WINDOW(cur_toplevel)) {
+ GtkWindowGroup *group;
+ GtkWindow *window;
+
+ window = GTK_WINDOW(cur_toplevel);
+ group = window->group;
+ if (group)
+ grab_widget = GTK_WIDGET(group->grabs->data);
+ }
+ }
+ }
+
+ return FALSE;
+}
+
static void
update_client_widget(IMUIMContext *uic)
{
GtkWidget *new_widget = widget_for_window(uic->win);
if (new_widget != uic->widget) {
- if (uic->widget)
+ if (uic->widget) {
g_signal_handlers_disconnect_by_func(uic->widget,
(gpointer)on_client_widget_hierarchy_changed, uic);
+ g_signal_handlers_disconnect_by_func(uic->widget,
+ (gpointer)on_client_widget_grab_notify, uic);
+ }
uic->widget = new_widget;
- if (uic->widget)
+ if (uic->widget) {
g_signal_connect(uic->widget, "hierarchy-changed",
G_CALLBACK(on_client_widget_hierarchy_changed), uic);
+ g_signal_connect(uic->widget, "grab-notify",
+ G_CALLBACK(on_client_widget_grab_notify), uic);
+ }
- update_in_toplevel(uic);
+ update_cur_toplevel(uic);
}
}
#endif /* IM_UIM_USE_TOPLEVEL */
+
+
/* utility functions */
static int
@@ -422,6 +475,7 @@
}
+
/* callback functions for libuim */
static void
@@ -850,11 +904,7 @@
#if IM_UIM_USE_SNOOPER
if (!snooper_installed) {
#elif IM_UIM_USE_TOPLEVEL
- /*
- * Sometimes key events are emitted from other than top level
- * widget, so check time of the event...
- */
- if (!cur_toplevel || key->time != uic->event_rec.time) {
+ if (!cur_toplevel || (cur_toplevel && grab_widget)) {
#else
if (TRUE) {
#endif
@@ -922,9 +972,6 @@
{
IMUIMContext *uic = IM_UIM_CONTEXT(ic);
IMUIMContext *cc;
-#if IM_UIM_USE_TOPLEVEL
- GtkWidget *toplevel;
-#endif
focused_context = uic;
disable_focused_context = FALSE;
@@ -936,24 +983,7 @@
snooper_installed = TRUE;
}
#elif IM_UIM_USE_TOPLEVEL
- if (cur_toplevel) {
- if (cur_key_press_handler_id)
- g_signal_handler_disconnect(cur_toplevel, cur_key_press_handler_id);
- if (cur_key_press_handler_id)
- g_signal_handler_disconnect(cur_toplevel, cur_key_release_handler_id);
- }
-
- toplevel = gtk_widget_get_toplevel(uic->widget);
- cur_toplevel = toplevel;
-
- if (toplevel && GTK_WIDGET_TOPLEVEL(toplevel)) {
- cur_key_press_handler_id = g_signal_connect(cur_toplevel,
- "key-press-event", G_CALLBACK(handle_key_on_toplevel),
- uic);
- cur_key_release_handler_id = g_signal_connect(cur_toplevel,
- "key-release-event", G_CALLBACK(handle_key_on_toplevel),
- uic);
- }
+ update_cur_toplevel(uic);
#endif
check_helper_connection();
@@ -983,11 +1013,7 @@
snooper_installed = FALSE;
}
#elif IM_UIM_USE_TOPLEVEL
- if (cur_toplevel) {
- g_signal_handler_disconnect(cur_toplevel, cur_key_press_handler_id);
- g_signal_handler_disconnect(cur_toplevel, cur_key_release_handler_id);
- cur_toplevel = NULL;
- }
+ remove_cur_toplevel();
#endif
check_helper_connection();
@@ -1058,8 +1084,6 @@
uic->win = NULL;
#if IM_UIM_USE_TOPLEVEL
uic->widget = NULL;
- uic->in_toplevel = FALSE;
- uic->event_rec.time = 0;
#endif
uic->caret_state_indicator = NULL;
uic->pseg = NULL;
@@ -1229,8 +1253,6 @@
if (focused_context == uic) {
int rv, kv, mod;
- uic->event_rec.time = event->time;
-
im_uim_convert_keyevent(event, &kv, &mod);
if (event->type == GDK_KEY_RELEASE)
More information about the uim-commit
mailing list