Add f1 key and add callback before main loop
This commit is contained in:
+14
-14
@@ -120,7 +120,7 @@ fn wlFrameHandleDone(data: ?*anyopaque, callback: ?*c.wl_callback, callback_data
|
|||||||
const new_callback: ?*c.wl_callback = c.wl_surface_frame(wl_state.surface);
|
const new_callback: ?*c.wl_callback = c.wl_surface_frame(wl_state.surface);
|
||||||
_ = c.wl_callback_add_listener(new_callback, &frame_callback_listener, wl_state);
|
_ = c.wl_callback_add_listener(new_callback, &frame_callback_listener, wl_state);
|
||||||
|
|
||||||
std.debug.print("[Wayland] Frame ready\n", .{});
|
// std.debug.print("[Wayland] Frame ready\n", .{});
|
||||||
wl_state.frame_ready = true;
|
wl_state.frame_ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,6 +677,11 @@ fn wlKeyboardHandleKey(data: ?*anyopaque, keyboard: ?*c.wl_keyboard, serial: u32
|
|||||||
c.XKB_KEY_Escape => {
|
c.XKB_KEY_Escape => {
|
||||||
wl_state.running = false;
|
wl_state.running = false;
|
||||||
},
|
},
|
||||||
|
c.XKB_KEY_F1 => {
|
||||||
|
const already_pressed: bool = wl_state.app_input.key.f1.down;
|
||||||
|
wl_state.app_input.key.f1.down = pressed;
|
||||||
|
wl_state.app_input.key.f1.pressing = pressed and already_pressed;
|
||||||
|
},
|
||||||
c.XKB_KEY_f => {
|
c.XKB_KEY_f => {
|
||||||
const already_pressed: bool = wl_state.app_input.key.f.down;
|
const already_pressed: bool = wl_state.app_input.key.f.down;
|
||||||
wl_state.app_input.key.f.down = pressed;
|
wl_state.app_input.key.f.down = pressed;
|
||||||
@@ -880,7 +885,12 @@ pub fn main() u8 {
|
|||||||
.permanent_storage = app_permanent_storage,
|
.permanent_storage = app_permanent_storage,
|
||||||
};
|
};
|
||||||
|
|
||||||
var frame_callback_added = false;
|
const callback: ?*c.wl_callback = c.wl_surface_frame(wl_surface);
|
||||||
|
if (callback) |cb| {
|
||||||
|
const ret: c_int = c.wl_callback_add_listener(cb, &frame_callback_listener, &wl_state);
|
||||||
|
std.debug.print("[Wayland] Added frame callback with ret {d}.\n", .{ret});
|
||||||
|
}
|
||||||
|
wl_state.frame_ready = true;
|
||||||
|
|
||||||
var timer = std.time.Timer.start() catch {
|
var timer = std.time.Timer.start() catch {
|
||||||
std.debug.print("[Wayland] ERROR: timer not supported.\n", .{});
|
std.debug.print("[Wayland] ERROR: timer not supported.\n", .{});
|
||||||
@@ -998,23 +1008,13 @@ pub fn main() u8 {
|
|||||||
|
|
||||||
_ = c.wl_display_roundtrip(display);
|
_ = c.wl_display_roundtrip(display);
|
||||||
|
|
||||||
if (!frame_callback_added) {
|
|
||||||
const callback: ?*c.wl_callback = c.wl_surface_frame(wl_surface);
|
|
||||||
if (callback) |cb| {
|
|
||||||
const ret: c_int = c.wl_callback_add_listener(cb, &frame_callback_listener, &wl_state);
|
|
||||||
std.debug.print("[Wayland] Added frame callback with ret {d}.\n", .{ret});
|
|
||||||
}
|
|
||||||
frame_callback_added = true;
|
|
||||||
wl_state.frame_ready = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// std.posix.nanosleep(0, std.time.ns_per_ms * 32);
|
// std.posix.nanosleep(0, std.time.ns_per_ms * 32);
|
||||||
|
|
||||||
const current = timer.lap();
|
const current = timer.lap();
|
||||||
const current_ms = current / std.time.ns_per_ms;
|
const current_ms: f64 = @as(f64, @floatFromInt(current)) / std.time.ns_per_ms;
|
||||||
const sleep_time_ms: f64 = @as(f64, @floatFromInt(sleep_time)) / @as(f64, @floatFromInt(std.time.ns_per_ms));
|
const sleep_time_ms: f64 = @as(f64, @floatFromInt(sleep_time)) / @as(f64, @floatFromInt(std.time.ns_per_ms));
|
||||||
std.debug.print(
|
std.debug.print(
|
||||||
"Render: {d:.3}ms, Sleeping: {d:.3}ms, Frame: {d}ms.\n",
|
"Render: {d:2.3}ms, Sleeping: {d:2.3}ms, Frame: {d:.3}ms.\n",
|
||||||
.{ render_time_ms, sleep_time_ms, current_ms },
|
.{ render_time_ms, sleep_time_ms, current_ms },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub const Key = struct {
|
|||||||
|
|
||||||
const Keyboard = struct {
|
const Keyboard = struct {
|
||||||
esc: Key,
|
esc: Key,
|
||||||
|
f1: Key,
|
||||||
f: Key,
|
f: Key,
|
||||||
r: Key,
|
r: Key,
|
||||||
q: Key,
|
q: Key,
|
||||||
|
|||||||
Reference in New Issue
Block a user