Skip to content

Commit

Permalink
JBR-6138 Wayland: utilize gtk_shell1 protocol to mark dialogs as modal
Browse files Browse the repository at this point in the history
  • Loading branch information
mkartashev authored and jbrbot committed Nov 8, 2024
1 parent 20b2eeb commit ba60bfa
Show file tree
Hide file tree
Showing 9 changed files with 552 additions and 18 deletions.
36 changes: 22 additions & 14 deletions src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,12 @@ public Color getBackground() {
}

public void postPaintEvent(int x, int y, int w, int h) {
if (!hasSurface()) {
log.warning("WLComponentPeer: No surface. Skipping paint request x=" + x + " y=" + y +
" width=" + w + " height=" + h);
return;
}
PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
createPaintEvent(target, x, y, w, h);
if (event != null) {
WLToolkit.postEvent(event);
if (isVisible()) {
PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
createPaintEvent(target, x, y, w, h);
if (event != null) {
WLToolkit.postEvent(event);
}
}
}

Expand All @@ -168,7 +165,7 @@ void postPaintEvent() {
}

boolean isVisible() {
return visible;
return visible && hasSurface();
}

boolean hasSurface() {
Expand Down Expand Up @@ -232,11 +229,12 @@ public boolean requestFocus(Component lightweightChild, boolean temporary,

protected void wlSetVisible(boolean v) {
this.visible = v;
if (this.visible) {
if (v) {
final String title = getTitle();
final boolean isWlPopup = targetIsWlPopup();
final int thisWidth = getWidth();
final int thisHeight = getHeight();
final boolean isModal = targetIsModal();
performLocked(() -> {
if (isWlPopup) {
Window popup = (Window) target;
Expand All @@ -262,7 +260,10 @@ protected void wlSetVisible(boolean v) {
offsetX, offsetY);
} else {
nativeCreateWLSurface(nativePtr,
getParentNativePtr(target), target.getX(), target.getY(), title, appID);
getParentNativePtr(target),
target.getX(), target.getY(),
isModal,
title, appID);
}
final long wlSurfacePtr = getWLSurface(nativePtr);
WLToolkit.registerWLSurface(wlSurfacePtr, this);
Expand Down Expand Up @@ -291,6 +292,12 @@ private boolean targetIsWlPopup() {
&& AWTAccessor.getWindowAccessor().getPopupParent(window) != null;
}

private boolean targetIsModal() {
return target instanceof Dialog dialog
&& (dialog.getModalityType() == Dialog.ModalityType.APPLICATION_MODAL
|| dialog.getModalityType() == Dialog.ModalityType.TOOLKIT_MODAL);
}

void configureWLSurface() {
synchronized (sizeLock) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
Expand Down Expand Up @@ -373,7 +380,7 @@ public void print(Graphics g) {

public void setBounds(int x, int y, int width, int height, int op) {
final boolean positionChanged = this.x != x || this.y != y;
if (positionChanged) {
if (positionChanged && isVisible()) {
performLocked(() -> WLRobotPeer.setLocationOfWLSurface(getWLSurface(nativePtr), x, y));
}
this.x = x;
Expand All @@ -400,6 +407,7 @@ public void setBounds(int x, int y, int width, int height, int op) {

WLToolkit.postEvent(new ComponentEvent(getTarget(), ComponentEvent.COMPONENT_RESIZED));
}

postPaintEvent();
}

Expand Down Expand Up @@ -845,7 +853,7 @@ final void activate() {
protected native long nativeCreateFrame();

protected native void nativeCreateWLSurface(long ptr, long parentPtr,
int x, int y,
int x, int y, boolean isModal,
String title, String appID);

protected native void nativeCreateWLPopup(long ptr, long parentPtr,
Expand Down
8 changes: 5 additions & 3 deletions src/java.desktop/unix/classes/sun/awt/wl/WLDecoratedPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ final void notifyClientDecorationsChanged() {
}

void postPaintEvent() {
// Full re-paint must include window decorations, if any
notifyClientDecorationsChanged();
super.postPaintEvent();
if (isVisible()) {
// Full re-paint must include window decorations, if any
notifyClientDecorationsChanged();
super.postPaintEvent();
}
}

final void paintClientDecorations(final Graphics g) {
Expand Down
14 changes: 13 additions & 1 deletion src/java.desktop/unix/native/libawt_wlawt/WLComponentPeer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <jni.h>
#include <Trace.h>
#include <assert.h>
#include <gtk-shell1-client-protocol.h>

#include "jni_util.h"
#include "WLToolkit.h"
Expand Down Expand Up @@ -88,6 +89,7 @@ struct WLFrame {
jobject nativeFramePeer; // weak reference
struct wl_surface *wl_surface;
struct xdg_surface *xdg_surface;
struct gtk_surface1 *gtk_surface;
struct WLFrame *parent;
struct xdg_positioner *xdg_positioner;
struct activation_token_list_item *activation_token_list;
Expand Down Expand Up @@ -409,14 +411,17 @@ Java_sun_awt_wl_WLComponentPeer_nativeRequestUnsetFullScreen
JNIEXPORT void JNICALL
Java_sun_awt_wl_WLComponentPeer_nativeCreateWLSurface
(JNIEnv *env, jobject obj, jlong ptr, jlong parentPtr,
jint x, jint y,
jint x, jint y, jboolean isModal,
jstring title, jstring appid)
{
struct WLFrame *frame = (struct WLFrame *) ptr;
struct WLFrame *parentFrame = (struct WLFrame*) parentPtr;
if (frame->wl_surface) return;
frame->wl_surface = wl_compositor_create_surface(wl_compositor);
frame->xdg_surface = xdg_wm_base_get_xdg_surface(xdg_wm_base, frame->wl_surface);
if (gtk_shell1 != NULL) {
frame->gtk_surface = gtk_shell1_get_gtk_surface(gtk_shell1, frame->wl_surface);
}

wl_surface_add_listener(frame->wl_surface, &wl_surface_listener, frame);
xdg_surface_add_listener(frame->xdg_surface, &xdg_surface_listener, frame);
Expand All @@ -433,6 +438,10 @@ Java_sun_awt_wl_WLComponentPeer_nativeCreateWLSurface
xdg_toplevel_set_parent(frame->xdg_toplevel, parentFrame->xdg_toplevel);
}

if (isModal && frame->gtk_surface != NULL) {
gtk_surface1_set_modal(frame->gtk_surface);
}

#ifdef WAKEFIELD_ROBOT
if (wakefield) {
// TODO: this doesn't work quite as expected for some reason
Expand Down Expand Up @@ -498,6 +507,9 @@ DoHide(struct WLFrame *frame)
if (wl_surface_in_focus == frame->wl_surface) {
wl_surface_in_focus = NULL;
}
if (frame->gtk_surface != NULL) {
gtk_surface1_destroy(frame->gtk_surface);
}
xdg_surface_destroy(frame->xdg_surface);
wl_surface_destroy(frame->wl_surface);
delete_all_tokens(frame->activation_token_list);
Expand Down
5 changes: 5 additions & 0 deletions src/java.desktop/unix/native/libawt_wlawt/WLToolkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <unistd.h>
#include <time.h>

#include "gtk-shell1-client-protocol.h"

#include "jvm_md.h"
#include "jni_util.h"
#include "awt.h"
Expand All @@ -60,6 +62,7 @@ struct wl_shm *wl_shm = NULL;
struct wl_compositor *wl_compositor = NULL;
struct xdg_wm_base *xdg_wm_base = NULL;
struct xdg_activation_v1 *xdg_activation_v1 = NULL;
struct gtk_shell1* gtk_shell1 = NULL;
struct wl_seat *wl_seat = NULL;

struct wl_keyboard *wl_keyboard;
Expand Down Expand Up @@ -685,6 +688,8 @@ registry_global(void *data, struct wl_registry *wl_registry,
process_new_listener_before_end_of_init();
} else if (strcmp(interface, xdg_activation_v1_interface.name) == 0) {
xdg_activation_v1 = wl_registry_bind(wl_registry, name, &xdg_activation_v1_interface, 1);
} else if (strcmp(interface, gtk_shell1_interface.name) == 0) {
gtk_shell1 = wl_registry_bind(wl_registry, name, &gtk_shell1_interface, 1);
}
#ifdef WAKEFIELD_ROBOT
else if (strcmp(interface, wakefield_interface.name) == 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/java.desktop/unix/native/libawt_wlawt/WLToolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@
} \
} while(0) \

struct gtk_shell1;

extern struct wl_seat *wl_seat;
extern struct wl_display *wl_display;
extern struct wl_pointer *wl_pointer;
extern struct wl_compositor *wl_compositor;
extern struct xdg_wm_base *xdg_wm_base;
extern struct xdg_activation_v1 *xdg_activation_v1;
extern struct gtk_shell1* gtk_shell1; // optional, check for NULL before use

extern struct wl_cursor_theme *wl_cursor_theme;

extern struct wl_surface *wl_surface_in_focus;
Expand Down
Loading

0 comments on commit ba60bfa

Please sign in to comment.