aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--river/View.zig13
-rw-r--r--river/XdgToplevel.zig44
-rw-r--r--river/command/toggle_float.zig9
3 files changed, 27 insertions, 39 deletions
diff --git a/river/View.zig b/river/View.zig
index ffa7e4e..5a1e4c4 100644
--- a/river/View.zig
+++ b/river/View.zig
@@ -251,6 +251,19 @@ pub fn getTitle(self: Self) [*:0]const u8 {
};
}
+/// Return a box centered on the usable area of the current output and with
+/// the natural width/height of the view.
+pub fn getDefaultFloatBox(self: Self) Box {
+ return .{
+ .x = std.math.max(0, @divTrunc(@intCast(i32, self.output.usable_box.width) -
+ @intCast(i32, self.natural_width), 2)),
+ .y = std.math.max(0, @divTrunc(@intCast(i32, self.output.usable_box.height) -
+ @intCast(i32, self.natural_height), 2)),
+ .width = self.natural_width,
+ .height = self.natural_height,
+ };
+}
+
/// Called by the impl when the surface is ready to be displayed
pub fn map(self: *Self) void {
const root = self.output.root;
diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig
index b08e8bd..607bb92 100644
--- a/river/XdgToplevel.zig
+++ b/river/XdgToplevel.zig
@@ -154,46 +154,28 @@ fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
view.natural_width = @intCast(u32, self.wlr_xdg_surface.geometry.width);
view.natural_height = @intCast(u32, self.wlr_xdg_surface.geometry.height);
- if (view.natural_width == 0 and view.natural_height == 0) {
- view.natural_width = @intCast(u32, self.wlr_xdg_surface.surface.*.current.width);
- view.natural_height = @intCast(u32, self.wlr_xdg_surface.surface.*.current.height);
- }
-
const wlr_xdg_toplevel: *c.wlr_xdg_toplevel = @field(
self.wlr_xdg_surface,
c.wlr_xdg_surface_union,
).toplevel;
const state = &wlr_xdg_toplevel.current;
+ 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);
const app_id: [*:0]const u8 = if (wlr_xdg_toplevel.app_id) |id| id else "NULL";
- for (root.server.config.float_filter.items) |filter_app_id| {
+ if (wlr_xdg_toplevel.parent != null or has_fixed_size) {
+ // If the toplevel has a parent or has a fixed size make it float
+ view.pending.mode = .float;
+ view.pending.box = view.getDefaultFloatBox();
+ } else {
// Make views with app_ids listed in the float filter float
- if (std.mem.eql(u8, std.mem.span(app_id), std.mem.span(filter_app_id))) {
- view.pending.mode = .float;
- view.pending.box = .{
- .x = std.math.max(0, @divTrunc(@intCast(i32, view.output.usable_box.width) -
- @intCast(i32, view.natural_width), 2)),
- .y = std.math.max(0, @divTrunc(@intCast(i32, view.output.usable_box.height) -
- @intCast(i32, view.natural_height), 2)),
- .width = view.natural_width,
- .height = view.natural_height,
- };
- break;
+ for (root.server.config.float_filter.items) |filter_app_id| {
+ if (std.mem.eql(u8, std.mem.span(app_id), std.mem.span(filter_app_id))) {
+ view.pending.mode = .float;
+ view.pending.box = view.getDefaultFloatBox();
+ break;
+ }
}
- } else if ((wlr_xdg_toplevel.parent != null) or
- (state.min_width != 0 and state.min_height != 0 and
- (state.min_width == state.max_width or state.min_height == state.max_height)))
- {
- // If the toplevel has a parent or is of fixed size make it float
- view.pending.mode = .float;
- view.pending.box = .{
- .x = std.math.max(0, @divTrunc(@intCast(i32, view.output.usable_box.width) -
- @intCast(i32, view.natural_width), 2)),
- .y = std.math.max(0, @divTrunc(@intCast(i32, view.output.usable_box.height) -
- @intCast(i32, view.natural_height), 2)),
- .width = view.natural_width,
- .height = view.natural_height,
- };
}
// If the toplevel has no parent, inform it that it is tiled. This
diff --git a/river/command/toggle_float.zig b/river/command/toggle_float.zig
index b918043..62f14ba 100644
--- a/river/command/toggle_float.zig
+++ b/river/command/toggle_float.zig
@@ -33,14 +33,7 @@ pub fn toggleFloat(
switch (view.current.mode) {
.layout => {
view.pending.mode = .float;
- view.pending.box = .{
- .x = std.math.max(0, @divTrunc(@intCast(i32, view.output.usable_box.width) -
- @intCast(i32, view.natural_width), 2)),
- .y = std.math.max(0, @divTrunc(@intCast(i32, view.output.usable_box.height) -
- @intCast(i32, view.natural_height), 2)),
- .width = view.natural_width,
- .height = view.natural_height,
- };
+ view.pending.box = view.getDefaultFloatBox();
},
.float => view.pending.mode = .layout,
}