Skip to content

Commit aeabd50

Browse files
mkartashevOnePatchGuy
authored andcommitted
JBR-9902 Wayland: support modal dialogs without native modality aid
1 parent 662f578 commit aeabd50

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,14 @@ final void activate() {
11921192
}
11931193
}
11941194

1195+
final void reactivate(long serial, long surface) {
1196+
performLocked(() -> {
1197+
if (serial != 0 &&wlSurface != null && surface != 0) {
1198+
wlSurface.activateByAnotherSurface(serial, surface);
1199+
}
1200+
});
1201+
}
1202+
11951203
private static long getSerialForActivation() {
11961204
long serial;
11971205
if (WLToolkit.isKDE()) {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424
*/
2525
package sun.awt.wl;
2626

27-
import java.awt.*;
27+
import sun.awt.AWTAccessor;
28+
29+
import java.awt.Dialog;
30+
import java.awt.Frame;
31+
import java.awt.Window;
2832
import java.awt.peer.DialogPeer;
33+
import java.awt.peer.WindowPeer;
2934
import java.util.List;
3035

3136
public class WLDialogPeer extends WLDecoratedPeer implements DialogPeer {
@@ -41,7 +46,12 @@ public void setVisible(boolean vis) {
4146

4247
@Override
4348
public void blockWindows(List<Window> windows) {
44-
49+
for (Window w : windows) {
50+
WindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);
51+
if (wp != null) {
52+
wp.setModalBlocked((Dialog)getTarget(), true);
53+
}
54+
}
4555
}
4656

4757
@Override

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -439,22 +439,32 @@ private static void dispatchKeyboardEnterEvent(long serial, long surfacePtr) {
439439
+ Long.toHexString(surfacePtr));
440440
}
441441

442-
final WLInputState newInputState = inputState.updatedFromKeyboardEnterEvent(serial, surfacePtr);
443442
final WLWindowPeer peer = peerFromSurface(surfacePtr);
443+
final WLInputState newInputState = inputState.updatedFromKeyboardEnterEvent(serial, surfacePtr);
444444
if (peer != null) {
445-
Window window = (Window) peer.getTarget();
446-
Window winToFocus = window;
447-
448-
Component s = peer.getSyntheticFocusOwner();
449-
if (s instanceof Window synthWindow) {
450-
if (synthWindow.isVisible() && synthWindow.isFocusableWindow()) {
451-
winToFocus = synthWindow;
445+
Dialog blocker = peer.getBlocker();
446+
if (blocker != null) { // Modality support
447+
long activationSerial = serial;
448+
if (WLToolkit.isKDE()) {
449+
activationSerial = inputState.latestInputSerial();
450+
}
451+
WLWindowPeer blockerPeer = AWTAccessor.getComponentAccessor().getPeer(blocker);
452+
blockerPeer.reactivate(activationSerial, surfacePtr);
453+
} else {
454+
Window window = (Window) peer.getTarget();
455+
Window winToFocus = window;
456+
457+
Component s = peer.getSyntheticFocusOwner();
458+
if (s instanceof Window synthWindow) {
459+
if (synthWindow.isVisible() && synthWindow.isFocusableWindow()) {
460+
winToFocus = synthWindow;
461+
}
452462
}
453-
}
454463

455-
WLKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(window);
456-
WindowEvent windowEnterEvent = new WindowEvent(winToFocus, WindowEvent.WINDOW_GAINED_FOCUS);
457-
postPriorityEvent(windowEnterEvent);
464+
WLKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(window);
465+
WindowEvent windowEnterEvent = new WindowEvent(winToFocus, WindowEvent.WINDOW_GAINED_FOCUS);
466+
postPriorityEvent(windowEnterEvent);
467+
}
458468
}
459469
inputState = newInputState;
460470
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
public class WLWindowPeer extends WLComponentPeer implements WindowPeer, SurfacePixelGrabber {
6060
private static Font defaultFont;
61-
private Dialog blocker;
61+
private Dialog blocker; // guarded by getStateLock()
6262
private static WLWindowPeer grabbingWindow; // fake, kept for UngrabEvent only
6363

6464
// If this window gets focus from Wayland, we need to transfer focus synthFocusOwner, if any
@@ -180,7 +180,15 @@ public void updateFocusableWindowState() {
180180

181181
@Override
182182
public void setModalBlocked(Dialog blocker, boolean blocked) {
183-
this.blocker = blocked ? blocker : null;
183+
synchronized (getStateLock()) {
184+
this.blocker = blocked ? blocker : null;
185+
}
186+
}
187+
188+
public Dialog getBlocker() {
189+
synchronized (getStateLock()) {
190+
return blocker;
191+
}
184192
}
185193

186194
@Override

0 commit comments

Comments
 (0)