RFR: 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

2021-01-23 Thread Kevin Rushforth
The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM LOCK 
on the keyboard. Being able to read the lock state would allow an application 
to inform the user that caps lock was enabled for passwords or other usages 
where the keyboard input might not be echoed. It would also allow an 
application to do spell checking / auto-correction that might ordinarily be 
skipped when typing all upper-case letters.

We need an equivalent JavaFX API to the existing AWT 
`java.awt.ToolKit::getLockingKeyState` method. A natural place to put this in 
JavaFX is in the `javafx.application.Platform` class, so we propose to create a 
new `Platform::isKeyLocked` method, which will take a `KeyCode` -- either 
`CAPS` or `NUM_LOCK` -- and return an `Optional` indicating whether or 
not that key is in the locked or "on" state. If we can't read the key state on 
a particular platform, we will return `Optional.empty()`, rather than throwing 
a runtime exception as AWT does.

I have provided both an automated Robot test and a manual test. The latter is 
needed primarily because we can't set the CAPS lock on Mac using Robot, but 
also because we want  way to test the case where the user has enabled CAPS lock 
before the program starts.

-

Commit messages:
 - 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

Changes: https://git.openjdk.java.net/jfx/pull/385/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jfx=385=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8259680
  Stats: 419 lines in 15 files changed: 418 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jfx/pull/385.diff
  Fetch: git fetch https://git.openjdk.java.net/jfx pull/385/head:pull/385

PR: https://git.openjdk.java.net/jfx/pull/385


Re: RFR: 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

2021-01-23 Thread Nir Lisker
On Sat, 23 Jan 2021 15:40:04 GMT, Kevin Rushforth  wrote:

> The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM 
> LOCK on the keyboard. Being able to read the lock state would allow an 
> application to inform the user that caps lock was enabled for passwords or 
> other usages where the keyboard input might not be echoed. It would also 
> allow an application to do spell checking / auto-correction that might 
> ordinarily be skipped when typing all upper-case letters.
> 
> We need an equivalent JavaFX API to the existing AWT 
> `java.awt.ToolKit::getLockingKeyState` method. A natural place to put this in 
> JavaFX is in the `javafx.application.Platform` class, so we propose to create 
> a new `Platform::isKeyLocked` method, which will take a `KeyCode` -- either 
> `CAPS` or `NUM_LOCK` -- and return an `Optional` indicating whether 
> or not that key is in the locked or "on" state. If we can't read the key 
> state on a particular platform, we will return `Optional.empty()`, rather 
> than throwing a runtime exception as AWT does.
> 
> I have provided both an automated Robot test and a manual test. The latter is 
> needed primarily because we can't set the CAPS lock on Mac using Robot, but 
> also because we want  way to test the case where the user has enabled CAPS 
> lock before the program starts.

modules/javafx.graphics/src/main/java/javafx/application/Platform.java line 351:

> 349:  *
> 350:  * @throws IllegalArgumentException if {@code keyCode} is not one of 
> the
> 351:  * valid KeyCode values.

`{@code KeyCode}`

-

PR: https://git.openjdk.java.net/jfx/pull/385


Re: RFR: 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

2021-01-23 Thread Nir Lisker
On Sat, 23 Jan 2021 15:40:04 GMT, Kevin Rushforth  wrote:

> The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM 
> LOCK on the keyboard. Being able to read the lock state would allow an 
> application to inform the user that caps lock was enabled for passwords or 
> other usages where the keyboard input might not be echoed. It would also 
> allow an application to do spell checking / auto-correction that might 
> ordinarily be skipped when typing all upper-case letters.
> 
> We need an equivalent JavaFX API to the existing AWT 
> `java.awt.ToolKit::getLockingKeyState` method. A natural place to put this in 
> JavaFX is in the `javafx.application.Platform` class, so we propose to create 
> a new `Platform::isKeyLocked` method, which will take a `KeyCode` -- either 
> `CAPS` or `NUM_LOCK` -- and return an `Optional` indicating whether 
> or not that key is in the locked or "on" state. If we can't read the key 
> state on a particular platform, we will return `Optional.empty()`, rather 
> than throwing a runtime exception as AWT does.
> 
> I have provided both an automated Robot test and a manual test. The latter is 
> needed primarily because we can't set the CAPS lock on Mac using Robot, but 
> also because we want  way to test the case where the user has enabled CAPS 
> lock before the program starts.

modules/javafx.graphics/src/main/java/javafx/application/Platform.java line 342:

