From: Po Lu Date: Fri, 10 Mar 2023 11:13:22 +0000 (+0800) Subject: Update Android port X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1eb546309b24f41b124a0f94aee4009c6dbd8580;p=emacs.git Update Android port * doc/emacs/android.texi (Android Windowing): Document how to pass multimedia keys to the system. * java/org/gnu/emacs/EmacsNative.java (EmacsNative): New function. * java/org/gnu/emacs/EmacsView.java (onKeyDown, onKeyMultiple) (onKeyUp): Check that function. * java/org/gnu/emacs/EmacsWindow.java (defineCursor): Handle cases where cursor is NULL. * src/android.c (NATIVE_NAME): New function. * src/androidfns.c (syms_of_androidfns): New variable. * src/keyboard.c (lispy_function_keys): Add volume keys. --- diff --git a/doc/emacs/android.texi b/doc/emacs/android.texi index 8e98b92314a..d50acda7710 100644 --- a/doc/emacs/android.texi +++ b/doc/emacs/android.texi @@ -498,6 +498,16 @@ selection, Emacs provides an emulation instead. This means there is no way to transfer the contents of the primary selection to another 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 +@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. + @node Android Fonts @section Font backends and selection under Android @cindex fonts, android diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index d96c93a83a1..7d13ff99abb 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java @@ -174,6 +174,10 @@ public final class EmacsNative main thread's looper to respond. */ public static native void endSynchronous (); + /* Return whether or not KEYCODE_VOLUME_DOWN, KEYCODE_VOLUME_UP and + KEYCODE_VOLUME_MUTE should be forwarded to Emacs. */ + public static native boolean shouldForwardMultimediaButtons (); + /* Input connection functions. These mostly correspond to their diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index 6ace609f386..878ef2f3fbf 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java @@ -361,6 +361,12 @@ public final class EmacsView extends ViewGroup public boolean onKeyDown (int keyCode, KeyEvent event) { + if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP + || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN + || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) + && !EmacsNative.shouldForwardMultimediaButtons ()) + return false; + window.onKeyDown (keyCode, event); return true; } @@ -369,6 +375,12 @@ public final class EmacsView extends ViewGroup public boolean onKeyMultiple (int keyCode, int repeatCount, KeyEvent event) { + if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP + || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN + || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) + && !EmacsNative.shouldForwardMultimediaButtons ()) + return false; + window.onKeyDown (keyCode, event); return true; } @@ -377,6 +389,12 @@ public final class EmacsView extends ViewGroup public boolean onKeyUp (int keyCode, KeyEvent event) { + if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP + || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN + || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) + && !EmacsNative.shouldForwardMultimediaButtons ()) + return false; + window.onKeyUp (keyCode, event); return true; } diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 6be609edcfe..d786c104153 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java @@ -1234,7 +1234,10 @@ public final class EmacsWindow extends EmacsHandleObject public void run () { - view.setPointerIcon (cursor.icon); + if (cursor != null) + view.setPointerIcon (cursor.icon); + else + view.setPointerIcon (null); } }); } diff --git a/src/android.c b/src/android.c index e39c34136de..79598ab86df 100644 --- a/src/android.c +++ b/src/android.c @@ -2825,6 +2825,15 @@ NATIVE_NAME (sendExpose) (JNIEnv *env, jobject object, return event_serial; } +JNIEXPORT jboolean JNICALL +NATIVE_NAME (shouldForwardMultimediaButtons) (JNIEnv *env, + jobject object) +{ + /* Yes, android_pass_multimedia_buttons_to_system is being + read from the UI thread. */ + return !android_pass_multimedia_buttons_to_system; +} + /* Forward declarations of deadlock prevention functions. */ static void android_begin_query (void); diff --git a/src/androidfns.c b/src/androidfns.c index 589ae4331cb..e1d423ab3eb 100644 --- a/src/androidfns.c +++ b/src/androidfns.c @@ -3075,6 +3075,17 @@ syms_of_androidfns (void) doc: /* SKIP: real doc in xfns.c. */); Vx_max_tooltip_size = Qnil; + DEFVAR_BOOL ("android-pass-multimedia-buttons-to-system", + android_pass_multimedia_buttons_to_system, + doc: /* Whether or not to pass volume control buttons to the system. +Generally, the `volume-up', `volume-down' and `volume-mute' keys are +processed by Emacs, but setting this to non-nil they are passed to the +operating system instead of being intercepted by Emacs. + +Note that if you set this, you will no longer be able to quit Emacs +using the volume down button. */); + android_pass_multimedia_buttons_to_system = false; + /* Functions defined. */ defsubr (&Sx_create_frame); defsubr (&Sxw_color_defined_p); diff --git a/src/keyboard.c b/src/keyboard.c index a38c7394543..0a74b435f0e 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -4972,6 +4972,7 @@ const char *const lispy_function_keys[] = [111] = "escape", [112] = "delete", [121] = "break", + [120] = "sysrq", [122] = "home", [123] = "end", [124] = "insert", @@ -4988,6 +4989,7 @@ const char *const lispy_function_keys[] = [141] = "f11", [142] = "f12", [160] = "kp-ret", + [164] = "volume-mute", [19] = "up", [20] = "down", [213] = "muhenkan", @@ -4996,6 +4998,8 @@ const char *const lispy_function_keys[] = [218] = "kana", [21] = "left", [22] = "right", + [24] = "volume-up", + [25] = "volume-down", [259] = "help", [268] = "kp-up-left", [269] = "kp-down-left", @@ -5010,6 +5014,7 @@ const char *const lispy_function_keys[] = [66] = "return", [67] = "backspace", [82] = "menu", + [84] = "find", [92] = "prior", [93] = "next", };