mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
add WIP grabbing cursor for linux backend (addresses #731)
This commit is contained in:
parent
bd451b7f31
commit
a69ca77e2c
@ -67,6 +67,7 @@
|
|||||||
#define OPT_CLASSIC_CHAT "nostalgia-classicchat"
|
#define OPT_CLASSIC_CHAT "nostalgia-classicchat"
|
||||||
#define OPT_MAX_CHUNK_UPDATES "gfx-maxchunkupdates"
|
#define OPT_MAX_CHUNK_UPDATES "gfx-maxchunkupdates"
|
||||||
#define OPT_CAMERA_MASS "cameramass"
|
#define OPT_CAMERA_MASS "cameramass"
|
||||||
|
#define OPT_GRAB_CURSOR "win-grab-cursor"
|
||||||
|
|
||||||
extern struct StringsBuffer Options;
|
extern struct StringsBuffer Options;
|
||||||
/* Frees any memory allocated in storing options. */
|
/* Frees any memory allocated in storing options. */
|
||||||
|
15
src/Window.c
15
src/Window.c
@ -6,6 +6,7 @@
|
|||||||
#include "Funcs.h"
|
#include "Funcs.h"
|
||||||
#include "ExtMath.h"
|
#include "ExtMath.h"
|
||||||
#include "Bitmap.h"
|
#include "Bitmap.h"
|
||||||
|
#include "Options.h"
|
||||||
|
|
||||||
struct _DisplayData DisplayInfo;
|
struct _DisplayData DisplayInfo;
|
||||||
struct _WinData WindowInfo;
|
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_clipboard, xa_targets, xa_utf8_string, xa_data_sel;
|
||||||
static Atom xa_atom = 4;
|
static Atom xa_atom = 4;
|
||||||
static long win_eventMask;
|
static long win_eventMask;
|
||||||
|
static cc_bool grabCursor;
|
||||||
|
|
||||||
static int MapNativeKey(KeySym key, unsigned int state) {
|
static int MapNativeKey(KeySym key, unsigned int state) {
|
||||||
if (key >= XK_0 && key <= XK_9) { return '0' + (key - XK_0); }
|
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);
|
RefreshWindowBounds(width, height);
|
||||||
WindowInfo.Exists = true;
|
WindowInfo.Exists = true;
|
||||||
WindowInfo.Handle = (void*)win_handle;
|
WindowInfo.Handle = (void*)win_handle;
|
||||||
|
grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false);
|
||||||
|
|
||||||
/* So right name appears in e.g. Ubuntu Unity launchbar */
|
/* So right name appears in e.g. Ubuntu Unity launchbar */
|
||||||
XClassHint hint = { 0 };
|
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 */
|
XFlush(win_display); /* TODO: not sure if XFlush call is necessary */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Cursor blankCursor;
|
||||||
static void Cursor_DoSetVisible(cc_bool visible) {
|
static void Cursor_DoSetVisible(cc_bool visible) {
|
||||||
static Cursor blankCursor;
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
XUndefineCursor(win_display, win_handle);
|
XUndefineCursor(win_display, win_handle);
|
||||||
} else {
|
} else {
|
||||||
@ -1889,6 +1892,10 @@ void Window_EnableRawMouse(void) {
|
|||||||
DefaultEnableRawMouse();
|
DefaultEnableRawMouse();
|
||||||
if (!rawMouseInited) InitRawMouse();
|
if (!rawMouseInited) InitRawMouse();
|
||||||
rawMouseInited = true;
|
rawMouseInited = true;
|
||||||
|
|
||||||
|
if (!grabCursor) return;
|
||||||
|
XGrabPointer(win_display, win_handle, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
||||||
|
GrabModeAsync, GrabModeAsync, win_handle, blankCursor, CurrentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window_UpdateRawMouse(void) {
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user