code: use a tagged union to store focus
This simplifies the code and is more robust than two separate pointers.
This commit is contained in:
@ -29,5 +29,5 @@ pub fn close(
|
||||
) Error!void {
|
||||
// Note: we don't call arrange() here as it will be called
|
||||
// automatically when the view is unmapped.
|
||||
if (seat.focused_view) |view| view.close();
|
||||
if (seat.focused == .view) seat.focused.view.close();
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ pub fn focusView(
|
||||
const direction = std.meta.stringToEnum(Direction, args[1]) orelse return Error.InvalidDirection;
|
||||
const output = seat.focused_output;
|
||||
|
||||
if (seat.focused_view) |current_focus| {
|
||||
if (seat.focused == .view) {
|
||||
// If the focused view is fullscreen, do nothing
|
||||
if (current_focus.current.fullscreen) return;
|
||||
if (seat.focused.view.current.fullscreen) return;
|
||||
|
||||
// If there is a currently focused view, focus the next visible view in the stack.
|
||||
const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
||||
const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", seat.focused.view);
|
||||
var it = switch (direction) {
|
||||
.next => ViewStack(View).iterator(focused_node, output.current.tags),
|
||||
.previous => ViewStack(View).reverseIterator(focused_node, output.current.tags),
|
||||
|
@ -36,22 +36,22 @@ pub fn sendToOutput(
|
||||
const direction = std.meta.stringToEnum(Direction, args[1]) orelse return Error.InvalidDirection;
|
||||
const root = &seat.input_manager.server.root;
|
||||
|
||||
if (seat.focused_view) |view| {
|
||||
if (seat.focused == .view) {
|
||||
// If the noop output is focused, there is nowhere to send the view
|
||||
if (view.output == &root.noop_output) {
|
||||
if (seat.focused_output == &root.noop_output) {
|
||||
std.debug.assert(root.outputs.len == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Send to the next/prev output in the list if there is one, else wrap
|
||||
const current_node = @fieldParentPtr(std.TailQueue(Output).Node, "data", view.output);
|
||||
const current_node = @fieldParentPtr(std.TailQueue(Output).Node, "data", seat.focused_output);
|
||||
const destination_output = switch (direction) {
|
||||
.next => if (current_node.next) |node| &node.data else &root.outputs.first.?.data,
|
||||
.previous => if (current_node.prev) |node| &node.data else &root.outputs.last.?.data,
|
||||
};
|
||||
|
||||
// Move the view to the target output
|
||||
view.sendToOutput(destination_output);
|
||||
seat.focused.view.sendToOutput(destination_output);
|
||||
|
||||
// Handle the change and focus whatever's next in the focus stack
|
||||
root.arrange();
|
||||
|
@ -42,9 +42,9 @@ pub fn setViewTags(
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
const tags = try parseTags(allocator, args, out);
|
||||
if (seat.focused_view) |view| {
|
||||
view.pending.tags = tags;
|
||||
view.output.root.arrange();
|
||||
if (seat.focused == .view) {
|
||||
seat.focused.view.pending.tags = tags;
|
||||
seat.focused.view.output.root.arrange();
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,11 +72,11 @@ pub fn toggleViewTags(
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
const tags = try parseTags(allocator, args, out);
|
||||
if (seat.focused_view) |view| {
|
||||
const new_tags = view.current.tags ^ tags;
|
||||
if (seat.focused == .view) {
|
||||
const new_tags = seat.focused.view.current.tags ^ tags;
|
||||
if (new_tags != 0) {
|
||||
view.pending.tags = new_tags;
|
||||
view.output.root.arrange();
|
||||
seat.focused.view.pending.tags = new_tags;
|
||||
seat.focused.view.output.root.arrange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,9 @@ pub fn toggleFloat(
|
||||
) Error!void {
|
||||
if (args.len > 1) return Error.TooManyArguments;
|
||||
|
||||
if (seat.focused_view) |view| {
|
||||
if (seat.focused == .view) {
|
||||
const view = seat.focused.view;
|
||||
|
||||
// Don't float fullscreen views
|
||||
if (view.pending.fullscreen) return;
|
||||
|
||||
|
@ -29,8 +29,8 @@ pub fn toggleFullscreen(
|
||||
) Error!void {
|
||||
if (args.len > 1) return Error.TooManyArguments;
|
||||
|
||||
if (seat.focused_view) |view| {
|
||||
view.setFullscreen(!view.pending.fullscreen);
|
||||
view.output.root.arrange();
|
||||
if (seat.focused == .view) {
|
||||
seat.focused.view.setFullscreen(!seat.focused.view.pending.fullscreen);
|
||||
seat.focused.view.output.root.arrange();
|
||||
}
|
||||
}
|
||||
|
@ -32,19 +32,19 @@ pub fn zoom(
|
||||
) Error!void {
|
||||
if (args.len > 1) return Error.TooManyArguments;
|
||||
|
||||
if (seat.focused_view) |current_focus| {
|
||||
const output = seat.focused_output;
|
||||
const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
|
||||
|
||||
if (seat.focused == .view) {
|
||||
// Only zoom views that are part of the layout
|
||||
if (current_focus.pending.float or current_focus.pending.fullscreen) return;
|
||||
if (seat.focused.view.pending.float or seat.focused.view.pending.fullscreen) return;
|
||||
|
||||
// If the the first view that is part of the layout is focused, zoom
|
||||
// If the first view that is part of the layout is focused, zoom
|
||||
// the next view in the layout. Otherwise zoom the focused view.
|
||||
const output = seat.focused_output;
|
||||
var it = ViewStack(View).iterator(output.views.first, output.current.tags);
|
||||
const layout_first = while (it.next()) |node| {
|
||||
if (!node.view.pending.float and !node.view.pending.fullscreen) break node;
|
||||
} else unreachable;
|
||||
|
||||
const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", seat.focused.view);
|
||||
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;
|
||||
|
Reference in New Issue
Block a user