2020-05-02 10:21:10 -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-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
|
2022-01-31 10:33:22 -08:00
|
|
|
// the Free Software Foundation, version 3.
|
2020-05-02 10:21:10 -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/>.
|
|
|
|
|
2020-05-02 07:27:00 -07:00
|
|
|
const Self = @This();
|
|
|
|
|
2020-04-07 12:48:56 -07:00
|
|
|
const std = @import("std");
|
2022-10-16 12:49:40 -07:00
|
|
|
const mem = std.mem;
|
|
|
|
const xkb = @import("xkbcommon");
|
2020-05-02 07:27:00 -07:00
|
|
|
|
2020-06-16 13:08:36 -07:00
|
|
|
const util = @import("util.zig");
|
2020-04-07 12:48:56 -07:00
|
|
|
|
2020-05-02 14:11:56 -07:00
|
|
|
const Server = @import("Server.zig");
|
2020-08-24 05:52:47 -07:00
|
|
|
const Mode = @import("Mode.zig");
|
2021-06-08 00:50:42 -07:00
|
|
|
const AttachMode = @import("view_stack.zig").AttachMode;
|
2021-08-31 12:26:17 -07:00
|
|
|
const View = @import("View.zig");
|
2020-04-07 12:48:56 -07:00
|
|
|
|
2020-09-14 15:38:50 -07:00
|
|
|
pub const FocusFollowsCursorMode = enum {
|
|
|
|
disabled,
|
|
|
|
/// Only change focus on entering a surface
|
|
|
|
normal,
|
2022-06-03 02:09:18 -07:00
|
|
|
/// Change focus on any cursor movement
|
|
|
|
always,
|
2020-09-14 15:38:50 -07:00
|
|
|
};
|
|
|
|
|
2021-05-06 18:46:26 -07:00
|
|
|
pub const WarpCursorMode = enum {
|
|
|
|
disabled,
|
|
|
|
@"on-output-change",
|
2022-08-01 17:31:50 -07:00
|
|
|
@"on-focus-change",
|
2021-05-06 18:46:26 -07:00
|
|
|
};
|
|
|
|
|
2022-02-27 15:39:10 -08:00
|
|
|
pub const HideCursorWhenTypingMode = enum {
|
|
|
|
disabled,
|
|
|
|
enabled,
|
|
|
|
};
|
|
|
|
|
2023-01-06 00:37:21 -08:00
|
|
|
/// Color of background in RGBA with premultiplied alpha (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-06-19 09:44:28 -07:00
|
|
|
|
2020-05-02 07:27:00 -07:00
|
|
|
/// Width of borders in pixels
|
2022-11-11 11:25:21 -08:00
|
|
|
border_width: u31 = 2,
|
2020-04-22 14:35:16 -07:00
|
|
|
|
2023-01-06 00:37:21 -08:00
|
|
|
/// Color of border of focused window in RGBA with premultiplied alpha
|
2020-08-21 10:32:21 -07:00
|
|
|
border_color_focused: [4]f32 = [_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 }, // Solarized base1
|
2020-06-12 09:07:39 -07:00
|
|
|
|
2023-01-06 00:37:21 -08:00
|
|
|
/// Color of border of unfocused window in RGBA with premultiplied alpha
|
2021-07-26 11:36:46 -07:00
|
|
|
border_color_unfocused: [4]f32 = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }, // Solarized base01
|
2020-06-12 09:07:39 -07:00
|
|
|
|
2023-01-06 00:37:21 -08:00
|
|
|
/// Color of border of urgent window in RGBA with premultiplied alpha
|
2021-08-12 07:16:23 -07:00
|
|
|
border_color_urgent: [4]f32 = [_]f32{ 0.86274510, 0.19607843, 0.18431373, 1.0 }, // Solarized red
|
|
|
|
|
2020-06-01 06:16:18 -07:00
|
|
|
/// Map of keymap mode name to mode id
|
2022-05-31 09:09:03 -07:00
|
|
|
/// Does not own the string keys. They are owned by the corresponding Mode struct.
|
|
|
|
mode_to_id: std.StringHashMap(u32),
|
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
|
2022-02-07 05:30:15 -08:00
|
|
|
modes: std.ArrayListUnmanaged(Mode),
|
2020-05-02 07:27:00 -07:00
|
|
|
|
2021-08-31 12:26:17 -07:00
|
|
|
/// Sets of app_ids and titles which will be started floating
|
|
|
|
float_filter_app_ids: std.StringHashMapUnmanaged(void) = .{},
|
|
|
|
float_filter_titles: std.StringHashMapUnmanaged(void) = .{},
|
2020-05-02 07:27:00 -07:00
|
|
|
|
2021-09-06 06:28:05 -07:00
|
|
|
/// Sets of app_ids and titles which are allowed to use client side decorations
|
|
|
|
csd_filter_app_ids: std.StringHashMapUnmanaged(void) = .{},
|
|
|
|
csd_filter_titles: std.StringHashMapUnmanaged(void) = .{},
|
2020-07-15 16:21:22 -07:00
|
|
|
|
2020-09-14 15:38:50 -07:00
|
|
|
/// The selected focus_follows_cursor mode
|
|
|
|
focus_follows_cursor: FocusFollowsCursorMode = .disabled,
|
|
|
|
|
2021-05-06 18:46:26 -07:00
|
|
|
/// If true, the cursor warps to the center of the focused output
|
|
|
|
warp_cursor: WarpCursorMode = .disabled,
|
|
|
|
|
2021-04-26 07:35:26 -07:00
|
|
|
/// 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{},
|
|
|
|
|
2023-01-01 15:54:53 -08:00
|
|
|
/// Bitmask restricting the tags of newly created views.
|
|
|
|
spawn_tagmask: u32 = std.math.maxInt(u32),
|
|
|
|
|
2021-06-08 00:50:42 -07:00
|
|
|
/// Determines where new views will be attached to the view stack.
|
|
|
|
attach_mode: AttachMode = .top,
|
|
|
|
|
2020-12-26 10:17:24 -08:00
|
|
|
/// Keyboard repeat rate in characters per second
|
|
|
|
repeat_rate: u31 = 25,
|
|
|
|
|
|
|
|
/// Keyboard repeat delay in milliseconds
|
|
|
|
repeat_delay: u31 = 600,
|
|
|
|
|
2022-02-27 15:39:10 -08:00
|
|
|
/// Cursor hide timeout in milliseconds
|
|
|
|
cursor_hide_timeout: u31 = 0,
|
|
|
|
|
|
|
|
/// Hide the cursor while typing
|
|
|
|
cursor_hide_when_typing: HideCursorWhenTypingMode = .disabled,
|
|
|
|
|
2022-12-30 14:11:04 -08:00
|
|
|
xkb_context: *xkb.Context,
|
|
|
|
/// The xkb keymap used for all keyboards
|
|
|
|
keymap: *xkb.Keymap,
|
2022-10-16 12:49:40 -07:00
|
|
|
|
2020-08-21 10:32:21 -07:00
|
|
|
pub fn init() !Self {
|
2022-12-30 14:11:04 -08:00
|
|
|
const xkb_context = xkb.Context.new(.no_flags) orelse return error.XkbContextFailed;
|
|
|
|
defer xkb_context.unref();
|
|
|
|
|
|
|
|
// Passing null here indicates that defaults from libxkbcommon and
|
|
|
|
// its XKB_DEFAULT_LAYOUT, XKB_DEFAULT_OPTIONS, etc. should be used.
|
|
|
|
const keymap = xkb.Keymap.newFromNames(xkb_context, null, .no_flags) orelse return error.XkbKeymapFailed;
|
|
|
|
defer keymap.unref();
|
|
|
|
|
2020-08-24 05:52:47 -07:00
|
|
|
var self = Self{
|
2022-05-31 09:09:03 -07:00
|
|
|
.mode_to_id = std.StringHashMap(u32).init(util.gpa),
|
2022-02-07 05:30:15 -08:00
|
|
|
.modes = try std.ArrayListUnmanaged(Mode).initCapacity(util.gpa, 2),
|
2022-12-30 14:11:04 -08:00
|
|
|
.xkb_context = xkb_context.ref(),
|
|
|
|
.keymap = keymap.ref(),
|
2020-08-21 10:32:21 -07:00
|
|
|
};
|
2020-08-24 05:52:47 -07:00
|
|
|
errdefer self.deinit();
|
2020-10-19 03:39:52 -07:00
|
|
|
|
|
|
|
// Start with two empty modes, "normal" and "locked"
|
|
|
|
{
|
|
|
|
// Normal mode, id 0
|
2022-05-31 09:09:03 -07:00
|
|
|
const owned_slice = try util.gpa.dupeZ(u8, "normal");
|
2020-10-19 03:39:52 -07:00
|
|
|
try self.mode_to_id.putNoClobber(owned_slice, 0);
|
2022-05-31 09:09:03 -07:00
|
|
|
self.modes.appendAssumeCapacity(.{ .name = owned_slice });
|
2020-10-19 03:39:52 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// Locked mode, id 1
|
2022-05-31 09:09:03 -07:00
|
|
|
const owned_slice = try util.gpa.dupeZ(u8, "locked");
|
2020-10-19 03:39:52 -07:00
|
|
|
try self.mode_to_id.putNoClobber(owned_slice, 1);
|
2022-05-31 09:09:03 -07:00
|
|
|
self.modes.appendAssumeCapacity(.{ .name = owned_slice });
|
2020-10-19 03:39:52 -07:00
|
|
|
}
|
2020-08-24 05:52:47 -07:00
|
|
|
|
|
|
|
return self;
|
2020-05-02 07:27:00 -07:00
|
|
|
}
|
2020-05-16 15:03:26 -07:00
|
|
|
|
2020-08-31 06:23:01 -07:00
|
|
|
pub fn deinit(self: *Self) void {
|
2022-05-31 09:09:03 -07:00
|
|
|
self.mode_to_id.deinit();
|
2022-02-07 05:30:15 -08:00
|
|
|
for (self.modes.items) |*mode| mode.deinit();
|
|
|
|
self.modes.deinit(util.gpa);
|
2020-06-26 03:58:11 -07:00
|
|
|
|
2021-07-12 10:37:56 -07:00
|
|
|
{
|
2021-08-31 12:26:17 -07:00
|
|
|
var it = self.float_filter_app_ids.keyIterator();
|
2021-07-12 10:37:56 -07:00
|
|
|
while (it.next()) |key| util.gpa.free(key.*);
|
2021-08-31 12:26:17 -07:00
|
|
|
self.float_filter_app_ids.deinit(util.gpa);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
var it = self.float_filter_titles.keyIterator();
|
|
|
|
while (it.next()) |key| util.gpa.free(key.*);
|
|
|
|
self.float_filter_titles.deinit(util.gpa);
|
2021-07-12 10:37:56 -07:00
|
|
|
}
|
2020-12-10 10:41:57 -08:00
|
|
|
|
2021-07-12 10:37:56 -07:00
|
|
|
{
|
2021-09-06 06:28:05 -07:00
|
|
|
var it = self.csd_filter_app_ids.keyIterator();
|
2021-07-12 10:37:56 -07:00
|
|
|
while (it.next()) |key| util.gpa.free(key.*);
|
2021-09-06 06:28:05 -07:00
|
|
|
self.csd_filter_app_ids.deinit(util.gpa);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
var it = self.csd_filter_titles.keyIterator();
|
|
|
|
while (it.next()) |key| util.gpa.free(key.*);
|
|
|
|
self.csd_filter_titles.deinit(util.gpa);
|
2021-07-12 10:37:56 -07:00
|
|
|
}
|
2021-04-26 07:35:26 -07:00
|
|
|
|
|
|
|
util.gpa.free(self.default_layout_namespace);
|
2022-12-30 14:11:04 -08:00
|
|
|
|
|
|
|
self.keymap.unref();
|
|
|
|
self.xkb_context.unref();
|
2020-05-19 13:59:50 -07:00
|
|
|
}
|
2021-08-31 12:26:17 -07:00
|
|
|
|
|
|
|
pub fn shouldFloat(self: Self, view: *View) bool {
|
|
|
|
if (view.getAppId()) |app_id| {
|
|
|
|
if (self.float_filter_app_ids.contains(std.mem.span(app_id))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view.getTitle()) |title| {
|
|
|
|
if (self.float_filter_titles.contains(std.mem.span(title))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-06 06:28:05 -07:00
|
|
|
|
|
|
|
pub fn csdAllowed(self: Self, view: *View) bool {
|
|
|
|
if (view.getAppId()) |app_id| {
|
|
|
|
if (self.csd_filter_app_ids.contains(std.mem.span(app_id))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view.getTitle()) |title| {
|
|
|
|
if (self.csd_filter_titles.contains(std.mem.span(title))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|