2018-11-07 11:10:38 +00:00
|
|
|
#include "utils.hpp"
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QtCore>
|
|
|
|
|
2018-11-10 13:50:13 +00:00
|
|
|
QString getPlatformName()
|
2018-11-07 11:10:38 +00:00
|
|
|
{
|
2018-11-10 13:50:13 +00:00
|
|
|
QGuiApplication* qapp = qobject_cast<QGuiApplication*>(QCoreApplication::instance());
|
2018-11-07 11:10:38 +00:00
|
|
|
return qapp->platformName();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <QX11Info>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#include <X11/extensions/dpms.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
2018-11-10 13:50:13 +00:00
|
|
|
void SetDPMS(bool on)
|
2018-11-07 11:10:38 +00:00
|
|
|
{
|
2018-11-07 17:22:18 +00:00
|
|
|
qDebug() << getPlatformName();
|
|
|
|
if (getPlatformName() != "xcb") {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-07 11:10:38 +00:00
|
|
|
Display* dpy = QX11Info::display();
|
|
|
|
if (on) {
|
|
|
|
DPMSEnable(dpy);
|
|
|
|
qDebug() << "Enabled DPMS.";
|
|
|
|
} else {
|
|
|
|
DPMSDisable(dpy);
|
|
|
|
qDebug() << "Disabled DPMS.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-10 13:50:13 +00:00
|
|
|
void AlwaysOnTop(WId wid, bool on)
|
2018-11-07 11:10:38 +00:00
|
|
|
{
|
|
|
|
qDebug() << "On Top:" << on;
|
|
|
|
Display* display = QX11Info::display();
|
|
|
|
XEvent event;
|
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
event.xclient.serial = 0;
|
|
|
|
event.xclient.send_event = True;
|
|
|
|
event.xclient.display = display;
|
|
|
|
event.xclient.window = wid;
|
|
|
|
event.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", False);
|
|
|
|
event.xclient.format = 32;
|
|
|
|
|
|
|
|
event.xclient.data.l[0] = on;
|
|
|
|
event.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_ABOVE", False);
|
|
|
|
event.xclient.data.l[2] = 0;
|
|
|
|
event.xclient.data.l[3] = 0;
|
|
|
|
event.xclient.data.l[4] = 0;
|
|
|
|
|
2018-11-10 13:50:13 +00:00
|
|
|
XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &event);
|
2018-11-07 11:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2018-11-10 13:50:13 +00:00
|
|
|
void AlwaysOnTop(WId wid, bool on)
|
2018-11-07 11:10:38 +00:00
|
|
|
{
|
|
|
|
qDebug() << "Can't set on top for platform: " << getPlatformName();
|
|
|
|
}
|
|
|
|
|
2018-11-10 13:50:13 +00:00
|
|
|
void SetDPMS(bool on)
|
2018-11-07 11:10:38 +00:00
|
|
|
{
|
|
|
|
qDebug() << "Can't set DPMS for platform: " << getPlatformName();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|