[client] wayland: move wayland early init code out of main.c

This commit is contained in:
Geoffrey McRae 2021-01-16 20:31:58 +11:00
parent bad25c409c
commit 9f74bb785e
2 changed files with 24 additions and 6 deletions

View File

@ -22,6 +22,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <SDL2/SDL.h>
#include <wayland-client.h>
@ -254,6 +255,28 @@ static const struct wl_seat_listener seatListener = {
.name = seatNameHandler,
};
static bool waylandEarlyInit(void)
{
if (getenv("SDL_VIDEODRIVER") != NULL)
return true;
int err = setenv("SDL_VIDEODRIVER", "wayland", 1);
if (err < 0)
{
DEBUG_ERROR("Unable to set the env variable SDL_VIDEODRIVER: %d", err);
return false;
}
DEBUG_INFO("SDL_VIDEODRIVER has been set to wayland");
// Request to receive EPIPE instead of SIGPIPE when one end of a pipe
// disconnects while a write is pending. This is useful to the Wayland
// clipboard backend, where an arbitrary application is on the other end of
// that pipe.
signal(SIGPIPE, SIG_IGN);
return true;
}
static void waylandInit(SDL_SysWMinfo * info)
{
memset(&wm, 0, sizeof(wm));
@ -711,6 +734,7 @@ static void waylandCBRelease(void)
struct LG_DisplayServerOps LGDS_Wayland =
{
.subsystem = SDL_SYSWM_WAYLAND,
.earlyInit = waylandEarlyInit,
.init = waylandInit,
.startup = waylandStartup,
.free = waylandFree,

View File

@ -1712,12 +1712,6 @@ static int lg_run(void)
signal(SIGINT , int_handler);
signal(SIGTERM, int_handler);
// Request to receive EPIPE instead of SIGPIPE when one end of a pipe
// disconnects while a write is pending. This is useful to the Wayland
// clipboard backend, where an arbitrary application is on the other end of
// that pipe.
signal(SIGPIPE, SIG_IGN);
// try map the shared memory
if (!ivshmemOpen(&g_state.shm))
{