Enable customization of the quit key on Android

* doc/emacs/android.texi (Android Windowing):

* doc/emacs/input.texi (On-Screen Keyboards): Document various
tidbits related to the quit key.

* java/org/gnu/emacs/EmacsNative.java (getQuitKeycode): New
function.

* java/org/gnu/emacs/EmacsWindow.java (EmacsWindow): Rename
`lastVolumeButtonRelease' to `lastQuitKeyRelease'.
(onKeyUp): Treat value returned by getQuitKeycode as the quit
key rather than mandate KEYCODE_VOLUME_DOWN.

* src/android.c (getQuitKeycode): Implement new function.

* src/androidterm.c (syms_of_androidterm)
<android_quit_keycode>: New variable.
This commit is contained in:
Po Lu 2024-04-27 10:47:12 +08:00
parent 763eaa5a32
commit db8f7ed7f6
6 changed files with 47 additions and 18 deletions

View file

@ -948,13 +948,16 @@ application via cut-and-paste.
@vindex android-pass-multimedia-buttons-to-system
@cindex volume/multimedia buttons, Android
The volume keys are normally reserved by Emacs and used to provide
the ability to quit Emacs without a physical keyboard
(@pxref{On-Screen Keyboards}.) However, if you want them to adjust
the volume instead, you can set the variable
The volume keys are normally reserved by Emacs and used to provide the
ability to quit Emacs without a physical keyboard (@pxref{On-Screen
Keyboards}). However, if you want them to adjust the volume instead,
you can set the variable
@code{android-pass-multimedia-buttons-to-system} to a non-@code{nil}
value; note that you will no longer be able to quit Emacs using the
volume buttons in that case.
volume buttons in that case, and that it is generally easier to activate
the notification shade or another interface that momentarily deprives
Emacs of the keyboard focus while the volume buttons are being
depressed.
@cindex dialog boxes, android
Emacs is unable to display dialog boxes (@pxref{Dialog Boxes}) while

View file

@ -156,9 +156,11 @@ which two rapid clicks of a hardware button that is always present on
the device induces a quit. @xref{Quitting}.
@vindex x-quit-keysym
No such button is enabled on X, but one can be configured through
the variable @code{x-quit-keysym}. On Android this button is always
the volume down button.
@vindex android-quit-keycode
No such button is enabled on X, but one can be configured through the
variable @code{x-quit-keysym}, whereas the default key is the volume
down button on Android, which is also configurable through a variable,
@code{android-quit-keycode}.
@cindex text conversion, keyboards
Most input methods designed to work with virtual keyboards edit text

View file

@ -228,6 +228,10 @@ public static native long sendDndText (short window, int x, int y,
be prevented from reaching the system input method. */
public static native boolean shouldForwardCtrlSpace ();
/* Return the keycode repeated activation of which should signal
quit. */
public static native int getQuitKeycode ();
/* Initialize the current thread, by blocking signals that do not
interest it. */
public static native void setupSystemThread ();

View file

@ -136,10 +136,10 @@ private static class Coordinate
there is no such window manager. */
private WindowManager windowManager;
/* The time of the last KEYCODE_VOLUME_DOWN release. This is used
to quit Emacs upon two rapid clicks of the volume down
button. */
private long lastVolumeButtonRelease;
/* The time of the last release of the quit keycode, generally
KEYCODE_VOLUME_DOWN. This is used to signal quit upon two rapid
presses of such key. */
private long lastQuitKeyRelease;
/* Linked list of character strings which were recently sent as
events. */
@ -790,15 +790,12 @@ private static class Coordinate
if ((event.getFlags () & KeyEvent.FLAG_CANCELED) != 0)
return;
EmacsNative.sendKeyPress (this.handle, event.getEventTime (),
state, keyCode, unicode_char);
}
EmacsNative.sendKeyRelease (this.handle, event.getEventTime (),
state, keyCode, unicode_char);
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
if (keyCode == EmacsNative.getQuitKeycode ())
{
/* Check if this volume down press should quit Emacs.
Most Android devices have no physical keyboard, so it
@ -806,10 +803,10 @@ private static class Coordinate
time = event.getEventTime ();
if (time - lastVolumeButtonRelease < 350)
if (time - lastQuitKeyRelease < 350)
EmacsNative.quit ();
lastVolumeButtonRelease = time;
lastQuitKeyRelease = time;
}
}

View file

@ -2645,6 +2645,13 @@ NATIVE_NAME (shouldForwardMultimediaButtons) (JNIEnv *env,
return !android_pass_multimedia_buttons_to_system;
}
JNIEXPORT jint JNICALL
NATIVE_NAME (getQuitKeycode) (JNIEnv *env, jobject object)
{
/* Likewise. */
return (jint) android_quit_keycode;
}
JNIEXPORT jboolean JNICALL
NATIVE_NAME (shouldForwardCtrlSpace) (JNIEnv *env, jobject object)
{

View file

@ -6703,6 +6703,22 @@ so it is important to limit the wait.
If set to a non-float value, there will be no wait at all. */);
Vandroid_wait_for_event_timeout = make_float (0.1);
DEFVAR_INT ("android-quit-keycode", android_quit_keycode,
doc: /* Keycode that signals quit when typed twice in rapid succession.
This is the key code of a key whose repeated activation should prompt
Emacs to quit, enabling quitting on systems where a keyboard capable of
typing C-g is unavailable, when set to a key that does exist on the
device. Its value must be a keycode defined by the operating system,
and defaults to 25 (KEYCODE_VOLUME_DOWN), though one of the following
values might be desired on those devices where this default is also
unavailable, or if another key must otherwise serve this function
instead:
- 4 (KEYCODE_BACK)
- 24 (KEYCODE_VOLUME_UP) */);
android_quit_keycode = 25;
DEFVAR_BOOL ("x-use-underline-position-properties",
x_use_underline_position_properties,
doc: /* SKIP: real doc in xterm.c. */);