start "hide league client" feature

This commit is contained in:
mrbesen 2023-09-05 22:20:06 +02:00
parent 90c328aa4b
commit 16e1813f95
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
6 changed files with 164 additions and 29 deletions

View File

@ -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

32
include/x11helper.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef X11HELPER_H
#define X11HELPER_H
#include <QObject>
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

View File

@ -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

View File

@ -8,10 +8,12 @@
#include <Log.h>
#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;

64
src/x11helper.cpp Normal file
View File

@ -0,0 +1,64 @@
#include "x11helper.h"
#include <X11/Xlib.h>
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);
}
}

View File

@ -62,6 +62,30 @@
<property name="spacing">
<number>9</number>
</property>
<item row="6" column="0">
<widget class="QCheckBox" name="enableAutoWrite">
<property name="toolTip">
<string>Write a Text as soon as you are in a champ select lobby.</string>
</property>
<property name="text">
<string>Auto Write</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QPushButton" name="dodgeBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Dodge without closing the client.
You will still be punished.</string>
</property>
<property name="text">
<string>Dodge</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="enableSmiteWarning">
<property name="toolTip">
@ -75,7 +99,7 @@
</property>
</widget>
</item>
<item row="0" column="1" rowspan="6">
<item row="0" column="1" rowspan="7">
<widget class="QLabel" name="copyrightlabel">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
@ -97,7 +121,7 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::North</enum>
@ -190,17 +214,7 @@
</widget>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="enableAutoWrite">
<property name="toolTip">
<string>Write a Text as soon as you are in a champ select lobby.</string>
</property>
<property name="text">
<string>Auto Write</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QTextEdit" name="autoWriteText">
<property name="minimumSize">
<size>
@ -237,6 +251,13 @@
</property>
</widget>
</item>
<item row="2" column="0" rowspan="2">
<widget class="QCheckBox" name="enableAll">
<property name="text">
<string>Enable LoL-Auto-Accept</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="mainswitch">
<property name="toolTip">
@ -247,24 +268,15 @@
</property>
</widget>
</item>
<item row="2" column="0" rowspan="2">
<widget class="QCheckBox" name="enableAll">
<property name="text">
<string>Enable LoL-Auto-Accept</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QPushButton" name="dodgeBtn">
<property name="enabled">
<bool>false</bool>
</property>
<item row="5" column="0">
<widget class="QCheckBox" name="hideLeague">
<property name="toolTip">
<string>Dodge without closing the client.
You will still be punished.</string>
<string>This hides the League Client.
It will not anoy you anymore.
Only available on Linux with X11.</string>
</property>
<property name="text">
<string>Dodge</string>
<string>Hide League Client</string>
</property>
</widget>
</item>