Skip to content

Commit

Permalink
Update cursor location when key pressed
Browse files Browse the repository at this point in the history
In some GTK applications, when input window is visible and the user moves
the application wdinow to another location, the cursor location will not
be updated. Then if the user presses some new keys, the input window will
not move to the new cursor location automatically. So it's necessary to
update the cursor location when key pressed.
  • Loading branch information
kingysu committed Jun 13, 2024
1 parent 2b78dfe commit 2d37448
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions gtk2/fcitximcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,13 @@ static gboolean fcitx_im_context_filter_keypress(GtkIMContext *context,
if (fcitxcontext->client_window == NULL && event->window != NULL) {
gtk_im_context_set_client_window((GtkIMContext *)fcitxcontext,
event->window);

/* set_cursor_location_internal() will get origin from X server,
* it blocks UI. So delay it to idle callback. */
gdk_threads_add_idle_full(
G_PRIORITY_DEFAULT_IDLE,
(GSourceFunc)_set_cursor_location_internal,
g_object_ref(fcitxcontext), (GDestroyNotify)g_object_unref);
}

/* set_cursor_location_internal() will get origin from X server,
* it blocks UI. So delay it to idle callback. */
gdk_threads_add_idle_full(
G_PRIORITY_DEFAULT_IDLE, (GSourceFunc)_set_cursor_location_internal,
g_object_ref(fcitxcontext), (GDestroyNotify)g_object_unref);
}

if (event->state & (guint64)HandledMask) {
Expand Down
13 changes: 6 additions & 7 deletions gtk3/fcitximcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,13 @@ static gboolean fcitx_im_context_filter_keypress(GtkIMContext *context,
if (fcitxcontext->client_window == NULL && event->window != NULL) {
gtk_im_context_set_client_window((GtkIMContext *)fcitxcontext,
event->window);

/* set_cursor_location_internal() will get origin from X server,
* it blocks UI. So delay it to idle callback. */
gdk_threads_add_idle_full(
G_PRIORITY_DEFAULT_IDLE,
(GSourceFunc)_set_cursor_location_internal,
g_object_ref(fcitxcontext), (GDestroyNotify)g_object_unref);
}

/* set_cursor_location_internal() will get origin from X server,
* it blocks UI. So delay it to idle callback. */
gdk_threads_add_idle_full(
G_PRIORITY_DEFAULT_IDLE, (GSourceFunc)_set_cursor_location_internal,
g_object_ref(fcitxcontext), (GDestroyNotify)g_object_unref);
}

if (event->state & (guint64)HandledMask) {
Expand Down

0 comments on commit 2d37448

Please sign in to comment.