config: change color format to 0xRRGGBBAA

The current format of #RRGGBBAA is problematic as # starts a comment
in POSIX compliant shells, requiring escaping/quoting and increasing
complexity.

This is a breaking change.
This commit is contained in:
Isaac Freund 2021-07-26 20:36:46 +02:00
parent ae871c2fee
commit 8a1e96cddc
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
5 changed files with 19 additions and 12 deletions

View File

@ -230,13 +230,13 @@ A complete list may be found in _/usr/include/linux/input-event-codes.h_
*attach-mode* *top*|*bottom* *attach-mode* *top*|*bottom*
Configure where new views should attach to the view stack. Configure where new views should attach to the view stack.
*background-color* _#RRGGBB_|_#RRGGBBAA_ *background-color* _0xRRGGBB_|_0xRRGGBBAA_
Set the background color. Set the background color.
*border-color-focused* _#RRGGBB_|_#RRGGBBAA_ *border-color-focused* _0xRRGGBB_|_0xRRGGBBAA_
Set the border color of focused views. Set the border color of focused views.
*border-color-unfocused* _#RRGGBB_|_#RRGGBBAA_ *border-color-unfocused* _0xRRGGBB_|_0xRRGGBBAA_
Set the border color of unfocused views. Set the border color of unfocused views.
*border-width* _pixels_ *border-width* _pixels_

View File

@ -140,6 +140,11 @@ do
riverctl map $mode None XF86MonBrightnessDown spawn 'light -U 5' riverctl map $mode None XF86MonBrightnessDown spawn 'light -U 5'
done done
# Set background and border color
riverctl background-color 0x002b36
riverctl border-color-focused 0x93a1a1
riverctl border-color-unfocused 0x586e75
# Set repeat rate # Set repeat rate
riverctl set-repeat 50 300 riverctl set-repeat 50 300

View File

@ -48,7 +48,7 @@ border_width: u32 = 2,
border_color_focused: [4]f32 = [_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 }, // Solarized base1 border_color_focused: [4]f32 = [_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 }, // Solarized base1
/// Color of border of unfocused window in RGBA /// Color of border of unfocused window in RGBA
border_color_unfocused: [4]f32 = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }, // Solarized base0 border_color_unfocused: [4]f32 = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }, // Solarized base01
/// Map of keymap mode name to mode id /// Map of keymap mode name to mode id
mode_to_id: std.StringHashMap(usize), mode_to_id: std.StringHashMap(usize),

View File

@ -144,7 +144,7 @@ pub fn errToMsg(err: Error) [:0]const u8 {
Error.InvalidDirection => "invalid direction. Must be 'next' or 'previous'", Error.InvalidDirection => "invalid direction. Must be 'next' or 'previous'",
Error.InvalidPhysicalDirection => "invalid direction. Must be 'up', 'down', 'left' or 'right'", Error.InvalidPhysicalDirection => "invalid direction. Must be 'up', 'down', 'left' or 'right'",
Error.InvalidOrientation => "invalid orientation. Must be 'horizontal', or 'vertical'", Error.InvalidOrientation => "invalid orientation. Must be 'horizontal', or 'vertical'",
Error.InvalidRgba => "invalid color format, must be #RRGGBB or #RRGGBBAA", Error.InvalidRgba => "invalid color format, must be hexadecimal 0xRRGGBB or 0xRRGGBBAA",
Error.InvalidValue => "invalid value", Error.InvalidValue => "invalid value",
Error.OutOfMemory => "out of memory", Error.OutOfMemory => "out of memory",
Error.Other => unreachable, Error.Other => unreachable,

View File

@ -16,6 +16,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std"); const std = @import("std");
const fmt = std.fmt;
const server = &@import("../main.zig").server; const server = &@import("../main.zig").server;
@ -32,7 +33,7 @@ pub fn borderWidth(
if (args.len < 2) return Error.NotEnoughArguments; if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments; if (args.len > 2) return Error.TooManyArguments;
server.config.border_width = try std.fmt.parseInt(u32, args[1], 10); server.config.border_width = try fmt.parseInt(u32, args[1], 10);
server.root.arrangeAll(); server.root.arrangeAll();
server.root.startTransaction(); server.root.startTransaction();
} }
@ -94,14 +95,15 @@ pub fn setCursorWarp(
return Error.UnknownOption; return Error.UnknownOption;
} }
/// Parse a color in the format #RRGGBB or #RRGGBBAA /// Parse a color in the format 0xRRGGBB or 0xRRGGBBAA
fn parseRgba(string: []const u8) ![4]f32 { fn parseRgba(string: []const u8) ![4]f32 {
if ((string.len != 7 and string.len != 9) or string[0] != '#') return error.InvalidRgba; if (string.len != 8 and string.len != 10) return error.InvalidRgba;
if (string[0] != '0' or string[1] != 'x') return error.InvalidRgba;
const r = try std.fmt.parseInt(u8, string[1..3], 16); const r = try fmt.parseInt(u8, string[2..4], 16);
const g = try std.fmt.parseInt(u8, string[3..5], 16); const g = try fmt.parseInt(u8, string[4..6], 16);
const b = try std.fmt.parseInt(u8, string[5..7], 16); const b = try fmt.parseInt(u8, string[6..8], 16);
const a = if (string.len == 9) try std.fmt.parseInt(u8, string[7..9], 16) else 255; const a = if (string.len == 10) try fmt.parseInt(u8, string[8..10], 16) else 255;
return [4]f32{ return [4]f32{
@intToFloat(f32, r) / 255.0, @intToFloat(f32, r) / 255.0,