diff --git a/README.md b/README.md index e9e3043..d381456 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ river -c /path/to/config.sh An example script with sane defaults is provided [here](contrib/config.sh) in the contrib directory. -Some configuration options are still hardcoded in [Config.zig](src/Config.zig). +Some configuration options are still hardcoded in [Config.zig](river/Config.zig). Eventually all configuration will be moved to the `riverctl` binary. ## Development diff --git a/doc/riverctl.1 b/doc/riverctl.1 index df59ffb..1b93f9f 100644 --- a/doc/riverctl.1 +++ b/doc/riverctl.1 @@ -159,6 +159,19 @@ can be any of the above commands. A mapping without modifiers can be created by passing an empty string as the modifiers argument. +.TP +.B set-option \c +.I option value +Set +.I option +to a specified +.IR value . +List of valid options: +.IP \(bu +border_width (non-negative integer) +.IP \(bu +outer_padding (non-negative integer) + .SH EXAMPLES Bind bemenu-run to Super+P: diff --git a/river/Control.zig b/river/Control.zig index 89b009f..96d587f 100644 --- a/river/Control.zig +++ b/river/Control.zig @@ -120,6 +120,7 @@ fn runCommand( switch (err) { command.Error.NoCommand => "no command given", command.Error.UnknownCommand => "unknown command", + command.Error.UnknownOption => "unknown option", command.Error.NotEnoughArguments => "not enough arguments", command.Error.TooManyArguments => "too many arguments", command.Error.Overflow => "value out of bounds", diff --git a/river/command.zig b/river/command.zig index 243acfa..9f045fe 100644 --- a/river/command.zig +++ b/river/command.zig @@ -32,6 +32,7 @@ const impl = struct { const modMasterFactor = @import("command/mod_master_factor.zig").modMasterFactor; 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; @@ -54,6 +55,20 @@ pub const Direction = enum { } }; +pub const Option = enum { + BorderWidth, + OuterPadding, + + pub fn parse(str: []const u8) error{UnknownOption}!Option { + return if (std.mem.eql(u8, str, "border_width")) + Option.BorderWidth + else if (std.mem.eql(u8, str, "outer_padding")) + Option.OuterPadding + else + error.UnknownOption; + } +}; + // TODO: this could be replaced with a comptime hashmap // zig fmt: off const str_to_impl_fn = [_]struct { @@ -72,6 +87,7 @@ const str_to_impl_fn = [_]struct { .{ .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 }, @@ -89,6 +105,7 @@ pub const Error = error{ Overflow, InvalidCharacter, InvalidDirection, + UnknownOption, OutOfMemory, CommandFailed, }; diff --git a/river/command/set_option.zig b/river/command/set_option.zig new file mode 100644 index 0000000..303ae83 --- /dev/null +++ b/river/command/set_option.zig @@ -0,0 +1,46 @@ +// This file is part of river, a dynamic tiling wayland compositor. +// +// Copyright 2020 Rishabh Das +// +// 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 . + +const std = @import("std"); + +const Error = @import("../command.zig").Error; +const Option = @import("../command.zig").Option; +const Seat = @import("../Seat.zig"); + +/// Set option to a specified value. +pub fn setOption( + allocator: *std.mem.Allocator, + seat: *Seat, + args: []const []const u8, + failure_message: *[]const u8, +) Error!void { + if (args.len < 3) return Error.NotEnoughArguments; + if (args.len > 3) return Error.TooManyArguments; + + // Parse option and value. + const option = try Option.parse(args[1]); + const value = try std.fmt.parseInt(u32, args[2], 10); + + // Assign value to option. + switch (option) { + .BorderWidth => seat.focused_output.root.server.config.border_width = value, + .OuterPadding => seat.focused_output.root.server.config.outer_padding = value, + } + + // 'Refresh' focused output to display the desired changes. + seat.focused_output.root.arrange(); +}