Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8311922: [macOS] right-Option key fails to generate release event #15432

Closed

Conversation

DamonGuy
Copy link
Contributor

@DamonGuy DamonGuy commented Aug 25, 2023

Previously, a new key combination involving the option key was added to Aqua LAF for JTextAreas. In doing so, some code was removed that created this regression. The regression caused the right option key on Mac OS to incorrectly show another KeyPressed event instead of a KeyReleased event when pressing and releasing the key. Additionally, the location of the key was 'standard' instead of 'right'. Adding back the key mask and its following code resolves the issue and doesn't cause any other CI tests to fail.

The headful test included displays the key events as they're pressed. After the changes, the test correctly shows the right option key's KeyPressed and KeyReleased events and shows the location as 'right'.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8311922: [macOS] right-Option key fails to generate release event (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15432/head:pull/15432
$ git checkout pull/15432

Update a local copy of the PR:
$ git checkout pull/15432
$ git pull https://git.openjdk.org/jdk.git pull/15432/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15432

View PR using the GUI difftool:
$ git pr show -t 15432

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15432.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 25, 2023

👋 Welcome back dnguyen! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 25, 2023
@openjdk
Copy link

openjdk bot commented Aug 25, 2023

@DamonGuy The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Aug 25, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 25, 2023

Webrevs

@honkar-jdk
Copy link
Contributor

honkar-jdk commented Aug 25, 2023

@DamonGuy Tested with the patch. Observed that the key code and extended modifier differ for left vs right option key. This is not the case for other left/right modifier keys such as Shift, Command. I think some extra flags (key masks) are being set in case of Right Option Key.

LEFT SHIFT KEY
-----------------
KEY PRESSED: 
 key code = 16 (⇧)
 extended modifiers = 64 (⇧)
 action key? NO
 key location: left
KEY RELEASED: 
 key code = 16 (⇧)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: left

RIGHT SHIFT KEY
-----------------
KEY PRESSED: 
 key code = 16 (⇧)
 extended modifiers = 64 (⇧)
 action key? NO
 key location: right
KEY RELEASED: 
 key code = 16 (⇧)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: right

------------------------------------------------------------------

LEFT OPTION KEY
------------------
KEY PRESSED: 
 key code = 18 (⌥)
 extended modifiers = 512 (⌥)
 action key? NO
 key location: left
KEY RELEASED: 
 key code = 18 (⌥)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: left

RIGHT OPTION KEY
-------------------
KEY PRESSED: 
 key code = 65406 (⌥)
 extended modifiers = 8704 (⌥+⌥)
 action key? NO
 key location: right
KEY RELEASED: 
 key code = 65406 (⌥)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: right

@prsadhuk
Copy link
Contributor

prsadhuk commented Aug 28, 2023

I guess it was removed in as part of JDK-8267374 fix. Please see PR#9230 where it was concluded that we dont need ALT_GRAPH mapping for macos and RightOption key was mapped to ALT_GRAPH which makes Option key not work
#9230 (comment)
#9230 (comment)

Please run the regression test added/modified to see it does not regress those, mainly
test/jdk/javax/swing/JTextArea/TestAltUpDown.java

@DamonGuy
Copy link
Contributor Author

@DamonGuy Tested with the patch. Observed that the key code and extended modifier differ for left vs right option key. This is not the case for other left/right modifier keys such as Shift, Command. I think some extra flags (key masks) are being set in case of Right Option Key.

LEFT SHIFT KEY
-----------------
KEY PRESSED: 
 key code = 16 (⇧)
 extended modifiers = 64 (⇧)
 action key? NO
 key location: left
KEY RELEASED: 
 key code = 16 (⇧)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: left

RIGHT SHIFT KEY
-----------------
KEY PRESSED: 
 key code = 16 (⇧)
 extended modifiers = 64 (⇧)
 action key? NO
 key location: right
KEY RELEASED: 
 key code = 16 (⇧)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: right

------------------------------------------------------------------

LEFT OPTION KEY
------------------
KEY PRESSED: 
 key code = 18 (⌥)
 extended modifiers = 512 (⌥)
 action key? NO
 key location: left
KEY RELEASED: 
 key code = 18 (⌥)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: left

RIGHT OPTION KEY
-------------------
KEY PRESSED: 
 key code = 65406 (⌥)
 extended modifiers = 8704 (⌥+⌥)
 action key? NO
 key location: right
KEY RELEASED: 
 key code = 65406 (⌥)
 extended modifiers = 0 (no extended modifiers)
 action key? NO
 key location: right

Thanks for catching this. I believe the edit I just pushed fixes this. My test now shows the correct key code and location on my end.

@DamonGuy
Copy link
Contributor Author

I guess it was removed in as part of JDK-8267374 fix. Please see PR#9230 where it was concluded that we dont need ALT_GRAPH mapping for macos and RightOption key was mapped to ALT_GRAPH which makes Option key not work #9230 (comment) #9230 (comment)

Please run the regression test added/modified to see it does not regress those, mainly test/jdk/javax/swing/JTextArea/TestAltUpDown.java

I see the comments. I removed the code that was removed again and instead edited the existing NSAlternateKeyMask. Fix now shows the correct key code as well. TestAltUpDown passes as well as my new test.

@alisenchung
Copy link
Contributor

why was the keycode wrong with the previous fix? and why do we need to manually set leftAltKeyPressed = YES? should this be done in a different part of the code?

@@ -291,7 +291,7 @@
//kCGSFlagsMaskAppleLeftAlternateKey,
//kCGSFlagsMaskAppleRightAlternateKey,
58,
0,
61,
Copy link
Contributor

@honkar-jdk honkar-jdk Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the only change required to make right option key working is adding in the rightKeyCode (61) here. I don't think it is required to revert changes related toleftAltKeyPressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems correct. I updated it to only include the key code. Re-ran my test and TestAltUpDown, and both passed still.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated changes look good.

@DamonGuy
Copy link
Contributor Author

why was the keycode wrong with the previous fix? and why do we need to manually set leftAltKeyPressed = YES? should this be done in a different part of the code?

I originally added back the code that was removed. There seemed to be 2 instances of NSAlternateKeyMask afterwards, so the key code value was incorrect. This must've been the case before the regression as well I'd assume. leftAltKeyPressed has been removed as well since it doesn't seem necessary to fix this particular issue.

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Manual test looks good.

I guess this test cannot be automated using Robot since the VK_ALT defaults to the left option key.

@DamonGuy
Copy link
Contributor Author

LGTM. Manual test looks good.

I guess this test cannot be automated using Robot since the VK_ALT defaults to the left option keypress.

Right. I looked into automating this and making the test headless, but I didn't see a way around this. Thanks

@openjdk
Copy link

openjdk bot commented Sep 20, 2023

@DamonGuy This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8311922: [macOS] right-Option key fails to generate release event

Reviewed-by: honkar, prr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 539 new commits pushed to the master branch:

  • 54028e7: 8316562: serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java times out after JDK-8314829
  • 7c991cc: 8296246: Update Unicode Data Files to Version 15.1.0
  • a021dbc: 8316149: Open source several Swing JTree JViewport KeyboardManager tests
  • 455cfae: 8315880: change LockingMode default from LM_LEGACY to LM_LIGHTWEIGHT
  • 9e00949: 8316427: Duplicated code for {obj,type}ArrayKlass::array_klass
  • c43ebd3: 8315981: Opensource five more random Swing tests
  • e30e356: 8316461: Fix: make test outputs TEST SUCCESS after unsuccessful exit
  • 242eeae: 8286757: adlc tries to build with /pathmap but without /experimental:deterministic
  • b275bdd: 8308995: Update Network IO JFR events to be static mirror events
  • e1870d3: 8316411: compiler/compilercontrol/TestConflictInlineCommands.java fails intermittent with force inline by CompileCommand missing
  • ... and 529 more: https://git.openjdk.org/jdk/compare/6864441163f946d0bec7380a2a120e31b812a6dc...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 20, 2023
@DamonGuy
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 21, 2023

Going to push as commit 83b01cf.
Since your change was applied there have been 564 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 21, 2023
@openjdk openjdk bot closed this Sep 21, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 21, 2023
@openjdk
Copy link

openjdk bot commented Sep 21, 2023

@DamonGuy Pushed as commit 83b01cf.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants