code: simplify option handling
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
// 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
|
||||
@ -18,9 +19,15 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Option = @import("../command.zig").Option;
|
||||
const Seat = @import("../Seat.zig");
|
||||
|
||||
pub const Option = enum {
|
||||
border_width,
|
||||
border_color_focused,
|
||||
border_color_unfocused,
|
||||
outer_padding,
|
||||
};
|
||||
|
||||
/// Set option to a specified value.
|
||||
pub fn setOption(
|
||||
allocator: *std.mem.Allocator,
|
||||
@ -34,14 +41,14 @@ pub fn setOption(
|
||||
const config = &seat.focused_output.root.server.config;
|
||||
|
||||
// Parse option and value.
|
||||
const option = try Option.parse(args[1]);
|
||||
const option = std.meta.stringToEnum(Option, args[1]) orelse return Error.UnknownOption;
|
||||
|
||||
// Assign value to option.
|
||||
switch (option) {
|
||||
.BorderWidth => config.border_width = try std.fmt.parseInt(u32, args[2], 10),
|
||||
.BorderFocusedColor => try config.border_focused_color.parseString(args[2]),
|
||||
.BorderUnfocusedColor => try config.border_unfocused_color.parseString(args[2]),
|
||||
.OuterPadding => config.outer_padding = try std.fmt.parseInt(u32, args[2], 10),
|
||||
.border_width => config.border_width = try std.fmt.parseInt(u32, args[2], 10),
|
||||
.border_color_focused => try config.border_color_focused.parseString(args[2]),
|
||||
.border_color_unfocused => try config.border_color_unfocused.parseString(args[2]),
|
||||
.outer_padding => config.outer_padding = try std.fmt.parseInt(u32, args[2], 10),
|
||||
}
|
||||
|
||||
// 'Refresh' focused output to display the desired changes.
|
||||
|
Reference in New Issue
Block a user