Skip to content

Commit b8c22c8

Browse files
mkartashevjbrbot
authored andcommitted
JBR-6145 Wayland: refactor surface-to-peer mapping
1 parent 39da643 commit b8c22c8

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ Point nativeLocationForPopup(Window popup, Component popupParent, Window topleve
344344
}
345345

346346
protected void wlSetVisible(boolean v) {
347+
// TODO: this whole method should be moved to WLWindowPeer
347348
synchronized (getStateLock()) {
348349
if (this.visible == v) return;
349350

@@ -364,7 +365,7 @@ protected void wlSetVisible(boolean v) {
364365

365366
performLocked(() -> {
366367
assert wlSurface == null;
367-
wlSurface = new WLMainSurface(this);
368+
wlSurface = new WLMainSurface((WLWindowPeer) this);
368369
long wlSurfacePtr = wlSurface.getWlSurfacePtr();
369370
if (isWlPopup) {
370371
Window popup = (Window) target;
@@ -1074,7 +1075,7 @@ final void activate() {
10741075
long surface = WLToolkit.getInputState().surfaceForKeyboardInput();
10751076
// The surface pointer may be out of date, which will cause a protocol error.
10761077
// So make sure it is valid and do that under AWT lock.
1077-
if (wlSurface != null && surface != 0 && WLToolkit.componentPeerFromSurface(surface) != null) {
1078+
if (wlSurface != null && surface != 0 && WLToolkit.peerFromSurface(surface) != null) {
10781079
wlSurface.activateByAnotherSurface(serial, surface);
10791080
}
10801081
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public synchronized void rejectDrag() {
154154
}
155155

156156
public synchronized void handleEnter(WLDataOffer offer, long serial, long surfacePtr, double x, double y) {
157-
var peer = WLToolkit.componentPeerFromSurface(surfacePtr);
157+
var peer = WLToolkit.peerFromSurface(surfacePtr);
158158
if (peer == null) {
159159
return;
160160
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public int getPointerY() {
316316
*/
317317
public WLComponentPeer peerForPointerEvents() {
318318
return eventWithSurface != null
319-
? WLToolkit.componentPeerFromSurface(eventWithSurface.getSurface())
319+
? WLToolkit.peerFromSurface(eventWithSurface.getSurface())
320320
: null;
321321
}
322322

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
import java.util.List;
3434

3535
public class WLMainSurface extends WLSurface {
36-
private final WLComponentPeer peer;
36+
private final WLWindowPeer peer;
3737

3838
// Graphics devices this top-level component is visible on
3939
private final List<WLGraphicsDevice> devices = new ArrayList<>();
4040

41-
public WLMainSurface(WLComponentPeer peer) {
41+
public WLMainSurface(WLWindowPeer peer) {
4242
this.peer = peer;
4343
}
4444

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private static void dispatchKeyboardKeyEvent(long serial,
334334
}
335335

336336
final long surfacePtr = inputState.surfaceForKeyboardInput();
337-
final WLComponentPeer peer = componentPeerFromSurface(surfacePtr);
337+
final WLComponentPeer peer = peerFromSurface(surfacePtr);
338338
if (peer != null) {
339339
if (extendedKeyCode >= 0x1000000) {
340340
int ch = extendedKeyCode - 0x1000000;
@@ -401,7 +401,7 @@ private static void dispatchKeyboardEnterEvent(long serial, long surfacePtr) {
401401
}
402402

403403
final WLInputState newInputState = inputState.updatedFromKeyboardEnterEvent(serial, surfacePtr);
404-
final WLComponentPeer peer = componentPeerFromSurface(surfacePtr);
404+
final WLWindowPeer peer = peerFromSurface(surfacePtr);
405405
if (peer != null && peer.getTarget() instanceof Window window) {
406406
WLKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(window);
407407
final WindowEvent windowEnterEvent = new WindowEvent(window, WindowEvent.WINDOW_GAINED_FOCUS);
@@ -422,7 +422,7 @@ private static void dispatchKeyboardLeaveEvent(long serial, long surfacePtr) {
422422
keyboard.onLostFocus();
423423

424424
final WLInputState newInputState = inputState.updatedFromKeyboardLeaveEvent(serial, surfacePtr);
425-
final WLComponentPeer peer = componentPeerFromSurface(surfacePtr);
425+
final WLWindowPeer peer = peerFromSurface(surfacePtr);
426426
if (peer != null && peer.getTarget() instanceof Window window) {
427427
final WindowEvent winLostFocusEvent = new WindowEvent(window, WindowEvent.WINDOW_LOST_FOCUS);
428428
WLKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
@@ -435,28 +435,28 @@ private static void dispatchKeyboardLeaveEvent(long serial, long surfacePtr) {
435435
/**
436436
* Maps 'struct wl_surface*' to WLComponentPeer that owns the Wayland surface.
437437
*/
438-
private static final Map<Long, WLComponentPeer> wlSurfaceToComponentMap = new HashMap<>();
438+
private static final Map<Long, WLWindowPeer> wlSurfaceToPeerMap = new HashMap<>();
439439

440-
static void registerWLSurface(long wlSurfacePtr, WLComponentPeer componentPeer) {
440+
static void registerWLSurface(long wlSurfacePtr, WLWindowPeer peer) {
441441
if (log.isLoggable(PlatformLogger.Level.FINE)) {
442-
log.fine("registerWLSurface: 0x" + Long.toHexString(wlSurfacePtr) + "->" + componentPeer);
442+
log.fine("registerWLSurface: 0x" + Long.toHexString(wlSurfacePtr) + "->" + peer);
443443
}
444-
synchronized (wlSurfaceToComponentMap) {
445-
wlSurfaceToComponentMap.put(wlSurfacePtr, componentPeer);
444+
synchronized (wlSurfaceToPeerMap) {
445+
wlSurfaceToPeerMap.put(wlSurfacePtr, peer);
446446
}
447447
}
448448

449449
static void unregisterWLSurface(long wlSurfacePtr) {
450-
synchronized (wlSurfaceToComponentMap) {
451-
wlSurfaceToComponentMap.remove(wlSurfacePtr);
450+
synchronized (wlSurfaceToPeerMap) {
451+
wlSurfaceToPeerMap.remove(wlSurfacePtr);
452452
}
453453

454454
inputState = inputState.updatedFromUnregisteredSurface(wlSurfacePtr);
455455
}
456456

457-
static WLComponentPeer componentPeerFromSurface(long wlSurfacePtr) {
458-
synchronized (wlSurfaceToComponentMap) {
459-
return wlSurfaceToComponentMap.get(wlSurfacePtr);
457+
static WLWindowPeer peerFromSurface(long wlSurfacePtr) {
458+
synchronized (wlSurfaceToPeerMap) {
459+
return wlSurfaceToPeerMap.get(wlSurfacePtr);
460460
}
461461
}
462462

@@ -465,15 +465,15 @@ static WLComponentPeer componentPeerFromSurface(long wlSurfacePtr) {
465465
* associated with that surface.
466466
* Otherwise, throw UOE.
467467
*/
468-
static WLComponentPeer getSingularWindowPeer() {
469-
synchronized (wlSurfaceToComponentMap) {
470-
if (wlSurfaceToComponentMap.size() > 1) {
468+
static WLWindowPeer getSingularWindowPeer() {
469+
synchronized (wlSurfaceToPeerMap) {
470+
if (wlSurfaceToPeerMap.size() > 1) {
471471
throw new UnsupportedOperationException("More than one native window");
472-
} else if (wlSurfaceToComponentMap.isEmpty()) {
472+
} else if (wlSurfaceToPeerMap.isEmpty()) {
473473
throw new UnsupportedOperationException("No native windows");
474474
}
475475

476-
return wlSurfaceToComponentMap.values().iterator().next();
476+
return wlSurfaceToPeerMap.values().iterator().next();
477477
}
478478
}
479479

0 commit comments

Comments
 (0)