command: split set-option into "toplevel" commands

`riverctl set-option view_padding 10` becomes `riverctl view-padding 10`

Having set-option doesn't really gain us anything and is more verbose as
well as being slightly inaccurate as the changes instantly apply.
This commit is contained in:
Isaac Freund 2020-07-15 12:42:20 +02:00
parent 6bdb152808
commit 2b2b78dd4d
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
4 changed files with 164 additions and 105 deletions

View file

@ -88,6 +88,18 @@ that tag 1 through 9 are visible.
## CONFIGURATION COMMANDS ## CONFIGURATION COMMANDS
*background-color* _#RRGGBB_|_#RRGGBBAA_
Set the background color.
*border-color-focused* _#RRGGBB_|_#RRGGBBAA_
Set the border color of focused views.
*border-color-unfocused* _#RRGGBB_|_#RRGGBBAA_
Set the border color of unfocused views.
*border-width* _pixels_
Set the border width to _pixels_.
*declare-mode* _name_ *declare-mode* _name_
Create a new mode called _name_ for use in mappings. Create a new mode called _name_ for use in mappings.
@ -114,15 +126,11 @@ that tag 1 through 9 are visible.
A mapping without modifiers can be created by passing an empty string as A mapping without modifiers can be created by passing an empty string as
the modifiers argument. the modifiers argument.
*set-option* _option_ _value_ *outer-padding* _pixels_
Set _option_ to a specified _value_. List of valid options: Set the padding around the edge of the screen to _pixels_.
- *background_color* _RGB/RGBA_hex_code_ *view-padding* _pixels_
- *border_width* _non-negative_integer_ Set the padding around the edge of each view to _pixels_.
- *border_color_focused* _RGB/RGBA_hex_code_
- *border_color_unfocused* _RGB/RGBA_hex_code_
- *outer_padding* _non-negative_integer_
- *view_padding* _non-negative_integer_
*xcursor-theme* _theme_name_ [_size_] *xcursor-theme* _theme_name_ [_size_]
Set the xcursor theme to _theme_name_ and optionally set the Set the xcursor theme to _theme_name_ and optionally set the

View file

