lib/xkb/src/keysym/kind.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const std = @import("std");
 2 const Keysym = @import("root.zig").Keysym;
 3 const data = @import("generated/root.zig").kind;
 4 
 5 pub fn isModifier(value: Keysym) bool {
 6     const raw = @backingInt(value);
 7     return (raw >= data.modifier_core_min and raw <= data.modifier_core_max) or
 8         (raw >= data.modifier_iso_min and raw <= data.modifier_iso_max) or
 9         raw == data.mode_switch or
10         raw == data.num_lock;
11 }
12 
13 pub fn isKeypad(value: Keysym) bool {
14     const raw = @backingInt(value);
15     return raw >= data.keypad_min and raw <= data.keypad_max;
16 }
17 
18 test "modifier classification covers XKB ranges and isolated symbols" {
19     const modifiers = [_]u32{ 0xffe1, 0xffee, 0xfe01, 0xfe13, 0xff7e, 0xff7f };
20     const other = [_]u32{ 0xffe0, 0xffef, 0xfe00, 0xfe14, 0xff7d, 0xff80 };
21     for (modifiers) |value| try std.testing.expect(isModifier(@fromBackingInt(@intCast(value))));
22     for (other) |value| try std.testing.expect(!isModifier(@fromBackingInt(@intCast(value))));
23 }
24 
25 test "keypad classification uses the complete contiguous range" {
26     try std.testing.expect(!isKeypad(@fromBackingInt(@intCast(0xff7f))));
27     try std.testing.expect(isKeypad(@fromBackingInt(@intCast(0xff80))));
28     try std.testing.expect(isKeypad(@fromBackingInt(@intCast(0xffbd))));
29     try std.testing.expect(!isKeypad(@fromBackingInt(@intCast(0xffbe))));
30 }