river/river/Config.zig

134 lines
4.3 KiB
Zig
Raw Normal View History

2020-05-02 10:21:10 -07:00
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2020 The River Developers
2020-05-02 10:21:10 -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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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/>.
2020-05-02 07:27:00 -07:00
const Self = @This();
const std = @import("std");
2020-05-02 07:27:00 -07:00
const util = @import("util.zig");
const Server = @import("Server.zig");
const Mode = @import("Mode.zig");
2021-06-08 00:50:42 -07:00
const AttachMode = @import("view_stack.zig").AttachMode;
2020-09-14 15:38:50 -07:00
pub const FocusFollowsCursorMode = enum {
disabled,
/// Only change focus on entering a surface
normal,
/// On cursor movement the focus will be updated to the surface below the cursor
strict,
};
/// Color of background in RGBA (alpha should only affect nested sessions)
2020-08-21 10:32:21 -07:00
background_color: [4]f32 = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }, // Solarized base03
2020-05-02 07:27:00 -07:00
/// Width of borders in pixels
2020-08-21 10:32:21 -07:00
border_width: u32 = 2,
/// Color of border of focused window in RGBA
2020-08-21 10:32:21 -07:00
border_color_focused: [4]f32 = [_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 }, // Solarized base1
/// Color of border of unfocused window in RGBA
2020-08-21 10:32:21 -07:00
border_color_unfocused: [4]f32 = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }, // Solarized base0
2020-06-01 06:16:18 -07:00
/// Map of keymap mode name to mode id
2020-05-31 15:20:49 -07:00
mode_to_id: std.StringHashMap(usize),
2020-05-31 14:56:25 -07:00
2020-06-01 06:16:18 -07:00
/// All user-defined keymap modes, indexed by mode id
modes: std.ArrayList(Mode),
2020-05-02 07:27:00 -07:00
/// List of app_ids which will be started floating
2020-07-16 09:14:00 -07:00
float_filter: std.ArrayList([]const u8),
2020-05-02 07:27:00 -07:00
2020-07-15 16:21:22 -07:00
/// List of app_ids which are allowed to use client side decorations
csd_filter: std.ArrayList([]const u8),
2020-09-14 15:38:50 -07:00
/// The selected focus_follows_cursor mode
focus_follows_cursor: FocusFollowsCursorMode = .disabled,
/// The default layout namespace for outputs which have never had a per-output
/// value set. Call Output.handleLayoutNamespaceChange() on setting this if
/// Output.layout_namespace is null.
default_layout_namespace: []const u8 = &[0]u8{},
2021-06-08 00:50:42 -07:00
/// Determines where new views will be attached to the view stack.
attach_mode: AttachMode = .top,
opacity: struct {
/// The opacity of focused views
focused: f32 = 1.0,
/// The opacity of unfocused views
unfocused: f32 = 1.0,
/// The initial opacity of new views
initial: f32 = 1.0,
/// View opacity transition step
delta: f32 = 1.0,
/// Time between view opacity transition steps in milliseconds
delta_t: u31 = 20,
} = .{},
/// Keyboard repeat rate in characters per second
repeat_rate: u31 = 25,
/// Keyboard repeat delay in milliseconds
repeat_delay: u31 = 600,
2020-08-21 10:32:21 -07:00
pub fn init() !Self {
var self = Self{
.mode_to_id = std.StringHashMap(usize).init(util.gpa),
.modes = std.ArrayList(Mode).init(util.gpa),
2020-08-21 10:32:21 -07:00
.float_filter = std.ArrayList([]const u8).init(util.gpa),
.csd_filter = std.ArrayList([]const u8).init(util.gpa),
};
errdefer self.deinit();
// Start with two empty modes, "normal" and "locked"
try self.modes.ensureCapacity(2);
{
// Normal mode, id 0
const owned_slice = try std.mem.dupe(util.gpa, u8, "normal");
try self.mode_to_id.putNoClobber(owned_slice, 0);
self.modes.appendAssumeCapacity(Mode.init());
}
{
// Locked mode, id 1
const owned_slice = try std.mem.dupe(util.gpa, u8, "locked");
try self.mode_to_id.putNoClobber(owned_slice, 1);
self.modes.appendAssumeCapacity(Mode.init());
}
return self;
2020-05-02 07:27:00 -07:00
}
2020-05-16 15:03:26 -07:00
pub fn deinit(self: *Self) void {
2021-05-23 04:35:37 -07:00
var it = self.mode_to_id.keyIterator();
while (it.next()) |key| util.gpa.free(key.*);
2020-05-31 14:56:25 -07:00
self.mode_to_id.deinit();
2020-06-26 03:58:11 -07:00
for (self.modes.items) |mode| mode.deinit();
self.modes.deinit();
2020-06-26 03:58:11 -07:00
2020-12-10 10:41:57 -08:00
for (self.float_filter.items) |s| util.gpa.free(s);
2020-06-02 04:45:56 -07:00
self.float_filter.deinit();
2020-12-10 10:41:57 -08:00
for (self.csd_filter.items) |s| util.gpa.free(s);
2020-07-15 16:21:22 -07:00
self.csd_filter.deinit();
util.gpa.free(self.default_layout_namespace);
}