]> git.tdb.fi Git - libs/gui.git/commitdiff
Require xtst for the input synthesizer on Linux
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Oct 2023 09:52:50 +0000 (12:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 5 Oct 2023 09:53:29 +0000 (12:53 +0300)
Make it an optional feature as well so the dependency can be avoided.

Build
source/input/x11/synthesizer.cpp

diff --git a/Build b/Build
index 2edee77c2b1bf74d72ad4eb5365593d33b125221..848b24041cfc3a456e5bffd7c4175a7f58d2c7cc 100644 (file)
--- 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
index 7326b33a229ebc4f27ec74f808988abfb2cbc6a7..2f7c8daf70c3f004f1b5109e0adf031118b16040 100644 (file)
@@ -1,4 +1,6 @@
+#ifdef WITH_XTEST
 #include <X11/extensions/XTest.h>
+#endif
 #include <msp/graphics/display_private.h>
 #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