[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 334b362bf4: Make `x-gtk-use-native-input' take effect immediately
From: |
Po Lu |
Subject: |
master 334b362bf4: Make `x-gtk-use-native-input' take effect immediately |
Date: |
Thu, 3 Feb 2022 21:12:24 -0500 (EST) |
branch: master
commit 334b362bf46859bc581643b0fab6674b4c5e1b54
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Make `x-gtk-use-native-input' take effect immediately
* lisp/term/x-win.el (x-internal-focus-input-context): New
declaration.
(x-gtk-use-native-input-watcher): New variable watcher.
* src/xfns.c (Fx_internal_focus_input_context): New function.
(syms_of_xfns): Define new subr.
---
lisp/term/x-win.el | 14 ++++++++++++++
src/xfns.c | 18 ++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el
index 019a01e22c..80a7d81d08 100644
--- a/lisp/term/x-win.el
+++ b/lisp/term/x-win.el
@@ -1563,6 +1563,20 @@ EVENT is a preedit-text event."
(defvaralias 'x-gtk-use-system-tooltips 'use-system-tooltips)
+(declare-function x-internal-focus-input-context (frame) "xfns.c")
+
+(defun x-gtk-use-native-input-watcher (_symbol newval &rest _ignored)
+ "Variable watcher for `x-gtk-use-native-input'.
+If NEWVAL is non-nil and the selected frame is displayed through X,
+focus the GTK input context."
+ (when (and (featurep 'gtk)
+ newval
+ (eq (framep (selected-frame)) 'x))
+ (x-internal-focus-input-context (selected-frame))))
+
+(add-variable-watcher 'x-gtk-use-native-input
+ #'x-gtk-use-native-input-watcher)
+
(provide 'x-win)
(provide 'term/x-win)
diff --git a/src/xfns.c b/src/xfns.c
index 7007f70b19..7ca791afa1 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -8565,6 +8565,22 @@ DEFUN ("x-gtk-debug", Fx_gtk_debug, Sx_gtk_debug, 1, 1,
0,
#endif /* GTK_CHECK_VERSION (3, 14, 0) */
#endif /* HAVE_GTK3 */
#endif /* USE_GTK */
+
+DEFUN ("x-internal-focus-input-context", Fx_internal_focus_input_context,
+ Sx_internal_focus_input_context, 1, 1, 0,
+ doc: /* Focus and set the client window of FRAME's GTK input context.
+This should be called from a variable watcher for `x-gtk-use-native-input'.
*/)
+ (Lisp_Object frame)
+{
+#ifdef USE_GTK
+ struct frame *f = decode_window_system_frame (frame);
+ GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f);
+
+ gtk_im_context_focus_in (FRAME_X_OUTPUT (f)->im_context);
+ gtk_im_context_set_client_window (FRAME_X_OUTPUT (f)->im_context,
+ gtk_widget_get_window (widget));
+#endif
+}
/***********************************************************************
Initialization
@@ -8942,6 +8958,8 @@ eliminated in future versions of Emacs. */);
defsubr (&Sx_select_font);
#endif
+ defsubr (&Sx_internal_focus_input_context);
+
#ifdef USE_CAIRO
defsubr (&Sx_export_frames);
#ifdef USE_GTK
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 334b362bf4: Make `x-gtk-use-native-input' take effect immediately,
Po Lu <=