From bf223158d01939883206b660af1ca96f07ea2e1f Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 9 Jan 2021 19:55:10 -0500 Subject: [PATCH] [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 --- client/clipboards/Wayland/src/wayland.c | 1 - client/clipboards/X11/src/x11.c | 1 - client/src/main.c | 21 +++++++++------------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/client/clipboards/Wayland/src/wayland.c b/client/clipboards/Wayland/src/wayland.c index 3dded896..48b506b6 100644 --- a/client/clipboards/Wayland/src/wayland.c +++ b/client/clipboards/Wayland/src/wayland.c @@ -398,7 +398,6 @@ static bool wayland_cb_init( { if (wminfo->subsystem != SDL_SYSWM_WAYLAND) { - DEBUG_ERROR("wrong subsystem"); return false; } diff --git a/client/clipboards/X11/src/x11.c b/client/clipboards/X11/src/x11.c index c5c9f0d0..78165529 100644 --- a/client/clipboards/X11/src/x11.c +++ b/client/clipboards/X11/src/x11.c @@ -71,7 +71,6 @@ static bool x11_cb_init( // final sanity check if (wminfo->subsystem != SDL_SYSWM_X11) { - DEBUG_ERROR("wrong subsystem"); return false; } diff --git a/client/src/main.c b/client/src/main.c index a93f6fc5..18aff8a6 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -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)