From 1ba1108099e95ec433959ba0971552ec8ebcfde7 Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 15 Feb 2021 20:54:02 -0500 Subject: [PATCH] [client] wayland: add option to enable cursor warp This is enabled on default. Specify wayland:warpSupport=no to disable it, which may be useful on certain compositors that do not warp when the pointer is confined. --- client/README.md | 6 ++++++ client/displayservers/SDL/sdl.c | 5 +++++ client/displayservers/Wayland/wayland.c | 21 +++++++++++++++++++++ client/displayservers/X11/x11.c | 5 +++++ client/include/interface/displayserver.h | 4 ++++ client/src/main.c | 3 +++ 6 files changed, 44 insertions(+) diff --git a/client/README.md b/client/README.md index 4fce8c55..6fcd1c92 100644 --- a/client/README.md +++ b/client/README.md @@ -196,4 +196,10 @@ Command line arguments will override any options loaded from the config files. | opengl:preventBuffer | | yes | Prevent the driver from buffering frames | | opengl:amdPinnedMem | | yes | Use GL_AMD_pinned_memory if it is available | |------------------------------------------------------------------------------------| + +|-------------------------------------------------------------| +| Long | Short | Value | Description | +|-------------------------------------------------------------| +| wayland:warpSupport | | yes | Enable cursor warping | +|-------------------------------------------------------------| ``` diff --git a/client/displayservers/SDL/sdl.c b/client/displayservers/SDL/sdl.c index f1d628ce..80e9c027 100644 --- a/client/displayservers/SDL/sdl.c +++ b/client/displayservers/SDL/sdl.c @@ -53,6 +53,10 @@ static struct SDLDSState sdl; /* forwards */ static int sdlEventFilter(void * userdata, SDL_Event * event); +static void sdlSetup(void) +{ +} + static bool sdlProbe(void) { return true; @@ -504,6 +508,7 @@ static bool sdlGetFullscreen(void) struct LG_DisplayServerOps LGDS_SDL = { + .setup = sdlSetup, .probe = sdlProbe, .earlyInit = sdlEarlyInit, .init = sdlInit, diff --git a/client/displayservers/Wayland/wayland.c b/client/displayservers/Wayland/wayland.c index 9253a35c..83d053d0 100644 --- a/client/displayservers/Wayland/wayland.c +++ b/client/displayservers/Wayland/wayland.c @@ -42,6 +42,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/debug.h" #include "common/locking.h" #include "common/countedbuffer.h" +#include "common/option.h" #include "wayland-xdg-shell-client-protocol.h" #include "wayland-xdg-decoration-unstable-v1-client-protocol.h" @@ -166,6 +167,18 @@ struct WCBState static struct WaylandDSState wm; static struct WCBState wcb; +static struct Option waylandOptions[] = +{ + { + .module = "wayland", + .name = "warpSupport", + .description = "Enable cursor warping", + .type = OPTION_TYPE_BOOL, + .value.x_bool = true, + }, + {0} +}; + static const uint32_t cursorBitmap[] = { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xFFFFFF, 0xFFFFFF, 0x000000, @@ -618,6 +631,11 @@ static bool waylandEarlyInit(void) return true; } +static void waylandSetup(void) +{ + option_register(waylandOptions); +} + static bool waylandProbe(void) { return getenv("WAYLAND_DISPLAY") != NULL; @@ -630,6 +648,8 @@ static bool waylandInit(const LG_DSInitParams params) { memset(&wm, 0, sizeof(wm)); + wm.warpSupport = option_get_bool("wayland", "warpSupport"); + wm.epollFd = epoll_create1(EPOLL_CLOEXEC); if (wm.epollFd < 0) { @@ -1514,6 +1534,7 @@ static void waylandCBRelease(void) struct LG_DisplayServerOps LGDS_Wayland = { + .setup = waylandSetup, .probe = waylandProbe, .earlyInit = waylandEarlyInit, .init = waylandInit, diff --git a/client/displayservers/X11/x11.c b/client/displayservers/X11/x11.c index ab5ca01f..661590d7 100644 --- a/client/displayservers/X11/x11.c +++ b/client/displayservers/X11/x11.c @@ -118,6 +118,10 @@ static void x11SetFullscreen(bool fs); static int x11EventThread(void * unused); static void x11GenericEvent(XGenericEventCookie *cookie); +static void x11Setup(void) +{ +} + static bool x11Probe(void) { return getenv("DISPLAY") != NULL; @@ -1490,6 +1494,7 @@ static void x11CBRequest(LG_ClipboardData type) struct LG_DisplayServerOps LGDS_X11 = { + .setup = x11Setup, .probe = x11Probe, .earlyInit = x11EarlyInit, .init = x11Init, diff --git a/client/include/interface/displayserver.h b/client/include/interface/displayserver.h index d3cf16d4..fb451c29 100644 --- a/client/include/interface/displayserver.h +++ b/client/include/interface/displayserver.h @@ -84,6 +84,9 @@ typedef struct LG_DSGLContext struct LG_DisplayServerOps { + /* called before options are parsed, useful for registering options */ + void (*setup)(void); + /* return true if the selected ds is valid for the current platform */ bool (*probe)(void); @@ -175,6 +178,7 @@ struct LG_DisplayServerOps #endif #define ASSERT_LG_DS_VALID(x) \ + assert((x)->setup ); \ assert((x)->probe ); \ assert((x)->earlyInit ); \ assert((x)->init ); \ diff --git a/client/src/main.c b/client/src/main.c index 18cbd055..a0130a68 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1032,6 +1032,9 @@ int main(int argc, char * argv[]) for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i) LG_Renderers[i]->setup(); + for(unsigned int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i) + LG_DisplayServers[i]->setup(); + if (!config_load(argc, argv)) return -1;