kwin/dbusinterface.cpp
Martin Gräßlin 6a19f50cac Add a debugging console to KWin
Summary:
The idea behind the debugging console is to have a feature comparable
to xprop and xwininfo just for Wayland. We cannot have command line
utils as that violates the security restrictions, thus it needs to be
exposed directly in KWin.

The debugging console is invoked through DBus:
qdbus org.kde.KWin /KWin showDebugConsole

This opens a window with a tree view. The DebugConsoleModel which is
used by the tree view groups all windows into four categories:
* x11 clients (that is Workspace::clientList() and Workspace::desktopList())
* x11 unmanaged (Workspace::unmanagedList())
* wayland shell clients (WaylandServer::clients())
* wayland internal clients (KWin's own QWindows - WaylandServer::internalClients())

Each window is a child to one of the four categories. Each window itself
has all it's QProperties exposed as children.

This allows to properly inspect KWin's internal knowledge for windows and
should make it easier to investigate problems. E.g. what's a window's
geometry, what's it's window type and so on.

The debugging console is intended as a developer tool and not expected to
be used by users. That's why it's invokation is rather hidden. Due to
the fact that it's internal to KWin it results in:
* no window decoration
* stealing keyboard focus
* no way to resize, close, move from KWin side
* rendered above all other windows

There is a dedicated close button to get rid of it again. While the
console is shown it's hardly possible to interact with the system in
a normal way anymore. This is something which might be improved in
future.

At the moment the model is able to update when windows are added/removed,
but not yet when a property changes. Due to the lack of interaction with
the existing system, that's not a high priority at the moment, but can
be added in future.

Reviewers: #plasma

Differential Revision: https://phabricator.kde.org/D1146
2016-03-16 14:30:19 +01:00

265 lines
7.2 KiB
C++

/********************************************************************
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"
#include "compositingadaptor.h"
// kwin
#include "atoms.h"
#include "composite.h"
#include "compositingprefs.h"
#include "debug_console.h"
#include "main.h"
#include "placement.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()));
}
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"));
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());
}
// 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();
}
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:
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 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;
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