aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-07-09 13:13:53 +0800
committerPo Lu2023-07-09 13:13:53 +0800
commited5ade097e5b675167f9c7e4916a4beec62d118a (patch)
tree77917567d0407311636dc4817280bdf7986cf6de /java
parent97f926b82d5674f90a16327b0ad4d6b226fcacb4 (diff)
downloademacs-ed5ade097e5b675167f9c7e4916a4beec62d118a.tar.gz
emacs-ed5ade097e5b675167f9c7e4916a4beec62d118a.zip
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.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsWindow.java99
1 files changed, 57 insertions, 42 deletions
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java
index 2d8a8627468..15d5fe8a175 100644
--- a/java/org/gnu/emacs/EmacsWindow.java
+++ b/java/org/gnu/emacs/EmacsWindow.java
@@ -99,9 +99,8 @@ public final class EmacsWindow extends EmacsHandleObject
99 private EmacsGC scratchGC; 99 private EmacsGC scratchGC;
100 100
101 /* The button state and keyboard modifier mask at the time of the 101 /* The button state and keyboard modifier mask at the time of the
102 last button press or release event. The modifier mask is reset 102 last button press or release event. */
103 upon each window focus change. */ 103 public int lastButtonState;
104 public int lastButtonState, lastModifiers;
105 104
106 /* Whether or not the window is mapped. */ 105 /* Whether or not the window is mapped. */
107 private volatile boolean isMapped; 106 private volatile boolean isMapped;
@@ -562,15 +561,16 @@ public final class EmacsWindow extends EmacsHandleObject
562 eventStrings.put (serial, string); 561 eventStrings.put (serial, string);
563 } 562 }
564 563
565 /* event.getCharacters is used because older input methods still 564
566 require it. */ 565
567 @SuppressWarnings ("deprecation") 566 /* Return the modifier mask associated with the specified keyboard
568 public void 567 input EVENT. Replace bits corresponding to Left or Right keys
569 onKeyDown (int keyCode, KeyEvent event) 568 with their corresponding general modifier bits. */
569
570 private int
571 eventModifiers (KeyEvent event)
570 { 572 {
571 int state, state_1; 573 int state;
572 long serial;
573 String characters;
574 574
575 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) 575 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
576 state = event.getModifiers (); 576 state = event.getModifiers ();
@@ -592,6 +592,46 @@ public final class EmacsWindow extends EmacsHandleObject
592 state |= KeyEvent.META_CTRL_MASK; 592 state |= KeyEvent.META_CTRL_MASK;
593 } 593 }
594 594
595 return state;
596 }
597
598 /* Return the modifier mask associated with the specified motion
599 EVENT. Replace bits corresponding to Left or Right keys with
600 their corresponding general modifier bits. */
601
602 private int
603 motionEventModifiers (MotionEvent event)
604 {
605 int state;
606
607 state = event.getMetaState ();
608
609 /* Normalize the state by setting the generic modifier bit if
610 either a left or right modifier is pressed. */
611
612 if ((state & KeyEvent.META_ALT_LEFT_ON) != 0
613 || (state & KeyEvent.META_ALT_RIGHT_ON) != 0)
614 state |= KeyEvent.META_ALT_MASK;
615
616 if ((state & KeyEvent.META_CTRL_LEFT_ON) != 0
617 || (state & KeyEvent.META_CTRL_RIGHT_ON) != 0)
618 state |= KeyEvent.META_CTRL_MASK;
619
620 return state;
621 }
622
623 /* event.getCharacters is used because older input methods still
624 require it. */
625 @SuppressWarnings ("deprecation")
626 public void
627 onKeyDown (int keyCode, KeyEvent event)
628 {
629 int state, state_1;
630 long serial;
631 String characters;
632
633 state = eventModifiers (event);
634
595 /* Ignore meta-state understood by Emacs for now, or Ctrl+C will 635 /* Ignore meta-state understood by Emacs for now, or Ctrl+C will
596 not be recognized as an ASCII key press event. */ 636 not be recognized as an ASCII key press event. */
597 state_1 637 state_1
@@ -605,7 +645,6 @@ public final class EmacsWindow extends EmacsHandleObject
605 state, keyCode, 645 state, keyCode,
606 getEventUnicodeChar (event, 646 getEventUnicodeChar (event,
607 state_1)); 647 state_1));
608 lastModifiers = state;
609 648
610 characters = event.getCharacters (); 649 characters = event.getCharacters ();
611 650
@@ -620,25 +659,8 @@ public final class EmacsWindow extends EmacsHandleObject
620 int state, state_1; 659 int state, state_1;
621 long time; 660 long time;
622 661
623 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) 662 /* Compute the event's modifier mask. */
624 state = event.getModifiers (); 663 state = eventModifiers (event);
625 else
626 {
627 /* Replace this with getMetaState and manual
628 normalization. */
629 state = event.getMetaState ();
630
631 /* Normalize the state by setting the generic modifier bit if
632 either a left or right modifier is pressed. */
633
634 if ((state & KeyEvent.META_ALT_LEFT_ON) != 0
635 || (state & KeyEvent.META_ALT_RIGHT_ON) != 0)
636 state |= KeyEvent.META_ALT_MASK;
637
638 if ((state & KeyEvent.META_CTRL_LEFT_ON) != 0
639 || (state & KeyEvent.META_CTRL_RIGHT_ON) != 0)
640 state |= KeyEvent.META_CTRL_MASK;
641 }
642 664
643 /* Ignore meta-state understood by Emacs for now, or Ctrl+C will 665 /* Ignore meta-state understood by Emacs for now, or Ctrl+C will
644 not be recognized as an ASCII key press event. */ 666 not be recognized as an ASCII key press event. */
@@ -650,7 +672,6 @@ public final class EmacsWindow extends EmacsHandleObject
650 state, keyCode, 672 state, keyCode,
651 getEventUnicodeChar (event, 673 getEventUnicodeChar (event,
652 state_1)); 674 state_1));
653 lastModifiers = state;
654 675
655 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) 676 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
656 { 677 {
@@ -671,12 +692,6 @@ public final class EmacsWindow extends EmacsHandleObject
671 onFocusChanged (boolean gainFocus) 692 onFocusChanged (boolean gainFocus)
672 { 693 {
673 EmacsActivity.invalidateFocus (); 694 EmacsActivity.invalidateFocus ();
674
675 /* If focus has been lost, reset the keyboard modifier state, as
676 subsequent changes will not be recorded. */
677
678 if (!gainFocus)
679 lastModifiers = 0;
680 } 695 }
681 696
682 /* Notice that the activity has been detached or destroyed. 697 /* Notice that the activity has been detached or destroyed.
@@ -940,7 +955,7 @@ public final class EmacsWindow extends EmacsHandleObject
940 EmacsNative.sendButtonPress (this.handle, (int) event.getX (), 955 EmacsNative.sendButtonPress (this.handle, (int) event.getX (),
941 (int) event.getY (), 956 (int) event.getY (),
942 event.getEventTime (), 957 event.getEventTime (),
943 lastModifiers, 958 motionEventModifiers (event),
944 whatButtonWasIt (event, true)); 959 whatButtonWasIt (event, true));
945 960
946 if (Build.VERSION.SDK_INT 961 if (Build.VERSION.SDK_INT
@@ -955,7 +970,7 @@ public final class EmacsWindow extends EmacsHandleObject
955 EmacsNative.sendButtonRelease (this.handle, (int) event.getX (), 970 EmacsNative.sendButtonRelease (this.handle, (int) event.getX (),
956 (int) event.getY (), 971 (int) event.getY (),
957 event.getEventTime (), 972 event.getEventTime (),
958 lastModifiers, 973 motionEventModifiers (event),
959 whatButtonWasIt (event, false)); 974 whatButtonWasIt (event, false));
960 975
961 if (Build.VERSION.SDK_INT 976 if (Build.VERSION.SDK_INT
@@ -988,7 +1003,7 @@ public final class EmacsWindow extends EmacsHandleObject
988 EmacsNative.sendButtonRelease (this.handle, (int) event.getX (), 1003 EmacsNative.sendButtonRelease (this.handle, (int) event.getX (),
989 (int) event.getY (), 1004 (int) event.getY (),
990 event.getEventTime (), 1005 event.getEventTime (),
991 lastModifiers, 1006 motionEventModifiers (event),
992 whatButtonWasIt (event, false)); 1007 whatButtonWasIt (event, false));
993 lastButtonState = event.getButtonState (); 1008 lastButtonState = event.getButtonState ();
994 } 1009 }
@@ -1000,7 +1015,7 @@ public final class EmacsWindow extends EmacsHandleObject
1000 EmacsNative.sendWheel (this.handle, (int) event.getX (), 1015 EmacsNative.sendWheel (this.handle, (int) event.getX (),
1001 (int) event.getY (), 1016 (int) event.getY (),
1002 event.getEventTime (), 1017 event.getEventTime (),
1003 lastModifiers, 1018 motionEventModifiers (event),
1004 event.getAxisValue (MotionEvent.AXIS_HSCROLL), 1019 event.getAxisValue (MotionEvent.AXIS_HSCROLL),
1005 event.getAxisValue (MotionEvent.AXIS_VSCROLL)); 1020 event.getAxisValue (MotionEvent.AXIS_VSCROLL));
1006 return true; 1021 return true;