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

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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -875,7 +875,7 @@ public KeyCode getPlatformShortcutKey() {
}

/**
* Return the lock state for the given keyCode.
* Returns the lock state for the given keyCode.
* @param keyCode the keyCode to check
* @return the lock state for the given keyCode.
*/
@@ -378,23 +378,23 @@ JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1isKeyLocked
return com_sun_glass_events_KeyEvent_KEY_LOCK_UNKNOWN;
}

Atom atom = None;
Atom keyCodeAtom = None;
switch (keyCode) {
case com_sun_glass_events_KeyEvent_VK_CAPS_LOCK:
atom = XInternAtom(display, "Caps Lock", True);
keyCodeAtom = XInternAtom(display, "Caps Lock", True);
break;

case com_sun_glass_events_KeyEvent_VK_NUM_LOCK:
atom = XInternAtom(display, "Num Lock", True);
keyCodeAtom = XInternAtom(display, "Num Lock", True);
break;
}

if (atom == None) {
if (keyCodeAtom == None) {
return com_sun_glass_events_KeyEvent_KEY_LOCK_UNKNOWN;
}

Bool isLocked = False;
if (XkbGetNamedIndicator(display, atom, NULL, &isLocked, NULL, NULL)) {
if (XkbGetNamedIndicator(display, keyCodeAtom, NULL, &isLocked, NULL, NULL)) {
if (isLocked) {
return com_sun_glass_events_KeyEvent_KEY_LOCK_ON;
} else {
@@ -404,7 +404,6 @@ BOOL GetMacKey(jint javaKeyCode, unsigned short *outMacKeyCode)
JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacApplication__1isKeyLocked
(JNIEnv * env, jobject obj, jint keyCode)
{
NSUInteger modifierFlags = [NSEvent modifierFlags];
NSUInteger mask = 0;
switch (keyCode) {
case com_sun_glass_events_KeyEvent_VK_CAPS_LOCK:
@@ -415,6 +414,7 @@ BOOL GetMacKey(jint javaKeyCode, unsigned short *outMacKeyCode)
default:
return com_sun_glass_events_KeyEvent_KEY_LOCK_UNKNOWN;
}
NSUInteger modifierFlags = [NSEvent modifierFlags];
return (modifierFlags & mask) ? com_sun_glass_events_KeyEvent_KEY_LOCK_ON
: com_sun_glass_events_KeyEvent_KEY_LOCK_OFF;
}