Skip to content

Commit

Permalink
Add spacial output operations
Browse files Browse the repository at this point in the history
List based output operations are tedious for complex output layouts.
  • Loading branch information
Leon-Plickat authored and ifreund committed Jun 23, 2021
1 parent 3efcfed commit d3a9e96
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 124 deletions.
9 changes: 5 additions & 4 deletions doc/riverctl.1.scd
Expand Up @@ -32,8 +32,8 @@ over the Wayland protocol.
Add _app-id_ to the float filter list. Views with this _app-id_
will start floating.

*focus-output* *next*|*previous*
Focus the next or previous output.
*focus-output* *next*|*previous*|*up*|*right*|*down*|*left*
Focus the next or previous output or the closest output in any direction.

*focus-view* *next*|*previous*
Focus the next or previous view in the stack.
Expand All @@ -50,8 +50,9 @@ over the Wayland protocol.
Snap the focused view to the specified screen edge. The view will
be set to floating.

*send-to-output* *next*|*previous*
Send the focused view to the next or the previous output.
*send-to-output* *next*|*previous*|*up*|*right*|*down*|*left*
Send the focused view to the next or previous output or the closest
output in any direction.

*spawn* _shell_command_
Run _shell_command_ using _/bin/sh -c_. Put single quotes around
Expand Down
4 changes: 2 additions & 2 deletions river/command.zig
Expand Up @@ -55,7 +55,7 @@ const str_to_impl_fn = [_]struct {
.{ .name = "exit", .impl = @import("command/exit.zig").exit },
.{ .name = "float-filter-add", .impl = @import("command/filter.zig").floatFilterAdd },
.{ .name = "focus-follows-cursor", .impl = @import("command/focus_follows_cursor.zig").focusFollowsCursor },
.{ .name = "focus-output", .impl = @import("command/focus_output.zig").focusOutput },
.{ .name = "focus-output", .impl = @import("command/output.zig").focusOutput },
.{ .name = "focus-view", .impl = @import("command/focus_view.zig").focusView },
.{ .name = "input", .impl = @import("command/input.zig").input },
.{ .name = "list-inputs", .impl = @import("command/input.zig").listInputs },
Expand All @@ -67,7 +67,7 @@ const str_to_impl_fn = [_]struct {
.{ .name = "opacity", .impl = @import("command/opacity.zig").opacity },
.{ .name = "output-layout", .impl = @import("command/layout.zig").outputLayout },
.{ .name = "resize", .impl = @import("command/move.zig").resize },
.{ .name = "send-to-output", .impl = @import("command/send_to_output.zig").sendToOutput },
.{ .name = "send-to-output", .impl = @import("command/output.zig").sendToOutput },
.{ .name = "set-focused-tags", .impl = @import("command/tags.zig").setFocusedTags },
.{ .name = "set-layout-value", .impl = @import("command/layout.zig").setLayoutValue },
.{ .name = "set-repeat", .impl = @import("command/set_repeat.zig").setRepeat },
Expand Down
55 changes: 0 additions & 55 deletions river/command/focus_output.zig

This file was deleted.

99 changes: 99 additions & 0 deletions river/command/output.zig
@@ -0,0 +1,99 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2021 The River Developers
//
// 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 wlr = @import("wlroots");

const server = &@import("../main.zig").server;

const Direction = @import("../command.zig").Direction;
const PhysicalDirectionDirection = @import("../command.zig").PhysicalDirection;
const Error = @import("../command.zig").Error;
const Output = @import("../Output.zig");
const Seat = @import("../Seat.zig");

pub fn focusOutput(
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 the noop output is focused, there are no other outputs to switch to
if (seat.focused_output == &server.root.noop_output) {
std.debug.assert(server.root.outputs.len == 0);
return;
}

seat.focusOutput((try getOutput(seat, args[1])) orelse return);
seat.focus(null);
server.root.startTransaction();
}

pub fn sendToOutput(
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 the noop output is focused, there is nowhere to send the view
if (seat.focused_output == &server.root.noop_output) {
std.debug.assert(server.root.outputs.len == 0);
return;
}

if (seat.focused == .view) {
const destination_output = (try getOutput(seat, args[1])) orelse return;
seat.focused.view.sendToOutput(destination_output);

// Handle the change and focus whatever's next in the focus stack
seat.focus(null);
seat.focused_output.arrangeViews();
destination_output.arrangeViews();
server.root.startTransaction();
}
}

/// Find an output adjacent to the currently focused based on either logical or
/// spacial direction
fn getOutput(seat: *Seat, str: []const u8) !?*Output {
if (std.meta.stringToEnum(Direction, str)) |direction| { // Logical direction
// Return the next/prev output in the list if there is one, else wrap
const focused_node = @fieldParentPtr(std.TailQueue(Output).Node, "data", seat.focused_output);
return switch (direction) {
.next => if (focused_node.next) |node| &node.data else &server.root.outputs.first.?.data,
.previous => if (focused_node.prev) |node| &node.data else &server.root.outputs.last.?.data,
};
} else if (std.meta.stringToEnum(wlr.OutputLayout.Direction, str)) |direction| { // Spacial direction
const focus_box = server.root.output_layout.getBox(seat.focused_output.wlr_output) orelse return null;
const wlr_output = server.root.output_layout.adjacentOutput(
direction,
seat.focused_output.wlr_output,
@intToFloat(f64, focus_box.x + @divFloor(focus_box.width, 2)),
@intToFloat(f64, focus_box.y + @divFloor(focus_box.height, 2)),
) orelse return null;
return @intToPtr(*Output, wlr_output.data);
} else {
return Error.InvalidDirection;
}
}
63 changes: 0 additions & 63 deletions river/command/send_to_output.zig

This file was deleted.

0 comments on commit d3a9e96

Please sign in to comment.