From: Mikko Rasa Date: Thu, 5 Oct 2023 09:52:50 +0000 (+0300) Subject: Require xtst for the input synthesizer on Linux X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=9ab96a2c50cb2c96beffb31d0a26b7366c47a6bf;p=libs%2Fgui.git Require xtst for the input synthesizer on Linux Make it an optional feature as well so the dependency can be avoided. --- diff --git a/Build b/Build index 2edee77..848b240 100644 --- a/Build +++ b/Build @@ -106,6 +106,16 @@ package "mspgui" { require "xrandr"; }; + + feature "xtest" "Include support for synthesizing input with XTest" + { + default "yes"; + export true; + }; + if_feature "xtest" + { + require "xtst"; + }; }; build_info diff --git a/source/input/x11/synthesizer.cpp b/source/input/x11/synthesizer.cpp index 7326b33..2f7c8da 100644 --- a/source/input/x11/synthesizer.cpp +++ b/source/input/x11/synthesizer.cpp @@ -1,4 +1,6 @@ +#ifdef WITH_XTEST #include +#endif #include #include "keys_private.h" #include "synthesizer.h" @@ -11,6 +13,7 @@ namespace Input { Synthesizer::Synthesizer(Graphics::Display &d): display(d) { +#ifdef WITH_XEST ::Display *dpy = display.get_private().display; int event_base; int error_base; @@ -18,38 +21,62 @@ Synthesizer::Synthesizer(Graphics::Display &d): int minor_ver; if(!XTestQueryExtension(dpy, &event_base, &error_base, &major_ver, &minor_ver)) throw runtime_error("XTest is not supported"); +#else + throw unsupported("Input::Synthesizer"); +#endif } void Synthesizer::press_key(Key key) { +#ifdef WITH_XTEST ::Display *dpy = display.get_private().display; unsigned code = XKeysymToKeycode(dpy, key_to_sys(key)); XTestFakeKeyEvent(dpy, code, true, CurrentTime); +#else + (void)key; +#endif } void Synthesizer::release_key(Key key) { +#ifdef WITH_XTEST ::Display *dpy = display.get_private().display; unsigned code = XKeysymToKeycode(dpy, key_to_sys(key)); XTestFakeKeyEvent(dpy, code, false, CurrentTime); +#else + (void)key; +#endif } void Synthesizer::move_mouse_to(int x, int y) { +#ifdef WITH_XTEST ::Display *dpy = display.get_private().display; XTestFakeMotionEvent(dpy, -1, x, y, CurrentTime); +#else + (void)x; + (void)y; +#endif } void Synthesizer::press_mouse_button(MouseButton button) { +#ifdef WITH_XTEST ::Display *dpy = display.get_private().display; XTestFakeButtonEvent(dpy, button, true, CurrentTime); +#else + (void)button; +#endif } void Synthesizer::release_mouse_button(MouseButton button) { +#ifdef WITH_XTEST ::Display *dpy = display.get_private().display; XTestFakeButtonEvent(dpy, button, false, CurrentTime); +#else + (void)button; +#endif } } // namespace Input