Skip to content

Commit d56d90e

Browse files
committed
8360647: [XWayland] [OL10] NumPad keys are not triggered
Reviewed-by: mbaesken Backport-of: 0029554d20f22648994040a041c418d48a2a0eb4
1 parent 5071889 commit d56d90e

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

src/java.desktop/unix/native/libawt_xawt/awt/screencast_pipewire.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#ifndef _AIX
3535
#include "screencast_pipewire.h"
3636
#include "fp_pipewire.h"
37+
#include "java_awt_event_KeyEvent.h"
38+
3739
#include <stdio.h>
3840

3941
#include "gtk_interface.h"
@@ -1142,6 +1144,24 @@ JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_remoteDesktopMou
11421144
return result ? RESULT_OK : pw.pwFd;
11431145
}
11441146

1147+
static int getNumpadKey(jint jkey) {
1148+
switch (jkey) {
1149+
case java_awt_event_KeyEvent_VK_NUMPAD0: return XK_KP_Insert;
1150+
case java_awt_event_KeyEvent_VK_NUMPAD1: return XK_KP_End;
1151+
case java_awt_event_KeyEvent_VK_NUMPAD2: return XK_KP_Down;
1152+
case java_awt_event_KeyEvent_VK_NUMPAD3: return XK_KP_Page_Down;
1153+
case java_awt_event_KeyEvent_VK_NUMPAD4: return XK_KP_Left;
1154+
case java_awt_event_KeyEvent_VK_NUMPAD5: return XK_KP_Begin;
1155+
case java_awt_event_KeyEvent_VK_NUMPAD6: return XK_KP_Right;
1156+
case java_awt_event_KeyEvent_VK_NUMPAD7: return XK_KP_Home;
1157+
case java_awt_event_KeyEvent_VK_NUMPAD8: return XK_KP_Up;
1158+
case java_awt_event_KeyEvent_VK_NUMPAD9: return XK_KP_Prior;
1159+
case java_awt_event_KeyEvent_VK_DECIMAL:
1160+
case java_awt_event_KeyEvent_VK_SEPARATOR: return XK_KP_Delete;
1161+
default: return 0;
1162+
}
1163+
}
1164+
11451165
/*
11461166
* Class: sun_awt_screencast_ScreencastHelper
11471167
* Method: remoteDesktopKeyImpl
@@ -1150,9 +1170,12 @@ JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_remoteDesktopMou
11501170
JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_remoteDesktopKeyImpl
11511171
(JNIEnv *env, jclass cls, jboolean isPress, jint jkey, jstring jtoken) {
11521172

1153-
AWT_LOCK();
1154-
int key = awt_getX11KeySym(jkey);
1155-
AWT_UNLOCK();
1173+
int key = getNumpadKey(jkey);
1174+
if (!key) {
1175+
AWT_LOCK();
1176+
key = awt_getX11KeySym(jkey);
1177+
AWT_UNLOCK();
1178+
}
11561179

11571180
if (key == NoSymbol || (*env)->ExceptionCheck(env)) {
11581181
return RESULT_ERROR;

test/jdk/java/awt/event/KeyEvent/KeyCharTest/KeyCharTest.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/*
2525
@test
26-
@bug 5013984
26+
@bug 5013984 8360647
2727
@summary Tests KEY_PRESSED has the same KeyChar as KEY_RELEASED
2828
@key headful
2929
@run main KeyCharTest
@@ -37,7 +37,7 @@
3737
import java.util.HashMap;
3838

3939
public class KeyCharTest extends Frame implements KeyListener {
40-
HashMap<Integer, Character> transMap = new HashMap();
40+
HashMap<Integer, Character> transMap = new HashMap<>();
4141

4242
public void keyTyped(KeyEvent e){
4343
}
@@ -47,22 +47,35 @@ public void keyPressed(KeyEvent e){
4747
}
4848

4949
public void keyReleased(KeyEvent e){
50-
Object value = transMap.get(e.getKeyCode());
51-
if (value != null && e.getKeyChar() != ((Character)value).charValue()) {
50+
Character value = transMap.get(e.getKeyCode());
51+
if (value != null && e.getKeyChar() != value) {
5252
throw new RuntimeException("Wrong KeyChar on KEY_RELEASED "+
5353
KeyEvent.getKeyText(e.getKeyCode()));
5454
}
5555
}
5656

57-
public void start () {
57+
private void testKeyRange(Robot robot, int start, int end) {
58+
System.out.printf("\nTesting range on %d to %d\n", start, end);
59+
for(int vkey = start; vkey <= end; vkey++) {
60+
try {
61+
robot.keyPress(vkey);
62+
robot.keyRelease(vkey);
63+
System.out.println(KeyEvent.getKeyText(vkey) + " " + vkey);
64+
} catch (RuntimeException ignored) {}
65+
}
66+
robot.delay(100);
67+
}
68+
69+
public void start() throws Exception {
70+
Robot robot = new Robot();
5871
addKeyListener(this);
5972
setLocationRelativeTo(null);
6073
setSize(200, 200);
6174
setVisible(true);
6275
requestFocus();
6376

77+
boolean wasNumlockPressed = false;
6478
try {
65-
Robot robot = new Robot();
6679
robot.setAutoDelay(10);
6780
robot.setAutoWaitForIdle(true);
6881
robot.delay(100);
@@ -72,22 +85,25 @@ public void start () {
7285
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
7386
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
7487

75-
for(int vkey = 0x20; vkey < 0x7F; vkey++) {
76-
try {
77-
robot.keyPress(vkey);
78-
robot.keyRelease(vkey);
79-
System.out.println(KeyEvent.getKeyText(vkey) + " " + vkey);
80-
} catch (RuntimeException e) {
81-
}
82-
}
83-
robot.delay(100);
88+
testKeyRange(robot, 0x20, 0x7E);
89+
90+
// Try again with a different numpad state.
91+
robot.keyPress(KeyEvent.VK_NUM_LOCK);
92+
robot.keyRelease(KeyEvent.VK_NUM_LOCK);
93+
wasNumlockPressed = true;
94+
95+
testKeyRange(robot, KeyEvent.VK_NUMPAD0, KeyEvent.VK_DIVIDE);
8496
} catch(Exception e){
85-
e.printStackTrace();
8697
throw new RuntimeException("Exception while performing Robot actions.");
98+
} finally {
99+
if (wasNumlockPressed) {
100+
robot.keyPress(KeyEvent.VK_NUM_LOCK);
101+
robot.keyRelease(KeyEvent.VK_NUM_LOCK);
102+
}
87103
}
88104
}
89105

90-
public static void main(String[] args) {
106+
public static void main(String[] args) throws Exception {
91107
KeyCharTest test = new KeyCharTest();
92108
try {
93109
test.start();

0 commit comments

Comments
 (0)