Update Android port

* java/org/gnu/emacs/EmacsWindow.java (eventModifiers)
(motionEventModifiers): New functions.
(onKeyDown, onKeyUp, onFocusChanged, onSomeKindOfMotionEvent):
Don't record the previous modifier mask; instead, always use the
modifier state specified in the event.
* src/androidterm.c (handle_one_android_event): Don't dispatch
button release events when a popup is active.
This commit is contained in:
Po Lu 2023-07-09 13:13:53 +08:00
parent 97f926b82d
commit ed5ade097e
2 changed files with 63 additions and 47 deletions

View file

@ -99,9 +99,8 @@ private static class Coordinate
private EmacsGC scratchGC;
/* The button state and keyboard modifier mask at the time of the
last button press or release event. The modifier mask is reset
upon each window focus change. */
public int lastButtonState, lastModifiers;
last button press or release event. */
public int lastButtonState;
/* Whether or not the window is mapped. */
private volatile boolean isMapped;
@ -562,15 +561,16 @@ private static class Coordinate
eventStrings.put (serial, string);
}
/* event.getCharacters is used because older input methods still
require it. */
@SuppressWarnings ("deprecation")
public void
onKeyDown (int keyCode, KeyEvent event)
/* Return the modifier mask associated with the specified keyboard
input EVENT. Replace bits corresponding to Left or Right keys
with their corresponding general modifier bits. */
private int
eventModifiers (KeyEvent event)
{
int state, state_1;
long serial;
String characters;
int state;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
state = event.getModifiers ();
@ -592,6 +592,46 @@ private static class Coordinate
state |= KeyEvent.META_CTRL_MASK;
}
return state;
}
/* Return the modifier mask associated with the specified motion
EVENT. Replace bits corresponding to Left or Right keys with
their corresponding general modifier bits. */
private int
motionEventModifiers (MotionEvent event)
{
int state;
state = event.getMetaState ();
/* Normalize the state by setting the generic modifier bit if
either a left or right modifier is pressed. */
if ((state & KeyEvent.META_ALT_LEFT_ON) != 0
|| (state & KeyEvent.META_ALT_RIGHT_ON) != 0)
state |= KeyEvent.META_ALT_MASK;
if ((state & KeyEvent.META_CTRL_LEFT_ON) != 0
|| (state & KeyEvent.META_CTRL_RIGHT_ON) != 0)
state |= KeyEvent.META_CTRL_MASK;
return state;
}
/* event.getCharacters is used because older input methods still
require it. */
@SuppressWarnings ("deprecation")
public void
onKeyDown (int keyCode, KeyEvent event)
{
int state, state_1;
long serial;
String characters;
state = eventModifiers (event);
/* Ignore meta-state understood by Emacs for now, or Ctrl+C will
not be recognized as an ASCII key press event. */
state_1
@ -605,7 +645,6 @@ private static class Coordinate
state, keyCode,
getEventUnicodeChar (event,
state_1));
lastModifiers = state;
characters = event.getCharacters ();
@ -620,25 +659,8 @@ private static class Coordinate
int state, state_1;
long time;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
state = event.getModifiers ();
else
{
/* Replace this with getMetaState and manual
normalization. */
state = event.getMetaState ();
/* Normalize the state by setting the generic modifier bit if
either a left or right modifier is pressed. */
if ((state & KeyEvent.META_ALT_LEFT_ON) != 0
|| (state & KeyEvent.META_ALT_RIGHT_ON) != 0)
state |= KeyEvent.META_ALT_MASK;
if ((state & KeyEvent.META_CTRL_LEFT_ON) != 0
|| (state & KeyEvent.META_CTRL_RIGHT_ON) != 0)
state |= KeyEvent.META_CTRL_MASK;
}
/* 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. */
@ -650,7 +672,6 @@ private static class Coordinate
state, keyCode,
getEventUnicodeChar (event,
state_1));
lastModifiers = state;
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
@ -671,12 +692,6 @@ private static class Coordinate
onFocusChanged (boolean gainFocus)
{
EmacsActivity.invalidateFocus ();
/* If focus has been lost, reset the keyboard modifier state, as
subsequent changes will not be recorded. */
if (!gainFocus)
lastModifiers = 0;
}
/* Notice that the activity has been detached or destroyed.
@ -940,7 +955,7 @@ else if (event.getSource () != InputDevice.SOURCE_CLASS_POINTER)
EmacsNative.sendButtonPress (this.handle, (int) event.getX (),
(int) event.getY (),
event.getEventTime (),
lastModifiers,
motionEventModifiers (event),
whatButtonWasIt (event, true));
if (Build.VERSION.SDK_INT
@ -955,7 +970,7 @@ else if (event.getSource () != InputDevice.SOURCE_CLASS_POINTER)
EmacsNative.sendButtonRelease (this.handle, (int) event.getX (),
(int) event.getY (),
event.getEventTime (),
lastModifiers,
motionEventModifiers (event),
whatButtonWasIt (event, false));
if (Build.VERSION.SDK_INT
@ -988,7 +1003,7 @@ else if (event.getSource () != InputDevice.SOURCE_CLASS_POINTER)
EmacsNative.sendButtonRelease (this.handle, (int) event.getX (),
(int) event.getY (),
event.getEventTime (),
lastModifiers,
motionEventModifiers (event),
whatButtonWasIt (event, false));
lastButtonState = event.getButtonState ();
}
@ -1000,7 +1015,7 @@ else if (event.getSource () != InputDevice.SOURCE_CLASS_POINTER)
EmacsNative.sendWheel (this.handle, (int) event.getX (),
(int) event.getY (),
event.getEventTime (),
lastModifiers,
motionEventModifiers (event),
event.getAxisValue (MotionEvent.AXIS_HSCROLL),
event.getAxisValue (MotionEvent.AXIS_VSCROLL));
return true;

View file

@ -1315,12 +1315,13 @@ handle_one_android_event (struct android_display_info *dpyinfo,
}
if (!(tab_bar_p && NILP (tab_bar_arg)) && !tool_bar_p)
{
android_construct_mouse_click (&inev.ie, &event->xbutton, f);
if (! popup_activated ())
{
android_construct_mouse_click (&inev.ie, &event->xbutton, f);
if (!NILP (tab_bar_arg))
inev.ie.arg = tab_bar_arg;
}
if (!NILP (tab_bar_arg))
inev.ie.arg = tab_bar_arg;
}
}
if (event->type == ANDROID_BUTTON_PRESS)