Add borders to windows; add navigation keybinds
Right now, colors are hardcoded in the Config in main.zig. This commit also adds a couple of new keybinds for navigating between windows. All keybinds are hardcoded as well right now.
This commit is contained in:
parent
42494ae5d1
commit
578e2f449e
7 changed files with 235 additions and 23 deletions
67
src/utils.zig
Normal file
67
src/utils.zig
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
pub const RiverColor = struct {
|
||||
red: u32,
|
||||
green: u32,
|
||||
blue: u32,
|
||||
alpha: u32,
|
||||
};
|
||||
|
||||
/// Parse a color in the format 0xRRGGBB or 0xRRGGBBAA and convert it to
|
||||
/// 32-bit color values (used by Window.set_borders in rwm).
|
||||
pub fn parseRgba(s: []const u8) !RiverColor {
|
||||
if (s.len != 8 and s.len != 10) return error.InvalidRgba;
|
||||
if (s[0] != '0' or s[1] != 'x') return error.InvalidRgba;
|
||||
|
||||
// If the color is 0xRRGGBB, add FF for the alpha channel
|
||||
var color = try fmt.parseUnsigned(u32, s[2..], 16);
|
||||
if (s.len == 8) {
|
||||
color <<= 8;
|
||||
color |= 0xff;
|
||||
}
|
||||
|
||||
const bytes: [4]u8 = @as([4]u8, @bitCast(color));
|
||||
return parseRgbaHelper(bytes);
|
||||
}
|
||||
|
||||
/// Parse a color in the format 0xRRGGBB or 0xRRGGBBAA and convert it to
|
||||
/// 32-bit color values (used by Window.set_borders in rwm) at comptime.
|
||||
pub fn parseRgbaComptime(comptime s: []const u8) RiverColor {
|
||||
if (s.len != 8 and s.len != 10) @compileError("Invalid RGBA");
|
||||
if (s[0] != '0' or s[1] != 'x') @compileError("Invalid RGBA");
|
||||
|
||||
// If the color is 0xRRGGBB, add FF for the alpha channel
|
||||
comptime var color = try fmt.parseUnsigned(u32, s[2..], 16);
|
||||
if (s.len == 8) {
|
||||
color <<= 8;
|
||||
color |= 0xff;
|
||||
}
|
||||
|
||||
const bytes = @as([4]u8, @bitCast(color));
|
||||
return parseRgbaHelper(bytes);
|
||||
}
|
||||
|
||||
fn parseRgbaHelper(bytes: [4]u8) RiverColor {
|
||||
const r: u32 = bytes[3];
|
||||
const g: u32 = bytes[2];
|
||||
const b: u32 = bytes[1];
|
||||
const a: u32 = bytes[0];
|
||||
|
||||
// To convert from an 8-bit color to 32-bit color, we need to do
|
||||
// color * 2^32 / 2^8
|
||||
// which is equivalent to
|
||||
// color * 2^24
|
||||
// or, in other words,
|
||||
// color << 24
|
||||
return .{
|
||||
.red = r << 24,
|
||||
.green = g << 24,
|
||||
.blue = b << 24,
|
||||
.alpha = a << 24,
|
||||
};
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const fmt = std.fmt;
|
||||
Loading…
Add table
Add a link
Reference in a new issue