2012-08-30 06:20:26 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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"
|
2014-06-02 06:51:28 +00:00
|
|
|
#include "compositingadaptor.h"
|
2012-12-29 23:15:30 +00:00
|
|
|
|
2012-08-30 06:20:26 +00:00
|
|
|
// kwin
|
2015-01-23 08:06:05 +00:00
|
|
|
#include "atoms.h"
|
2014-06-02 06:51:28 +00:00
|
|
|
#include "composite.h"
|
|
|
|
#include "compositingprefs.h"
|
2016-03-14 09:23:52 +00:00
|
|
|
#include "debug_console.h"
|
2014-06-02 06:51:28 +00:00
|
|
|
#include "main.h"
|
2013-07-28 15:42:21 +00:00
|
|
|
#include "placement.h"
|
2012-08-30 06:20:26 +00:00
|
|
|
#include "kwinadaptor.h"
|
2014-06-02 06:51:28 +00:00
|
|
|
#include "scene.h"
|
2012-08-30 06:20:26 +00:00
|
|
|
#include "workspace.h"
|
2012-11-16 07:23:47 +00:00
|
|
|
#include "virtualdesktops.h"
|
2013-04-04 14:14:12 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
|
|
|
#include "activities.h"
|
|
|
|
#endif
|
2012-08-30 06:20:26 +00:00
|
|
|
|
2012-12-29 23:15:30 +00:00
|
|
|
// Qt
|
2015-10-30 12:18:30 +00:00
|
|
|
#include <QOpenGLContext>
|
2012-12-29 23:15:30 +00:00
|
|
|
#include <QDBusServiceWatcher>
|
|
|
|
|
2012-08-30 06:20:26 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
DBusInterface::DBusInterface(QObject *parent)
|
|
|
|
: QObject(parent)
|
2014-10-13 20:35:04 +00:00
|
|
|
, m_serviceName(QStringLiteral("org.kde.KWin"))
|
2012-08-30 06:20:26 +00:00
|
|
|
{
|
|
|
|
(void) new KWinAdaptor(this);
|
|
|
|
|
|
|
|
QDBusConnection dbus = QDBusConnection::sessionBus();
|
2013-07-23 05:02:52 +00:00
|
|
|
dbus.registerObject(QStringLiteral("/KWin"), this);
|
2014-10-13 20:35:04 +00:00
|
|
|
const QByteArray dBusSuffix = qgetenv("KWIN_DBUS_SERVICE_SUFFIX");
|
|
|
|
if (!dBusSuffix.isNull()) {
|
2015-11-05 14:14:06 +00:00
|
|
|
m_serviceName = m_serviceName + QLatin1Char('.') + dBusSuffix;
|
2014-10-13 20:35:04 +00:00
|
|
|
}
|
|
|
|
if (!dbus.registerService(m_serviceName)) {
|
|
|
|
QDBusServiceWatcher *dog = new QDBusServiceWatcher(m_serviceName, dbus, QDBusServiceWatcher::WatchForUnregistration, this);
|
2013-05-11 12:09:15 +00:00
|
|
|
connect (dog, SIGNAL(serviceUnregistered(QString)), SLOT(becomeKWinService(QString)));
|
2015-01-23 08:06:05 +00:00
|
|
|
} else {
|
|
|
|
announceService();
|
2012-12-29 23:15:30 +00:00
|
|
|
}
|
2013-07-23 05:02:52 +00:00
|
|
|
dbus.connect(QString(), QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig"),
|
2012-08-30 06:20:26 +00:00
|
|
|
Workspace::self(), SLOT(slotReloadConfig()));
|
|
|
|
}
|
|
|
|
|
2012-12-29 23:15:30 +00:00
|
|
|
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
|
2014-10-13 20:35:04 +00:00
|
|
|
if (service == m_serviceName && QDBusConnection::sessionBus().registerService(m_serviceName) && sender()) {
|
2012-12-29 23:15:30 +00:00
|
|
|
sender()->deleteLater(); // bye doggy :'(
|
2015-01-23 08:06:05 +00:00
|
|
|
announceService();
|
2012-12-29 23:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-30 06:20:26 +00:00
|
|
|
DBusInterface::~DBusInterface()
|
|
|
|
{
|
2014-10-13 20:35:04 +00:00
|
|
|
QDBusConnection::sessionBus().unregisterService(m_serviceName);
|
2012-12-29 23:15:30 +00:00
|
|
|
// KApplication automatically also grabs org.kde.kwin, so it's often been used externally - ensure to free it as well
|
2013-07-23 05:02:52 +00:00
|
|
|
QDBusConnection::sessionBus().unregisterService(QStringLiteral("org.kde.kwin"));
|
2015-01-23 08:06:05 +00:00
|
|
|
xcb_delete_property(connection(), rootWindow(), atoms->kwin_dbus_service);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBusInterface::announceService()
|
|
|
|
{
|
|
|
|
const QByteArray service = m_serviceName.toUtf8();
|
|
|
|
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, rootWindow(), atoms->kwin_dbus_service,
|
|
|
|
atoms->utf8_string, 8, service.size(), service.constData());
|
2012-08-30 06:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// wrap void methods with no arguments to Workspace
|
|
|
|
#define WRAP(name) \
|
|
|
|
void DBusInterface::name() \
|
|
|
|
{\
|
|
|
|
Workspace::self()->name();\
|
|
|
|
}
|
|
|
|
|
|
|
|
WRAP(reconfigure)
|
2012-11-22 10:07:33 +00:00
|
|
|
|
|
|
|
#undef WRAP
|
|
|
|
|
2013-04-08 12:30:24 +00:00
|
|
|
void DBusInterface::killWindow()
|
|
|
|
{
|
|
|
|
Workspace::self()->slotKillWindow();
|
|
|
|
}
|
|
|
|
|
2012-11-22 10:07:33 +00:00
|
|
|
#define WRAP(name) \
|
|
|
|
void DBusInterface::name() \
|
|
|
|
{\
|
|
|
|
Placement::self()->name();\
|
|
|
|
}
|
|
|
|
|
|
|
|
WRAP(cascadeDesktop)
|
2012-08-30 06:20:26 +00:00
|
|
|
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
|
|
|
|
|
2013-04-04 14:14:12 +00:00
|
|
|
bool DBusInterface::startActivity(const QString &in0)
|
|
|
|
{
|
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2015-07-07 09:48:42 +00:00
|
|
|
if (!Activities::self()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-04 14:14:12 +00:00
|
|
|
return Activities::self()->start(in0);
|
|
|
|
#else
|
2014-11-21 15:48:39 +00:00
|
|
|
Q_UNUSED(in0)
|
2013-04-04 14:14:12 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
2012-08-30 06:20:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 14:14:12 +00:00
|
|
|
bool DBusInterface::stopActivity(const QString &in0)
|
|
|
|
{
|
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2015-07-07 09:48:42 +00:00
|
|
|
if (!Activities::self()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-04 14:14:12 +00:00
|
|
|
return Activities::self()->stop(in0);
|
|
|
|
#else
|
2014-11-21 15:48:39 +00:00
|
|
|
Q_UNUSED(in0)
|
2013-04-04 14:14:12 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2012-08-30 06:20:26 +00:00
|
|
|
|
2012-11-16 07:23:47 +00:00
|
|
|
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>();
|
|
|
|
}
|
|
|
|
|
2016-03-14 09:23:52 +00:00
|
|
|
void DBusInterface::showDebugConsole()
|
|
|
|
{
|
|
|
|
DebugConsole *console = new DebugConsole;
|
|
|
|
console->show();
|
|
|
|
}
|
2014-06-02 06:51:28 +00:00
|
|
|
|
|
|
|
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 CompositingPrefs::compositingNotPossibleReason();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CompositorDBusInterface::compositingType() const
|
|
|
|
{
|
|
|
|
if (!m_compositor->hasScene()) {
|
|
|
|
return QStringLiteral("none");
|
|
|
|
}
|
|
|
|
switch (m_compositor->scene()->compositingType()) {
|
|
|
|
case XRenderCompositing:
|
|
|
|
return QStringLiteral("xrender");
|
|
|
|
case OpenGL2Compositing:
|
2015-10-30 12:18:30 +00:00
|
|
|
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
|
|
|
|
return QStringLiteral("gles");
|
|
|
|
} else {
|
|
|
|
return QStringLiteral("gl2");
|
|
|
|
}
|
2014-06-02 06:51:28 +00:00
|
|
|
case QPainterCompositing:
|
2015-01-24 02:13:45 +00:00
|
|
|
return QStringLiteral("qpainter");
|
2014-06-02 06:51:28 +00:00
|
|
|
case NoCompositing:
|
|
|
|
default:
|
|
|
|
return QStringLiteral("none");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompositorDBusInterface::isActive() const
|
|
|
|
{
|
|
|
|
return m_compositor->isActive();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompositorDBusInterface::isCompositingPossible() const
|
|
|
|
{
|
|
|
|
return CompositingPrefs::compositingPossible();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompositorDBusInterface::isOpenGLBroken() const
|
|
|
|
{
|
|
|
|
return CompositingPrefs::openGlIsBroken();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositorDBusInterface::resume()
|
|
|
|
{
|
|
|
|
m_compositor->resume(Compositor::ScriptSuspend);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositorDBusInterface::suspend()
|
|
|
|
{
|
|
|
|
m_compositor->suspend(Compositor::ScriptSuspend);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList CompositorDBusInterface::supportedOpenGLPlatformInterfaces() const
|
|
|
|
{
|
|
|
|
QStringList interfaces;
|
2015-10-30 10:50:31 +00:00
|
|
|
bool supportsGlx = false;
|
|
|
|
#if HAVE_EPOXY_GLX
|
|
|
|
supportsGlx = (kwinApp()->operationMode() == Application::OperationModeX11);
|
|
|
|
#endif
|
2015-10-30 12:18:30 +00:00
|
|
|
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
|
|
|
|
supportsGlx = false;
|
|
|
|
}
|
2014-06-02 06:51:28 +00:00
|
|
|
if (supportsGlx) {
|
|
|
|
interfaces << QStringLiteral("glx");
|
|
|
|
}
|
|
|
|
interfaces << QStringLiteral("egl");
|
|
|
|
return interfaces;
|
|
|
|
}
|
|
|
|
|
2012-08-30 06:20:26 +00:00
|
|
|
} // namespace
|