view: introduce state struct to simplify code

The state struct holds all of the state that is double-buffered and
applied through transactions. This more explicit handling simplifies
much of the code, and will allow for easier implementation of new
feature such as fullscreen.
This commit is contained in:
Isaac Freund
2020-06-27 22:43:15 +02:00
parent 89d0fb012d
commit c04112b81a
12 changed files with 105 additions and 124 deletions

View File

@ -43,10 +43,8 @@ pub fn setViewTags(
) Error!void {
const tags = try parseTags(allocator, args, out);
if (seat.focused_view) |view| {
if (view.current_tags != tags) {
view.pending_tags = tags;
seat.input_manager.server.root.arrange();
}
view.pending.tags = tags;
view.output.root.arrange();
}
}
@ -75,10 +73,10 @@ pub fn toggleViewTags(
) Error!void {
const tags = try parseTags(allocator, args, out);
if (seat.focused_view) |view| {
const new_tags = view.current_tags ^ tags;
const new_tags = view.current.tags ^ tags;
if (new_tags != 0) {
view.pending_tags = new_tags;
seat.input_manager.server.root.arrange();
view.pending.tags = new_tags;
view.output.root.arrange();
}
}
}

View File

@ -30,9 +30,19 @@ pub fn toggleFloat(
) Error!void {
if (args.len > 1) return Error.TooManyArguments;
if (seat.focused_view) |view| {
switch (view.mode) {
.layout => view.setMode(.float),
.float => view.setMode(.layout),
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,
};
},
.float => view.pending.mode = .layout,
}
view.output.root.arrange();
}

View File

@ -37,7 +37,7 @@ 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.mode != .layout) return;
if (current_focus.current.mode != .layout) return;
var it = ViewStack(View).iterator(output.views.first, output.current_focused_tags);
const zoom_node = if (focused_node == it.next())