From a69ca77e2cd9e50da444e724e68a7c8a9deafb1b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 17 Oct 2020 09:56:51 +1100 Subject: [PATCH] add WIP grabbing cursor for linux backend (addresses #731) --- src/Options.h | 1 + src/Window.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Options.h b/src/Options.h index 810e44372..9f4956cde 100644 --- a/src/Options.h +++ b/src/Options.h @@ -67,6 +67,7 @@ #define OPT_CLASSIC_CHAT "nostalgia-classicchat" #define OPT_MAX_CHUNK_UPDATES "gfx-maxchunkupdates" #define OPT_CAMERA_MASS "cameramass" +#define OPT_GRAB_CURSOR "win-grab-cursor" extern struct StringsBuffer Options; /* Frees any memory allocated in storing options. */ diff --git a/src/Window.c b/src/Window.c index 71fb54241..7450079d1 100644 --- a/src/Window.c +++ b/src/Window.c @@ -6,6 +6,7 @@ #include "Funcs.h" #include "ExtMath.h" #include "Bitmap.h" +#include "Options.h" struct _DisplayData DisplayInfo; struct _WinData WindowInfo; @@ -981,6 +982,7 @@ static Atom net_wm_state_fullscreen; static Atom xa_clipboard, xa_targets, xa_utf8_string, xa_data_sel; static Atom xa_atom = 4; static long win_eventMask; +static cc_bool grabCursor; static int MapNativeKey(KeySym key, unsigned int state) { if (key >= XK_0 && key <= XK_9) { return '0' + (key - XK_0); } @@ -1204,6 +1206,7 @@ void Window_Create(int width, int height) { RefreshWindowBounds(width, height); WindowInfo.Exists = true; WindowInfo.Handle = (void*)win_handle; + grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false); /* So right name appears in e.g. Ubuntu Unity launchbar */ XClassHint hint = { 0 }; @@ -1526,8 +1529,8 @@ void Cursor_SetPosition(int x, int y) { XFlush(win_display); /* TODO: not sure if XFlush call is necessary */ } +static Cursor blankCursor; static void Cursor_DoSetVisible(cc_bool visible) { - static Cursor blankCursor; if (visible) { XUndefineCursor(win_display, win_handle); } else { @@ -1889,6 +1892,10 @@ void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); if (!rawMouseInited) InitRawMouse(); rawMouseInited = true; + + if (!grabCursor) return; + XGrabPointer(win_display, win_handle, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, + GrabModeAsync, GrabModeAsync, win_handle, blankCursor, CurrentTime); } void Window_UpdateRawMouse(void) { @@ -1900,7 +1907,11 @@ void Window_UpdateRawMouse(void) { } } -void Window_DisableRawMouse(void) { DefaultDisableRawMouse(); } +void Window_DisableRawMouse(void) { + DefaultDisableRawMouse(); + if (!grabCursor) return; + XUngrabPointer(win_display, CurrentTime); +} /*########################################################################################################################*