[input] Allow drivers to initialize cvars early

Input driver can now have an optional init_cvars function. This allows
them to create all their cvars before the actual init pass thus avoiding
some initialization order interdependency issues (in this case, fixing a
segfault when starting x11 clients fullscreen due to the in_dga cvar not
existing yet).
This commit is contained in:
Bill Currie 2021-11-21 11:33:58 +09:00
parent 799d247e1a
commit 925a55f6cc
3 changed files with 9 additions and 3 deletions

View file

@ -52,6 +52,7 @@ typedef struct in_buttoninfo_s {
struct qf_fd_set;
typedef struct in_driver_s {
void (*init_cvars) (void *data);
void (*init) (void *data);
void (*shutdown) (void *data);

View file

@ -456,6 +456,12 @@ IN_Init_Cvars (void)
"mouse in_mouse_pre_amp multiplier");
lookstrafe = Cvar_Get ("lookstrafe", "0", CVAR_ARCHIVE, NULL,
"when mlook/klook on player will strafe");
for (size_t i = 0; i < in_drivers.size; i++) {
in_regdriver_t *rd = &in_drivers.a[i];
if (rd->driver.init_cvars) {
rd->driver.init_cvars (rd->data);
}
}
}
void

View file

@ -1059,7 +1059,7 @@ in_x11_get_device_event_data (void *device, void *data)
}
static void
in_x11_init_cvars (void)
in_x11_init_cvars (void *data)
{
in_snd_block = Cvar_Get ("in_snd_block", "0", CVAR_ARCHIVE, NULL,
"block sound output on window focus loss");
@ -1091,8 +1091,6 @@ in_x11_init (void *data)
if (!x_win)
Sys_Error ("IN: No window!!");
in_x11_init_cvars ();
X11_OpenDisplay (); // call to increment the reference counter
x11_fd = ConnectionNumber (x_disp);
@ -1140,6 +1138,7 @@ in_x11_clear_states (void *data)
}
static in_driver_t in_x11_driver = {
.init_cvars = in_x11_init_cvars,
.init = in_x11_init,
.shutdown = in_x11_shutdown,
.set_device_event_data = in_x11_set_device_event_data,