Skip to content

8360647: [XWayland] [OL10] NumPad keys are not triggered #26170

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/java.desktop/unix/native/libawt_xawt/awt/screencast_pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#ifndef _AIX
#include "screencast_pipewire.h"
#include "java_awt_event_KeyEvent.h"

struct pw_buffer *(*fp_pw_stream_dequeue_buffer)(struct pw_stream *stream);
const char * (*fp_pw_stream_state_as_string)(enum pw_stream_state state);
Expand Down Expand Up @@ -1197,6 +1198,24 @@ JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_remoteDesktopMou
return result ? RESULT_OK : pw.pwFd;
}

static int getNumpadKey(jint jkey) {
switch (jkey) {
case java_awt_event_KeyEvent_VK_NUMPAD0: return XK_KP_Insert;
case java_awt_event_KeyEvent_VK_NUMPAD1: return XK_KP_End;
case java_awt_event_KeyEvent_VK_NUMPAD2: return XK_KP_Down;
case java_awt_event_KeyEvent_VK_NUMPAD3: return XK_KP_Page_Down;
case java_awt_event_KeyEvent_VK_NUMPAD4: return XK_KP_Left;
case java_awt_event_KeyEvent_VK_NUMPAD5: return XK_KP_Begin;
case java_awt_event_KeyEvent_VK_NUMPAD6: return XK_KP_Right;
case java_awt_event_KeyEvent_VK_NUMPAD7: return XK_KP_Home;
case java_awt_event_KeyEvent_VK_NUMPAD8: return XK_KP_Up;
case java_awt_event_KeyEvent_VK_NUMPAD9: return XK_KP_Prior;
case java_awt_event_KeyEvent_VK_DECIMAL:
case java_awt_event_KeyEvent_VK_SEPARATOR: return XK_KP_Delete;
default: return 0;
}
}

/*
* Class: sun_awt_screencast_ScreencastHelper
* Method: remoteDesktopKeyImpl
Expand All @@ -1205,9 +1224,12 @@ JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_remoteDesktopMou
JNIEXPORT jint JNICALL Java_sun_awt_screencast_ScreencastHelper_remoteDesktopKeyImpl
(JNIEnv *env, jclass cls, jboolean isPress, jint jkey, jstring jtoken) {

AWT_LOCK();
int key = awt_getX11KeySym(jkey);
AWT_UNLOCK();
int key = getNumpadKey(jkey);
if (!key) {
AWT_LOCK();
key = awt_getX11KeySym(jkey);
AWT_UNLOCK();
}

if (key == NoSymbol || (*env)->ExceptionCheck(env)) {
return RESULT_ERROR;
Expand Down
48 changes: 30 additions & 18 deletions test/jdk/java/awt/event/KeyEvent/KeyCharTest/KeyCharTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

/*
@test
@bug 5013984
@bug 5013984 8360647
@summary Tests KEY_PRESSED has the same KeyChar as KEY_RELEASED
@key headful
@run main KeyCharTest
Expand All @@ -37,7 +37,7 @@
import java.util.HashMap;

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

public void keyTyped(KeyEvent e){
}
Expand All @@ -47,22 +47,34 @@ public void keyPressed(KeyEvent e){
}

public void keyReleased(KeyEvent e){
Object value = transMap.get(e.getKeyCode());
if (value != null && e.getKeyChar() != ((Character)value).charValue()) {
Character value = transMap.get(e.getKeyCode());
if (value != null && e.getKeyChar() != value) {
throw new RuntimeException("Wrong KeyChar on KEY_RELEASED "+
KeyEvent.getKeyText(e.getKeyCode()));
}
}

public void start () {
private void testKeyRange(Robot robot, int start, int end) {
System.out.printf("\nTesting range on %d to %d\n", start, end);
for(int vkey = start; vkey <= end; vkey++) {
try {
robot.keyPress(vkey);
robot.keyRelease(vkey);
System.out.println(KeyEvent.getKeyText(vkey) + " " + vkey);
} catch (RuntimeException ignored) {}
}
robot.delay(100);
}

public void start() throws Exception {
Robot robot = new Robot();
addKeyListener(this);
setLocationRelativeTo(null);
setSize(200, 200);
setVisible(true);
requestFocus();

try {
Robot robot = new Robot();
robot.setAutoDelay(10);
robot.setAutoWaitForIdle(true);
robot.delay(100);
Expand All @@ -72,22 +84,22 @@ public void start () {
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);

for(int vkey = 0x20; vkey < 0x7F; vkey++) {
try {
robot.keyPress(vkey);
robot.keyRelease(vkey);
System.out.println(KeyEvent.getKeyText(vkey) + " " + vkey);
} catch (RuntimeException e) {
}
}
robot.delay(100);
testKeyRange(robot, 0x20, 0x7E);

// Try again with a different numpad state.
robot.keyPress(KeyEvent.VK_NUM_LOCK);
robot.keyRelease(KeyEvent.VK_NUM_LOCK);

testKeyRange(robot, KeyEvent.VK_NUMPAD0, KeyEvent.VK_DIVIDE);
} catch(Exception e){
e.printStackTrace();
throw new RuntimeException("Exception while performing Robot actions.");
} finally {
robot.keyPress(KeyEvent.VK_NUM_LOCK);
robot.keyRelease(KeyEvent.VK_NUM_LOCK);
}
}

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
KeyCharTest test = new KeyCharTest();
try {
test.start();
Expand Down