@ -20,6 +20,10 @@ const std = @import("std");
const Seat = @import("Seat.zig"); const Seat = @import("Seat.zig");
const impl = struct { const impl = struct {
const backgroundColor = @import("command/config.zig").backgroundColor;
const borderColorFocused = @import("command/config.zig").borderColorFocused;
const borderColorUnfocused = @import("command/config.zig").borderColorUnfocused;
const borderWidth = @import("command/config.zig").borderWidth;
const close = @import("command/close.zig").close; const close = @import("command/close.zig").close;
const declareMode = @import("command/declare_mode.zig").declareMode; const declareMode = @import("command/declare_mode.zig").declareMode;
const enterMode = @import("command/enter_mode.zig").enterMode; const enterMode = @import("command/enter_mode.zig").enterMode;
@ -30,15 +34,16 @@ const impl = struct {
const map = @import("command/map.zig").map; const map = @import("command/map.zig").map;
const modMasterCount = @import("command/mod_master_count.zig").modMasterCount; const modMasterCount = @import("command/mod_master_count.zig").modMasterCount;
const modMasterFactor = @import("command/mod_master_factor.zig").modMasterFactor; const modMasterFactor = @import("command/mod_master_factor.zig").modMasterFactor;
const outerPadding = @import("command/config.zig").outerPadding;
const sendToOutput = @import("command/send_to_output.zig").sendToOutput; const sendToOutput = @import("command/send_to_output.zig").sendToOutput;
const setFocusedTags = @import("command/tags.zig").setFocusedTags; const setFocusedTags = @import("command/tags.zig").setFocusedTags;
const setOption = @import("command/set_option.zig").setOption;
const setViewTags = @import("command/tags.zig").setViewTags; const setViewTags = @import("command/tags.zig").setViewTags;
const spawn = @import("command/spawn.zig").spawn; const spawn = @import("command/spawn.zig").spawn;
const toggleFloat = @import("command/toggle_float.zig").toggleFloat; const toggleFloat = @import("command/toggle_float.zig").toggleFloat;
const toggleFocusedTags = @import("command/tags.zig").toggleFocusedTags; const toggleFocusedTags = @import("command/tags.zig").toggleFocusedTags;
const toggleFullscreen = @import("command/toggle_fullscreen.zig").toggleFullscreen; const toggleFullscreen = @import("command/toggle_fullscreen.zig").toggleFullscreen;
const toggleViewTags = @import("command/tags.zig").toggleViewTags; const toggleViewTags = @import("command/tags.zig").toggleViewTags;
const viewPadding = @import("command/config.zig").viewPadding;
const xcursorTheme = @import("command/xcursor_theme.zig").xcursorTheme; const xcursorTheme = @import("command/xcursor_theme.zig").xcursorTheme;
const zoom = @import("command/zoom.zig").zoom; const zoom = @import("command/zoom.zig").zoom;
}; };
@ -63,27 +68,32 @@ const str_to_impl_fn = [_]struct {
name: []const u8, name: []const u8,
impl: fn (*std.mem.Allocator, *Seat, []const []const u8, *?[]const u8) Error!void, impl: fn (*std.mem.Allocator, *Seat, []const []const u8, *?[]const u8) Error!void,
}{ }{
.{ .name = "close", .impl = impl.close }, .{ .name = "background-color", .impl = impl.backgroundColor },
.{ .name = "declare-mode", .impl = impl.declareMode }, .{ .name = "border-color-focused", .impl = impl.borderColorFocused },
.{ .name = "enter-mode", .impl = impl.enterMode }, .{ .name = "border-color-unfocused", .impl = impl.borderColorUnfocused },
.{ .name = "exit", .impl = impl.exit }, .{ .name = "border-width", .impl = impl.borderWidth },
.{ .name = "focus-output", .impl = impl.focusOutput }, .{ .name = "close", .impl = impl.close },
.{ .name = "focus-view", .impl = impl.focusView }, .{ .name = "declare-mode", .impl = impl.declareMode },
.{ .name = "layout", .impl = impl.layout }, .{ .name = "enter-mode", .impl = impl.enterMode },
.{ .name = "map", .impl = impl.map }, .{ .name = "exit", .impl = impl.exit },
.{ .name = "mod-master-count", .impl = impl.modMasterCount }, .{ .name = "focus-output", .impl = impl.focusOutput },
.{ .name = "mod-master-factor", .impl = impl.modMasterFactor }, .{ .name = "focus-view", .impl = impl.focusView },
.{ .name = "send-to-output", .impl = impl.sendToOutput }, .{ .name = "layout", .impl = impl.layout },
.{ .name = "set-focused-tags", .impl = impl.setFocusedTags }, .{ .name = "map", .impl = impl.map },
.{ .name = "set-option", .impl = impl.setOption }, .{ .name = "mod-master-count", .impl = impl.modMasterCount },
.{ .name = "set-view-tags", .impl = impl.setViewTags }, .{ .name = "mod-master-factor", .impl = impl.modMasterFactor },
.{ .name = "spawn", .impl = impl.spawn }, .{ .name = "outer-padding", .impl = impl.outerPadding },
.{ .name = "toggle-float", .impl = impl.toggleFloat }, .{ .name = "send-to-output", .impl = impl.sendToOutput },
.{ .name = "toggle-focused-tags", .impl = impl.toggleFocusedTags }, .{ .name = "set-focused-tags", .impl = impl.setFocusedTags },
.{ .name = "toggle-fullscreen", .impl = impl.toggleFullscreen }, .{ .name = "set-view-tags", .impl = impl.setViewTags },
.{ .name = "toggle-view-tags", .impl = impl.toggleViewTags }, .{ .name = "spawn", .impl = impl.spawn },
.{ .name = "xcursor-theme", .impl = impl.xcursorTheme }, .{ .name = "toggle-float", .impl = impl.toggleFloat },
.{ .name = "zoom", .impl = impl.zoom }, .{ .name = "toggle-focused-tags", .impl = impl.toggleFocusedTags },
.{ .name = "toggle-fullscreen", .impl = impl.toggleFullscreen },
.{ .name = "toggle-view-tags", .impl = impl.toggleViewTags },
.{ .name = "view-padding", .impl = impl.viewPadding },
.{ .name = "xcursor-theme", .impl = impl.xcursorTheme },
.{ .name = "zoom", .impl = impl.zoom },
}; };
// zig fmt: on // zig fmt: on

