about summary refs log tree commit diff
path: root/src/Window.zig
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-28 16:04:36 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-28 16:04:36 +0700
commit1b46807d29060e3cee8897d3a8764d9c6c5d8091 (patch)
tree1cdf6ac61abf5c64c186f241b3795473bb5684e5 /src/Window.zig
parent3e6d3467bec4c5850b3b1f5c555ca88e5dcf2016 (diff)
downloadgfz-1b46807d29060e3cee8897d3a8764d9c6c5d8091.tar.gz
Wrap keyboard keys
Diffstat (limited to 'src/Window.zig')
-rw-r--r--src/Window.zig9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/Window.zig b/src/Window.zig
index d15dad3..74433e8 100644
--- a/src/Window.zig
+++ b/src/Window.zig
@@ -18,6 +18,7 @@
 
 usingnamespace @import("cimport.zig");
 const Error = gfz.Error;
+const Key = @import("input.zig").Key;
 const Monitor = @import("Monitor.zig");
 const checkError = gfz.checkError;
 const getError = gfz.getError;
@@ -25,7 +26,7 @@ const gfz = @import("gfz.zig");
 
 const Self = @This();
 const CursorPosFun = fn (window: Self, xpos: f64, ypos: f64) void;
-const KeyFun = fn (window: Self, key: c_int, scancode: c_int,
+const KeyFun = fn (window: Self, key: Key, scancode: c_int,
                    action: c_int, mods: c_int) void;
 const MouseButtonFun = fn (window: Self, button: c_int,
                            action: c_int, mods: c_int) void;
@@ -46,7 +47,7 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType {
             pub fn callback(window: ?*Impl, key: c_int, scancode: c_int,
                             action: c_int, mods: c_int) callconv(.C) void {
                 fun(@fieldParentPtr(Self, "pimpl", &window.?).*,
-                    key, scancode, action, mods);
+                    @intToEnum(Key, key), scancode, action, mods);
             }
         },
         GLFWmousebuttonfun => struct {
@@ -325,8 +326,8 @@ pub fn setMouseButtonCallback(self: Self,
 }
 
 /// Return the last reported state of a keyboard key.
-pub fn getKey(self: Self, key: c_int) Error!State {
-    const state = glfwGetKey(self.pimpl, key);
+pub fn getKey(self: Self, key: Key) Error!State {
+    const state = glfwGetKey(self.pimpl, @enumToInt(key));
     try checkError();
     return @intToEnum(State, state);
 }