diff --git a/include/x11helper.h b/include/x11helper.h index 17a0841..35a954c 100644 --- a/include/x11helper.h +++ b/include/x11helper.h @@ -17,7 +17,7 @@ public: explicit X11Helper(QObject* parent = nullptr); virtual ~X11Helper(); - Window findWindow(const QString& name); + Window findWindow(const QString& name, float aspektRatio = 0.0); public slots: void map(Window win); @@ -25,7 +25,7 @@ public slots: void setMap(Window win, bool b); private: - Window searchWindows(Window top, const QString& search); + Window searchWindows(Window top, const QString& search, float aspektRatio); #ifdef X11SUPPORT Display* disp; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8a8daaf..7cf5fa3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,6 +22,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui x11Helper(INIT_X11HELPER) { ui->setupUi(this); + ui->hideLeague->setEnabled(X11Helper::IsSupported); + QObject::connect(&dd, &DataDragon::fetchingChamp, lwin, &LoadingWindow::setChampion); QObject::connect(&dd, &DataDragon::loading, lwin, &LoadingWindow::setProgress); QObject::connect(&dd, &DataDragon::loading, this, &MainWindow::loadingStatus); @@ -110,7 +112,7 @@ void MainWindow::loadingStatus(float f) { void MainWindow::toggleLeagueVisibility() { if(x11Helper) { const bool shouldBeHidden = ui->hideLeague->isChecked(); - Window win = x11Helper->findWindow("League of Legends"); + Window win = x11Helper->findWindow("League of Legends", 1280.0/720.0); qInfo() << "LeagueClient win id:" << win; if(win != 0) { x11Helper->setMap(win, shouldBeHidden); diff --git a/src/x11helper_other.cpp b/src/x11helper_other.cpp index 2bb2061..d8c410b 100644 --- a/src/x11helper_other.cpp +++ b/src/x11helper_other.cpp @@ -10,12 +10,12 @@ X11Helper::X11Helper(QObject *parent) : QObject(parent) { X11Helper::~X11Helper() {} -Window X11Helper::findWindow(const QString& name) { - return 0; +Window X11Helper::findWindow(const QString&, float) { + return InvalidWindow; } -Window X11Helper::searchWindows(Window top, const QString& search) { - return 0; +Window X11Helper::searchWindows(Window, const QString&, float) { + return InvalidWindow; } void X11Helper::map(Window win) {} diff --git a/src/x11helper_x11.cpp b/src/x11helper_x11.cpp index d893783..e8d0dc7 100644 --- a/src/x11helper_x11.cpp +++ b/src/x11helper_x11.cpp @@ -12,18 +12,29 @@ X11Helper::~X11Helper() { XCloseDisplay(this->disp); } -Window X11Helper::findWindow(const QString& name) { - return searchWindows(DefaultRootWindow(disp), name); +Window X11Helper::findWindow(const QString& name, float aspektRatio) { + return searchWindows(DefaultRootWindow(disp), name, aspektRatio); } -Window X11Helper::searchWindows(Window top, const QString& search) { +Window X11Helper::searchWindows(Window top, const QString& search, float aspektRatio) { { 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 + + if(aspektRatio == 0.0) { + return top; // dont look for kids + } + + XWindowAttributes attribs; + if(XGetWindowAttributes(disp, top, &attribs)) { + const float winAspektRation = attribs.width / (float) attribs.height; + if(qAbs(winAspektRation - aspektRatio) < aspektRatio/10.0) { + return top; + } + } } } } @@ -36,7 +47,7 @@ Window X11Helper::searchWindows(Window top, const QString& search) { } for (unsigned int i = 0; i < nchildren; i++) { - Window res = searchWindows(children[i], search); + Window res = searchWindows(children[i], search, aspektRatio); if(res != InvalidWindow) { XFree((char*) children); return res;