diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/gui.zig | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index c83b8209..4eaf7860 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -549,6 +549,8 @@ const Gui = struct { window_slot: ?*?*c.SDL_Window = null, gamepad: ?*c.SDL_Gamepad = null, + /// The gamepad subsystem started (startGamepads). + gamepads: bool = false, pad_x: f32 = 0, pad_y: f32 = 0, pad_scroll: f32 = 0, // fractional vertical wheel ticks (left stick) @@ -805,7 +807,8 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di _ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI", "1"); // SDL_HINT_JOYSTICK_HIDAPI _ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI_STEAMDECK", "1"); // ..._STEAMDECK if (comptime builtin.os.tag == .macos) _ = c.SDL_SetHint(c.SDL_HINT_MAC_SCROLL_MOMENTUM, "1"); - if (!c.SDL_Init(c.SDL_INIT_VIDEO | c.SDL_INIT_GAMEPAD)) { + // The gamepads after the first frame (startGamepads). + if (!c.SDL_Init(c.SDL_INIT_VIDEO)) { log.err("SDL_Init: {s}", .{c.SDL_GetError()}); return error.SdlInit; } @@ -1460,6 +1463,7 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ if (link.quietCheck()) |wait| ms = if (ms < 0) @intCast(wait) else @min(ms, @as(c_int, @intCast(wait))); // Idle, its frame drawn: the next input needs no copy taken. if (ms != 0) r.ready(); + if (shell.surface != null) startGamepads(g); var sev = std.mem.zeroes(c.SDL_Event); g.input_seen = false; var got = c.SDL_WaitEventTimeout(&sev, ms); @@ -2780,6 +2784,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { s.took_input = false; defer s.waited = true; if (s.gui) |g| { + if (s.surface != null) startGamepads(g); var sev = std.mem.zeroes(c.SDL_Event); // Idle is asleep until an event: SDL's own, and the user events the // shell's queue raises for a terminal's output, a completion, a file @@ -3226,6 +3231,15 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void { if (!s.presented and s.skipped_presents <= 3) core.present_skipped = true; } +/// The gamepad subsystem, started once the first frame is drawn, as the +/// loop first waits: its scan (udev, hidapi, libusb) took 40 ms of a start. +/// A pad plugged in already is added by it (GAMEPAD_ADDED). +fn startGamepads(g: *Gui) void { + if (g.gamepads) return; + g.gamepads = true; + if (!c.SDL_InitSubSystem(c.SDL_INIT_GAMEPAD)) log.warn("SDL_InitSubSystem(GAMEPAD): {s}", .{c.SDL_GetError()}); +} + fn postPresent(ctx: ?*anyopaque) void { const s = shellOf(ctx); const g = s.gui orelse return; |
