Skip to content

Commit 2cb3fb2

Browse files
OnePatchGuymkartashev
authored andcommitted
JBR-9904: Wayland: double shift or double ctrl is not working well after press space or alt key.
Fixing the timestamps of each KeyEvent/MouseEvent/MouseWheelEvent created by WLToolkit. (cherry picked from commit 4d1f4d9)
1 parent 52473c2 commit 2cb3fb2

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,14 +1289,14 @@ void postMouseEvent(MouseEvent e) {
12891289
* the freshly updated WLInputState, and the previous WLInputState.
12901290
*/
12911291
void dispatchPointerEventInContext(WLPointerEvent e, WLInputState oldInputState, WLInputState newInputState) {
1292+
final long timestamp = System.currentTimeMillis();
1293+
12921294
final int x = newInputState.getPointerX();
12931295
final int y = newInputState.getPointerY();
12941296
final Point abs = relativePointToAbsolute(new Point(x, y));
12951297
int xAbsolute = abs.x;
12961298
int yAbsolute = abs.y;
12971299

1298-
final long timestamp = newInputState.getTimestamp();
1299-
13001300
if (e.hasEnterEvent()) {
13011301
updateCursorImmediately();
13021302
final MouseEvent mouseEvent = new MouseEvent(getTarget(), MouseEvent.MOUSE_ENTERED,

src/java.desktop/unix/classes/sun/awt/wl/WLInputState.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ public boolean isPointerOverPeer() {
354354
return true;
355355
}
356356

357+
/**
358+
* @return the timestamp of the most recent known {@code wl_pointer::*} event or 0 if no such event is known.
359+
*
360+
* @apiNote don't use these timestamps for constructing any new {@link java.awt.event.InputEvent}s
361+
* because they are not guaranteed to be based on the midnight of Jan 1, 1970 UTC.
362+
*/
357363
public long getTimestamp() {
358364
return eventWithTimestamp != null ? eventWithTimestamp.getTimestamp() : 0;
359365
}

src/java.desktop/unix/classes/sun/awt/wl/WLToolkit.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ private static void dispatchPointerEvent(WLPointerEvent e) {
353353
}
354354

355355
private static void dispatchKeyboardKeyEvent(long serial,
356-
long timestamp,
357356
int id,
358357
int keyCode,
359358
int keyLocation,
@@ -364,13 +363,9 @@ private static void dispatchKeyboardKeyEvent(long serial,
364363
// Invoked from the native code
365364
assert EventQueue.isDispatchThread() : "Method must only be invoked on EDT";
366365

367-
inputState = inputState.updatedFromKeyEvent(serial);
366+
final long timestamp = System.currentTimeMillis();
368367

369-
if (timestamp == 0) {
370-
// Happens when a surface was focused with keys already pressed.
371-
// Fake the timestamp by peeking at the last known event.
372-
timestamp = inputState.getTimestamp();
373-
}
368+
inputState = inputState.updatedFromKeyEvent(serial);
374369

375370
final long surfacePtr = inputState.surfaceForKeyboardInput();
376371
final WLComponentPeer peer = peerFromSurface(surfacePtr);

src/java.desktop/unix/native/libawt_wlawt/WLToolkit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ wlPostKeyEvent(const struct WLKeyEvent* event)
454454
tkClass,
455455
dispatchKeyboardKeyEventMID,
456456
event->serial,
457-
event->timestamp,
458457
event->id,
459458
event->keyCode,
460459
event->keyLocation,
@@ -807,7 +806,7 @@ initJavaRefs(JNIEnv *env, jclass clazz)
807806
JNI_FALSE);
808807
CHECK_NULL_RETURN(dispatchKeyboardKeyEventMID = (*env)->GetStaticMethodID(env, tkClass,
809808
"dispatchKeyboardKeyEvent",
810-
"(JJIIIIICI)V"),
809+
"(JIIIIICI)V"),
811810
JNI_FALSE);
812811
CHECK_NULL_RETURN(dispatchKeyboardModifiersEventMID = (*env)->GetStaticMethodID(env, tkClass,
813812
"dispatchKeyboardModifiersEvent",

0 commit comments

Comments
 (0)