mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
input: various more helpers
This commit is contained in:
@ -45,6 +45,26 @@ pub const Entry = struct {
|
||||
sequence: []const u8,
|
||||
};
|
||||
|
||||
/// The list of modifier combinations for modify other key sequences.
|
||||
/// The mode value is index + 2.
|
||||
pub const modifiers: []const key.Mods = &.{
|
||||
.{ .shift = true },
|
||||
.{ .alt = true },
|
||||
.{ .shift = true, .alt = true },
|
||||
.{ .ctrl = true },
|
||||
.{ .shift = true, .ctrl = true },
|
||||
.{ .alt = true, .ctrl = true },
|
||||
.{ .shift = true, .alt = true, .ctrl = true },
|
||||
.{ .super = true },
|
||||
.{ .shift = true, .super = true },
|
||||
.{ .alt = true, .super = true },
|
||||
.{ .shift = true, .alt = true, .super = true },
|
||||
.{ .ctrl = true, .super = true },
|
||||
.{ .shift = true, .ctrl = true, .super = true },
|
||||
.{ .alt = true, .ctrl = true, .super = true },
|
||||
.{ .shift = true, .alt = true, .ctrl = true, .super = true },
|
||||
};
|
||||
|
||||
/// This is the array of entries for the PC style function keys as mapped to
|
||||
/// our set of possible key codes. Not every key has any entries.
|
||||
pub const KeyEntryArray = std.EnumArray(key.Key, []const Entry);
|
||||
@ -239,24 +259,6 @@ fn pcStyle(comptime fmt: []const u8) []const Entry {
|
||||
// The comptime {} wrapper is superflous but it prevents us from
|
||||
// accidentally running this function at runtime.
|
||||
comptime {
|
||||
const modifiers: []const key.Mods = &.{
|
||||
.{ .shift = true },
|
||||
.{ .alt = true },
|
||||
.{ .shift = true, .alt = true },
|
||||
.{ .ctrl = true },
|
||||
.{ .shift = true, .ctrl = true },
|
||||
.{ .alt = true, .ctrl = true },
|
||||
.{ .shift = true, .alt = true, .ctrl = true },
|
||||
.{ .super = true },
|
||||
.{ .shift = true, .super = true },
|
||||
.{ .alt = true, .super = true },
|
||||
.{ .shift = true, .alt = true, .super = true },
|
||||
.{ .ctrl = true, .super = true },
|
||||
.{ .shift = true, .ctrl = true, .super = true },
|
||||
.{ .alt = true, .ctrl = true, .super = true },
|
||||
.{ .shift = true, .alt = true, .ctrl = true, .super = true },
|
||||
};
|
||||
|
||||
var entries: [modifiers.len]Entry = undefined;
|
||||
for (modifiers, 2.., 0..) |mods, code, i| {
|
||||
entries[i] = .{
|
||||
|
@ -14,6 +14,24 @@ pub const Mods = packed struct(u8) {
|
||||
num_lock: bool = false,
|
||||
_padding: u2 = 0,
|
||||
|
||||
/// Returns true if no modifiers are set.
|
||||
pub fn empty(self: Mods) bool {
|
||||
return @as(u8, @bitCast(self)) == 0;
|
||||
}
|
||||
|
||||
/// Returns true if two mods are equal.
|
||||
pub fn equal(self: Mods, other: Mods) bool {
|
||||
return @as(u8, @bitCast(self)) == @as(u8, @bitCast(other));
|
||||
}
|
||||
|
||||
/// Returns the mods without locks set.
|
||||
pub fn withoutLocks(self: Mods) Mods {
|
||||
var copy = self;
|
||||
copy.caps_lock = false;
|
||||
copy.num_lock = false;
|
||||
return copy;
|
||||
}
|
||||
|
||||
// For our own understanding
|
||||
test {
|
||||
const testing = std.testing;
|
||||
|
Reference in New Issue
Block a user