command/attach-modes: above and below options

This commit is contained in:
Peter Kaplan 2024-03-05 09:47:26 +01:00 committed by Isaac Freund
parent f6cc4de884
commit d71bebc032
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
5 changed files with 37 additions and 3 deletions

View File

@ -345,18 +345,20 @@ matches everything while _\*\*_ and the empty string are invalid.
## CONFIGURATION
*default-attach-mode* *top*|*bottom*|*after <N>*
*default-attach-mode* *top*|*bottom*|*above*|*below*|*after <N>*
Set the attach mode to be used by all outputs by default.
Possible values:
- top: Prepends the newly spawned view at the top of the stack.
- bottom: Appends the newly spawned view at the bottom of the stack.
- above: Inserts the newly spawned view above the currently focused view.
- below: Inserts the newly spawned view below the currently focused view.
- after <N>: Inserts the newly spawned view after N views in the stack.
Note that the deprecated *attach-mode* command is aliased to
*default-attach-mode* for backwards compatibility.
*output-attach-mode* *top*|*bottom*|*after <N>*
*output-attach-mode* *top*|*bottom*|*above*|*below*|*after <N>*
Set the attach mode of the currently focused output, overriding the value of
default-attach-mode if any.

View File

@ -35,6 +35,8 @@ pub const AttachMode = union(enum) {
top,
bottom,
after: u32,
above,
below,
};
pub const FocusFollowsCursorMode = enum {

View File

@ -60,6 +60,20 @@ pub const PendingState = struct {
///
/// This includes both floating/fullscreen views and those arranged in the layout.
wm_stack: wl.list.Head(View, .pending_wm_stack_link),
///
/// Index of the first view in focus_stack in the wm_stack list.
pub fn focusedIndex(self: *PendingState) ?u32 {
var focus_stack_it = self.focus_stack.iterator(.forward);
const focused_view = focus_stack_it.next() orelse return null;
var it = self.wm_stack.iterator(.forward);
var count: u32 = 0;
while (it.next()) |other| {
if (other == focused_view) break;
count += 1;
}
return count;
}
};
wlr_output: *wlr.Output,

View File

@ -479,6 +479,14 @@ pub fn setPendingOutput(view: *Self, output: *Output) void {
.top => output.pending.wm_stack.prepend(view),
.bottom => output.pending.wm_stack.append(view),
.after => |n| view.attachAfter(&output.pending, n),
.above => view.attachAfter(
&output.pending,
output.pending.focusedIndex() orelse 0,
),
.below => view.attachAfter(
&output.pending,
(output.pending.focusedIndex() orelse 0) + 1,
),
}
output.pending.focus_stack.prepend(view);
@ -607,6 +615,14 @@ pub fn map(view: *Self) !void {
.top => server.root.fallback_pending.wm_stack.prepend(view),
.bottom => server.root.fallback_pending.wm_stack.append(view),
.after => |n| view.attachAfter(&server.root.fallback_pending, n),
.above => view.attachAfter(
&server.root.fallback_pending,
server.root.fallback_pending.focusedIndex() orelse 0,
),
.below => view.attachAfter(
&server.root.fallback_pending,
(server.root.fallback_pending.focusedIndex() orelse 0) + 1,
),
}
server.root.fallback_pending.focus_stack.prepend(view);

View File

@ -29,7 +29,7 @@ fn parseAttachMode(args: []const [:0]const u8) Error!Config.AttachMode {
const tag = meta.stringToEnum(meta.Tag(Config.AttachMode), args[1]) orelse return Error.UnknownOption;
switch (tag) {
inline .top, .bottom => |mode| {
inline .top, .bottom, .above, .below => |mode| {
if (args.len > 2) return Error.TooManyArguments;
return mode;