From 5b96d831d385b233fa4eddb1e2219bd008d2f9d3 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 28 Jun 2020 20:30:12 +0200 Subject: [PATCH] view: replace mode with float/fullscreen bools The enum would be awkward here since if a view is fullscreened while floating it should still be floating when defullscreened. --- river/Output.zig | 6 +++--- river/View.zig | 12 +++++------- river/XdgToplevel.zig | 4 ++-- river/command.zig | 1 + river/command/toggle_float.zig | 13 ++++++------- river/command/zoom.zig | 18 +++++++++++++----- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/river/Output.zig b/river/Output.zig index 7dc10cf..5b6855e 100644 --- a/river/Output.zig +++ b/river/Output.zig @@ -181,7 +181,7 @@ fn layoutFull(self: *Self, visible_count: u32, output_tags: u32) void { var it = ViewStack(View).pendingIterator(self.views.first, output_tags); while (it.next()) |node| { const view = &node.view; - if (view.pending.mode == .layout) view.pending.box = full_box; + if (!view.pending.float and !view.pending.fullscreen) view.pending.box = full_box; } } @@ -286,7 +286,7 @@ fn layoutExternal(self: *Self, visible_count: u32, output_tags: u32) !void { var view_it = ViewStack(View).pendingIterator(self.views.first, output_tags); while (view_it.next()) |node| { const view = &node.view; - if (view.pending.mode == .layout) { + if (!view.pending.float and !view.pending.fullscreen) { view.pending.box = view_boxen.items[i]; i += 1; } @@ -310,7 +310,7 @@ pub fn arrangeViews(self: *Self) void { var count: u32 = 0; var it = ViewStack(View).pendingIterator(self.views.first, output_tags); while (it.next()) |node| { - if (node.view.pending.mode == .layout) count += 1; + if (!node.view.pending.float and !node.view.pending.fullscreen) count += 1; } break :blk count; }; diff --git a/river/View.zig b/river/View.zig index adb3002..10622ee 100644 --- a/river/View.zig +++ b/river/View.zig @@ -36,11 +36,6 @@ const Impl = union(enum) { xwayland_view: XwaylandView, }; -const Mode = enum { - layout, - float, -}; - const State = struct { /// The output-relative coordinates and dimensions of the view. The /// surface itself may have other dimensions which are stored in the @@ -50,7 +45,8 @@ const State = struct { /// The tags of the view, as a bitmask tags: u32, - mode: Mode, + float: bool, + fullscreen: bool, }; const SavedBuffer = struct { @@ -108,8 +104,10 @@ pub fn init(self: *Self, output: *Output, tags: u32, surface: var) void { .width = 0, }, .tags = tags, - .mode = .layout, + .float = false, + .fullscreen = false, }; + self.pending = self.current; self.pending_serial = null; diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 7d71bd4..40463d5 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -174,13 +174,13 @@ fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { 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.float = true; view.pending.box = view.getDefaultFloatBox(); } else { // Make views with app_ids listed in the float filter float 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.float = true; view.pending.box = view.getDefaultFloatBox(); break; } diff --git a/river/command.zig b/river/command.zig index 4194026..d5e0b6e 100644 --- a/river/command.zig +++ b/river/command.zig @@ -37,6 +37,7 @@ const impl = struct { const spawn = @import("command/spawn.zig").spawn; const toggleFloat = @import("command/toggle_float.zig").toggleFloat; const toggleFocusedTags = @import("command/tags.zig").toggleFocusedTags; + const toggleFullscreen = @import("command/toggle_fullscreen.zig").toggleFullscreen; const toggleViewTags = @import("command/tags.zig").toggleViewTags; const zoom = @import("command/zoom.zig").zoom; }; diff --git a/river/command/toggle_float.zig b/river/command/toggle_float.zig index 62f14ba..29f433d 100644 --- a/river/command/toggle_float.zig +++ b/river/command/toggle_float.zig @@ -29,14 +29,13 @@ pub fn toggleFloat( out: *?[]const u8, ) Error!void { if (args.len > 1) return Error.TooManyArguments; + if (seat.focused_view) |view| { - switch (view.current.mode) { - .layout => { - view.pending.mode = .float; - view.pending.box = view.getDefaultFloatBox(); - }, - .float => view.pending.mode = .layout, - } + // Don't float fullscreen views + if (view.pending.fullscreen) return; + + if (!view.pending.float) view.pending.box = view.getDefaultFloatBox(); + view.pending.float = !view.pending.float; view.output.root.arrange(); } } diff --git a/river/command/zoom.zig b/river/command/zoom.zig index 783570f..5c17260 100644 --- a/river/command/zoom.zig +++ b/river/command/zoom.zig @@ -37,13 +37,21 @@ pub fn zoom( const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus); // Only zoom views that are part of the layout - if (current_focus.current.mode != .layout) return; + if (current_focus.pending.float or current_focus.pending.fullscreen) return; + // If the the first view that is part of the layout is focused, zoom + // the next view in the layout. Otherwise zoom the focused view. var it = ViewStack(View).iterator(output.views.first, output.current_focused_tags); - const zoom_node = if (focused_node == it.next()) - if (it.next()) |second| second else null - else - focused_node; + const layout_first = while (it.next()) |node| { + if (!node.view.pending.float and !node.view.pending.fullscreen) break node; + } else unreachable; + const zoom_node = if (focused_node == layout_first) blk: { + while (it.next()) |node| { + if (!node.view.pending.float and !node.view.pending.fullscreen) break :blk node; + } else { + break :blk null; + } + } else focused_node; if (zoom_node) |to_bump| { output.views.remove(to_bump);