diff --git a/include/mainwindow.h b/include/mainwindow.h index 7d38802..ada9c11 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -16,6 +16,7 @@ class QMessageBox; class QTimer; class LoadingWindow; +class X11Helper; class MainWindow : public QMainWindow { @@ -37,6 +38,8 @@ public slots: private slots: void loadingStatus(float); + void toggleLeagueVisibility(); + void toggleMainswitch(bool); void aatoggled(bool); void smitewarntoggled(bool); @@ -63,6 +66,7 @@ private: LolAutoAccept lolaa; LoadingWindow* lwin; QMessageBox* dodgeQuestion; + X11Helper* x11Helper; }; #endif // MAINWINDOW_H diff --git a/include/x11helper.h b/include/x11helper.h new file mode 100644 index 0000000..b28d382 --- /dev/null +++ b/include/x11helper.h @@ -0,0 +1,32 @@ +#ifndef X11HELPER_H +#define X11HELPER_H + +#include + +using Window = unsigned long; +struct _XDisplay; +using Display = struct _XDisplay; + +class X11Helper : public QObject +{ + Q_OBJECT +public: + static Window InvalidWindow; + + explicit X11Helper(QObject* parent = nullptr); + virtual ~X11Helper(); + + Window findWindow(const QString& name); + +public slots: + void map(Window win); + void unmap(Window win); + void setMap(Window win, bool b); + +private: + Window searchWindows(Window top, const QString& search); + + Display* disp; +}; + +#endif // X11HELPER_H diff --git a/lolautoaccept.pro b/lolautoaccept.pro index 93b165d..3be3f7f 100644 --- a/lolautoaccept.pro +++ b/lolautoaccept.pro @@ -66,6 +66,7 @@ SOURCES += \ src/runepagelist.cpp \ src/settingstab.cpp \ src/stagesettings.cpp \ + src/x11helper.cpp \ thirdparty/Log/Log.cpp # platform specific implementations @@ -101,6 +102,7 @@ HEADERS += \ include/runepagelist.h \ include/settingstab.h \ include/stagesettings.h \ + include/x11helper.h \ thirdparty/Log/Log.h FORMS += \ @@ -130,6 +132,9 @@ QMAKE_EXTRA_TARGETS += updatelang # build AppImage unix { + DEFINES += X11SUPPORT=1 + LIBS += -lX11 + linuxdeploy-x86_64.AppImage.commands = wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage && chmod u+x linuxdeploy-x86_64.AppImage resources/lolautoaccept.png.depends = resources/lolautoaccept.svg diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6695161..7a305a1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -8,10 +8,12 @@ #include #include "loadingwindow.h" +#include "x11helper.h" 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)) { + 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)) { ui->setupUi(this); QObject::connect(&dd, &DataDragon::fetchingChamp, lwin, &LoadingWindow::setChampion); @@ -27,6 +29,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui QObject::connect(&lolaa, &LolAutoAccept::statusChanged, this, &MainWindow::lolaaStatusChanged); QObject::connect(&lolaa, &LolAutoAccept::positionChanged, this, &MainWindow::onPosChange); + QObject::connect(ui->hideLeague, &QCheckBox::stateChanged, this, &MainWindow::toggleLeagueVisibility); + saveTimer->setInterval(std::chrono::minutes(1)); saveTimer->setSingleShot(true); QObject::connect(saveTimer, &QTimer::timeout, this, &MainWindow::saveConfig); @@ -97,6 +101,20 @@ void MainWindow::loadingStatus(float f) { } } +void MainWindow::toggleLeagueVisibility() { + if(x11Helper) { + const bool shouldBeHidden = ui->hideLeague->isChecked(); + Window win = x11Helper->findWindow("League of Legends"); + qInfo() << "LeagueClient win id:" << win; + if(win != 0) { + x11Helper->setMap(win, shouldBeHidden); + } else { + // TODO: show error in status bar? + // TODO: reset checkbox to unchecked? + } + } +} + void MainWindow::toggleMainswitch(bool state) { qDebug() << "mainswitch toggled: " << state; diff --git a/src/x11helper.cpp b/src/x11helper.cpp new file mode 100644 index 0000000..ae54d8b --- /dev/null +++ b/src/x11helper.cpp @@ -0,0 +1,64 @@ +#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); + } +} diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 5c2bf16..fbdb8e2 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -62,6 +62,30 @@ 9 + + + + Write a Text as soon as you are in a champ select lobby. + + + Auto Write + + + + + + + false + + + Dodge without closing the client. +You will still be punished. + + + Dodge + + + @@ -75,7 +99,7 @@ - + Qt::NoContextMenu @@ -97,7 +121,7 @@ - + QTabWidget::North @@ -190,17 +214,7 @@ - - - - Write a Text as soon as you are in a champ select lobby. - - - Auto Write - - - - + @@ -237,6 +251,13 @@ + + + + Enable LoL-Auto-Accept + + + @@ -247,24 +268,15 @@ - - - - Enable LoL-Auto-Accept - - - - - - - false - + + - Dodge without closing the client. -You will still be punished. + This hides the League Client. +It will not anoy you anymore. +Only available on Linux with X11. - Dodge + Hide League Client