From adc4e1297128ff3abe3b2b85bf92a214c0f498d9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 Apr 2020 14:40:58 +0200 Subject: [PATCH] Zoom to second view in stack if top is focused --- src/command/zoom.zig | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/command/zoom.zig b/src/command/zoom.zig index 507620d..b24683e 100644 --- a/src/command/zoom.zig +++ b/src/command/zoom.zig @@ -5,16 +5,23 @@ const Seat = @import("../seat.zig").Seat; const View = @import("../view.zig").View; const ViewStack = @import("../view_stack.zig").ViewStack; -/// Bump the focused view to the top of the stack. -/// TODO: if the top of the stack is focused, bump the next visible view. +/// Bump the focused view to the top of the stack. If the view on the top of +/// the stack is focused, bump the second view to the top. pub fn zoom(seat: *Seat, arg: Arg) void { if (seat.focused_view) |current_focus| { const output = seat.focused_output; - const node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus); - if (node != output.views.first) { - output.views.remove(node); - output.views.push(node); + const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus); + + const zoom_node = if (focused_node == output.views.first) + if (focused_node.next) |second| second else null + else + focused_node; + + if (zoom_node) |to_bump| { + output.views.remove(to_bump); + output.views.push(to_bump); seat.input_manager.server.root.arrange(); + seat.focus(&to_bump.view); } } }