rivertile: simplify commands

Instead of having separate commands for modifying/setting a value, use
the presence of a +/- sign to indicate modification.
This commit is contained in:
Isaac Freund 2021-07-15 22:57:50 +02:00
parent 22251fa7ed
commit 1d000e5666
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
3 changed files with 54 additions and 54 deletions

View file

@ -33,42 +33,42 @@ modified while rivertile is running with the help of *riverctl*(1).
layout. (Default: 1) layout. (Default: 1)
*-main-ratio* _ratio_ *-main-ratio* _ratio_
Set the initial ratio of main area to total layout area. The _ratio_ Set the initial ratio of the main area to total layout area. The
must be between 0.1 and 0.9, inclusive. (Default: 0.6) _ratio_ must be between 0.1 and 0.9, inclusive. (Default: 0.6)
# COMMANDS # COMMANDS
These commands may be sent to rivertile at runtime with the help of These commands may be sent to rivertile at runtime with the help of
*riverctl*(1). *riverctl*(1).
*set-main-location* [*top*|*bottom*|*left*|*right*] *main-location* [*top*|*bottom*|*left*|*right*]
Set the location of the main area in the layout. Set the location of the main area in the layout.
*set-main-count* _count_ *main-count* _value_
Set the number of views in the main area of the layout. Set or modify the number of views in the main area of the layout. If
_value_ is prefixed by a +/- sign, _value_ is added/subtracted from the
current count. If there is no sign, the main count is set to _value_.
*mod-main-count* _delta_ *main-count* _value_
Modify the number of views in the main area of the layout by a Set or modify the ratio of the main area to total layout area. If
positive or negative _delta_. _value_ is prefixed by a +/- sign, _value_ is added/subtracted from
the current ratio. If there is no sign, the main ratio is set to
*set-main-ratio* _ratio_ _value_. Note that the ratio will always be clamped to the range
Set the ratio of main area to total layout area. The _ratio_ must 0.1 to 0.9.
be between 0.1 and 0.9, inclusive.
*mod-main-ratio* _delta_
Modify the ratio of main area to total layout area by a positive or
negative _delta_. The resulting ratio will be clamped to be between
0.1 and 0.9, inclusive.
# EXAMPLES # EXAMPLES
Start *rivertile* with 4 pixels outer padding and 2 main views: Start *rivertile* with 4 pixels outer padding and the *top* main location:
rivertile -outer-padding 4 -main-count 2 rivertile -outer-padding 4 -main-location top
Set the main location of rivertile to *top* at runtime: Increase the main ratio by 0.1 at runtime:
riverctl send-layout-cmd rivertile "set-main-location top" riverctl send-layout-cmd rivertile "main-ratio +0.1"
Set the main count to 3 at runtime:
riverctl send-layout-cmd rivertile "main-count 3"
# AUTHORS # AUTHORS

View file

@ -41,12 +41,12 @@ riverctl map normal $mod+Shift Comma send-to-output previous
riverctl map normal $mod Return zoom riverctl map normal $mod Return zoom
# Mod+H and Mod+L to decrease/increase the main ratio of rivertile(1) # Mod+H and Mod+L to decrease/increase the main ratio of rivertile(1)
riverctl map normal $mod H send-layout-cmd rivertile "mod-main-ratio -0.05" riverctl map normal $mod H send-layout-cmd rivertile "main-ratio -0.05"
riverctl map normal $mod L send-layout-cmd rivertile "mod-main-ratio +0.05" riverctl map normal $mod L send-layout-cmd rivertile "main-ratio +0.05"
# Mod+Shift+H and Mod+Shift+L to increment/decrement the main count of rivertile(1) # Mod+Shift+H and Mod+Shift+L to increment/decrement the main count of rivertile(1)
riverctl map normal $mod+Shift H send-layout-cmd rivertile "mod-main-count +1" riverctl map normal $mod+Shift H send-layout-cmd rivertile "main-count +1"
riverctl map normal $mod+Shift L send-layout-cmd rivertile "mod-main-count -1" riverctl map normal $mod+Shift L send-layout-cmd rivertile "main-count -1"
# Mod+Alt+{H,J,K,L} to move views # Mod+Alt+{H,J,K,L} to move views
riverctl map normal $mod+Mod1 H move left 100 riverctl map normal $mod+Mod1 H move left 100
@ -102,10 +102,10 @@ riverctl map normal $mod Space toggle-float
riverctl map normal $mod F toggle-fullscreen riverctl map normal $mod F toggle-fullscreen
# Mod+{Up,Right,Down,Left} to change layout orientation # Mod+{Up,Right,Down,Left} to change layout orientation
riverctl map normal $mod Up send-layout-cmd rivertile "set-main-location top" riverctl map normal $mod Up send-layout-cmd rivertile "main-location top"
riverctl map normal $mod Right send-layout-cmd rivertile "set-main-location right" riverctl map normal $mod Right send-layout-cmd rivertile "main-location right"
riverctl map normal $mod Down send-layout-cmd rivertile "set-main-location bottom" riverctl map normal $mod Down send-layout-cmd rivertile "main-location bottom"
riverctl map normal $mod Left send-layout-cmd rivertile "set-main-location left" riverctl map normal $mod Left send-layout-cmd rivertile "main-location left"
# Declare a passthrough mode. This mode has only a single mapping to return to # Declare a passthrough mode. This mode has only a single mapping to return to
# normal mode. This makes it useful for testing a nested wayland compositor # normal mode. This makes it useful for testing a nested wayland compositor

