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:
parent
6bdb152808
commit
2b2b78dd4d
4 changed files with 164 additions and 105 deletions
|
@ -88,6 +88,18 @@ that tag 1 through 9 are visible.
|
|||
|
||||
## 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_
|
||||
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
|
||||
the modifiers argument.
|
||||
|
||||
*set-option* _option_ _value_
|
||||
Set _option_ to a specified _value_. List of valid options:
|
||||
*outer-padding* _pixels_
|
||||
Set the padding around the edge of the screen to _pixels_.
|
||||
|
||||
- *background_color* _RGB/RGBA_hex_code_
|
||||
- *border_width* _non-negative_integer_
|
||||
- *border_color_focused* _RGB/RGBA_hex_code_
|
||||
- *border_color_unfocused* _RGB/RGBA_hex_code_
|
||||
- *outer_padding* _non-negative_integer_
|
||||
- *view_padding* _non-negative_integer_
|
||||
*view-padding* _pixels_
|
||||
Set the padding around the edge of each view to _pixels_.
|
||||
|
||||
*xcursor-theme* _theme_name_ [_size_]
|
||||
Set the xcursor theme to _theme_name_ and optionally set the
|
||||
|
|
|
@ -20,6 +20,10 @@ const std = @import("std");
|
|||
const Seat = @import("Seat.zig");
|
||||
|
||||
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 declareMode = @import("command/declare_mode.zig").declareMode;
|
||||
const enterMode = @import("command/enter_mode.zig").enterMode;
|
||||
|
@ -30,15 +34,16 @@ const impl = struct {
|
|||
const map = @import("command/map.zig").map;
|
||||
const modMasterCount = @import("command/mod_master_count.zig").modMasterCount;
|
||||
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 setFocusedTags = @import("command/tags.zig").setFocusedTags;
|
||||
const setOption = @import("command/set_option.zig").setOption;
|
||||
const setViewTags = @import("command/tags.zig").setViewTags;
|
||||
const spawn = @import("command/spawn.zig").spawn;
|
||||
const toggleFloat = @import("command/toggle_float.zig").toggleFloat;
|
||||
const toggleFocusedTags = @import("command/tags.zig").toggleFocusedTags;
|
||||
const toggleFullscreen = @import("command/toggle_fullscreen.zig").toggleFullscreen;
|
||||
const toggleViewTags = @import("command/tags.zig").toggleViewTags;
|
||||
const viewPadding = @import("command/config.zig").viewPadding;
|
||||
const xcursorTheme = @import("command/xcursor_theme.zig").xcursorTheme;
|
||||
const zoom = @import("command/zoom.zig").zoom;
|
||||
};
|
||||
|
@ -63,27 +68,32 @@ const str_to_impl_fn = [_]struct {
|
|||
name: []const u8,
|
||||
impl: fn (*std.mem.Allocator, *Seat, []const []const u8, *?[]const u8) Error!void,
|
||||
}{
|
||||
.{ .name = "close", .impl = impl.close },
|
||||
.{ .name = "declare-mode", .impl = impl.declareMode },
|
||||
.{ .name = "enter-mode", .impl = impl.enterMode },
|
||||
.{ .name = "exit", .impl = impl.exit },
|
||||
.{ .name = "focus-output", .impl = impl.focusOutput },
|
||||
.{ .name = "focus-view", .impl = impl.focusView },
|
||||
.{ .name = "layout", .impl = impl.layout },
|
||||
.{ .name = "map", .impl = impl.map },
|
||||
.{ .name = "mod-master-count", .impl = impl.modMasterCount },
|
||||
.{ .name = "mod-master-factor", .impl = impl.modMasterFactor },
|
||||
.{ .name = "send-to-output", .impl = impl.sendToOutput },
|
||||
.{ .name = "set-focused-tags", .impl = impl.setFocusedTags },
|
||||
.{ .name = "set-option", .impl = impl.setOption },
|
||||
.{ .name = "set-view-tags", .impl = impl.setViewTags },
|
||||
.{ .name = "spawn", .impl = impl.spawn },
|
||||
.{ .name = "toggle-float", .impl = impl.toggleFloat },
|
||||
.{ .name = "toggle-focused-tags", .impl = impl.toggleFocusedTags },
|
||||
.{ .name = "toggle-fullscreen", .impl = impl.toggleFullscreen },
|
||||
.{ .name = "toggle-view-tags", .impl = impl.toggleViewTags },
|
||||
.{ .name = "xcursor-theme", .impl = impl.xcursorTheme },
|
||||
.{ .name = "zoom", .impl = impl.zoom },
|
||||
.{ .name = "background-color", .impl = impl.backgroundColor },
|
||||
.{ .name = "border-color-focused", .impl = impl.borderColorFocused },
|
||||
.{ .name = "border-color-unfocused", .impl = impl.borderColorUnfocused },
|
||||
.{ .name = "border-width", .impl = impl.borderWidth },
|
||||
.{ .name = "close", .impl = impl.close },
|
||||
.{ .name = "declare-mode", .impl = impl.declareMode },
|
||||
.{ .name = "enter-mode", .impl = impl.enterMode },
|
||||
.{ .name = "exit", .impl = impl.exit },
|
||||
.{ .name = "focus-output", .impl = impl.focusOutput },
|
||||
.{ .name = "focus-view", .impl = impl.focusView },
|
||||
.{ .name = "layout", .impl = impl.layout },
|
||||
.{ .name = "map", .impl = impl.map },
|
||||
.{ .name = "mod-master-count", .impl = impl.modMasterCount },
|
||||
.{ .name = "mod-master-factor", .impl = impl.modMasterFactor },
|
||||
.{ .name = "outer-padding", .impl = impl.outerPadding },
|
||||
.{ .name = "send-to-output", .impl = impl.sendToOutput },
|
||||
.{ .name = "set-focused-tags", .impl = impl.setFocusedTags },
|
||||
.{ .name = "set-view-tags", .impl = impl.setViewTags },
|
||||
.{ .name = "spawn", .impl = impl.spawn },
|
||||
.{ .name = "toggle-float", .impl = impl.toggleFloat },
|
||||
.{ .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
|
||||
|
||||
|
|
116
river/command/config.zig
Normal file
116
river/command/config.zig
Normal 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,
|
||||
};
|
||||
}
|
|
@ -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,
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue