Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

xdg: no configures to minimized windows; honour the fullscreen output

oxydizer98559fd98baf
diff --git a/src/toplevel/chrome_actions.zig b/src/toplevel/chrome_actions.zig
index 1df5b56..a007f6b 100644
--- a/src/toplevel/chrome_actions.zig
+++ b/src/toplevel/chrome_actions.zig
@@ -100,9 +100,7 @@ pub fn minimize(toplevel: *Toplevel) void {
adapter.xsurface.setMinimized(true);
adapter.xsurface.restack(null, .below);
},
- .xdg => |*adapter| {
- _ = adapter.xdg_toplevel.setSuspended(true);
- },
+ .xdg => |*adapter| setXdgSuspended(adapter, true),
.placeholder, .shell => {},
}
@@ -141,6 +139,17 @@ pub fn minimize(toplevel: *Toplevel) void {
}
}
+/// xdg_toplevel's suspended state exists from v6 on. wlroots checks the
+/// global's version, not the client's, so for an older client it still sends
+/// a configure that changes nothing visible. Wine (v2) takes any configure to
+/// a window it minimized itself as the compositor restoring it: a fullscreen
+/// game that minimizes on focus loss would come straight back, windowed and
+/// shown as foreground to nobody, while it still looks minimized here.
+fn setXdgSuspended(adapter: *xdg, suspended: bool) void {
+ if (adapter.xdg_toplevel.resource.getVersion() < 6) return;
+ _ = adapter.xdg_toplevel.setSuspended(suspended);
+}
+
pub fn restore(toplevel: *Toplevel) void {
toplevel.server.window_tabs.select(toplevel);
defer if (toplevel.tab_group != 0) @import("../window_tabs.zig").refreshVisibility(toplevel.server);
@@ -150,9 +159,7 @@ pub fn restore(toplevel: *Toplevel) void {
toplevel.frame_tree.node.setEnabled(@import("../window_tabs.zig").visible(toplevel));
switch (toplevel.backend) {
.xwayland => |*adapter| adapter.xsurface.setMinimized(false),
- .xdg => |*adapter| {
- _ = adapter.xdg_toplevel.setSuspended(false);
- },
+ .xdg => |*adapter| setXdgSuspended(adapter, false),
.placeholder, .shell => {},
}
toplevel.server.world.focus(toplevel);
diff --git a/src/toplevel/focus_close.zig b/src/toplevel/focus_close.zig
index 1f17922..6d85306 100644
--- a/src/toplevel/focus_close.zig
+++ b/src/toplevel/focus_close.zig
@@ -50,7 +50,11 @@ pub fn setActivated(toplevel: *Toplevel, activated: bool) void {
if (!activated) toplevel.setGlow(null);
if (toplevel.wlr_foreign) |handle| handle.setActivated(activated);
switch (toplevel.backend) {
- .xdg => |*adapter| _ = adapter.xdg_toplevel.setActivated(activated),
+ // wlroots sends a configure on every call; an unchanged one reads to
+ // Wine as a restore when it reaches a window it minimized itself.
+ .xdg => |*adapter| if (adapter.xdg_toplevel.scheduled.activated != activated) {
+ _ = adapter.xdg_toplevel.setActivated(activated);
+ },
.xwayland => |*adapter| {
if (activated) {
switch (adapter.xsurface.icccmInputModel()) {
diff --git a/src/xdg.zig b/src/xdg.zig
index 95c6498..07fcf40 100644
--- a/src/xdg.zig
+++ b/src/xdg.zig
@@ -6,6 +6,7 @@ const wl = @import("wayland").server.wl;
const wlr = @import("wlroots");
const Toplevel = @import("Toplevel.zig");
+const Output = @import("Output.zig");
const Adapter = @This();
@@ -116,13 +117,27 @@ fn handleRequestResize(
fn handleRequestMaximize(listener: *wl.Listener(void)) void {
const adapter: *Adapter = @fieldParentPtr("request_maximize", listener);
if (!adapter.window.isInitialized()) return;
+ if (adapter.window.minimized) return;
adapter.window.setMaximized(adapter.xdg_toplevel.requested.maximized);
}
+/// A minimized window's maximize/fullscreen requests are ignored: `restore`
+/// answers with a configure of the state the window still has, and a client
+/// that still wants the change asks again. Any configure sent to a minimized
+/// window reads to Wine as the compositor restoring it, and a fullscreen game
+/// drops out of fullscreen while minimized on focus loss (its display mode
+/// goes back to the desktop's). Answering then would un-minimize it, windowed;
+/// applying the request on restore would leave Wine, which re-enters
+/// fullscreen on activation, unable to ack that configure or ask again.
fn handleRequestFullscreen(listener: *wl.Listener(void)) void {
const adapter: *Adapter = @fieldParentPtr("request_fullscreen", listener);
- if (!adapter.window.isInitialized()) return;
- adapter.window.setFullscreen(adapter.xdg_toplevel.requested.fullscreen);
+ if (!adapter.window.isInitialized() or adapter.window.minimized) return;
+ const requested = &adapter.xdg_toplevel.requested;
+ // A game on a second monitor names it; otherwise the window's centre picks.
+ if (requested.fullscreen) if (requested.fullscreen_output) |wlr_output| if (Output.fromWlr(wlr_output)) |output| {
+ if (output.isLogicallyEnabled()) return adapter.window.setFullscreenOn(output);
+ };
+ adapter.window.setFullscreen(requested.fullscreen);
}
fn handleRequestMinimize(listener: *wl.Listener(void)) void {