KeycodeSet: move to Keyboard.zig
The file was too short and did't make much sense on its own; actually, it's quite clearly part of the Keyboard logic.
This commit is contained in:
parent
2bdbe414e8
commit
a1ce53a998
@ -26,12 +26,64 @@ const globber = @import("globber");
|
||||
const server = &@import("main.zig").server;
|
||||
const util = @import("util.zig");
|
||||
|
||||
const KeycodeSet = @import("KeycodeSet.zig");
|
||||
const Seat = @import("Seat.zig");
|
||||
const InputDevice = @import("InputDevice.zig");
|
||||
|
||||
const log = std.log.scoped(.keyboard);
|
||||
|
||||
const EatReason = enum {
|
||||
/// Not eaten
|
||||
none,
|
||||
mapping,
|
||||
im_grab,
|
||||
};
|
||||
|
||||
pub const KeycodeSet = struct {
|
||||
items: [32]u32 = undefined,
|
||||
reason: [32]EatReason = undefined,
|
||||
len: usize = 0,
|
||||
|
||||
pub fn add(set: *KeycodeSet, new: u32, reason: EatReason) EatReason {
|
||||
for (set.items[0..set.len]) |item| assert(new != item);
|
||||
|
||||
comptime assert(@typeInfo(std.meta.fieldInfo(KeycodeSet, .items).type).Array.len ==
|
||||
@typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).Array.len);
|
||||
|
||||
if (set.len == set.items.len) {
|
||||
log.err("KeycodeSet limit reached, code {d} omitted", .{new});
|
||||
// We can't eat the release, don't eat the press
|
||||
return .none;
|
||||
}
|
||||
|
||||
set.items[set.len] = new;
|
||||
set.reason[set.len] = reason;
|
||||
set.len += 1;
|
||||
|
||||
return reason;
|
||||
}
|
||||
|
||||
pub fn remove(set: *KeycodeSet, old: u32) EatReason {
|
||||
for (set.items[0..set.len], set.reason[0..set.len], 0..) |item, reason, idx| {
|
||||
if (old == item) {
|
||||
set.len -= 1;
|
||||
if (set.len > 0) {
|
||||
set.items[idx] = set.items[set.len];
|
||||
set.reason[idx] = set.reason[set.len];
|
||||
}
|
||||
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
|
||||
return .none;
|
||||
}
|
||||
|
||||
/// Removes other's contents from set (if present), regardless of reason
|
||||
pub fn subtract(set: *KeycodeSet, other: KeycodeSet) void {
|
||||
for (other.items[0..other.len]) |item| _ = set.remove(item);
|
||||
}
|
||||
};
|
||||
|
||||
device: InputDevice,
|
||||
|
||||
/// Pressed keys for which a mapping was triggered on press
|
||||
|
@ -1,74 +0,0 @@
|
||||
// This file is part of river, a dynamic tiling wayland compositor.
|
||||
//
|
||||
// Copyright 2022 - 2024 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 Self = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const log = std.log.scoped(.keyboard);
|
||||
|
||||
const wlr = @import("wlroots");
|
||||
|
||||
const EatReason = enum {
|
||||
/// Not eaten
|
||||
none,
|
||||
mapping,
|
||||
im_grab,
|
||||
};
|
||||
|
||||
items: [32]u32 = undefined,
|
||||
reason: [32]EatReason = undefined,
|
||||
len: usize = 0,
|
||||
|
||||
pub fn add(self: *Self, new: u32, reason: EatReason) EatReason {
|
||||
for (self.items[0..self.len]) |item| assert(new != item);
|
||||
|
||||
comptime assert(@typeInfo(std.meta.fieldInfo(Self, .items).type).Array.len ==
|
||||
@typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).Array.len);
|
||||
|
||||
if (self.len == self.items.len) {
|
||||
log.err("KeycodeSet limit reached, code {d} omitted", .{new});
|
||||
// We can't eat the release, don't eat the press
|
||||
return .none;
|
||||
}
|
||||
|
||||
self.items[self.len] = new;
|
||||
self.reason[self.len] = reason;
|
||||
self.len += 1;
|
||||
|
||||
return reason;
|
||||
}
|
||||
|
||||
pub fn remove(self: *Self, old: u32) EatReason {
|
||||
for (self.items[0..self.len], self.reason[0..self.len], 0..) |item, reason, idx| {
|
||||
if (old == item) {
|
||||
self.len -= 1;
|
||||
if (self.len > 0) {
|
||||
self.items[idx] = self.items[self.len];
|
||||
self.reason[idx] = self.reason[self.len];
|
||||
}
|
||||
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
|
||||
return .none;
|
||||
}
|
||||
|
||||
/// Removes other's contents from self (if present), regardless of reason
|
||||
pub fn subtract(self: *Self, other: Self) void {
|
||||
for (other.items[0..other.len]) |item| _ = self.remove(item);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// This file is part of river, a dynamic tiling wayland compositor.
|
||||
//
|
||||
// Copyright 2020 The River Developers
|
||||
// Copyright 2020 - 2024 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
|
||||
@ -34,7 +34,6 @@ const InputManager = @import("InputManager.zig");
|
||||
const InputRelay = @import("InputRelay.zig");
|
||||
const Keyboard = @import("Keyboard.zig");
|
||||
const KeyboardGroup = @import("KeyboardGroup.zig");
|
||||
const KeycodeSet = @import("KeycodeSet.zig");
|
||||
const LayerSurface = @import("LayerSurface.zig");
|
||||
const LockSurface = @import("LockSurface.zig");
|
||||
const Mapping = @import("Mapping.zig");
|
||||
@ -305,7 +304,7 @@ pub fn keyboardEnterOrLeave(self: *Self, target_surface: ?*wlr.Surface) void {
|
||||
|
||||
fn keyboardNotifyEnter(self: *Self, wlr_surface: *wlr.Surface) void {
|
||||
if (self.wlr_seat.getKeyboard()) |wlr_keyboard| {
|
||||
var keycodes = KeycodeSet{
|
||||
var keycodes = Keyboard.KeycodeSet{
|
||||
.items = wlr_keyboard.keycodes,
|
||||
.reason = .{.none} ** 32,
|
||||
.len = wlr_keyboard.num_keycodes,
|
||||
|
Loading…
Reference in New Issue
Block a user