View file

@ -65,11 +65,9 @@ const usage =
; ;
const Command = enum { const Command = enum {
@"set-main-location", @"main-location",
@"set-main-count", @"main-count",
@"mod-main-count", @"main-ratio",
@"set-main-ratio",
@"mod-main-ratio",
}; };
const Location = enum { const Location = enum {
@ -159,39 +157,41 @@ const Output = struct {
return; return;
}; };
switch (cmd) { switch (cmd) {
.@"set-main-location" => { .@"main-location" => {
output.main_location = std.meta.stringToEnum(Location, raw_arg) orelse { output.main_location = std.meta.stringToEnum(Location, raw_arg) orelse {
std.log.err("unknown location: {s}", .{raw_arg}); std.log.err("unknown location: {s}", .{raw_arg});
return; return;
}; };
}, },
.@"set-main-count" => { .@"main-count" => {
output.main_count = std.fmt.parseInt(u32, raw_arg, 10) catch |err| {
std.log.err("failed to parse argument: {}", .{err});
return;
};
},
.@"mod-main-count" => {
const arg = std.fmt.parseInt(i32, raw_arg, 10) catch |err| { const arg = std.fmt.parseInt(i32, raw_arg, 10) catch |err| {
std.log.err("failed to parse argument: {}", .{err}); std.log.err("failed to parse argument: {}", .{err});
return; return;
}; };
const result = math.add(i33, output.main_count, arg) catch math.maxInt(u32); switch (raw_arg[0]) {
if (result > 0) output.main_count = @intCast(u32, result); '+' => output.main_count = math.add(
u32,
output.main_count,
@intCast(u32, arg),
) catch math.maxInt(u32),
'-' => {
const result = @as(i33, output.main_count) + arg;
if (result >= 0) output.main_count = @intCast(u32, result);
},
else => output.main_count = @intCast(u32, arg),
}
}, },
.@"set-main-ratio" => { .@"main-ratio" => {
const arg = std.fmt.parseFloat(f64, raw_arg) catch |err| { const arg = std.fmt.parseFloat(f64, raw_arg) catch |err| {
std.log.err("failed to parse argument: {}", .{err}); std.log.err("failed to parse argument: {}", .{err});
return; return;
}; };
output.main_ratio = math.clamp(arg, 0.1, 0.9); switch (raw_arg[0]) {
}, '+', '-' => {
.@"mod-main-ratio" => { output.main_ratio = math.clamp(output.main_ratio + arg, 0.1, 0.9);
const arg = std.fmt.parseFloat(f64, raw_arg) catch |err| { },
std.log.err("failed to parse argument: {}", .{err}); else => output.main_ratio = math.clamp(arg, 0.1, 0.9),
return; }
};
output.main_ratio = math.clamp(output.main_ratio + arg, 0.1, 0.9);
}, },
} }
}, },
@ -360,7 +360,7 @@ pub fn main() !void {
_ = try display.roundtrip(); _ = try display.roundtrip();
if (context.layout_manager == null) { if (context.layout_manager == null) {
fatal("wayland compositor does not support river-layout-v2.\n", .{}); fatal("wayland compositor does not support river-layout-v3.\n", .{});
} }
context.initialized = true; context.initialized = true;