diff --git a/include/x11helper.h b/include/x11helper.h index b28d382..17a0841 100644 --- a/include/x11helper.h +++ b/include/x11helper.h @@ -11,7 +11,8 @@ class X11Helper : public QObject { Q_OBJECT public: - static Window InvalidWindow; + static const Window InvalidWindow; + static const bool IsSupported; explicit X11Helper(QObject* parent = nullptr); virtual ~X11Helper(); @@ -26,7 +27,9 @@ public slots: private: Window searchWindows(Window top, const QString& search); +#ifdef X11SUPPORT Display* disp; +#endif }; #endif // X11HELPER_H diff --git a/lolautoaccept.pro b/lolautoaccept.pro index 3be3f7f..ff00ebe 100644 --- a/lolautoaccept.pro +++ b/lolautoaccept.pro @@ -70,8 +70,8 @@ SOURCES += \ thirdparty/Log/Log.cpp # platform specific implementations -win32:SOURCES += src/clientaccess_windows.cpp -unix:SOURCES += src/clientaccess_linux.cpp +win32:SOURCES += src/clientaccess_windows.cpp src/x11helper_other.cpp +unix:SOURCES += src/clientaccess_linux.cpp src/x11helper_x11.cpp HEADERS += \ include/arg.h \ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7a305a1..8a8daaf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -10,10 +10,16 @@ #include "loadingwindow.h" #include "x11helper.h" +#ifdef X11SUPPORT +#define INIT_X11HELPER new X11Helper(this) +#else +#define INIT_X11HELPER nullptr +#endif + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui(new Ui::MainWindow), saveTimer(new QTimer(this)), dd(QLocale().name()), lolaa(conf.getConfig(), dd), lwin(new LoadingWindow(nullptr)), dodgeQuestion(new QMessageBox(QMessageBox::Icon::Warning, MainWindow::tr("Dodge?"), MainWindow::tr("Are you sure you want to dodge?"), QMessageBox::Cancel | QMessageBox::Yes, this)), - x11Helper(new X11Helper(this)) { + x11Helper(INIT_X11HELPER) { ui->setupUi(this); QObject::connect(&dd, &DataDragon::fetchingChamp, lwin, &LoadingWindow::setChampion); diff --git a/src/x11helper.cpp b/src/x11helper.cpp index ae54d8b..5233a8c 100644 --- a/src/x11helper.cpp +++ b/src/x11helper.cpp @@ -1,64 +1,3 @@ #include "x11helper.h" -#include - -X11Helper::X11Helper(QObject *parent) : QObject(parent), disp(XOpenDisplay(nullptr)) { - -} - -X11Helper::~X11Helper() { - XCloseDisplay(this->disp); -} - -Window X11Helper::findWindow(const QString& name) { - return searchWindows(DefaultRootWindow(disp), name); -} - -Window X11Helper::searchWindows(Window top, const QString& search) { - { - char* window_name; - if (XFetchName(disp, top, &window_name)) { - QString winName(window_name); - XFree(window_name); - if (search == winName) { - return top; // dont look for kids - } - } - } - - Window* children = nullptr; - Window dummy; - unsigned int nchildren; - if (!XQueryTree(disp, top, &dummy, &dummy, &children, &nchildren)) { - return 0; - } - - for (unsigned int i = 0; i < nchildren; i++) { - Window res = searchWindows(children[i], search); - if(res != 0) { - XFree((char*) children); - return res; - } - } - if (children) { - XFree((char*) children); - } - - return 0; -} - -void X11Helper::map(Window win) { - XMapRaised(disp, win); -} - -void X11Helper::unmap(Window win) { - XUnmapWindow(disp, win); -} - -void X11Helper::setMap(Window win, bool b) { - if(b) { - map(win); - } else { - unmap(win); - } -} +const Window X11Helper::InvalidWindow = 0; diff --git a/src/x11helper_other.cpp b/src/x11helper_other.cpp new file mode 100644 index 0000000..2bb2061 --- /dev/null +++ b/src/x11helper_other.cpp @@ -0,0 +1,25 @@ +#include "x11helper.h" + +#include + +const bool X11Helper::IsSupported = false; + +X11Helper::X11Helper(QObject *parent) : QObject(parent) { + +} + +X11Helper::~X11Helper() {} + +Window X11Helper::findWindow(const QString& name) { + return 0; +} + +Window X11Helper::searchWindows(Window top, const QString& search) { + return 0; +} + +void X11Helper::map(Window win) {} + +void X11Helper::unmap(Window win) {} + +void X11Helper::setMap(Window win, bool b) {} diff --git a/src/x11helper_x11.cpp b/src/x11helper_x11.cpp new file mode 100644 index 0000000..d893783 --- /dev/null +++ b/src/x11helper_x11.cpp @@ -0,0 +1,66 @@ +#include "x11helper.h" + +#include + +const bool X11Helper::IsSupported = true; + +X11Helper::X11Helper(QObject *parent) : QObject(parent), disp(XOpenDisplay(nullptr)) { + +} + +X11Helper::~X11Helper() { + XCloseDisplay(this->disp); +} + +Window X11Helper::findWindow(const QString& name) { + return searchWindows(DefaultRootWindow(disp), name); +} + +Window X11Helper::searchWindows(Window top, const QString& search) { + { + char* window_name; + if (XFetchName(disp, top, &window_name)) { + QString winName(window_name); + XFree(window_name); + if (search == winName) { + return top; // dont look for kids + } + } + } + + Window* children = nullptr; + Window dummy; + unsigned int nchildren; + if (!XQueryTree(disp, top, &dummy, &dummy, &children, &nchildren)) { + return InvalidWindow; + } + + for (unsigned int i = 0; i < nchildren; i++) { + Window res = searchWindows(children[i], search); + if(res != InvalidWindow) { + XFree((char*) children); + return res; + } + } + if (children) { + XFree((char*) children); + } + + return InvalidWindow; +} + +void X11Helper::map(Window win) { + XMapRaised(disp, win); +} + +void X11Helper::unmap(Window win) { + XUnmapWindow(disp, win); +} + +void X11Helper::setMap(Window win, bool b) { + if(b) { + map(win); + } else { + unmap(win); + } +}