From 8ff8a7fd5c50aaa7721a562a11836b4ec733ba5e Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 2 Aug 2023 09:09:53 +0800 Subject: [PATCH] Fix reporting of key events containing SYM and META * doc/emacs/android.texi (Android)::(What is Android?): (Android Startup, Android File System, Android Environment) (Android Windowing, Android Fonts, Android Troubleshooting): Improve section titles. (Android Windowing): Describe the relation between keyboard modifiers reported by Android and those in key events. * java/org/gnu/emacs/EmacsWindow.java (onKeyDown, onKeyUp): Clear META_SYM_ON and META_META_MASK when retrieving ASCII characters. * src/androidgui.h: Add ANDROID_META_MASK. * src/androidterm.c (android_android_to_emacs_modifiers) (android_emacs_to_android_modifiers): Transform META to Alt, and vice versa. --- doc/emacs/android.texi | 33 ++++++++++++++++++++--------- java/org/gnu/emacs/EmacsWindow.java | 18 ++++++++++------ src/androidgui.h | 1 + src/androidterm.c | 6 ++++-- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/doc/emacs/android.texi b/doc/emacs/android.texi index 4b8f36a65eb..9d352f3a484 100644 --- a/doc/emacs/android.texi +++ b/doc/emacs/android.texi @@ -26,7 +26,7 @@ about using such devices with Emacs, @pxref{Other Input Devices}. @end menu @node What is Android? -@section Android history +@section Android History Android is an operating system for mobile devices developed by the Open Handset Alliance, a group of companies interested in developing @@ -59,7 +59,7 @@ your freedom's sake. hope this taste of freedom will inspire users to escape from them. @node Android Startup -@section Starting up Emacs on Android +@section Starting Emacs on Android Emacs is not installed on Android devices from source code or through a package manager. Instead, Emacs is compiled for Android on @@ -155,7 +155,7 @@ case such files are copied to a temporary directory before being opened. @node Android File System -@section What files Emacs can access under Android +@section What Files Emacs Can Access on Android @cindex /assets directory, android Emacs exposes a special directory on Android systems: the name of @@ -281,7 +281,7 @@ files under @file{/sdcard} as usual. These settings are not present on some proprietary versions of Android. @node Android Document Providers -@section Accessing files from other programs under Android +@section Accessing Files from Other Programs on Android @cindex document providers, Android @cindex /content/storage directory, Android @@ -399,7 +399,7 @@ Startup}) connect the Android system to another computer, and run: $ adb shell "settings put global settings_enable_monitor_phantom_procs false" @end example -@section Running Emacs in the background +@section Running Emacs in the Background @cindex emacs killed, android @cindex emacs in the background, android @@ -429,7 +429,7 @@ the background in their proprietary versions of Android. There is a list of such troublesome manufacturers and sometimes workarounds at @url{https://dontkillmyapp.com/}. -@section Android permissions +@section Android Permissions @cindex external storage, android Android also defines a permissions system that determines what @@ -526,7 +526,7 @@ more details, as how to do this varies by device. @end itemize @node Android Windowing -@section The Android window system +@section The Android Window System Android has an unusual window system; there, all windows are maximized or full-screen, and only one window can be displayed at a @@ -650,8 +650,21 @@ System -> Apps -> Emacs -> More -> Display over other apps menu in the system settings, but this procedure may vary by device. +@cindex keyboard modifiers, android + There is a direct relation between physical modifier keys and Emacs +modifiers (@pxref{Modifier Keys}) reported within key events, subject +to a single exception: if @key{Alt} on your keyboard is depressed, +then the @key{Meta} modifier will be reported by Emacs in its place, +and vice versa. This irregularity is since most keyboards posses no +special @key{Meta} key, and the @key{Alt} modifier is seldom employed +in Emacs. + + Bear in mind that Android uses a different name for the @key{Super} +modifier: it is referred to as @key{SYM} on Android keyboards and +within the Settings keymap menu. + @node Android Fonts -@section Font backends and selection under Android +@section Font Backends and Selection under Android @cindex fonts, android Emacs supports two font backends under Android: they are respectively @@ -693,7 +706,7 @@ removed; distortable fonts with the same family will no longer be used to provide that style. @node Android Troubleshooting -@section What to do when something goes wrong on Android +@section Troubleshooting Startup Problems on Android @cindex troubleshooting, android @cindex emacs -Q, android @@ -741,7 +754,7 @@ manager that comes with your device, you can rename, delete, or edit your initialization or dump files from there instead. @node Android Software -@section Installing extra software on Android +@section Installing Extra Software on Android @cindex installing extra software on Android @cindex installing Unix software on Android diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 8118479319e..a1f70644e16 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java @@ -616,10 +616,13 @@ private static class Coordinate state = eventModifiers (event); - /* Ignore meta-state understood by Emacs for now, or Ctrl+C will - not be recognized as an ASCII key press event. */ + /* Ignore meta-state understood by Emacs for now, or key presses + such as Ctrl+C and Meta+C will not be recognized as an ASCII + key press event. */ + state_1 - = state & ~(KeyEvent.META_ALT_MASK | KeyEvent.META_CTRL_MASK); + = state & ~(KeyEvent.META_ALT_MASK | KeyEvent.META_CTRL_MASK + | KeyEvent.META_SYM_ON | KeyEvent.META_META_MASK); synchronized (eventStrings) { @@ -646,10 +649,13 @@ private static class Coordinate /* Compute the event's modifier mask. */ state = eventModifiers (event); - /* Ignore meta-state understood by Emacs for now, or Ctrl+C will - not be recognized as an ASCII key press event. */ + /* Ignore meta-state understood by Emacs for now, or key presses + such as Ctrl+C and Meta+C will not be recognized as an ASCII + key press event. */ + state_1 - = state & ~(KeyEvent.META_ALT_MASK | KeyEvent.META_CTRL_MASK); + = state & ~(KeyEvent.META_ALT_MASK | KeyEvent.META_CTRL_MASK + | KeyEvent.META_SYM_ON | KeyEvent.META_META_MASK); EmacsNative.sendKeyRelease (this.handle, event.getEventTime (), diff --git a/src/androidgui.h b/src/androidgui.h index 265ec29b678..14225f7bf80 100644 --- a/src/androidgui.h +++ b/src/androidgui.h @@ -263,6 +263,7 @@ enum android_modifier_mask ANDROID_CONTROL_MASK = 4096, ANDROID_ALT_MASK = 2, ANDROID_SUPER_MASK = 4, + ANDROID_META_MASK = 65536, }; struct android_key_event diff --git a/src/androidterm.c b/src/androidterm.c index bcb6cd6db45..f74463f88cd 100644 --- a/src/androidterm.c +++ b/src/androidterm.c @@ -365,7 +365,8 @@ android_android_to_emacs_modifiers (struct android_display_info *dpyinfo, return (((state & ANDROID_CONTROL_MASK) ? ctrl_modifier : 0) | ((state & ANDROID_SHIFT_MASK) ? shift_modifier : 0) | ((state & ANDROID_ALT_MASK) ? meta_modifier : 0) - | ((state & ANDROID_SUPER_MASK) ? super_modifier : 0)); + | ((state & ANDROID_SUPER_MASK) ? super_modifier : 0) + | ((state & ANDROID_META_MASK) ? alt_modifier : 0)); } static int @@ -375,7 +376,8 @@ android_emacs_to_android_modifiers (struct android_display_info *dpyinfo, return (((state & ctrl_modifier) ? ANDROID_CONTROL_MASK : 0) | ((state & shift_modifier) ? ANDROID_SHIFT_MASK : 0) | ((state & meta_modifier) ? ANDROID_ALT_MASK : 0) - | ((state & super_modifier) ? ANDROID_SUPER_MASK : 0)); + | ((state & super_modifier) ? ANDROID_SUPER_MASK : 0) + | ((state & alt_modifier) ? ANDROID_META_MASK : 0)); } static void android_frame_rehighlight (struct android_display_info *);