|
|
@@ -44,41 +44,16 @@ pub fn get_event_type(event: *const xlib.XEvent) EventType { |
| 44 |
44 |
} |
| 45 |
45 |
|
| 46 |
46 |
pub fn event_name(event_type: EventType) []const u8 { |
| 47 |
|
- return switch (event_type) { |
| 48 |
|
- .key_press => "key_press", |
| 49 |
|
- .key_release => "key_release", |
| 50 |
|
- .button_press => "button_press", |
| 51 |
|
- .button_release => "button_release", |
| 52 |
|
- .motion_notify => "motion_notify", |
| 53 |
|
- .enter_notify => "enter_notify", |
| 54 |
|
- .leave_notify => "leave_notify", |
| 55 |
|
- .focus_in => "focus_in", |
| 56 |
|
- .focus_out => "focus_out", |
| 57 |
|
- .keymap_notify => "keymap_notify", |
| 58 |
|
- .expose => "expose", |
| 59 |
|
- .graphics_expose => "graphics_expose", |
| 60 |
|
- .no_expose => "no_expose", |
| 61 |
|
- .visibility_notify => "visibility_notify", |
| 62 |
|
- .create_notify => "create_notify", |
| 63 |
|
- .destroy_notify => "destroy_notify", |
| 64 |
|
- .unmap_notify => "unmap_notify", |
| 65 |
|
- .map_notify => "map_notify", |
| 66 |
|
- .map_request => "map_request", |
| 67 |
|
- .reparent_notify => "reparent_notify", |
| 68 |
|
- .configure_notify => "configure_notify", |
| 69 |
|
- .configure_request => "configure_request", |
| 70 |
|
- .gravity_notify => "gravity_notify", |
| 71 |
|
- .resize_request => "resize_request", |
| 72 |
|
- .circulate_notify => "circulate_notify", |
| 73 |
|
- .circulate_request => "circulate_request", |
| 74 |
|
- .property_notify => "property_notify", |
| 75 |
|
- .selection_clear => "selection_clear", |
| 76 |
|
- .selection_request => "selection_request", |
| 77 |
|
- .selection_notify => "selection_notify", |
| 78 |
|
- .colormap_notify => "colormap_notify", |
| 79 |
|
- .client_message => "client_message", |
| 80 |
|
- .mapping_notify => "mapping_notify", |
| 81 |
|
- .generic_event => "generic_event", |
| 82 |
|
- _ => "unknown", |
| 83 |
|
- }; |
|
47 |
+ if (@intFromEnum(event_type) > @intFromEnum(EventType.generic_event)) return "unknown"; |
|
48 |
+ |
|
49 |
+ return @tagName(event_type); |
|
50 |
+} |
|
51 |
+ |
|
52 |
+test event_name { |
|
53 |
+ const testing = std.testing; |
|
54 |
+ |
|
55 |
+ const name = event_name(.key_press); |
|
56 |
+ try testing.expectEqualStrings("key_press", name); |
|
57 |
+ |
|
58 |
+ try testing.expectEqualStrings("unknown", event_name(@enumFromInt(100))); |
| 84 |
59 |
} |