-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbusinterface.cpp
317 lines (275 loc) · 9.76 KB
/
dbusinterface.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2012 Martin Gräßlin <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
// own
#include "dbusinterface.h"
#include "compositingadaptor.h"
// kwin
#include "abstract_client.h"
#include "atoms.h"
#include "composite.h"
#include "debug_console.h"
#include "main.h"
#include "placement.h"
#include "platform.h"
#include "kwinadaptor.h"
#include "scene.h"
#include "workspace.h"
#include "virtualdesktops.h"
#ifdef KWIN_BUILD_ACTIVITIES
#include "activities.h"
#endif
// Qt
#include <QOpenGLContext>
#include <QDBusServiceWatcher>
namespace KWin
{
DBusInterface::DBusInterface(QObject *parent)
: QObject(parent)
, m_serviceName(QStringLiteral("org.kde.KWin"))
{
(void) new KWinAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject(QStringLiteral("/KWin"), this);
const QByteArray dBusSuffix = qgetenv("KWIN_DBUS_SERVICE_SUFFIX");
if (!dBusSuffix.isNull()) {
m_serviceName = m_serviceName + QLatin1Char('.') + dBusSuffix;
}
if (!dbus.registerService(m_serviceName)) {
QDBusServiceWatcher *dog = new QDBusServiceWatcher(m_serviceName, dbus, QDBusServiceWatcher::WatchForUnregistration, this);
connect (dog, SIGNAL(serviceUnregistered(QString)), SLOT(becomeKWinService(QString)));
} else {
announceService();
}
dbus.connect(QString(), QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig"),
Workspace::self(), SLOT(slotReloadConfig()));
connect(kwinApp(), &Application::x11ConnectionChanged, this, &DBusInterface::announceService);
}
void DBusInterface::becomeKWinService(const QString &service)
{
// TODO: this watchdog exists to make really safe that we at some point get the service
// but it's probably no longer needed since we explicitly unregister the service with the deconstructor
if (service == m_serviceName && QDBusConnection::sessionBus().registerService(m_serviceName) && sender()) {
sender()->deleteLater(); // bye doggy :'(
announceService();
}
}
DBusInterface::~DBusInterface()
{
QDBusConnection::sessionBus().unregisterService(m_serviceName);
// KApplication automatically also grabs org.kde.kwin, so it's often been used externally - ensure to free it as well
QDBusConnection::sessionBus().unregisterService(QStringLiteral("org.kde.kwin"));
if (kwinApp()->x11Connection()) {
xcb_delete_property(kwinApp()->x11Connection(), kwinApp()->x11RootWindow(), atoms->kwin_dbus_service);
}
}
void DBusInterface::announceService()
{
if (!kwinApp()->x11Connection()) {
return;
}
const QByteArray service = m_serviceName.toUtf8();
xcb_change_property(kwinApp()->x11Connection(), XCB_PROP_MODE_REPLACE, kwinApp()->x11RootWindow(), atoms->kwin_dbus_service,
atoms->utf8_string, 8, service.size(), service.constData());
}
// wrap void methods with no arguments to Workspace
#define WRAP(name) \
void DBusInterface::name() \
{\
Workspace::self()->name();\
}
WRAP(reconfigure)
#undef WRAP
void DBusInterface::killWindow()
{
Workspace::self()->slotKillWindow();
}
#define WRAP(name) \
void DBusInterface::name() \
{\
Placement::self()->name();\
}
WRAP(cascadeDesktop)
WRAP(unclutterDesktop)
#undef WRAP
// wrap returning methods with no arguments to Workspace
#define WRAP( rettype, name ) \
rettype DBusInterface::name( ) \
{\
return Workspace::self()->name(); \
}
WRAP(QString, supportInformation)
#undef WRAP
bool DBusInterface::startActivity(const QString &in0)
{
#ifdef KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
return false;
}
return Activities::self()->start(in0);
#else
Q_UNUSED(in0)
return false;
#endif
}
bool DBusInterface::stopActivity(const QString &in0)
{
#ifdef KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
return false;
}
return Activities::self()->stop(in0);
#else
Q_UNUSED(in0)
return false;
#endif
}
int DBusInterface::currentDesktop()
{
return VirtualDesktopManager::self()->current();
}
bool DBusInterface::setCurrentDesktop(int desktop)
{
return VirtualDesktopManager::self()->setCurrent(desktop);
}
void DBusInterface::nextDesktop()
{
VirtualDesktopManager::self()->moveTo<DesktopNext>();
}
void DBusInterface::previousDesktop()
{
VirtualDesktopManager::self()->moveTo<DesktopPrevious>();
}
void DBusInterface::showDebugConsole()
{
DebugConsole *console = new DebugConsole;
console->show();
}
QVariantMap DBusInterface::queryWindowInfo()
{
m_replyQueryWindowInfo = message();
setDelayedReply(true);
kwinApp()->platform()->startInteractiveWindowSelection(
[this] (Toplevel *t) {
if (auto c = qobject_cast<AbstractClient*>(t)) {
const QVariantMap ret{
{QStringLiteral("resourceClass"), c->resourceClass()},
{QStringLiteral("resourceName"), c->resourceName()},
{QStringLiteral("role"), c->windowRole()},
{QStringLiteral("caption"), c->captionNormal()},
{QStringLiteral("clientMachine"), c->wmClientMachine(true)},
{QStringLiteral("type"), c->windowType()},
{QStringLiteral("x"), c->x()},
{QStringLiteral("y"), c->y()},
{QStringLiteral("width"), c->width()},
{QStringLiteral("height"), c->height()},
{QStringLiteral("x11DesktopNumber"), c->desktop()},
{QStringLiteral("minimized"), c->isMinimized()},
{QStringLiteral("shaded"), c->isShade()},
{QStringLiteral("fullscreen"), c->isFullScreen()},
{QStringLiteral("keepAbove"), c->keepAbove()},
{QStringLiteral("keepBelow"), c->keepBelow()},
{QStringLiteral("noBorder"), c->noBorder()},
{QStringLiteral("skipTaskbar"), c->skipTaskbar()},
{QStringLiteral("skipPager"), c->skipPager()},
{QStringLiteral("skipSwitcher"), c->skipSwitcher()},
{QStringLiteral("maximizeHorizontal"), c->maximizeMode() & MaximizeHorizontal},
{QStringLiteral("maximizeVertical"), c->maximizeMode() & MaximizeVertical}
};
QDBusConnection::sessionBus().send(m_replyQueryWindowInfo.createReply(ret));
} else {
QDBusConnection::sessionBus().send(m_replyQueryWindowInfo.createErrorReply(QString(), QString()));
}
}
);
return QVariantMap{};
}
CompositorDBusInterface::CompositorDBusInterface(Compositor *parent)
: QObject(parent)
, m_compositor(parent)
{
connect(m_compositor, &Compositor::compositingToggled, this, &CompositorDBusInterface::compositingToggled);
new CompositingAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject(QStringLiteral("/Compositor"), this);
dbus.connect(QString(), QStringLiteral("/Compositor"), QStringLiteral("org.kde.kwin.Compositing"),
QStringLiteral("reinit"), m_compositor, SLOT(slotReinitialize()));
}
QString CompositorDBusInterface::compositingNotPossibleReason() const
{
return kwinApp()->platform()->compositingNotPossibleReason();
}
QString CompositorDBusInterface::compositingType() const
{
if (!m_compositor->hasScene()) {
return QStringLiteral("none");
}
switch (m_compositor->scene()->compositingType()) {
case XRenderCompositing:
return QStringLiteral("xrender");
case OpenGL2Compositing:
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
return QStringLiteral("gles");
} else {
return QStringLiteral("gl2");
}
case QPainterCompositing:
return QStringLiteral("qpainter");
case NoCompositing:
default:
return QStringLiteral("none");
}
}
bool CompositorDBusInterface::isActive() const
{
return m_compositor->isActive();
}
bool CompositorDBusInterface::isCompositingPossible() const
{
return kwinApp()->platform()->compositingPossible();
}
bool CompositorDBusInterface::isOpenGLBroken() const
{
return kwinApp()->platform()->openGLCompositingIsBroken();
}
bool CompositorDBusInterface::platformRequiresCompositing() const
{
return kwinApp()->platform()->requiresCompositing();
}
void CompositorDBusInterface::resume()
{
m_compositor->resume(Compositor::ScriptSuspend);
}
void CompositorDBusInterface::suspend()
{
m_compositor->suspend(Compositor::ScriptSuspend);
}
QStringList CompositorDBusInterface::supportedOpenGLPlatformInterfaces() const
{
QStringList interfaces;
bool supportsGlx = false;
#if HAVE_EPOXY_GLX
supportsGlx = (kwinApp()->operationMode() == Application::OperationModeX11);
#endif
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
supportsGlx = false;
}
if (supportsGlx) {
interfaces << QStringLiteral("glx");
}
interfaces << QStringLiteral("egl");
return interfaces;
}
} // namespace