XdgToplevel: eliminate "self" naming convention
This commit is contained in:
parent
2eb2a13284
commit
0e2cac08df
@ -44,12 +44,12 @@ pub const Constraints = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Impl = union(enum) {
|
const Impl = union(enum) {
|
||||||
xdg_toplevel: XdgToplevel,
|
toplevel: XdgToplevel,
|
||||||
xwayland_view: if (build_options.xwayland) XwaylandView else noreturn,
|
xwayland_view: if (build_options.xwayland) XwaylandView else noreturn,
|
||||||
/// This state is assigned during destruction after the xdg toplevel
|
/// This state is assigned during destruction after the xdg toplevel
|
||||||
/// has been destroyed but while the transaction system is still rendering
|
/// has been destroyed but while the transaction system is still rendering
|
||||||
/// saved surfaces of the view.
|
/// saved surfaces of the view.
|
||||||
/// The xdg_toplevel could simply be set to undefined instead, but using a
|
/// The toplevel could simply be set to undefined instead, but using a
|
||||||
/// tag like this gives us better safety checks.
|
/// tag like this gives us better safety checks.
|
||||||
none,
|
none,
|
||||||
};
|
};
|
||||||
@ -132,7 +132,7 @@ saved_surface_tree: *wlr.SceneTree,
|
|||||||
borders: [4]*wlr.SceneRect,
|
borders: [4]*wlr.SceneRect,
|
||||||
popup_tree: *wlr.SceneTree,
|
popup_tree: *wlr.SceneTree,
|
||||||
|
|
||||||
/// Bounds on the width/height of the view, set by the xdg_toplevel/xwayland_view implementation.
|
/// Bounds on the width/height of the view, set by the toplevel/xwayland_view implementation.
|
||||||
constraints: Constraints = .{},
|
constraints: Constraints = .{},
|
||||||
|
|
||||||
mapped: bool = false,
|
mapped: bool = false,
|
||||||
@ -293,12 +293,12 @@ pub fn commitTransaction(view: *View) void {
|
|||||||
view.dropSavedSurfaceTree();
|
view.dropSavedSurfaceTree();
|
||||||
|
|
||||||
switch (view.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |*xdg_toplevel| {
|
.toplevel => |*toplevel| {
|
||||||
switch (xdg_toplevel.configure_state) {
|
switch (toplevel.configure_state) {
|
||||||
.inflight, .acked => {
|
.inflight, .acked => {
|
||||||
switch (xdg_toplevel.configure_state) {
|
switch (toplevel.configure_state) {
|
||||||
.inflight => |serial| xdg_toplevel.configure_state = .{ .timed_out = serial },
|
.inflight => |serial| toplevel.configure_state = .{ .timed_out = serial },
|
||||||
.acked => xdg_toplevel.configure_state = .timed_out_acked,
|
.acked => toplevel.configure_state = .timed_out_acked,
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,15 +321,15 @@ pub fn commitTransaction(view: *View) void {
|
|||||||
// we would be rendering the SSD border at initial size X but the surface
|
// we would be rendering the SSD border at initial size X but the surface
|
||||||
// would be rendered at size Y.
|
// would be rendered at size Y.
|
||||||
if (view.inflight.resizing) {
|
if (view.inflight.resizing) {
|
||||||
view.resizeUpdatePosition(xdg_toplevel.geometry.width, xdg_toplevel.geometry.height);
|
view.resizeUpdatePosition(toplevel.geometry.width, toplevel.geometry.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
view.current = view.inflight;
|
view.current = view.inflight;
|
||||||
view.current.box.width = xdg_toplevel.geometry.width;
|
view.current.box.width = toplevel.geometry.width;
|
||||||
view.current.box.height = xdg_toplevel.geometry.height;
|
view.current.box.height = toplevel.geometry.height;
|
||||||
},
|
},
|
||||||
.idle, .committed => {
|
.idle, .committed => {
|
||||||
xdg_toplevel.configure_state = .idle;
|
toplevel.configure_state = .idle;
|
||||||
view.current = view.inflight;
|
view.current = view.inflight;
|
||||||
},
|
},
|
||||||
.timed_out, .timed_out_acked => unreachable,
|
.timed_out, .timed_out_acked => unreachable,
|
||||||
@ -374,9 +374,9 @@ pub fn updateSceneState(view: *View) void {
|
|||||||
surface_clip.y -= box.y;
|
surface_clip.y -= box.y;
|
||||||
|
|
||||||
switch (view.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| {
|
.toplevel => |toplevel| {
|
||||||
surface_clip.x += xdg_toplevel.geometry.x;
|
surface_clip.x += toplevel.geometry.x;
|
||||||
surface_clip.y += xdg_toplevel.geometry.y;
|
surface_clip.y += toplevel.geometry.y;
|
||||||
},
|
},
|
||||||
.xwayland_view, .none => {},
|
.xwayland_view, .none => {},
|
||||||
}
|
}
|
||||||
@ -443,7 +443,7 @@ pub fn updateSceneState(view: *View) void {
|
|||||||
pub fn configure(view: *View) bool {
|
pub fn configure(view: *View) bool {
|
||||||
assert(view.mapped and !view.destroying);
|
assert(view.mapped and !view.destroying);
|
||||||
switch (view.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |*xdg_toplevel| return xdg_toplevel.configure(),
|
.toplevel => |*toplevel| return toplevel.configure(),
|
||||||
.xwayland_view => |*xwayland_view| return xwayland_view.configure(),
|
.xwayland_view => |*xwayland_view| return xwayland_view.configure(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
@ -452,7 +452,7 @@ pub fn configure(view: *View) bool {
|
|||||||
pub fn rootSurface(view: View) *wlr.Surface {
|
pub fn rootSurface(view: View) *wlr.Surface {
|
||||||
assert(view.mapped and !view.destroying);
|
assert(view.mapped and !view.destroying);
|
||||||
return switch (view.impl) {
|
return switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.rootSurface(),
|
.toplevel => |toplevel| toplevel.rootSurface(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.rootSurface(),
|
.xwayland_view => |xwayland_view| xwayland_view.rootSurface(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
};
|
};
|
||||||
@ -526,7 +526,7 @@ pub fn setPendingOutput(view: *View, output: *Output) void {
|
|||||||
pub fn close(view: View) void {
|
pub fn close(view: View) void {
|
||||||
assert(!view.destroying);
|
assert(!view.destroying);
|
||||||
switch (view.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.close(),
|
.toplevel => |toplevel| toplevel.close(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.close(),
|
.xwayland_view => |xwayland_view| xwayland_view.close(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
@ -535,7 +535,7 @@ pub fn close(view: View) void {
|
|||||||
pub fn destroyPopups(view: View) void {
|
pub fn destroyPopups(view: View) void {
|
||||||
assert(!view.destroying);
|
assert(!view.destroying);
|
||||||
switch (view.impl) {
|
switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.destroyPopups(),
|
.toplevel => |toplevel| toplevel.destroyPopups(),
|
||||||
.xwayland_view => {},
|
.xwayland_view => {},
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
@ -545,7 +545,7 @@ pub fn destroyPopups(view: View) void {
|
|||||||
pub fn getTitle(view: View) ?[*:0]const u8 {
|
pub fn getTitle(view: View) ?[*:0]const u8 {
|
||||||
assert(!view.destroying);
|
assert(!view.destroying);
|
||||||
return switch (view.impl) {
|
return switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.getTitle(),
|
.toplevel => |toplevel| toplevel.getTitle(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.getTitle(),
|
.xwayland_view => |xwayland_view| xwayland_view.getTitle(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
};
|
};
|
||||||
@ -555,7 +555,7 @@ pub fn getTitle(view: View) ?[*:0]const u8 {
|
|||||||
pub fn getAppId(view: View) ?[*:0]const u8 {
|
pub fn getAppId(view: View) ?[*:0]const u8 {
|
||||||
assert(!view.destroying);
|
assert(!view.destroying);
|
||||||
return switch (view.impl) {
|
return switch (view.impl) {
|
||||||
.xdg_toplevel => |xdg_toplevel| xdg_toplevel.getAppId(),
|
.toplevel => |toplevel| toplevel.getAppId(),
|
||||||
.xwayland_view => |xwayland_view| xwayland_view.getAppId(),
|
.xwayland_view => |xwayland_view| xwayland_view.getAppId(),
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
};
|
};
|
||||||
|
@ -34,32 +34,32 @@ request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) =
|
|||||||
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode),
|
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode),
|
||||||
|
|
||||||
pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
|
pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
|
||||||
const xdg_toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.toplevel.base.data);
|
const toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.toplevel.base.data);
|
||||||
|
|
||||||
xdg_toplevel.decoration = .{ .wlr_decoration = wlr_decoration };
|
toplevel.decoration = .{ .wlr_decoration = wlr_decoration };
|
||||||
const decoration = &xdg_toplevel.decoration.?;
|
const decoration = &toplevel.decoration.?;
|
||||||
|
|
||||||
wlr_decoration.events.destroy.add(&decoration.destroy);
|
wlr_decoration.events.destroy.add(&decoration.destroy);
|
||||||
wlr_decoration.events.request_mode.add(&decoration.request_mode);
|
wlr_decoration.events.request_mode.add(&decoration.request_mode);
|
||||||
|
|
||||||
const ssd = server.config.rules.ssd.match(xdg_toplevel.view) orelse
|
const ssd = server.config.rules.ssd.match(toplevel.view) orelse
|
||||||
(decoration.wlr_decoration.requested_mode != .client_side);
|
(decoration.wlr_decoration.requested_mode != .client_side);
|
||||||
|
|
||||||
// TODO(wlroots): make sure this is properly batched in a single configure
|
// TODO(wlroots): make sure this is properly batched in a single configure
|
||||||
// with all other initial state when wlroots makes this possible.
|
// with all other initial state when wlroots makes this possible.
|
||||||
_ = wlr_decoration.setMode(if (ssd) .server_side else .client_side);
|
_ = wlr_decoration.setMode(if (ssd) .server_side else .client_side);
|
||||||
|
|
||||||
xdg_toplevel.view.pending.ssd = ssd;
|
toplevel.view.pending.ssd = ssd;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(decoration: *XdgDecoration) void {
|
pub fn deinit(decoration: *XdgDecoration) void {
|
||||||
const xdg_toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
|
const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
|
||||||
|
|
||||||
decoration.destroy.link.remove();
|
decoration.destroy.link.remove();
|
||||||
decoration.request_mode.link.remove();
|
decoration.request_mode.link.remove();
|
||||||
|
|
||||||
assert(xdg_toplevel.decoration != null);
|
assert(toplevel.decoration != null);
|
||||||
xdg_toplevel.decoration = null;
|
toplevel.decoration = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleDestroy(
|
fn handleDestroy(
|
||||||
@ -77,10 +77,10 @@ fn handleRequestMode(
|
|||||||
) void {
|
) void {
|
||||||
const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener);
|
const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener);
|
||||||
|
|
||||||
const xdg_toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
|
const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
|
||||||
const view = xdg_toplevel.view;
|
const view = toplevel.view;
|
||||||
|
|
||||||
const ssd = server.config.rules.ssd.match(xdg_toplevel.view) orelse
|
const ssd = server.config.rules.ssd.match(toplevel.view) orelse
|
||||||
(decoration.wlr_decoration.requested_mode != .client_side);
|
(decoration.wlr_decoration.requested_mode != .client_side);
|
||||||
|
|
||||||
if (view.pending.ssd != ssd) {
|
if (view.pending.ssd != ssd) {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const Self = @This();
|
const XdgToplevel = @This();
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
@ -36,7 +36,7 @@ const log = std.log.scoped(.xdg_shell);
|
|||||||
/// TODO(zig): get rid of this and use @fieldParentPtr(), https://github.com/ziglang/zig/issues/6611
|
/// TODO(zig): get rid of this and use @fieldParentPtr(), https://github.com/ziglang/zig/issues/6611
|
||||||
view: *View,
|
view: *View,
|
||||||
|
|
||||||
xdg_toplevel: *wlr.XdgToplevel,
|
wlr_toplevel: *wlr.XdgToplevel,
|
||||||
|
|
||||||
decoration: ?XdgDecoration = null,
|
decoration: ?XdgDecoration = null,
|
||||||
|
|
||||||
@ -76,14 +76,14 @@ request_resize: wl.Listener(*wlr.XdgToplevel.event.Resize) =
|
|||||||
set_title: wl.Listener(void) = wl.Listener(void).init(handleSetTitle),
|
set_title: wl.Listener(void) = wl.Listener(void).init(handleSetTitle),
|
||||||
set_app_id: wl.Listener(void) = wl.Listener(void).init(handleSetAppId),
|
set_app_id: wl.Listener(void) = wl.Listener(void).init(handleSetAppId),
|
||||||
|
|
||||||
pub fn create(xdg_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
|
pub fn create(wlr_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
|
||||||
const view = try View.create(.{ .xdg_toplevel = .{
|
const view = try View.create(.{ .toplevel = .{
|
||||||
.view = undefined,
|
.view = undefined,
|
||||||
.xdg_toplevel = xdg_toplevel,
|
.wlr_toplevel = wlr_toplevel,
|
||||||
} });
|
} });
|
||||||
errdefer view.destroy();
|
errdefer view.destroy();
|
||||||
|
|
||||||
const self = &view.impl.xdg_toplevel;
|
const toplevel = &view.impl.toplevel;
|
||||||
|
|
||||||
// This listener must be added before the scene xdg surface is created.
|
// This listener must be added before the scene xdg surface is created.
|
||||||
// Otherwise, the scene surface nodes will already be disabled by the unmap
|
// Otherwise, the scene surface nodes will already be disabled by the unmap
|
||||||
@ -93,38 +93,38 @@ pub fn create(xdg_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
|
|||||||
// so that we can save the buffers for frame perfection.
|
// so that we can save the buffers for frame perfection.
|
||||||
// TODO(wlroots) This is fragile, it would be good if wlroots gave us a
|
// TODO(wlroots) This is fragile, it would be good if wlroots gave us a
|
||||||
// better alternative here.
|
// better alternative here.
|
||||||
xdg_toplevel.base.surface.events.unmap.add(&self.unmap);
|
wlr_toplevel.base.surface.events.unmap.add(&toplevel.unmap);
|
||||||
errdefer self.unmap.link.remove();
|
errdefer toplevel.unmap.link.remove();
|
||||||
|
|
||||||
_ = try view.surface_tree.createSceneXdgSurface(xdg_toplevel.base);
|
_ = try view.surface_tree.createSceneXdgSurface(wlr_toplevel.base);
|
||||||
|
|
||||||
self.view = view;
|
toplevel.view = view;
|
||||||
|
|
||||||
xdg_toplevel.base.data = @intFromPtr(self);
|
wlr_toplevel.base.data = @intFromPtr(toplevel);
|
||||||
xdg_toplevel.base.surface.data = @intFromPtr(&view.tree.node);
|
wlr_toplevel.base.surface.data = @intFromPtr(&view.tree.node);
|
||||||
|
|
||||||
// Add listeners that are active over the toplevel's entire lifetime
|
// Add listeners that are active over the toplevel's entire lifetime
|
||||||
xdg_toplevel.base.events.destroy.add(&self.destroy);
|
wlr_toplevel.base.events.destroy.add(&toplevel.destroy);
|
||||||
xdg_toplevel.base.surface.events.map.add(&self.map);
|
wlr_toplevel.base.surface.events.map.add(&toplevel.map);
|
||||||
xdg_toplevel.base.events.new_popup.add(&self.new_popup);
|
wlr_toplevel.base.events.new_popup.add(&toplevel.new_popup);
|
||||||
|
|
||||||
_ = xdg_toplevel.setWmCapabilities(.{ .fullscreen = true });
|
_ = wlr_toplevel.setWmCapabilities(.{ .fullscreen = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a configure event, applying the inflight state of the view.
|
/// Send a configure event, applying the inflight state of the view.
|
||||||
pub fn configure(self: *Self) bool {
|
pub fn configure(toplevel: *XdgToplevel) bool {
|
||||||
switch (self.configure_state) {
|
switch (toplevel.configure_state) {
|
||||||
.idle, .timed_out, .timed_out_acked => {},
|
.idle, .timed_out, .timed_out_acked => {},
|
||||||
.inflight, .acked, .committed => unreachable,
|
.inflight, .acked, .committed => unreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
defer switch (self.configure_state) {
|
defer switch (toplevel.configure_state) {
|
||||||
.idle, .inflight, .acked => {},
|
.idle, .inflight, .acked => {},
|
||||||
.timed_out, .timed_out_acked, .committed => unreachable,
|
.timed_out, .timed_out_acked, .committed => unreachable,
|
||||||
};
|
};
|
||||||
|
|
||||||
const inflight = &self.view.inflight;
|
const inflight = &toplevel.view.inflight;
|
||||||
const current = &self.view.current;
|
const current = &toplevel.view.current;
|
||||||
|
|
||||||
const inflight_float = inflight.float or (inflight.output != null and inflight.output.?.layout == null);
|
const inflight_float = inflight.float or (inflight.output != null and inflight.output.?.layout == null);
|
||||||
const current_float = current.float or (current.output != null and current.output.?.layout == null);
|
const current_float = current.float or (current.output != null and current.output.?.layout == null);
|
||||||
@ -142,167 +142,167 @@ pub fn configure(self: *Self) bool {
|
|||||||
{
|
{
|
||||||
// If no new configure is required, continue to track a timed out configure
|
// If no new configure is required, continue to track a timed out configure
|
||||||
// from the previous transaction if any.
|
// from the previous transaction if any.
|
||||||
switch (self.configure_state) {
|
switch (toplevel.configure_state) {
|
||||||
.idle => return false,
|
.idle => return false,
|
||||||
.timed_out => |serial| {
|
.timed_out => |serial| {
|
||||||
self.configure_state = .{ .inflight = serial };
|
toplevel.configure_state = .{ .inflight = serial };
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
.timed_out_acked => {
|
.timed_out_acked => {
|
||||||
self.configure_state = .acked;
|
toplevel.configure_state = .acked;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
.inflight, .acked, .committed => unreachable,
|
.inflight, .acked, .committed => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = self.xdg_toplevel.setActivated(inflight.focus != 0);
|
const wlr_toplevel = toplevel.wlr_toplevel;
|
||||||
|
|
||||||
_ = self.xdg_toplevel.setFullscreen(inflight.fullscreen);
|
_ = wlr_toplevel.setActivated(inflight.focus != 0);
|
||||||
|
_ = wlr_toplevel.setFullscreen(inflight.fullscreen);
|
||||||
|
_ = wlr_toplevel.setResizing(inflight.resizing);
|
||||||
|
|
||||||
if (inflight_float) {
|
if (inflight_float) {
|
||||||
_ = self.xdg_toplevel.setTiled(.{ .top = false, .bottom = false, .left = false, .right = false });
|
_ = wlr_toplevel.setTiled(.{ .top = false, .bottom = false, .left = false, .right = false });
|
||||||
} else {
|
} else {
|
||||||
_ = self.xdg_toplevel.setTiled(.{ .top = true, .bottom = true, .left = true, .right = true });
|
_ = wlr_toplevel.setTiled(.{ .top = true, .bottom = true, .left = true, .right = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.decoration) |decoration| {
|
if (toplevel.decoration) |decoration| {
|
||||||
_ = decoration.wlr_decoration.setMode(if (inflight.ssd) .server_side else .client_side);
|
_ = decoration.wlr_decoration.setMode(if (inflight.ssd) .server_side else .client_side);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = self.xdg_toplevel.setResizing(inflight.resizing);
|
|
||||||
|
|
||||||
// We need to call this wlroots function even if the inflight dimensions
|
// We need to call this wlroots function even if the inflight dimensions
|
||||||
// match the current dimensions in order to prevent wlroots internal state
|
// match the current dimensions in order to prevent wlroots internal state
|
||||||
// from getting out of sync in the case where a client has resized itself.
|
// from getting out of sync in the case where a client has resized ittoplevel.
|
||||||
const configure_serial = self.xdg_toplevel.setSize(inflight.box.width, inflight.box.height);
|
const configure_serial = wlr_toplevel.setSize(inflight.box.width, inflight.box.height);
|
||||||
|
|
||||||
// Only track configures with the transaction system if they affect the dimensions of the view.
|
// Only track configures with the transaction system if they affect the dimensions of the view.
|
||||||
// If the configure state is not idle this means we are currently tracking a timed out
|
// If the configure state is not idle this means we are currently tracking a timed out
|
||||||
// configure from a previous transaction and should instead track the newly sent configure.
|
// configure from a previous transaction and should instead track the newly sent configure.
|
||||||
if (inflight.box.width == current.box.width and
|
if (inflight.box.width == current.box.width and
|
||||||
inflight.box.height == current.box.height and
|
inflight.box.height == current.box.height and
|
||||||
self.configure_state == .idle)
|
toplevel.configure_state == .idle)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.configure_state = .{
|
toplevel.configure_state = .{
|
||||||
.inflight = configure_serial,
|
.inflight = configure_serial,
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rootSurface(self: Self) *wlr.Surface {
|
pub fn rootSurface(toplevel: XdgToplevel) *wlr.Surface {
|
||||||
return self.xdg_toplevel.base.surface;
|
return toplevel.wlr_toplevel.base.surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the view. This will lead to the unmap and destroy events being sent
|
/// Close the view. This will lead to the unmap and destroy events being sent
|
||||||
pub fn close(self: Self) void {
|
pub fn close(toplevel: XdgToplevel) void {
|
||||||
self.xdg_toplevel.sendClose();
|
toplevel.wlr_toplevel.sendClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the current title of the toplevel if any.
|
/// Return the current title of the toplevel if any.
|
||||||
pub fn getTitle(self: Self) ?[*:0]const u8 {
|
pub fn getTitle(toplevel: XdgToplevel) ?[*:0]const u8 {
|
||||||
return self.xdg_toplevel.title;
|
return toplevel.wlr_toplevel.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the current app_id of the toplevel if any .
|
/// Return the current app_id of the toplevel if any .
|
||||||
pub fn getAppId(self: Self) ?[*:0]const u8 {
|
pub fn getAppId(toplevel: XdgToplevel) ?[*:0]const u8 {
|
||||||
return self.xdg_toplevel.app_id;
|
return toplevel.wlr_toplevel.app_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroyPopups(self: Self) void {
|
pub fn destroyPopups(toplevel: XdgToplevel) void {
|
||||||
var it = self.xdg_toplevel.base.popups.safeIterator(.forward);
|
var it = toplevel.wlr_toplevel.base.popups.safeIterator(.forward);
|
||||||
while (it.next()) |wlr_xdg_popup| wlr_xdg_popup.destroy();
|
while (it.next()) |wlr_xdg_popup| wlr_xdg_popup.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||||
const self = @fieldParentPtr(Self, "destroy", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "destroy", listener);
|
||||||
|
|
||||||
// This can be be non-null here if the client commits a protocol error or
|
// This can be be non-null here if the client commits a protocol error or
|
||||||
// if it exits without destroying its wayland objects.
|
// if it exits without destroying its wayland objects.
|
||||||
if (self.decoration) |*decoration| {
|
if (toplevel.decoration) |*decoration| {
|
||||||
decoration.deinit();
|
decoration.deinit();
|
||||||
}
|
}
|
||||||
assert(self.decoration == null);
|
assert(toplevel.decoration == null);
|
||||||
|
|
||||||
// Remove listeners that are active for the entire lifetime of the view
|
// Remove listeners that are active for the entire lifetime of the view
|
||||||
self.destroy.link.remove();
|
toplevel.destroy.link.remove();
|
||||||
self.map.link.remove();
|
toplevel.map.link.remove();
|
||||||
self.unmap.link.remove();
|
toplevel.unmap.link.remove();
|
||||||
|
|
||||||
// The wlr_surface may outlive the wlr_xdg_surface so we must clean up the user data.
|
// The wlr_surface may outlive the wlr_xdg_surface so we must clean up the user data.
|
||||||
self.xdg_toplevel.base.surface.data = 0;
|
toplevel.wlr_toplevel.base.surface.data = 0;
|
||||||
|
|
||||||
const view = self.view;
|
const view = toplevel.view;
|
||||||
view.impl = .none;
|
view.impl = .none;
|
||||||
view.destroy();
|
view.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleMap(listener: *wl.Listener(void)) void {
|
fn handleMap(listener: *wl.Listener(void)) void {
|
||||||
const self = @fieldParentPtr(Self, "map", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "map", listener);
|
||||||
const view = self.view;
|
const view = toplevel.view;
|
||||||
|
|
||||||
// Add listeners that are only active while mapped
|
// Add listeners that are only active while mapped
|
||||||
self.xdg_toplevel.base.events.ack_configure.add(&self.ack_configure);
|
toplevel.wlr_toplevel.base.events.ack_configure.add(&toplevel.ack_configure);
|
||||||
self.xdg_toplevel.base.surface.events.commit.add(&self.commit);
|
toplevel.wlr_toplevel.base.surface.events.commit.add(&toplevel.commit);
|
||||||
self.xdg_toplevel.events.request_fullscreen.add(&self.request_fullscreen);
|
toplevel.wlr_toplevel.events.request_fullscreen.add(&toplevel.request_fullscreen);
|
||||||
self.xdg_toplevel.events.request_move.add(&self.request_move);
|
toplevel.wlr_toplevel.events.request_move.add(&toplevel.request_move);
|
||||||
self.xdg_toplevel.events.request_resize.add(&self.request_resize);
|
toplevel.wlr_toplevel.events.request_resize.add(&toplevel.request_resize);
|
||||||
self.xdg_toplevel.events.set_title.add(&self.set_title);
|
toplevel.wlr_toplevel.events.set_title.add(&toplevel.set_title);
|
||||||
self.xdg_toplevel.events.set_app_id.add(&self.set_app_id);
|
toplevel.wlr_toplevel.events.set_app_id.add(&toplevel.set_app_id);
|
||||||
|
|
||||||
self.xdg_toplevel.base.getGeometry(&self.geometry);
|
toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry);
|
||||||
|
|
||||||
view.pending.box = .{
|
view.pending.box = .{
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = 0,
|
.y = 0,
|
||||||
.width = self.geometry.width,
|
.width = toplevel.geometry.width,
|
||||||
.height = self.geometry.height,
|
.height = toplevel.geometry.height,
|
||||||
};
|
};
|
||||||
view.inflight.box = view.pending.box;
|
view.inflight.box = view.pending.box;
|
||||||
view.current.box = view.pending.box;
|
view.current.box = view.pending.box;
|
||||||
|
|
||||||
const state = &self.xdg_toplevel.current;
|
const state = &toplevel.wlr_toplevel.current;
|
||||||
const has_fixed_size = state.min_width != 0 and state.min_height != 0 and
|
const has_fixed_size = state.min_width != 0 and state.min_height != 0 and
|
||||||
(state.min_width == state.max_width or state.min_height == state.max_height);
|
(state.min_width == state.max_width or state.min_height == state.max_height);
|
||||||
|
|
||||||
if (self.xdg_toplevel.parent != null or has_fixed_size) {
|
if (toplevel.wlr_toplevel.parent != null or has_fixed_size) {
|
||||||
// If the self.xdg_toplevel has a parent or has a fixed size make it float.
|
// If the toplevel.wlr_toplevel has a parent or has a fixed size make it float.
|
||||||
// This will be overwritten in View.map() if the view is matched by a rule.
|
// This will be overwritten in View.map() if the view is matched by a rule.
|
||||||
view.pending.float = true;
|
view.pending.float = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.view.pending.fullscreen = self.xdg_toplevel.requested.fullscreen;
|
toplevel.view.pending.fullscreen = toplevel.wlr_toplevel.requested.fullscreen;
|
||||||
|
|
||||||
view.map() catch {
|
view.map() catch {
|
||||||
log.err("out of memory", .{});
|
log.err("out of memory", .{});
|
||||||
self.xdg_toplevel.resource.getClient().postNoMemory();
|
toplevel.wlr_toplevel.resource.getClient().postNoMemory();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when the surface is unmapped and will no longer be displayed.
|
/// Called when the surface is unmapped and will no longer be displayed.
|
||||||
fn handleUnmap(listener: *wl.Listener(void)) void {
|
fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||||
const self = @fieldParentPtr(Self, "unmap", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "unmap", listener);
|
||||||
|
|
||||||
// Remove listeners that are only active while mapped
|
// Remove listeners that are only active while mapped
|
||||||
self.ack_configure.link.remove();
|
toplevel.ack_configure.link.remove();
|
||||||
self.commit.link.remove();
|
toplevel.commit.link.remove();
|
||||||
self.request_fullscreen.link.remove();
|
toplevel.request_fullscreen.link.remove();
|
||||||
self.request_move.link.remove();
|
toplevel.request_move.link.remove();
|
||||||
self.request_resize.link.remove();
|
toplevel.request_resize.link.remove();
|
||||||
self.set_title.link.remove();
|
toplevel.set_title.link.remove();
|
||||||
self.set_app_id.link.remove();
|
toplevel.set_app_id.link.remove();
|
||||||
|
|
||||||
self.view.unmap();
|
toplevel.view.unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void {
|
fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void {
|
||||||
const self = @fieldParentPtr(Self, "new_popup", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "new_popup", listener);
|
||||||
|
|
||||||
XdgPopup.create(wlr_xdg_popup, self.view.popup_tree, self.view.popup_tree) catch {
|
XdgPopup.create(wlr_xdg_popup, toplevel.view.popup_tree, toplevel.view.popup_tree) catch {
|
||||||
wlr_xdg_popup.resource.postNoMemory();
|
wlr_xdg_popup.resource.postNoMemory();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -312,24 +312,24 @@ fn handleAckConfigure(
|
|||||||
listener: *wl.Listener(*wlr.XdgSurface.Configure),
|
listener: *wl.Listener(*wlr.XdgSurface.Configure),
|
||||||
acked_configure: *wlr.XdgSurface.Configure,
|
acked_configure: *wlr.XdgSurface.Configure,
|
||||||
) void {
|
) void {
|
||||||
const self = @fieldParentPtr(Self, "ack_configure", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "ack_configure", listener);
|
||||||
switch (self.configure_state) {
|
switch (toplevel.configure_state) {
|
||||||
.inflight => |serial| if (acked_configure.serial == serial) {
|
.inflight => |serial| if (acked_configure.serial == serial) {
|
||||||
self.configure_state = .acked;
|
toplevel.configure_state = .acked;
|
||||||
},
|
},
|
||||||
.timed_out => |serial| if (acked_configure.serial == serial) {
|
.timed_out => |serial| if (acked_configure.serial == serial) {
|
||||||
self.configure_state = .timed_out_acked;
|
toplevel.configure_state = .timed_out_acked;
|
||||||
},
|
},
|
||||||
.acked, .idle, .committed, .timed_out_acked => {},
|
.acked, .idle, .committed, .timed_out_acked => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||||
const self = @fieldParentPtr(Self, "commit", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "commit", listener);
|
||||||
const view = self.view;
|
const view = toplevel.view;
|
||||||
|
|
||||||
{
|
{
|
||||||
const state = &self.xdg_toplevel.current;
|
const state = &toplevel.wlr_toplevel.current;
|
||||||
view.constraints = .{
|
view.constraints = .{
|
||||||
.min_width = @max(state.min_width, 1),
|
.min_width = @max(state.min_width, 1),
|
||||||
.max_width = if (state.max_width > 0) @intCast(state.max_width) else math.maxInt(u31),
|
.max_width = if (state.max_width > 0) @intCast(state.max_width) else math.maxInt(u31),
|
||||||
@ -338,19 +338,19 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const old_geometry = self.geometry;
|
const old_geometry = toplevel.geometry;
|
||||||
self.xdg_toplevel.base.getGeometry(&self.geometry);
|
toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry);
|
||||||
|
|
||||||
switch (self.configure_state) {
|
switch (toplevel.configure_state) {
|
||||||
.idle, .committed, .timed_out => {
|
.idle, .committed, .timed_out => {
|
||||||
const size_changed = self.geometry.width != old_geometry.width or
|
const size_changed = toplevel.geometry.width != old_geometry.width or
|
||||||
self.geometry.height != old_geometry.height;
|
toplevel.geometry.height != old_geometry.height;
|
||||||
const no_layout = view.current.output != null and view.current.output.?.layout == null;
|
const no_layout = view.current.output != null and view.current.output.?.layout == null;
|
||||||
|
|
||||||
if (size_changed) {
|
if (size_changed) {
|
||||||
log.debug(
|
log.debug(
|
||||||
"client initiated size change: {}x{} -> {}x{}",
|
"client initiated size change: {}x{} -> {}x{}",
|
||||||
.{ old_geometry.width, old_geometry.height, self.geometry.width, self.geometry.height },
|
.{ old_geometry.width, old_geometry.height, toplevel.geometry.width, toplevel.geometry.height },
|
||||||
);
|
);
|
||||||
if (!(view.current.float or no_layout) and !view.current.fullscreen) {
|
if (!(view.current.float or no_layout) and !view.current.fullscreen) {
|
||||||
// It seems that a disappointingly high number of clients have a buggy
|
// It seems that a disappointingly high number of clients have a buggy
|
||||||
@ -365,10 +365,10 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
view.inflight.box.width = self.geometry.width;
|
view.inflight.box.width = toplevel.geometry.width;
|
||||||
view.inflight.box.height = self.geometry.height;
|
view.inflight.box.height = toplevel.geometry.height;
|
||||||
view.pending.box.width = self.geometry.width;
|
view.pending.box.width = toplevel.geometry.width;
|
||||||
view.pending.box.height = self.geometry.height;
|
view.pending.box.height = toplevel.geometry.height;
|
||||||
view.current = view.inflight;
|
view.current = view.inflight;
|
||||||
view.updateSceneState();
|
view.updateSceneState();
|
||||||
}
|
}
|
||||||
@ -380,21 +380,21 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
|||||||
.inflight => view.sendFrameDone(),
|
.inflight => view.sendFrameDone(),
|
||||||
.acked, .timed_out_acked => {
|
.acked, .timed_out_acked => {
|
||||||
if (view.inflight.resizing) {
|
if (view.inflight.resizing) {
|
||||||
view.resizeUpdatePosition(self.geometry.width, self.geometry.height);
|
view.resizeUpdatePosition(toplevel.geometry.width, toplevel.geometry.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
view.inflight.box.width = self.geometry.width;
|
view.inflight.box.width = toplevel.geometry.width;
|
||||||
view.inflight.box.height = self.geometry.height;
|
view.inflight.box.height = toplevel.geometry.height;
|
||||||
view.pending.box.width = self.geometry.width;
|
view.pending.box.width = toplevel.geometry.width;
|
||||||
view.pending.box.height = self.geometry.height;
|
view.pending.box.height = toplevel.geometry.height;
|
||||||
|
|
||||||
switch (self.configure_state) {
|
switch (toplevel.configure_state) {
|
||||||
.acked => {
|
.acked => {
|
||||||
self.configure_state = .committed;
|
toplevel.configure_state = .committed;
|
||||||
server.root.notifyConfigured();
|
server.root.notifyConfigured();
|
||||||
},
|
},
|
||||||
.timed_out_acked => {
|
.timed_out_acked => {
|
||||||
self.configure_state = .idle;
|
toplevel.configure_state = .idle;
|
||||||
view.current = view.inflight;
|
view.current = view.inflight;
|
||||||
view.updateSceneState();
|
view.updateSceneState();
|
||||||
},
|
},
|
||||||
@ -407,9 +407,9 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
|||||||
/// Called when the client asks to be fullscreened. We always honor the request
|
/// Called when the client asks to be fullscreened. We always honor the request
|
||||||
/// for now, perhaps it should be denied in some cases in the future.
|
/// for now, perhaps it should be denied in some cases in the future.
|
||||||
fn handleRequestFullscreen(listener: *wl.Listener(void)) void {
|
fn handleRequestFullscreen(listener: *wl.Listener(void)) void {
|
||||||
const self = @fieldParentPtr(Self, "request_fullscreen", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "request_fullscreen", listener);
|
||||||
if (self.view.pending.fullscreen != self.xdg_toplevel.requested.fullscreen) {
|
if (toplevel.view.pending.fullscreen != toplevel.wlr_toplevel.requested.fullscreen) {
|
||||||
self.view.pending.fullscreen = self.xdg_toplevel.requested.fullscreen;
|
toplevel.view.pending.fullscreen = toplevel.wlr_toplevel.requested.fullscreen;
|
||||||
server.root.applyPending();
|
server.root.applyPending();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,9 +418,9 @@ fn handleRequestMove(
|
|||||||
listener: *wl.Listener(*wlr.XdgToplevel.event.Move),
|
listener: *wl.Listener(*wlr.XdgToplevel.event.Move),
|
||||||
event: *wlr.XdgToplevel.event.Move,
|
event: *wlr.XdgToplevel.event.Move,
|
||||||
) void {
|
) void {
|
||||||
const self = @fieldParentPtr(Self, "request_move", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "request_move", listener);
|
||||||
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
|
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
|
||||||
const view = self.view;
|
const view = toplevel.view;
|
||||||
|
|
||||||
if (view.current.output == null or view.pending.output == null) return;
|
if (view.current.output == null or view.pending.output == null) return;
|
||||||
if (view.current.tags & view.current.output.?.current.tags == 0) return;
|
if (view.current.tags & view.current.output.?.current.tags == 0) return;
|
||||||
@ -434,9 +434,9 @@ fn handleRequestMove(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void {
|
fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void {
|
||||||
const self = @fieldParentPtr(Self, "request_resize", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "request_resize", listener);
|
||||||
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
|
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
|
||||||
const view = self.view;
|
const view = toplevel.view;
|
||||||
|
|
||||||
if (view.current.output == null or view.pending.output == null) return;
|
if (view.current.output == null or view.pending.output == null) return;
|
||||||
if (view.current.tags & view.current.output.?.current.tags == 0) return;
|
if (view.current.tags & view.current.output.?.current.tags == 0) return;
|
||||||
@ -451,12 +451,12 @@ fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), ev
|
|||||||
|
|
||||||
/// Called when the client sets / updates its title
|
/// Called when the client sets / updates its title
|
||||||
fn handleSetTitle(listener: *wl.Listener(void)) void {
|
fn handleSetTitle(listener: *wl.Listener(void)) void {
|
||||||
const self = @fieldParentPtr(Self, "set_title", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "set_title", listener);
|
||||||
self.view.notifyTitle();
|
toplevel.view.notifyTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when the client sets / updates its app_id
|
/// Called when the client sets / updates its app_id
|
||||||
fn handleSetAppId(listener: *wl.Listener(void)) void {
|
fn handleSetAppId(listener: *wl.Listener(void)) void {
|
||||||
const self = @fieldParentPtr(Self, "set_app_id", listener);
|
const toplevel = @fieldParentPtr(XdgToplevel, "set_app_id", listener);
|
||||||
self.view.notifyAppId();
|
toplevel.view.notifyAppId();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user