tony / oxwm

Branch: fc4ada9
Switch branches/tags
master
emzywastaken treewide: change function names to camelCase b3ae92e 2026-02-23
59 lines · 1.9 KB Raw Blame History
1 const std = @import("std");
2 const xlib = @import("xlib.zig");
3
4 pub const EventType = enum(c_int) {
5 key_press = xlib.KeyPress,
6 key_release = xlib.KeyRelease,
7 button_press = xlib.ButtonPress,
8 button_release = xlib.ButtonRelease,
9 motion_notify = xlib.MotionNotify,
10 enter_notify = xlib.EnterNotify,
11 leave_notify = xlib.LeaveNotify,
12 focus_in = xlib.FocusIn,
13 focus_out = xlib.FocusOut,
14 keymap_notify = xlib.KeymapNotify,
15 expose = xlib.Expose,
16 graphics_expose = xlib.GraphicsExpose,
17 no_expose = xlib.NoExpose,
18 visibility_notify = xlib.VisibilityNotify,
19 create_notify = xlib.CreateNotify,
20 destroy_notify = xlib.DestroyNotify,
21 unmap_notify = xlib.UnmapNotify,
22 map_notify = xlib.MapNotify,
23 map_request = xlib.MapRequest,
24 reparent_notify = xlib.ReparentNotify,
25 configure_notify = xlib.ConfigureNotify,
26 configure_request = xlib.ConfigureRequest,
27 gravity_notify = xlib.GravityNotify,
28 resize_request = xlib.ResizeRequest,
29 circulate_notify = xlib.CirculateNotify,
30 circulate_request = xlib.CirculateRequest,
31 property_notify = xlib.PropertyNotify,
32 selection_clear = xlib.SelectionClear,
33 selection_request = xlib.SelectionRequest,
34 selection_notify = xlib.SelectionNotify,
35 colormap_notify = xlib.ColormapNotify,
36 client_message = xlib.ClientMessage,
37 mapping_notify = xlib.MappingNotify,
38 generic_event = xlib.GenericEvent,
39 _,
40 };
41
42 pub fn getEventType(event: *const xlib.XEvent) EventType {
43 return @enumFromInt(event.type);
44 }
45
46 pub fn eventName(event_type: EventType) []const u8 {
47 if (@intFromEnum(event_type) > @intFromEnum(EventType.generic_event)) return "unknown";
48
49 return @tagName(event_type);
50 }
51
52 test eventName {
53 const testing = std.testing;
54
55 const name = eventName(.key_press);
56 try testing.expectEqualStrings("key_press", name);
57
58 try testing.expectEqualStrings("unknown", eventName(@enumFromInt(100)));
59 }