code: simplify option handling
This commit is contained in:
parent
efe2c2ce4b
commit
40c62577e1
@ -170,9 +170,9 @@ List of valid options:
|
||||
.IP \(bu
|
||||
border_width (non-negative integer)
|
||||
.IP \(bu
|
||||
border_focused_color (RGB hex code)
|
||||
border_color_focused (RGB hex code)
|
||||
.IP \(bu
|
||||
border_unfocused_color (RGB hex code)
|
||||
border_color_unfocused (RGB hex code)
|
||||
.IP \(bu
|
||||
outer_padding (non-negative integer)
|
||||
|
||||
|
@ -30,10 +30,10 @@ const Mapping = @import("Mapping.zig");
|
||||
border_width: u32,
|
||||
|
||||
/// Color of border of focused window in RGB
|
||||
border_focused_color: Rgb,
|
||||
border_color_focused: Rgb,
|
||||
|
||||
/// Color of border of unfocused window in RGB
|
||||
border_unfocused_color: Rgb,
|
||||
border_color_unfocused: Rgb,
|
||||
|
||||
/// Amount of view padding in pixels
|
||||
view_padding: u32,
|
||||
@ -52,8 +52,8 @@ float_filter: std.ArrayList([*:0]const u8),
|
||||
|
||||
pub fn init(self: *Self, allocator: *std.mem.Allocator) !void {
|
||||
self.border_width = 2;
|
||||
try self.border_focused_color.parseString("#93A1A1"); // Solarized base1
|
||||
try self.border_unfocused_color.parseString("#586E75"); // Solarized base0
|
||||
try self.border_color_focused.parseString("#93A1A1"); // Solarized base1
|
||||
try self.border_color_unfocused.parseString("#586E75"); // Solarized base0
|
||||
self.view_padding = 8;
|
||||
self.outer_padding = 8;
|
||||
|
||||
|
@ -55,26 +55,6 @@ pub const Direction = enum {
|
||||
}
|
||||
};
|
||||
|
||||
pub const Option = enum {
|
||||
BorderWidth,
|
||||
BorderFocusedColor,
|
||||
BorderUnfocusedColor,
|
||||
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, "border_focused_color"))
|
||||
Option.BorderFocusedColor
|
||||
else if (std.mem.eql(u8, str, "border_unfocused_color"))
|
||||
Option.BorderUnfocusedColor
|
||||
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 {
|
||||
|
@ -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.
|
||||
|
@ -240,9 +240,9 @@ fn renderTexture(
|
||||
fn renderBorders(output: Output, view: *View, now: *c.timespec) void {
|
||||
var border: Box = undefined;
|
||||
const color = if (view.focused)
|
||||
output.root.server.config.border_focused_color.getDecimalRgbaArray()
|
||||
output.root.server.config.border_color_focused.getDecimalRgbaArray()
|
||||
else
|
||||
output.root.server.config.border_unfocused_color.getDecimalRgbaArray();
|
||||
output.root.server.config.border_color_unfocused.getDecimalRgbaArray();
|
||||
const border_width = output.root.server.config.border_width;
|
||||
|
||||
// left and right, covering the corners as well
|
||||
|
Loading…
Reference in New Issue
Block a user