From 5f070c8f745daa4177ca21310ddec25283c41926 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 20 Apr 2022 20:54:41 -0300 Subject: [PATCH] Selectable mouse type on Linux, part 2 --- src/qt/qt_rendererstack.cpp | 58 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 88b2395d5..9186ee86f 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -50,21 +50,43 @@ RendererStack::RendererStack(QWidget *parent) ui->setupUi(this); #if defined __unix__ && !defined __HAIKU__ -# ifdef WAYLAND - if (QApplication::platformName().contains("wayland")) { - wl_init(); + char *mouse_type = getenv("EMU86BOX_MOUSE"), auto_mouse_type[16]; + if (!mouse_type || (mouse_type[0] == '\0') || !stricmp(mouse_type, "auto")) { + if (QApplication::platformName().contains("wayland")) + strcpy(auto_mouse_type, "wayland"); + else if (QApplication::platformName() == "eglfs") + strcpy(auto_mouse_type, "evdev"); + else if (QApplication::platformName() == "xcb") + strcpy(auto_mouse_type, "xinput2"); + else + auto_mouse_type[0] = '\0'; + mouse_type = auto_mouse_type; } + +# ifdef WAYLAND + if (!stricmp(mouse_type, "wayland")) { + this->mouse_init = wl_init; + this->mouse_poll = wl_mouse_poll; + this->mouse_capture = wl_mouse_capture; + this->mouse_uncapture = wl_mouse_uncapture; + } else # endif # ifdef EVDEV_INPUT - if (QApplication::platformName() == "eglfs") { - evdev_init(); - } + if (!stricmp(mouse_type, "evdev")) { + this->mouse_init = evdev_init; + this->mouse_poll = evdev_mouse_poll; + } else # endif - if (QApplication::platformName() == "xcb") { + if (!stricmp(mouse_type, "xinput2")) { extern void xinput2_init(); - xinput2_init(); + extern void xinput2_poll(); + this->mouse_init = xinput2_init; + this->mouse_poll = xinput2_poll; } #endif + + if (this->mouse_init) + this->mouse_init(); } RendererStack::~RendererStack() @@ -104,23 +126,9 @@ RendererStack::mousePoll() mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0; mouse_buttons = mousedata.mousebuttons; -# if defined __unix__ && !defined __HAIKU__ -# ifdef WAYLAND - if (QApplication::platformName().contains("wayland")) - wl_mouse_poll(); -# endif - -# ifdef EVDEV_INPUT - if (QApplication::platformName() == "eglfs") - evdev_mouse_poll(); - else -# endif - if (QApplication::platformName() == "xcb") { - extern void xinput2_poll(); - xinput2_poll(); - } -# endif /* defined __unix__ */ -#endif /* !defined __APPLE__ */ + if (this->mouse_poll) + this->mouse_poll(); +#endif /* !defined __APPLE__ */ } int ignoreNextMouseEvent = 1;