[client] clipboard: try each clipboard until one initializes

Previously, main.c would segfault at runtime if clipboards were disabled
via cmake flags, as the clipboards array would be empty but still
indexed during initialization.

Co-authored-by: Quantum <quantum2048@gmail.com>
This commit is contained in:
Tudor Brindus 2021-01-09 19:55:10 -05:00 committed by Geoffrey McRae
parent 2627381021
commit bf223158d0
3 changed files with 9 additions and 14 deletions

View File

@ -398,7 +398,6 @@ static bool wayland_cb_init(
{
if (wminfo->subsystem != SDL_SYSWM_WAYLAND)
{
DEBUG_ERROR("wrong subsystem");
return false;
}

View File

@ -71,7 +71,6 @@ static bool x11_cb_init(
// final sanity check
if (wminfo->subsystem != SDL_SYSWM_X11)
{
DEBUG_ERROR("wrong subsystem");
return false;
}

View File

@ -2025,29 +2025,26 @@ static int lg_run()
(unsigned char *)&value,
1
);
g_state.lgc = LG_Clipboards[0];
}
else if (g_state.wminfo.subsystem == SDL_SYSWM_WAYLAND)
{
g_state.lgc = LG_Clipboards[1];
}
} else {
DEBUG_ERROR("Could not get SDL window information %s", SDL_GetError());
return -1;
}
for (LG_Clipboard ** clipboard = LG_Clipboards; *clipboard; clipboard++)
if ((*clipboard)->init(&g_state.wminfo, clipboardRelease, clipboardNotify, clipboardData))
{
g_state.lgc = *clipboard;
break;
}
if (g_state.lgc)
{
DEBUG_INFO("Using Clipboard: %s", g_state.lgc->getName());
if (!g_state.lgc->init(&g_state.wminfo, clipboardRelease, clipboardNotify, clipboardData))
{
DEBUG_WARN("Failed to initialize the clipboard interface, continuing anyway");
g_state.lgc = NULL;
}
g_state.cbRequestList = ll_new();
}
else
DEBUG_WARN("Failed to initialize the clipboard interface, continuing anyway");
initSDLCursor();
if (params.hideMouse)