-
Notifications
You must be signed in to change notification settings - Fork 1
/
screeninfo.cpp
152 lines (135 loc) · 3.77 KB
/
screeninfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <QGuiApplication>
#include <QScreen>
#include <QDebug>
#include <QQuickItem>
#include <QQuickWindow>
#include "screeninfo.h"
#include "screeninfoscreen.h"
#ifdef Q_OS_LINUX
#include <X11/extensions/Xinerama.h>
#include <X11/Xlib.h>
#include <X11/X.h>
#endif
ScreenInfo::ScreenInfo(QObject *parent) :
QObject(parent),
m_fullScreen(false),
m_topMost(0),
m_bottomMost(0),
m_leftMost(0),
m_rightMost(0)
{
// QList<QScreen*> screenList = QGuiApplication::screens();
// int id = 0;
// for(QScreen *screen : screenList) {
Display* display;
display = XOpenDisplay(NULL);
int snumber = 0;
XineramaScreenInfo *screens = XineramaQueryScreens(display, &snumber);
for (int i=0; i<snumber; ++i)
{
const XineramaScreenInfo& screen = screens[i];
QRect geometry(screen.x_org, screen.y_org, screen.width, screen.height);
ScreenInfoScreen* screenInfoScreen = new ScreenInfoScreen(geometry, i, this);
m_screens.append(screenInfoScreen);
emit screensChanged();
}
}
void ScreenInfo::apply() {
QQuickItem *parentItem = dynamic_cast<QQuickItem*>(parent());
if(!parentItem) {
qWarning() << "Could not find parent window!";
return;
}
if(!parentItem->window()) {
qWarning() << "Could not find parent window!";
return;
}
qDebug() << "Applying new monitor settings, "
<< "topMost:" << m_topMost << "bottomMost:" << m_bottomMost
<< "leftMost:" << m_leftMost << "rightMost" << m_rightMost;
QQuickWindow* rootWindow = parentItem->window();
if(m_fullScreen) {
#ifdef Q_OS_LINUX
Display* display;
display = XOpenDisplay(NULL);
XSynchronize(display, True);
Atom fullmons = XInternAtom(display, "_NET_WM_FULLSCREEN_MONITORS", False);
XEvent xev2;
memset(&xev2, 0, sizeof(xev2));
xev2.type = ClientMessage;
xev2.xclient.window = parentItem->window()->winId();
xev2.xclient.message_type = fullmons;
xev2.xclient.format = 32;
xev2.xclient.data.l[0] = m_topMost; /* your topmost monitor number */
xev2.xclient.data.l[1] = m_bottomMost; /* bottommost */
xev2.xclient.data.l[2] = m_leftMost; /* leftmost */
xev2.xclient.data.l[3] = m_rightMost; /* rightmost */
xev2.xclient.data.l[4] = 0; /* source indication */
XSendEvent (display, DefaultRootWindow(display), False,
SubstructureRedirectMask | SubstructureNotifyMask, &xev2);
XFlush(display);
#endif
rootWindow->setVisibility(QQuickWindow::FullScreen);
} else {
rootWindow->setVisibility(QQuickWindow::Windowed);
}
}
QQmlListProperty<ScreenInfoScreen> ScreenInfo::screens()
{
return QQmlListProperty<ScreenInfoScreen>(this, m_screens);
}
bool ScreenInfo::fullScreen() const
{
return m_fullScreen;
}
int ScreenInfo::topMost() const
{
return m_topMost;
}
int ScreenInfo::bottomMost() const
{
return m_bottomMost;
}
int ScreenInfo::leftMost() const
{
return m_leftMost;
}
int ScreenInfo::rightMost() const
{
return m_rightMost;
}
void ScreenInfo::setFullScreen(bool arg)
{
if (m_fullScreen != arg) {
m_fullScreen = arg;
emit fullScreenChanged(arg);
}
}
void ScreenInfo::setTopMost(int arg)
{
if (m_topMost != arg) {
m_topMost = arg;
emit topMostChanged(arg);
}
}
void ScreenInfo::setBottomMost(int arg)
{
if (m_bottomMost != arg) {
m_bottomMost = arg;
emit bottomMostChanged(arg);
}
}
void ScreenInfo::setLeftMost(int arg)
{
if (m_leftMost != arg) {
m_leftMost = arg;
emit leftMostChanged(arg);
}
}
void ScreenInfo::setRightMost(int arg)
{
if (m_rightMost != arg) {
m_rightMost = arg;
emit rightMostChanged(arg);
}
}