View: use last set fullscreen state in applyPending()

This avoids a race where the fullscreen set is e.g. set then unset
before the transaction has been completed and the current state has
been updated.
This commit is contained in:
Isaac Freund 2022-02-05 00:08:21 +01:00
parent be870e058d
commit 147d9c2f90
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
4 changed files with 35 additions and 6 deletions

View File

@ -179,7 +179,7 @@ pub fn applyPending(self: *Self) void {
self.pending.box = self.float_box;
}
if (!self.current.fullscreen and self.pending.fullscreen) {
if (!self.lastSetFullscreenState() and self.pending.fullscreen) {
// If switching to fullscreen, set the dimensions to the full area of the output
self.setFullscreen(true);
self.post_fullscreen_box = self.current.box;
@ -190,7 +190,7 @@ pub fn applyPending(self: *Self) void {
.width = dimensions.width,
.height = dimensions.height,
};
} else if (self.current.fullscreen and !self.pending.fullscreen) {
} else if (self.lastSetFullscreenState() and !self.pending.fullscreen) {
self.setFullscreen(false);
self.pending.box = self.post_fullscreen_box;
}
@ -219,6 +219,13 @@ pub fn configure(self: *Self) void {
}
}
fn lastSetFullscreenState(self: Self) bool {
return switch (self.impl) {
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.lastSetFullscreenState(),
.xwayland_view => |xwayland_view| xwayland_view.lastSetFullscreenState(),
};
}
pub fn sendFrameDone(self: Self) void {
var now: os.timespec = undefined;
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
@ -330,11 +337,11 @@ pub fn setActivated(self: Self, activated: bool) void {
}
}
fn setFullscreen(self: Self, fullscreen: bool) void {
fn setFullscreen(self: *Self, fullscreen: bool) void {
if (self.foreign_toplevel_handle) |handle| handle.setFullscreen(fullscreen);
switch (self.impl) {
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.setFullscreen(fullscreen),
.xwayland_view => |xwayland_view| xwayland_view.setFullscreen(fullscreen),
.xwayland_view => |*xwayland_view| xwayland_view.setFullscreen(fullscreen),
}
}

View File

@ -30,6 +30,10 @@ pub fn configure(_: Self) void {
unreachable;
}
pub fn lastSetFullscreenState(_: Self) bool {
unreachable;
}
pub fn setActivated(_: Self, _: bool) void {
unreachable;
}

View File

@ -96,6 +96,10 @@ pub fn configure(self: *Self) void {
self.acked_pending_serial = false;
}
pub fn lastSetFullscreenState(self: Self) bool {
return self.xdg_surface.role_data.toplevel.scheduled.fullscreen;
}
/// Close the view. This will lead to the unmap and destroy events being sent
pub fn close(self: Self) void {
self.xdg_surface.role_data.toplevel.sendClose();

View File

@ -34,6 +34,11 @@ view: *View,
/// The corresponding wlroots object
xwayland_surface: *wlr.XwaylandSurface,
/// The wlroots Xwayland implementation overwrites xwayland_surface.fullscreen
/// immediately when the client requests it, so we track this state here to be
/// able to match the XdgToplevel API.
last_set_fullscreen_state: bool,
// Listeners that are always active over the view's lifetime
destroy: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleDestroy),
map: wl.Listener(*wlr.XwaylandSurface) = wl.Listener(*wlr.XwaylandSurface).init(handleMap),
@ -51,7 +56,11 @@ request_minimize: wl.Listener(*wlr.XwaylandSurface.event.Minimize) =
wl.Listener(*wlr.XwaylandSurface.event.Minimize).init(handleRequestMinimize),
pub fn init(self: *Self, view: *View, xwayland_surface: *wlr.XwaylandSurface) void {
self.* = .{ .view = view, .xwayland_surface = xwayland_surface };
self.* = .{
.view = view,
.xwayland_surface = xwayland_surface,
.last_set_fullscreen_state = xwayland_surface.fullscreen,
};
xwayland_surface.data = @ptrToInt(self);
// Add listeners that are active over the view's entire lifetime
@ -85,6 +94,10 @@ pub fn configure(self: Self) void {
);
}
pub fn lastSetFullscreenState(self: Self) bool {
return self.last_set_fullscreen_state;
}
/// Close the view. This will lead to the unmap and destroy events being sent
pub fn close(self: Self) void {
self.xwayland_surface.close();
@ -99,7 +112,8 @@ pub fn setActivated(self: Self, activated: bool) void {
self.xwayland_surface.restack(null, .above);
}
pub fn setFullscreen(self: Self, fullscreen: bool) void {
pub fn setFullscreen(self: *Self, fullscreen: bool) void {
self.last_set_fullscreen_state = fullscreen;
self.xwayland_surface.setFullscreen(fullscreen);
}