diff --git a/src/core/makefile b/src/core/makefile index 057cd9303..f285fb01e 100644 --- a/src/core/makefile +++ b/src/core/makefile @@ -36,6 +36,12 @@ ifneq ($(CHUCK_STRICT),) CFLAGS+= -Wall endif +# use X11? (Linux) +ifneq ($(USE_X11),) +CFLAGS+= -D__USE_X11__ +LDFLAGS+= -lX11 +endif + # ifneq ($(findstring arm,$(shell uname -m)),) # some sort of arm platform- enable aggressive optimizations # CFLAGS+= -ffast-math diff --git a/src/core/util_hid.cpp b/src/core/util_hid.cpp index ebeaa25f7..137460b91 100644 --- a/src/core/util_hid.cpp +++ b/src/core/util_hid.cpp @@ -6387,6 +6387,11 @@ Linux general HID support #include #include +#if defined(__USE_X11__) +// for Mouse | 1.5.4.2 (ge) added +#include +#endif + #define CK_HID_DIR ("/dev/input") #define CK_HID_MOUSEFILE ("mouse%d") #define CK_HID_JOYSTICKFILE ("js%d") @@ -7892,6 +7897,37 @@ t_CKVEC2 ck_get_mouse_xy_normalize() // t_CKFLOAT screenWidth = GetSystemMetrics( SM_CXVIRTUALSCREEN ); // t_CKFLOAT screenHeight = GetSystemMetrics( SM_CYVIRTUALSCREEN ); #elif defined(__PLATFORM_LINUX__) + + #if defined(__USE_X11__) + // stuff to query + Window root; + XWindowAttributes attributes; + int qRootX, qRootY, qChildX, qChildY; + Window qRoot, qChild; + unsigned int qMask; + // open connection to X server + Display * display = XOpenDisplay( nullptr ); + if( !display ) + { + // print error + std::cerr << "Mouse cannot open display (X server)..." << std::endl; + goto done; + } + // get root window + root = DefaultRootWindow( display ); + // get the point + XQueryPointer( display, root, &qRoot, &qChild, &qRootX, &qRootY, &qChildX, &qChildY, &qMask ); + // get window attributes + XGetWindowAttributes( display, root, &attributes ); + // copy to return value + retval.x = (t_CKFLOAT)qRootX / attributes.width; + retval.y = (t_CKFLOAT)qRootY / attributes.height; + // close the connection + XCloseDisplay(display); + #else // no __USE_X11__ + cerr << "Mouse needs X11 on Linux; to use, re-compile chuck with USE_X11=1" << endl; + #endif // if defined(__USE_X11__) + #else // unsupported, for now; return 0,0 #endif @@ -7925,8 +7961,39 @@ t_CKVEC2 ck_get_mouse_xy_absolute() retval.y = pt.y; } #elif defined(__PLATFORM_LINUX__) + + #if defined(__USE_X11__) + // stuff to query + Window root; + int qRootX, qRootY, qChildX, qChildY; + Window qRoot, qChild; + unsigned int qMask; + // open connection to X server + Display * display = XOpenDisplay( nullptr ); + if( !display ) + { + // print error + std::cerr << "Mouse cannot open display (X server)..." << std::endl; + goto done; + } + // get root window + root = DefaultRootWindow( display ); + // get the point + XQueryPointer( display, root, &qRoot, &qChild, &qRootX, &qRootY, &qChildX, &qChildY, &qMask ); + // copy to return value + retval.x = qRootX; + retval.y = qRootY; + // close the connection + XCloseDisplay(display); + #else // no __USE_X11__ + cerr << "Mouse needs X11 on Linux; to use, re-compile chuck with USE_X11=1" << endl; + #endif // if defined(__USE_X11__) + #else -#endif + // unsupported platform; nothing to do for now; return 0,0 +#endif // platform select + +done: return retval; } diff --git a/src/makefile b/src/makefile index d7d648469..157cb8fa9 100644 --- a/src/makefile +++ b/src/makefile @@ -127,6 +127,12 @@ ifneq ($(CHUCK_STRICT),) CFLAGS+= -Wall endif +# use X11? (Linux) +ifneq ($(USE_X11),) +CFLAGS+= -D__USE_X11__ +LDFLAGS+= -lX11 +endif + # ifneq ($(findstring arm,$(shell uname -m)),) # some sort of arm platform- enable aggressive optimizations # CFLAGS+= -ffast-math