From 5abc977bbb2d38f3c607f1575e02aa7a6c483db0 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 11 Jun 2023 08:52:10 +0800 Subject: [PATCH] Avoid extraneous calls to the UI thread * java/org/gnu/emacs/EmacsView.java (EmacsView) (showOnScreenKeyboard, hideOnScreenKeyboard) (onCheckIsTextEditor): Make synchronized. * java/org/gnu/emacs/EmacsWindow.java (EmacsWindow) (toggleOnScreenKeyboard): Don't post to the main thread. --- java/org/gnu/emacs/EmacsView.java | 6 +++--- java/org/gnu/emacs/EmacsWindow.java | 21 +++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index d432162132d..7fd672233f2 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java @@ -590,7 +590,7 @@ public final class EmacsView extends ViewGroup super.onAttachedToWindow (); } - public void + public synchronized void showOnScreenKeyboard () { /* Specifying no flags at all tells the system the user asked for @@ -599,7 +599,7 @@ public final class EmacsView extends ViewGroup isCurrentlyTextEditor = true; } - public void + public synchronized void hideOnScreenKeyboard () { imManager.hideSoftInputFromWindow (this.getWindowToken (), @@ -686,7 +686,7 @@ public final class EmacsView extends ViewGroup } @Override - public boolean + public synchronized boolean onCheckIsTextEditor () { /* If value is true, then the system will display the on screen diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index c14bf16b96e..f5e40e9a2d9 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java @@ -1201,19 +1201,16 @@ public final class EmacsWindow extends EmacsHandleObject } public void - toggleOnScreenKeyboard (final boolean on) + toggleOnScreenKeyboard (boolean on) { - EmacsService.SERVICE.runOnUiThread (new Runnable () { - @Override - public void - run () - { - if (on) - view.showOnScreenKeyboard (); - else - view.hideOnScreenKeyboard (); - } - }); + /* InputMethodManager functions are thread safe. Call + `showOnScreenKeyboard' etc from the Emacs thread in order to + keep the calls in sync with updates to the input context. */ + + if (on) + view.showOnScreenKeyboard (); + else + view.hideOnScreenKeyboard (); } public String -- 2.39.2