diff options
| author | Po Lu | 2024-05-12 15:46:38 +0800 |
|---|---|---|
| committer | Po Lu | 2024-05-12 15:49:53 +0800 |
| commit | ea98a6af2f30eccfed3e152149c6a039bd16ff33 (patch) | |
| tree | 816f1b65c38f4546e71d6f8a2074fd3380ba9d08 /java | |
| parent | af6df8e0454f3f51d3855683216dfd12843e6959 (diff) | |
| download | emacs-ea98a6af2f30eccfed3e152149c6a039bd16ff33.tar.gz emacs-ea98a6af2f30eccfed3e152149c6a039bd16ff33.zip | |
Additional changes to processing of Num Lock on Android
* java/org/gnu/emacs/EmacsView.java (onKeyDown, onKeyMultiple)
(onKeyDown): Disregard Num and Scroll Lock keys, and return
value of window functions to the system.
* java/org/gnu/emacs/EmacsWindow.java (eventModifiers): Return
normalized meta state, not only those bits the system considers
modifiers.
(onKeyDown, onKeyUp): Ignore numpad keys to which no base
characters are assigned, so that the system may generate the
proper action keys instead.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsView.java | 45 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsWindow.java | 43 |
2 files changed, 57 insertions, 31 deletions
diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java index 977ad90310d..074e7242540 100644 --- a/java/org/gnu/emacs/EmacsView.java +++ b/java/org/gnu/emacs/EmacsView.java | |||
| @@ -505,42 +505,45 @@ public final class EmacsView extends ViewGroup | |||
| 505 | public boolean | 505 | public boolean |
| 506 | onKeyDown (int keyCode, KeyEvent event) | 506 | onKeyDown (int keyCode, KeyEvent event) |
| 507 | { | 507 | { |
| 508 | if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP | 508 | if (((keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 509 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN | 509 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 510 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) | 510 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) |
| 511 | && !EmacsNative.shouldForwardMultimediaButtons ()) | 511 | && !EmacsNative.shouldForwardMultimediaButtons ()) |
| 512 | return false; | 512 | || keyCode == KeyEvent.KEYCODE_SCROLL_LOCK |
| 513 | || keyCode == KeyEvent.KEYCODE_NUM_LOCK) | ||
| 514 | return super.onKeyDown (keyCode, event); | ||
| 513 | 515 | ||
| 514 | window.onKeyDown (keyCode, event); | 516 | return window.onKeyDown (keyCode, event); |
| 515 | return true; | ||
| 516 | } | 517 | } |
| 517 | 518 | ||
| 518 | @Override | 519 | @Override |
| 519 | public boolean | 520 | public boolean |
| 520 | onKeyMultiple (int keyCode, int repeatCount, KeyEvent event) | 521 | onKeyMultiple (int keyCode, int repeatCount, KeyEvent event) |
| 521 | { | 522 | { |
| 522 | if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP | 523 | if (((keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 523 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN | 524 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 524 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) | 525 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) |
| 525 | && !EmacsNative.shouldForwardMultimediaButtons ()) | 526 | && !EmacsNative.shouldForwardMultimediaButtons ()) |
| 526 | return false; | 527 | || keyCode == KeyEvent.KEYCODE_SCROLL_LOCK |
| 528 | || keyCode == KeyEvent.KEYCODE_NUM_LOCK) | ||
| 529 | return super.onKeyMultiple (keyCode, repeatCount, event); | ||
| 527 | 530 | ||
| 528 | window.onKeyDown (keyCode, event); | 531 | return window.onKeyDown (keyCode, event); |
| 529 | return true; | ||
| 530 | } | 532 | } |
| 531 | 533 | ||
| 532 | @Override | 534 | @Override |
| 533 | public boolean | 535 | public boolean |
| 534 | onKeyUp (int keyCode, KeyEvent event) | 536 | onKeyUp (int keyCode, KeyEvent event) |
| 535 | { | 537 | { |
| 536 | if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP | 538 | if (((keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 537 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN | 539 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 538 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) | 540 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) |
| 539 | && !EmacsNative.shouldForwardMultimediaButtons ()) | 541 | && !EmacsNative.shouldForwardMultimediaButtons ()) |
| 540 | return false; | 542 | || keyCode == KeyEvent.KEYCODE_SCROLL_LOCK |
| 543 | || keyCode == KeyEvent.KEYCODE_NUM_LOCK) | ||
| 544 | return super.onKeyUp (keyCode, event); | ||
| 541 | 545 | ||
| 542 | window.onKeyUp (keyCode, event); | 546 | return window.onKeyUp (keyCode, event); |
| 543 | return true; | ||
| 544 | } | 547 | } |
| 545 | 548 | ||
| 546 | @Override | 549 | @Override |
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 6442f373736..f8dd8518af0 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java | |||
| @@ -633,8 +633,8 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 633 | 633 | ||
| 634 | 634 | ||
| 635 | /* Return the modifier mask associated with the specified keyboard | 635 | /* Return the modifier mask associated with the specified keyboard |
| 636 | input EVENT. Replace bits corresponding to Left or Right keys | 636 | input EVENT. Replace bits representing Left or Right keys with |
| 637 | with their corresponding general modifier bits. */ | 637 | their corresponding general modifier bits. */ |
| 638 | 638 | ||
| 639 | public static int | 639 | public static int |
| 640 | eventModifiers (KeyEvent event) | 640 | eventModifiers (KeyEvent event) |
| @@ -642,7 +642,7 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 642 | int state; | 642 | int state; |
| 643 | 643 | ||
| 644 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) | 644 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) |
| 645 | state = event.getModifiers (); | 645 | state = KeyEvent.normalizeMetaState (event.getMetaState ()); |
| 646 | else | 646 | else |
| 647 | { | 647 | { |
| 648 | /* Replace this with getMetaState and manual | 648 | /* Replace this with getMetaState and manual |
| @@ -667,10 +667,10 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 667 | /* event.getCharacters is used because older input methods still | 667 | /* event.getCharacters is used because older input methods still |
| 668 | require it. */ | 668 | require it. */ |
| 669 | @SuppressWarnings ("deprecation") | 669 | @SuppressWarnings ("deprecation") |
| 670 | public void | 670 | public boolean |
| 671 | onKeyDown (int keyCode, KeyEvent event) | 671 | onKeyDown (int keyCode, KeyEvent event) |
| 672 | { | 672 | { |
| 673 | int state, state_1, extra_ignored; | 673 | int state, state_1, extra_ignored, unicode_char; |
| 674 | long serial; | 674 | long serial; |
| 675 | String characters; | 675 | String characters; |
| 676 | 676 | ||
| @@ -686,7 +686,7 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 686 | Deliver onKeyDown events in onKeyUp instead, so as not to | 686 | Deliver onKeyDown events in onKeyUp instead, so as not to |
| 687 | navigate backwards during gesture navigation. */ | 687 | navigate backwards during gesture navigation. */ |
| 688 | 688 | ||
| 689 | return; | 689 | return true; |
| 690 | } | 690 | } |
| 691 | 691 | ||
| 692 | state = eventModifiers (event); | 692 | state = eventModifiers (event); |
| @@ -720,23 +720,36 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 720 | state &= ~KeyEvent.META_ALT_MASK; | 720 | state &= ~KeyEvent.META_ALT_MASK; |
| 721 | } | 721 | } |
| 722 | 722 | ||
| 723 | unicode_char = getEventUnicodeChar (event, state_1); | ||
| 724 | |||
| 725 | /* If a NUMPAD_ key is detected for which no character is returned, | ||
| 726 | return false without sending the key event, as this will prompt | ||
| 727 | the system to send an event with the corresponding action | ||
| 728 | key. */ | ||
| 729 | |||
| 730 | if (keyCode >= KeyEvent.KEYCODE_NUMPAD_0 | ||
| 731 | && keyCode <= KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN | ||
| 732 | && unicode_char == 0) | ||
| 733 | return false; | ||
| 734 | |||
| 723 | synchronized (eventStrings) | 735 | synchronized (eventStrings) |
| 724 | { | 736 | { |
| 725 | serial | 737 | serial |
| 726 | = EmacsNative.sendKeyPress (this.handle, | 738 | = EmacsNative.sendKeyPress (this.handle, |
| 727 | event.getEventTime (), | 739 | event.getEventTime (), |
| 728 | state, keyCode, | 740 | state, keyCode, |
| 729 | getEventUnicodeChar (event, | 741 | unicode_char); |
| 730 | state_1)); | ||
| 731 | 742 | ||
| 732 | characters = event.getCharacters (); | 743 | characters = event.getCharacters (); |
| 733 | 744 | ||
| 734 | if (characters != null && characters.length () > 1) | 745 | if (characters != null && characters.length () > 1) |
| 735 | saveUnicodeString ((int) serial, characters); | 746 | saveUnicodeString ((int) serial, characters); |
| 736 | } | 747 | } |
| 748 | |||
| 749 | return true; | ||
| 737 | } | 750 | } |
| 738 | 751 | ||
| 739 | public void | 752 | public boolean |
| 740 | onKeyUp (int keyCode, KeyEvent event) | 753 | onKeyUp (int keyCode, KeyEvent event) |
| 741 | { | 754 | { |
| 742 | int state, state_1, unicode_char, extra_ignored; | 755 | int state, state_1, unicode_char, extra_ignored; |
| @@ -781,12 +794,20 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 781 | /* If the key press's been canceled, return immediately. */ | 794 | /* If the key press's been canceled, return immediately. */ |
| 782 | 795 | ||
| 783 | if ((event.getFlags () & KeyEvent.FLAG_CANCELED) != 0) | 796 | if ((event.getFlags () & KeyEvent.FLAG_CANCELED) != 0) |
| 784 | return; | 797 | return true; |
| 785 | 798 | ||
| 786 | /* Dispatch the key press event that was deferred till now. */ | 799 | /* Dispatch the key press event that was deferred till now. */ |
| 787 | EmacsNative.sendKeyPress (this.handle, event.getEventTime (), | 800 | EmacsNative.sendKeyPress (this.handle, event.getEventTime (), |
| 788 | state, keyCode, unicode_char); | 801 | state, keyCode, unicode_char); |
| 789 | } | 802 | } |
| 803 | /* If a NUMPAD_ key is detected for which no character is returned, | ||
| 804 | return false without sending the key event, as this will prompt | ||
| 805 | the system to send an event with the corresponding action | ||
| 806 | key. */ | ||
| 807 | else if (keyCode >= KeyEvent.KEYCODE_NUMPAD_0 | ||
| 808 | && keyCode <= KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN | ||
| 809 | && unicode_char == 0) | ||
| 810 | return false; | ||
| 790 | 811 | ||
| 791 | EmacsNative.sendKeyRelease (this.handle, event.getEventTime (), | 812 | EmacsNative.sendKeyRelease (this.handle, event.getEventTime (), |
| 792 | state, keyCode, unicode_char); | 813 | state, keyCode, unicode_char); |
| @@ -804,6 +825,8 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 804 | 825 | ||
| 805 | lastQuitKeyRelease = time; | 826 | lastQuitKeyRelease = time; |
| 806 | } | 827 | } |
| 828 | |||
| 829 | return true; | ||
| 807 | } | 830 | } |
| 808 | 831 | ||
| 809 | public void | 832 | public void |