67 lines
1.2 KiB
C++
67 lines
1.2 KiB
C++
|
#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) {
|
||
|
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 InvalidWindow;
|
||
|
}
|
||
|
|
||
|
for (unsigned int i = 0; i < nchildren; i++) {
|
||
|
Window res = searchWindows(children[i], search);
|
||
|
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);
|
||
|
}
|
||
|
}
|