79d7775a3d
I don't need anyone's permission to make this change since GPL-3.0-or-later is one-way compatible with GPL-3.0-only.
129 lines
3.9 KiB
Zig
129 lines
3.9 KiB
Zig
// This file is part of river, a dynamic tiling wayland compositor.
|
|
//
|
|
// Copyright 2020 The River Developers
|
|
//
|
|
// 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, version 3.
|
|
//
|
|
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
const std = @import("std");
|
|
const fmt = std.fmt;
|
|
|
|
const server = &@import("../main.zig").server;
|
|
|
|
const Error = @import("../command.zig").Error;
|
|
const Seat = @import("../Seat.zig");
|
|
const Config = @import("../Config.zig");
|
|
|
|
pub fn borderWidth(
|
|
_: std.mem.Allocator,
|
|
_: *Seat,
|
|
args: []const [:0]const u8,
|
|
_: *?[]const u8,
|
|
) Error!void {
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
server.config.border_width = try fmt.parseInt(u32, args[1], 10);
|
|
server.root.arrangeAll();
|
|
server.root.startTransaction();
|
|
}
|
|
|
|
pub fn backgroundColor(
|
|
_: std.mem.Allocator,
|
|
_: *Seat,
|
|
args: []const [:0]const u8,
|
|
_: *?[]const u8,
|
|
) Error!void {
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
server.config.background_color = try parseRgba(args[1]);
|
|
|
|
var it = server.root.outputs.first;
|
|
while (it) |node| : (it = node.next) node.data.damage.addWhole();
|
|
}
|
|
|
|
pub fn borderColorFocused(
|
|
_: std.mem.Allocator,
|
|
_: *Seat,
|
|
args: []const [:0]const u8,
|
|
_: *?[]const u8,
|
|
) Error!void {
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
server.config.border_color_focused = try parseRgba(args[1]);
|
|
|
|
var it = server.root.outputs.first;
|
|
while (it) |node| : (it = node.next) node.data.damage.addWhole();
|
|
}
|
|
|
|
pub fn borderColorUnfocused(
|
|
_: std.mem.Allocator,
|
|
_: *Seat,
|
|
args: []const [:0]const u8,
|
|
_: *?[]const u8,
|
|
) Error!void {
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
server.config.border_color_unfocused = try parseRgba(args[1]);
|
|
|
|
var it = server.root.outputs.first;
|
|
while (it) |node| : (it = node.next) node.data.damage.addWhole();
|
|
}
|
|
|
|
pub fn borderColorUrgent(
|
|
_: std.mem.Allocator,
|
|
_: *Seat,
|
|
args: []const [:0]const u8,
|
|
_: *?[]const u8,
|
|
) Error!void {
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
server.config.border_color_urgent = try parseRgba(args[1]);
|
|
|
|
var it = server.root.outputs.first;
|
|
while (it) |node| : (it = node.next) node.data.damage.addWhole();
|
|
}
|
|
|
|
pub fn setCursorWarp(
|
|
_: std.mem.Allocator,
|
|
_: *Seat,
|
|
args: []const [:0]const u8,
|
|
_: *?[]const u8,
|
|
) Error!void {
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
server.config.warp_cursor = std.meta.stringToEnum(Config.WarpCursorMode, args[1]) orelse
|
|
return Error.UnknownOption;
|
|
}
|
|
|
|
/// Parse a color in the format 0xRRGGBB or 0xRRGGBBAA
|
|
fn parseRgba(string: []const u8) ![4]f32 {
|
|
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 fmt.parseInt(u8, string[2..4], 16);
|
|
const g = try fmt.parseInt(u8, string[4..6], 16);
|
|
const b = try fmt.parseInt(u8, string[6..8], 16);
|
|
const a = if (string.len == 10) try fmt.parseInt(u8, string[8..10], 16) else 255;
|
|
|
|
return [4]f32{
|
|
@intToFloat(f32, r) / 255.0,
|
|
@intToFloat(f32, g) / 255.0,
|
|
@intToFloat(f32, b) / 255.0,
|
|
@intToFloat(f32, a) / 255.0,
|
|
};
|
|
}
|