> 340:  * specified {@code keyCode}, an empty {@code Optional} is returned.
> 341:  * If the keyboard attached to the system doesn't have the specified 
> key,
> 342:  * {@code Boolean.FALSE} is returned.

Not `Optional.of(false)`?

-

PR: https://git.openjdk.java.net/jfx/pull/385


Re: RFR: 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

2021-01-23 Thread Kevin Rushforth
On Sat, 23 Jan 2021 15:40:04 GMT, Kevin Rushforth  wrote:

> The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM 
> LOCK on the keyboard. Being able to read the lock state would allow an 
> application to inform the user that caps lock was enabled for passwords or 
> other usages where the keyboard input might not be echoed. It would also 
> allow an application to do spell checking / auto-correction that might 
> ordinarily be skipped when typing all upper-case letters.
> 
> We need an equivalent JavaFX API to the existing AWT 
> `java.awt.ToolKit::getLockingKeyState` method. A natural place to put this in 
> JavaFX is in the `javafx.application.Platform` class, so we propose to create 
> a new `Platform::isKeyLocked` method, which will take a `KeyCode` -- either 
> `CAPS` or `NUM_LOCK` -- and return an `Optional` indicating whether 
> or not that key is in the locked or "on" state. If we can't read the key 
> state on a particular platform, we will return `Optional.empty()`, rather 
> than throwing a runtime exception as AWT does.
> 
> I have provided both an automated Robot test and a manual test. The latter is 
> needed primarily because we can't set the CAPS lock on Mac using Robot, but 
> also because we want  way to test the case where the user has enabled CAPS 
> lock before the program starts.

modules/javafx.graphics/src/main/native-glass/gtk/glass_key.cpp line 361:

> 359: switch (keyCode) {
> 360: case com_sun_glass_events_KeyEvent_VK_CAPS_LOCK:
> 361: lockState = gdk_keymap_get_caps_lock_state(keyMap);

It seems that `gdk_keymap_get_caps_lock_state` isn't reliable on GTK 3 either. 
At least not when I test it on a Linux VM. I may end up using raw Xlib calls 
instead (which would have the added benefit of removing the "ifdef" for GTK 3).

-

PR: https://git.openjdk.java.net/jfx/pull/385


Re: RFR: 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

2021-01-23 Thread Nir Lisker
On Sat, 23 Jan 2021 15:40:04 GMT, Kevin Rushforth  wrote:

> The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM 
> LOCK on the keyboard. Being able to read the lock state would allow an 
> application to inform the user that caps lock was enabled for passwords or 
> other usages where the keyboard input might not be echoed. It would also 
> allow an application to do spell checking / auto-correction that might 
> ordinarily be skipped when typing all upper-case letters.
> 
> We need an equivalent JavaFX API to the existing AWT 
> `java.awt.ToolKit::getLockingKeyState` method. A natural place to put this in 
> JavaFX is in the `javafx.application.Platform` class, so we propose to create 
> a new `Platform::isKeyLocked` method, which will take a `KeyCode` -- either 
> `CAPS` or `NUM_LOCK` -- and return an `Optional` indicating whether 
> or not that key is in the locked or "on" state. If we can't read the key 
> state on a particular platform, we will return `Optional.empty()`, rather 
> than throwing a runtime exception as AWT does.
> 
> I have provided both an automated Robot test and a manual test. The latter is 
> needed primarily because we can't set the CAPS lock on Mac using Robot, but 
> also because we want  way to test the case where the user has enabled CAPS 
> lock before the program starts.

modules/javafx.graphics/src/main/java/com/sun/glass/ui/Application.java line 
764:

> 762: default:
> 763: return Optional.empty();
> 764: }

This could be a switch expression:
return switch (lockState) {
case KeyEvent.KEY_LOCK_OFF -> Optional.of(false);
case KeyEvent.KEY_LOCK_ON -> Optional.of(true);
default -> Optional.empty();
}
Also, do we use a space after `switch`? I see many instances both with and 
without in the current source.

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java
 line 1250:

> 1248: default:
> 1249: return com.sun.glass.events.KeyEvent.VK_UNDEFINED;
> 1250: }

Also expression switch here.

-

PR: https://git.openjdk.java.net/jfx/pull/385


Re: RFR: 8233678: [macos 10.15] System menu bar does not work initially on macOS Catalina [v3]

2021-01-23 Thread Alex Blewitt
On Thu, 21 Jan 2021 00:07:30 GMT, Kevin Rushforth  wrote:

