]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't forcibly display dialogs on Android if a keyboard is present
authorPo Lu <luangruo@yahoo.com>
Tue, 6 Feb 2024 05:10:57 +0000 (13:10 +0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 7 Feb 2024 10:54:35 +0000 (11:54 +0100)
* java/org/gnu/emacs/EmacsService.java (detectKeyboard): New
function.

* lisp/subr.el (use-dialog-box-p): Don't always return t if a
keyboard is present on Android.

* src/android.c (android_init_emacs_service): Link to new
function.
(android_detect_keyboard): New function.

* src/android.h: Update prototypes.

* src/androidfns.c (Fandroid_detect_keyboard)
(syms_of_androidfns): New function.

(cherry picked from commit 0d2b7120783255fbb0f8e98717573c35425f4df6)

java/org/gnu/emacs/EmacsService.java
lisp/subr.el
src/android.c
src/android.h
src/androidfns.c

index 5cb1ceca0aacbfef6733ac4948bbca86d89cc4ef..93e34e6e694d5239b164b4922454ceaccbd7a0fd 100644 (file)
@@ -60,6 +60,7 @@ import android.content.UriPermission;
 import android.content.pm.PackageManager;
 
 import android.content.res.AssetManager;
+import android.content.res.Configuration;
 
 import android.hardware.input.InputManager;
 
@@ -581,6 +582,15 @@ public final class EmacsService extends Service
     return false;
   }
 
+  public boolean
+  detectKeyboard ()
+  {
+    Configuration configuration;
+
+    configuration = getResources ().getConfiguration ();
+    return configuration.keyboard != Configuration.KEYBOARD_NOKEYS;
+  }
+
   public String
   nameKeysym (int keysym)
   {
index 582415a9761219e4017dccde1c832bfc75105482..e53ef505522ec6a8293d7da2cb9208e415f052f1 100644 (file)
@@ -3829,13 +3829,17 @@ confusing to some users.")
 
 (defvar from--tty-menu-p nil
   "Non-nil means the current command was invoked from a TTY menu.")
+
+(declare-function android-detect-keyboard "androidfns.c")
+
 (defun use-dialog-box-p ()
   "Return non-nil if the current command should prompt the user via a dialog box."
   (and last-input-event                 ; not during startup
        (or (consp last-nonmenu-event)   ; invoked by a mouse event
            (and (null last-nonmenu-event)
                 (consp last-input-event))
-           (featurep 'android)         ; Prefer dialog boxes on Android.
+           (and (featurep 'android)    ; Prefer dialog boxes on Android.
+                (not (android-detect-keyboard))) ; If no keyboard is connected.
            from--tty-menu-p)            ; invoked via TTY menu
        use-dialog-box))
 
index 4a74f5b2af41917ae66b96eb4f399daa859d6a4e..2c0e4f845f4ce2a7a79ec348dff1d19bd39e83e1 100644 (file)
@@ -1593,6 +1593,7 @@ android_init_emacs_service (void)
   FIND_METHOD (get_screen_width, "getScreenWidth", "(Z)I");
   FIND_METHOD (get_screen_height, "getScreenHeight", "(Z)I");
   FIND_METHOD (detect_mouse, "detectMouse", "()Z");
+  FIND_METHOD (detect_keyboard, "detectKeyboard", "()Z");
   FIND_METHOD (name_keysym, "nameKeysym", "(I)Ljava/lang/String;");
   FIND_METHOD (browse_url, "browseUrl", "(Ljava/lang/String;Z)"
               "Ljava/lang/String;");
@@ -5626,6 +5627,21 @@ android_detect_mouse (void)
   return rc;
 }
 
+bool
+android_detect_keyboard (void)
+{
+  bool rc;
+  jmethodID method;
+
+  method = service_class.detect_keyboard;
+  rc = (*android_java_env)->CallNonvirtualBooleanMethod (android_java_env,
+                                                        emacs_service,
+                                                        service_class.class,
+                                                        method);
+  android_exception_check ();
+  return rc;
+}
+
 void
 android_set_dont_focus_on_map (android_window handle,
                               bool no_focus_on_map)
index 2f5f32037c54517d88a61381edc469c86d39f6fc..bd19c4d9ac8afe05a5dae7326009f9f4cdb382c1 100644 (file)
@@ -103,6 +103,7 @@ extern int android_get_screen_height (void);
 extern int android_get_mm_width (void);
 extern int android_get_mm_height (void);
 extern bool android_detect_mouse (void);
+extern bool android_detect_keyboard (void);
 
 extern void android_set_dont_focus_on_map (android_window, bool);
 extern void android_set_dont_accept_focus (android_window, bool);
@@ -265,6 +266,7 @@ struct android_emacs_service
   jmethodID get_screen_width;
   jmethodID get_screen_height;
   jmethodID detect_mouse;
+  jmethodID detect_keyboard;
   jmethodID name_keysym;
   jmethodID browse_url;
   jmethodID restart_emacs;
index eaecb78338bca611b20c5605bfd51accf6572ed3..48c3f3046d640b209da19ca9fdabe90f3c141389 100644 (file)
@@ -2476,6 +2476,25 @@ there is no mouse.  */)
 #endif
 }
 
+DEFUN ("android-detect-keyboard", Fandroid_detect_keyboard,
+       Sandroid_detect_keyboard, 0, 0, 0,
+       doc: /* Return whether a keyboard is connected.
+Return non-nil if a key is connected to this computer, or nil
+if there is no keyboard.  */)
+  (void)
+{
+#ifndef ANDROID_STUBIFY
+  /* If no display connection is present, just return nil.  */
+
+  if (!android_init_gui)
+    return Qnil;
+
+  return android_detect_keyboard () ? Qt : Qnil;
+#else /* ANDROID_STUBIFY */
+  return Qt;
+#endif /* ANDROID_STUBIFY */
+}
+
 DEFUN ("android-toggle-on-screen-keyboard",
        Fandroid_toggle_on_screen_keyboard,
        Sandroid_toggle_on_screen_keyboard, 2, 2, 0,
@@ -3560,6 +3579,7 @@ language to be US English if LANGUAGE is empty.  */);
   defsubr (&Sx_show_tip);
   defsubr (&Sx_hide_tip);
   defsubr (&Sandroid_detect_mouse);
+  defsubr (&Sandroid_detect_keyboard);
   defsubr (&Sandroid_toggle_on_screen_keyboard);
   defsubr (&Sx_server_vendor);
   defsubr (&Sx_server_version);