From 7cc850982fe7a43f3887ad2ecef2ff7a4a39d788 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 30 Oct 2021 12:56:36 -0700 Subject: [PATCH] glfw: fix failing Mod bitmask tests, make fromInt/toInt work on non-6-bit integers Helps hexops/mach#37 Signed-off-by: Stephen Gutekanst --- glfw/src/mod.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/glfw/src/mod.zig b/glfw/src/mod.zig index 6632b68a..fdc8005a 100644 --- a/glfw/src/mod.zig +++ b/glfw/src/mod.zig @@ -13,6 +13,7 @@ pub const Mods = packed struct { super: bool = false, caps_lock: bool = false, num_lock: bool = false, + _reserved: u2 = 0, inline fn verifyIntType(comptime IntType: type) void { comptime { @@ -25,12 +26,12 @@ pub const Mods = packed struct { pub inline fn toInt(self: Mods, comptime IntType: type) IntType { verifyIntType(IntType); - return @bitCast(IntType, self); + return @intCast(IntType, @bitCast(u8, self)); } pub inline fn fromInt(flags: anytype) Mods { verifyIntType(@TypeOf(flags)); - return @bitCast(Mods, flags); + return @bitCast(Mods, @intCast(u8, flags)); } };