>> I don't yet know whether there is an alternative that would allow the 
>> menubar to work without deactivating the app, but I filed a follow-up bug to 
>> track this:
>> 
>> [JDK-8257835](https://bugs.openjdk.java.net/browse/JDK-8257835): Brief flash 
>> in terminal window when launching FX app on macOS
>> 
>> It seems like it might be possible to fix this, since AWT initialization 
>> doesn't run into this. I note that AWT uses an Apple-provided "JavaRuntime 
>> Support" (JRS) Framework. We would need to see whether there is something 
>> else possible using public macOS  APIs.
>
> @tomsontom Thanks for letting me know. He reached to me directly as well, so 
> I'll plan to add the information to the follow-on bug, 
> [JDK-8257835](https://bugs.openjdk.java.net/browse/JDK-8257835).

BTW there were observations that the setActivationPolicy call needs to be 
inside the callback as well, at least on 10.15. I've updated the bug on the 
StackOverflow question, and the Eclipse bug 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=552063 has a fix about to go in 
with the suggested change.

-

PR: https://git.openjdk.java.net/jfx/pull/361


Re: RFR: 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

2021-01-23 Thread Nir Lisker
On Sat, 23 Jan 2021 15:40:04 GMT, Kevin Rushforth  wrote:

> The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM 
> LOCK on the keyboard. Being able to read the lock state would allow an 
> application to inform the user that caps lock was enabled for passwords or 
> other usages where the keyboard input might not be echoed. It would also 
> allow an application to do spell checking / auto-correction that might 
> ordinarily be skipped when typing all upper-case letters.
> 
> We need an equivalent JavaFX API to the existing AWT 
> `java.awt.ToolKit::getLockingKeyState` method. A natural place to put this in 
> JavaFX is in the `javafx.application.Platform` class, so we propose to create 
> a new `Platform::isKeyLocked` method, which will take a `KeyCode` -- either 
> `CAPS` or `NUM_LOCK` -- and return an `Optional` indicating whether 
> or not that key is in the locked or "on" state. If we can't read the key 
> state on a particular platform, we will return `Optional.empty()`, rather 
> than throwing a runtime exception as AWT does.
> 
> I have provided both an automated Robot test and a manual test. The latter is 
> needed primarily because we can't set the CAPS lock on Mac using Robot, but 
> also because we want  way to test the case where the user has enabled CAPS 
> lock before the program starts.

modules/javafx.graphics/src/main/java/javafx/application/Platform.java line 336:

> 334: /**
> 335:  * Returns a flag indicating whether the key corresponding to {@code 
> keyCode}
> 336:  * is in the locked or "on" state.

I would write "locked, or "on", state" or "locked (or "on") state" because in 
the current form it can be understood as 2 different conditions.

-

PR: https://git.openjdk.java.net/jfx/pull/385


Re: RFR: 8259680: Need API to query states of CAPS LOCK and NUM LOCK keys

2021-01-23 Thread Nir Lisker
On Sat, 23 Jan 2021 15:40:04 GMT, Kevin Rushforth  wrote:

> The JavaFX API does not provide a way to get the state of CAPS LOCK or NUM 
> LOCK on the keyboard. Being able to read the lock state would allow an 
> application to inform the user that caps lock was enabled for passwords or 
> other usages where the keyboard input might not be echoed. It would also 
> allow an application to do spell checking / auto-correction that might 
> ordinarily be skipped when typing all upper-case letters.
> 
> We need an equivalent JavaFX API to the existing AWT 
> `java.awt.ToolKit::getLockingKeyState` method. A natural place to put this in 
> JavaFX is in the `javafx.application.Platform` class, so we propose to create 
> a new `Platform::isKeyLocked` method, which will take a `KeyCode` -- either 
> `CAPS` or `NUM_LOCK` -- and return an `Optional` indicating whether 
> or not that key is in the locked or "on" state. If we can't read the key 
> state on a particular platform, we will return `Optional.empty()`, rather 
> than throwing a runtime exception as AWT does.
> 
> I have provided both an automated Robot test and a manual test. The latter is 
> needed primarily because we can't set the CAPS lock on Mac using Robot, but 
> also because we want  way to test the case where the user has enabled CAPS 
> lock before the program starts.

modules/javafx.graphics/src/main/java/javafx/application/Platform.java line 345:

> 343:  * This method must be called on the JavaFX Application thread.
> 344:  *
> 345:  * @param keyCode the KeyCode of the lock state to query

`{@code KeyCode}`

-

PR: https://git.openjdk.java.net/jfx/pull/385