Compare commits

...

3 Commits

Author SHA1 Message Date
mrbesen 2b4d718481
check aspect ratio 2023-10-21 21:30:25 +02:00
mrbesen b009411f55
windows compat 2023-09-06 21:17:05 +02:00
mrbesen 16e1813f95
start "hide league client" feature 2023-09-05 22:20:06 +02:00
8 changed files with 218 additions and 31 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

35
include/x11helper.h Normal file
View File

@ -0,0 +1,35 @@
#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 const Window InvalidWindow;
static const bool IsSupported;
explicit X11Helper(QObject* parent = nullptr);
virtual ~X11Helper();
Window findWindow(const QString& name, float aspektRatio = 0.0);
public slots:
void map(Window win);
void unmap(Window win);
void setMap(Window win, bool b);
private:
Window searchWindows(Window top, const QString& search, float aspektRatio);
#ifdef X11SUPPORT
Display* disp;
#endif
};
#endif // X11HELPER_H

View File

@ -66,11 +66,12 @@ SOURCES += \
src/runepagelist.cpp \
src/settingstab.cpp \
src/stagesettings.cpp \
src/x11helper.cpp \
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 \
@ -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,12 +8,22 @@
#include <Log.h>
#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)) {
dodgeQuestion(new QMessageBox(QMessageBox::Icon::Warning, MainWindow::tr("Dodge?"), MainWindow::tr("Are you sure you want to dodge?"), QMessageBox::Cancel | QMessageBox::Yes, this)),
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);
@ -27,6 +37,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 +109,20 @@ void MainWindow::loadingStatus(float f) {
}
}
void MainWindow::toggleLeagueVisibility() {
if(x11Helper) {
const bool shouldBeHidden = ui->hideLeague->isChecked();
Window win = x11Helper->findWindow("League of Legends", 1280.0/720.0);
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;

3
src/x11helper.cpp Normal file
View File

@ -0,0 +1,3 @@
#include "x11helper.h"
const Window X11Helper::InvalidWindow = 0;

25
src/x11helper_other.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "x11helper.h"
#include <X11/Xlib.h>
const bool X11Helper::IsSupported = false;
X11Helper::X11Helper(QObject *parent) : QObject(parent) {
}
X11Helper::~X11Helper() {}
Window X11Helper::findWindow(const QString&, float) {
return InvalidWindow;
}
Window X11Helper::searchWindows(Window, const QString&, float) {
return InvalidWindow;
}
void X11Helper::map(Window win) {}
void X11Helper::unmap(Window win) {}
void X11Helper::setMap(Window win, bool b) {}

77
src/x11helper_x11.cpp Normal file
View File

@ -0,0 +1,77 @@
#include "x11helper.h"
#include <X11/Xlib.h>
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, float aspektRatio) {
return searchWindows(DefaultRootWindow(disp), name, aspektRatio);
}
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) {
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;
}
}
}
}
}
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, aspektRatio);
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);
}
}

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>