check aspect ratio
This commit is contained in:
parent
b009411f55
commit
2b4d718481
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue