Implement "attach-mode"

This commit is contained in:
Leon Henrik Plickat 2020-08-17 23:13:16 +02:00 committed by Isaac Freund
parent 340bfbd7f1
commit 59d6432332
6 changed files with 84 additions and 2 deletions

View file

@ -95,6 +95,9 @@ that tag 1 through 9 are visible.
## CONFIGURATION COMMANDS
*attach-mode* *top*|*bottom*
Configure where new views should attach in the view stack for the currently focused output.
*background-color* _#RRGGBB_|_#RRGGBBAA_
Set the background color.

View file

@ -30,6 +30,7 @@ const LayerSurface = @import("LayerSurface.zig");
const Root = @import("Root.zig");
const View = @import("View.zig");
const ViewStack = @import("view_stack.zig").ViewStack;
const AttachMode = @import("view_stack.zig").AttachMode;
const OutputStatus = @import("OutputStatus.zig");
const State = struct {
@ -37,6 +38,8 @@ const State = struct {
tags: u32,
};
attach_mode: AttachMode,
root: *Root,
wlr_output: *c.wlr_output,
@ -107,6 +110,8 @@ pub fn init(self: *Self, root: *Root, wlr_output: *c.wlr_output) !void {
self.layout = try std.mem.dupe(util.gpa, u8, "full");
self.attach_mode = .top;
self.status_trackers = std.SinglyLinkedList(OutputStatus).init();
// Set up listeners

View file

@ -243,7 +243,7 @@ pub fn sendToOutput(self: *Self, destination_output: *Output) void {
const node = @fieldParentPtr(ViewStack(Self).Node, "view", self);
self.output.views.remove(node);
destination_output.views.push(node);
destination_output.views.attach(node, destination_output.attach_mode);
self.output.sendViewTags();
destination_output.sendViewTags();
@ -340,7 +340,7 @@ pub fn map(self: *Self) void {
// Add the view to the stack of its output
const node = @fieldParentPtr(ViewStack(Self).Node, "view", self);
self.output.views.push(node);
self.output.views.attach(node, self.output.attach_mode);
// Focus the new view, assuming the seat is focusing the proper output
// and there isn't something else like a fullscreen view grabbing focus.

View file

@ -30,6 +30,7 @@ const str_to_impl_fn = [_]struct {
name: []const u8,
impl: fn (*std.mem.Allocator, *Seat, []const []const u8, *?[]const u8) Error!void,
}{
.{ .name = "attach-mode", .impl = @import("command/attach_mode.zig").attach_mode },
.{ .name = "background-color", .impl = @import("command/config.zig").backgroundColor },
.{ .name = "border-color-focused", .impl = @import("command/config.zig").borderColorFocused },
.{ .name = "border-color-unfocused", .impl = @import("command/config.zig").borderColorUnfocused },

View file

@ -0,0 +1,41 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Leon Henrik Plickat
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const util = @import("../util.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
pub fn attach_mode(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
out: *?[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
if (std.mem.eql(u8, "top", args[1])) {
seat.focused_output.attach_mode = .top;
} else if (std.mem.eql(u8, "bottom", args[1])) {
seat.focused_output.attach_mode = .bottom;
} else {
return Error.UnknownOption;
}
}

View file

@ -17,6 +17,11 @@
const View = @import("View.zig");
pub const AttachMode = enum {
top,
bottom,
};
/// A specialized doubly-linked stack that allows for filtered iteration
/// over the nodes. T must be View or *View.
pub fn ViewStack(comptime T: type) type {
@ -64,6 +69,33 @@ pub fn ViewStack(comptime T: type) type {
self.first = new_node;
}
/// Add a node to the bottom of the stack.
pub fn append(self: *Self, new_node: *Node) void {
// Set the prev/next pointers of the new node
new_node.prev = self.last;
new_node.next = null;
if (self.last) |last| {
// If the list is not empty, set the next pointer of the current
// first node to the new node.
last.next = new_node;
} else {
// If the list is empty set the first pointer to the new node.
self.first = new_node;
}
// Set the last pointer to the new node
self.last = new_node;
}
/// Attach a node into the viewstack based on the attach mode
pub fn attach(self: *Self, new_node: *Node, mode: AttachMode) void {
switch (mode) {
.top => self.push(new_node),
.bottom => self.append(new_node),
}
}
/// Remove a node from the view stack. This removes it from the stack of
/// all views as well as the stack of visible ones.
pub fn remove(self: *Self, target_node: *Node) void {