116
river/command/config.zig Normal file
View file

@ -0,0 +1,116 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Isaac Freund
//
// 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 Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
pub fn borderWidth(
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;
const server = seat.input_manager.server;
server.config.border_width = try std.fmt.parseInt(u32, args[1], 10);
server.root.arrange();
}
pub fn viewPadding(
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;
const server = seat.input_manager.server;
server.config.view_padding = try std.fmt.parseInt(u32, args[1], 10);
server.root.arrange();
}
pub fn outerPadding(
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;
const server = seat.input_manager.server;
server.config.outer_padding = try std.fmt.parseInt(u32, args[1], 10);
server.root.arrange();
}
pub fn backgroundColor(
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;
seat.input_manager.server.config.background_color = try parseRgba(args[1]);
}
pub fn borderColorFocused(
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;
seat.input_manager.server.config.border_color_focused = try parseRgba(args[1]);
}
pub fn borderColorUnfocused(
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;
seat.input_manager.server.config.border_color_unfocused = try parseRgba(args[1]);
}
/// Parse a color in the format #RRGGBB or #RRGGBBAA
fn parseRgba(string: []const u8) ![4]f32 {
if (string[0] != '#' or (string.len != 7 and string.len != 9)) return error.InvalidRgba;
const r = try std.fmt.parseInt(u8, string[1..3], 16);
const g = try std.fmt.parseInt(u8, string[3..5], 16);
const b = try std.fmt.parseInt(u8, string[5..7], 16);
const a = if (string.len == 9) try std.fmt.parseInt(u8, string[7..9], 16) else 255;
return [4]f32{
@intToFloat(f32, r) / 255.0,
@intToFloat(f32, g) / 255.0,
@intToFloat(f32, b) / 255.0,
@intToFloat(f32, a) / 255.0,
};
}

View file

@ -1,75 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 Rishabh Das
// Copyright 2020 Isaac Freund
//
// 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 Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const Option = enum {
background_color,
border_width,
border_color_focused,
border_color_unfocused,
outer_padding,
view_padding,
};
/// Set option to a specified value.
pub fn setOption(
allocator: *std.mem.Allocator,
seat: *Seat,
args: []const []const u8,
out: *?[]const u8,
) Error!void {
if (args.len < 3) return Error.NotEnoughArguments;
if (args.len > 3) return Error.TooManyArguments;
const config = &seat.input_manager.server.config;
const option = std.meta.stringToEnum(Option, args[1]) orelse return Error.UnknownOption;
// Assign value to option.
switch (option) {
.background_color => config.background_color = try parseRgba(args[2]),
.border_width => config.border_width = try std.fmt.parseInt(u32, args[2], 10),
.border_color_focused => config.border_color_focused = try parseRgba(args[2]),
.border_color_unfocused => config.border_color_unfocused = try parseRgba(args[2]),
.outer_padding => config.outer_padding = try std.fmt.parseInt(u32, args[2], 10),
.view_padding => config.view_padding = try std.fmt.parseInt(u32, args[2], 10),
}
// 'Refresh' focused output to display the desired changes.
seat.focused_output.root.arrange();
}
/// Parse a color in the format #RRGGBB or #RRGGBBAA
fn parseRgba(string: []const u8) ![4]f32 {
if (string[0] != '#' or (string.len != 7 and string.len != 9)) return error.InvalidRgba;
const r = try std.fmt.parseInt(u8, string[1..3], 16);
const g = try std.fmt.parseInt(u8, string[3..5], 16);
const b = try std.fmt.parseInt(u8, string[5..7], 16);
const a = if (string.len == 9) try std.fmt.parseInt(u8, string[7..9], 16) else 255;
return [4]f32{
@intToFloat(f32, r) / 255.0,
@intToFloat(f32, g) / 255.0,
@intToFloat(f32, b) / 255.0,
@intToFloat(f32, a) / 255.0,
};
}