2020-07-15 03:42:20 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2020-11-11 11:30:21 -08:00
|
|
|
// Copyright 2020 The River Developers
|
2020-07-15 03:42:20 -07:00
|
|
|
//
|
|
|
|
// 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
|
2022-01-31 10:33:22 -08:00
|
|
|
// the Free Software Foundation, version 3.
|
2020-07-15 03:42:20 -07:00
|
|
|
//
|
|
|
|
// 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");
|
2021-07-26 11:36:46 -07:00
|
|
|
const fmt = std.fmt;
|
2022-02-07 13:07:27 -08:00
|
|
|
const mem = std.mem;
|
2020-07-15 03:42:20 -07:00
|
|
|
|
2021-05-13 05:53:08 -07:00
|
|
|
const server = &@import("../main.zig").server;
|
|
|
|
|
2020-07-15 03:42:20 -07:00
|
|
|
const Error = @import("../command.zig").Error;
|
|
|
|
const Seat = @import("../Seat.zig");
|
2021-05-06 18:46:26 -07:00
|
|
|
const Config = @import("../Config.zig");
|
2020-07-15 03:42:20 -07:00
|
|
|
|
|
|
|
pub fn borderWidth(
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *Seat,
|
2021-07-14 15:13:16 -07:00
|
|
|
args: []const [:0]const u8,
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *?[]const u8,
|
2020-07-15 03:42:20 -07:00
|
|
|
) Error!void {
|
|
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
|
2022-11-11 11:25:21 -08:00
|
|
|
server.config.border_width = try fmt.parseInt(u31, args[1], 10);
|
2023-02-24 10:28:37 -08:00
|
|
|
server.root.applyPending();
|
2020-07-15 03:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn backgroundColor(
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *Seat,
|
2021-07-14 15:13:16 -07:00
|
|
|
args: []const [:0]const u8,
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *?[]const u8,
|
2020-07-15 03:42:20 -07:00
|
|
|
) Error!void {
|
|
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
|
2021-05-13 05:53:08 -07:00
|
|
|
server.config.background_color = try parseRgba(args[1]);
|
2023-02-01 12:47:52 -08:00
|
|
|
var it = server.root.all_outputs.first;
|
|
|
|
while (it) |node| : (it = node.next) {
|
|
|
|
const output = node.data;
|
|
|
|
output.layers.background_color_rect.setColor(&server.config.background_color);
|
|
|
|
}
|
2020-07-15 03:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn borderColorFocused(
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *Seat,
|
2021-07-14 15:13:16 -07:00
|
|
|
args: []const [:0]const u8,
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *?[]const u8,
|
2020-07-15 03:42:20 -07:00
|
|
|
) Error!void {
|
|
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
|
2021-05-13 05:53:08 -07:00
|
|
|
server.config.border_color_focused = try parseRgba(args[1]);
|
2023-02-24 10:28:37 -08:00
|
|
|
server.root.applyPending();
|
2020-07-15 03:42:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn borderColorUnfocused(
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *Seat,
|
2021-07-14 15:13:16 -07:00
|
|
|
args: []const [:0]const u8,
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *?[]const u8,
|
2020-07-15 03:42:20 -07:00
|
|
|
) Error!void {
|
|
|
|
if (args.len < 2) return Error.NotEnoughArguments;
|
|
|
|
if (args.len > 2) return Error.TooManyArguments;
|
|
|
|
|
2021-05-13 05:53:08 -07:00
|
|
|
server.config.border_color_unfocused = try parseRgba(args[1]);
|
2023-02-24 10:28:37 -08:00
|
|
|
server.root.applyPending();
|
2020-07-15 03:42:20 -07:00
|
|
|
}
|
|
|
|
|
2021-08-12 07:16:23 -07:00
|
|
|
pub fn borderColorUrgent(
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *Seat,
|
2021-08-12 07:16:23 -07:00
|
|
|
args: []const [:0]const u8,
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *?[]const u8,
|
2021-08-12 07:16:23 -07:00
|
|
|
) 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]);
|
2023-02-24 10:28:37 -08:00
|
|
|
server.root.applyPending();
|
2021-08-12 07:16:23 -07:00
|
|
|
}
|
|
|
|
|
2021-05-06 18:46:26 -07:00
|
|
|
pub fn setCursorWarp(
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *Seat,
|
2021-07-14 15:13:16 -07:00
|
|
|
args: []const [:0]const u8,
|
2021-10-11 03:44:46 -07:00
|
|
|
_: *?[]const u8,
|
2021-05-06 18:46:26 -07:00
|
|
|
) 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;
|
|
|
|
}
|
|
|
|
|
2023-01-06 00:37:21 -08:00
|
|
|
/// Parse a color in the format 0xRRGGBB or 0xRRGGBBAA. Returned color has premultiplied alpha.
|
2020-07-15 03:42:20 -07:00
|
|
|
fn parseRgba(string: []const u8) ![4]f32 {
|
2021-07-26 11:36:46 -07:00
|
|
|
if (string.len != 8 and string.len != 10) return error.InvalidRgba;
|
|
|
|
if (string[0] != '0' or string[1] != 'x') return error.InvalidRgba;
|
2020-07-15 03:42:20 -07:00
|
|
|
|
2021-07-26 11:36:46 -07:00
|
|
|
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;
|
2020-07-15 03:42:20 -07:00
|
|
|
|
2023-01-06 00:37:21 -08:00
|
|
|
const alpha = @intToFloat(f32, a) / 255.0;
|
|
|
|
|
2020-07-15 03:42:20 -07:00
|
|
|
return [4]f32{
|
2023-01-06 00:37:21 -08:00
|
|
|
@intToFloat(f32, r) / 255.0 * alpha,
|
|
|
|
@intToFloat(f32, g) / 255.0 * alpha,
|
|
|
|
@intToFloat(f32, b) / 255.0 * alpha,
|
|
|
|
alpha,
|
2020-07-15 03:42:20 -07:00
|
|
|
};
|
|
|
|
}
|