2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2014-08-12 07:08:48 +00:00
|
|
|
#include "main_wayland.h"
|
2016-04-14 06:51:16 +00:00
|
|
|
#include "composite.h"
|
2016-04-29 13:05:03 +00:00
|
|
|
#include "virtualkeyboard.h"
|
2015-02-20 08:33:36 +00:00
|
|
|
#include "workspace.h"
|
2014-08-12 07:08:48 +00:00
|
|
|
#include <config-kwin.h>
|
|
|
|
// kwin
|
2016-04-07 07:24:17 +00:00
|
|
|
#include "platform.h"
|
2015-11-12 10:29:56 +00:00
|
|
|
#include "effects.h"
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
#include "tabletmodemanager.h"
|
2020-07-23 21:33:30 +00:00
|
|
|
|
|
|
|
#ifdef PipeWire_FOUND
|
2020-07-22 17:29:23 +00:00
|
|
|
#include "screencast/screencastmanager.h"
|
2020-07-23 21:33:30 +00:00
|
|
|
#endif
|
2015-02-09 12:28:37 +00:00
|
|
|
#include "wayland_server.h"
|
2019-02-19 08:50:20 +00:00
|
|
|
#include "xwl/xwayland.h"
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2015-02-09 12:28:37 +00:00
|
|
|
// KWayland
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/display.h>
|
|
|
|
#include <KWaylandServer/seat_interface.h>
|
2020-07-22 17:29:23 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
// KDE
|
2020-04-28 12:45:34 +00:00
|
|
|
#include <KCrash>
|
2014-08-12 07:08:48 +00:00
|
|
|
#include <KLocalizedString>
|
2015-05-05 15:58:09 +00:00
|
|
|
#include <KPluginLoader>
|
|
|
|
#include <KPluginMetaData>
|
2017-11-01 15:45:05 +00:00
|
|
|
#include <KQuickAddons/QtQuickSettings>
|
2020-04-28 12:45:34 +00:00
|
|
|
#include <KShell>
|
2017-11-01 15:45:05 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
// Qt
|
|
|
|
#include <qplatformdefs.h>
|
|
|
|
#include <QCommandLineParser>
|
2015-12-08 10:42:48 +00:00
|
|
|
#include <QFileInfo>
|
2015-04-21 09:21:28 +00:00
|
|
|
#include <QProcess>
|
2016-11-03 10:00:08 +00:00
|
|
|
#include <QStyle>
|
2015-02-20 08:33:36 +00:00
|
|
|
#include <QDebug>
|
2015-02-25 10:42:56 +00:00
|
|
|
#include <QWindow>
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
// system
|
2015-12-08 10:42:48 +00:00
|
|
|
#if HAVE_SYS_PRCTL_H
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#endif
|
Disallow ptrace on greeter and kwin_wayland process on FreeBSD [... for the future]
Summary:
Similar to[[ https://phabricator.kde.org/D1216 | D1216 ]] add procctl call to disable ptrace on FreeBSD.
We cannot do the procfs-lookup to check whether the process is already being run inside gdb -- however, on FreeBSD, we could use the P_TRACED flag of the process to figure this out:
> sys/proc.h:#define P_TRACED 0x00800 /* Debugged process being traced. */
And the code would look something similar to
```
pid_t pid = getpid();
struct procstat *prstat = procstat_open_sysctl();
struct kinfo_proc *procinfo;
unsigned int cnt;
procinfo = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt);
long p_flags = procinfo->ki_flag;
int p_traced = p_flags & P_TRACED;
if (p_traced != P_TRACED) {
mode = PROC_TRACE_CTL_DISABLE;
procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode);
}
procstat_freeprocs(prstat,procinfo);
procstat_close(prstat);
```
But as wayland is [far] in the future on FreeBSD, and that check above is a bit lengthy, I think it is enough if we add it once it is needed.
Reviewers: rakuco, graesslin
Reviewed By: graesslin
Subscribers: plasma-devel
Projects: #plasma
Differential Revision: https://phabricator.kde.org/D1425
2016-05-10 06:49:58 +00:00
|
|
|
#if HAVE_SYS_PROCCTL_H
|
|
|
|
#include <sys/procctl.h>
|
|
|
|
#endif
|
2015-12-08 10:42:48 +00:00
|
|
|
|
2017-09-10 10:05:29 +00:00
|
|
|
#if HAVE_LIBCAP
|
|
|
|
#include <sys/capability.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sched.h>
|
|
|
|
|
2014-08-12 13:27:35 +00:00
|
|
|
#include <iostream>
|
2015-10-02 07:31:47 +00:00
|
|
|
#include <iomanip>
|
2014-08-12 13:27:35 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2014-08-13 11:13:44 +00:00
|
|
|
static void sighandler(int)
|
|
|
|
{
|
|
|
|
QApplication::exit();
|
|
|
|
}
|
|
|
|
|
2018-11-12 09:58:36 +00:00
|
|
|
void disableDrKonqi()
|
|
|
|
{
|
|
|
|
KCrash::setDrKonqiEnabled(false);
|
|
|
|
}
|
|
|
|
// run immediately, before Q_CORE_STARTUP functions
|
|
|
|
// that would enable drkonqi
|
|
|
|
Q_CONSTRUCTOR_FUNCTION(disableDrKonqi)
|
|
|
|
|
2017-09-30 07:36:30 +00:00
|
|
|
enum class RealTimeFlags
|
|
|
|
{
|
|
|
|
DontReset,
|
|
|
|
ResetOnFork
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void gainRealTime(RealTimeFlags flags = RealTimeFlags::DontReset)
|
|
|
|
{
|
|
|
|
#if HAVE_SCHED_RESET_ON_FORK
|
|
|
|
const int minPriority = sched_get_priority_min(SCHED_RR);
|
|
|
|
struct sched_param sp;
|
|
|
|
sp.sched_priority = minPriority;
|
|
|
|
int policy = SCHED_RR;
|
|
|
|
if (flags == RealTimeFlags::ResetOnFork) {
|
|
|
|
policy |= SCHED_RESET_ON_FORK;
|
|
|
|
}
|
|
|
|
sched_setscheduler(0, policy, &sp);
|
Fix unused param warnings
Summary:
Compiler: GCC 7.3.1
Distro: Arch Linux
Compiler warnings:
```
/home/vlad/KDE/src/kde/workspace/kwin/effects/blur/blur.cpp: In member function ‘void KWin::BlurEffect::upscaleRenderToScreen(KWin::GLVertexBuffer*, int, int, QMatrix4x4, QRect, QPoint)’:
/home/vlad/KDE/src/kde/workspace/kwin/effects/blur/blur.cpp:677:129: warning: unused parameter ‘windowShape’ [-Wunused-parameter]
void BlurEffect::upscaleRenderToScreen(GLVertexBuffer *vbo, int vboStart, int blurRectCount, QMatrix4x4 screenProjection, QRect windowShape, QPoint windowPosition)
^~~~~~~~~~~
```
```
/home/vlad/KDE/src/kde/workspace/kwin/main_wayland.cpp: In function ‘void KWin::{anonymous}::gainRealTime(KWin::RealTimeFlags)’:
/home/vlad/KDE/src/kde/workspace/kwin/main_wayland.cpp:95:56: warning: unused parameter ‘flags’ [-Wunused-parameter]
void gainRealTime(RealTimeFlags flags = RealTimeFlags::DontReset)
```
Reviewers: #kwin, davidedmundson
Reviewed By: davidedmundson
Subscribers: anemeth, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D12208
2018-04-20 18:06:59 +00:00
|
|
|
#else
|
|
|
|
Q_UNUSED(flags);
|
2017-09-30 07:36:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
//************************************
|
|
|
|
// ApplicationWayland
|
|
|
|
//************************************
|
|
|
|
|
|
|
|
ApplicationWayland::ApplicationWayland(int &argc, char **argv)
|
2018-08-22 00:20:16 +00:00
|
|
|
: ApplicationWaylandAbstract(OperationModeWaylandOnly, argc, argv)
|
2014-08-12 07:08:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationWayland::~ApplicationWayland()
|
|
|
|
{
|
2019-01-06 16:05:10 +00:00
|
|
|
setTerminating();
|
2015-11-30 14:57:22 +00:00
|
|
|
if (!waylandServer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-05 14:59:53 +00:00
|
|
|
if (auto *platform = kwinApp()->platform()) {
|
|
|
|
platform->prepareShutdown();
|
2016-07-04 07:09:03 +00:00
|
|
|
}
|
2015-11-12 10:29:56 +00:00
|
|
|
// need to unload all effects prior to destroying X connection as they might do X calls
|
|
|
|
if (effects) {
|
|
|
|
static_cast<EffectsHandlerImpl*>(effects)->unloadAllEffects();
|
|
|
|
}
|
2020-07-20 08:07:08 +00:00
|
|
|
delete m_xwayland;
|
|
|
|
m_xwayland = nullptr;
|
wayland: Terminate client connections before Workspace is destroyed
Summary:
When ShellClient tears down, it needs to access RuleBook in order to
discard temporary rules. The problem is that WaylandServer outlives
Workspace and therefore so does ShellClient.
We can't guard against the case when RuleBook::self() is nullptr as it
is vital to discard temporary rules.
This change adjusts termination sequence so all shell clients are
destroyed before Workspace(and thus RuleBook) is gone.
ASAN output:
==19922==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000142060 at pc 0x7fbc0fb878bb bp 0x7ffd7d464520 sp 0x7ffd7d464518
READ of size 8 at 0x606000142060 thread T0
#0 0x7fbc0fb878ba in QList<KWin::Rules*>::detach() /usr/include/qt5/QtCore/qlist.h:172
#1 0x7fbc0fb8538d in QList<KWin::Rules*>::begin() /usr/include/qt5/QtCore/qlist.h:324
#2 0x7fbc0fb808b6 in KWin::RuleBook::discardUsed(KWin::AbstractClient*, bool) /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/rules.cpp:1144
#3 0x7fbc0fe36e32 in KWin::ShellClient::destroyClient() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/shell_client.cpp:435
#4 0x7fbc0fe7a726 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (KWin::ShellClient::*)()>::call(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
#5 0x7fbc0fe784c3 in void QtPrivate::FunctionPointer<void (KWin::ShellClient::*)()>::call<QtPrivate::List<>, void>(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
#6 0x7fbc0fe74de9 in QtPrivate::QSlotObject<void (KWin::ShellClient::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (/home/jenkins/install-prefix/lib64/libkwin.so.5+0x1677de9)
#7 0x7fbc04f27357 in QMetaObject::activate(QObject*, int, int, void**) (/usr/lib64/libQt5Core.so.5+0x2b3357)
#8 0x7fbc074e1970 in KWayland::Server::Resource::unbound() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/build/src/server/KF5WaylandServer_autogen/EWIEGA46WW/moc_resource.cpp:142
#9 0x7fbc0766b4b4 in KWayland::Server::Resource::Private::unbind(wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:68
#10 0x7fbc00bdc2ae (/usr/lib64/libwayland-server.so.0+0x92ae)
#11 0x7fbc00bdc32f in wl_resource_destroy (/usr/lib64/libwayland-server.so.0+0x932f)
#12 0x7fbc0766b53f in KWayland::Server::Resource::Private::resourceDestroyedCallback(wl_client*, wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:76
#13 0x7fbbff481d8c (/usr/lib64/libffi.so.7+0x6d8c)
#14 0x7fbbff481179 (/usr/lib64/libffi.so.7+0x6179)
#15 0x7fbc00bdfa5f (/usr/lib64/libwayland-server.so.0+0xca5f)
#16 0x7fbc00bdc6d1 (/usr/lib64/libwayland-server.so.0+0x96d1)
#17 0x7fbc00bddc71 in wl_event_loop_dispatch (/usr/lib64/libwayland-server.so.0+0xac71)
#18 0x7fbc07541e50 in KWayland::Server::Display::Private::dispatch() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:148
#19 0x7fbc075432de in KWayland::Server::Display::dispatchEvents(int) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:220
#20 0x7fbc0fe864ca in KWin::WaylandServer::dispatch() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/wayland_server.cpp:616
#21 0x451ce0 in KWin::WaylandTestApplication::~WaylandTestApplication() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/kwin_wayland_test.cpp:91
#22 0x42faa1 in main /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/globalshortcuts_test.cpp:381
#23 0x7fbc04796bca in __libc_start_main (/lib64/libc.so.6+0x26bca)
#24 0x413ea9 in _start (/home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/build/bin/testGlobalShortcuts+0x413ea9)
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22821
2019-07-30 08:40:18 +00:00
|
|
|
destroyWorkspace();
|
2019-08-07 08:21:30 +00:00
|
|
|
waylandServer()->dispatch();
|
wayland: Terminate client connections before Workspace is destroyed
Summary:
When ShellClient tears down, it needs to access RuleBook in order to
discard temporary rules. The problem is that WaylandServer outlives
Workspace and therefore so does ShellClient.
We can't guard against the case when RuleBook::self() is nullptr as it
is vital to discard temporary rules.
This change adjusts termination sequence so all shell clients are
destroyed before Workspace(and thus RuleBook) is gone.
ASAN output:
==19922==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000142060 at pc 0x7fbc0fb878bb bp 0x7ffd7d464520 sp 0x7ffd7d464518
READ of size 8 at 0x606000142060 thread T0
#0 0x7fbc0fb878ba in QList<KWin::Rules*>::detach() /usr/include/qt5/QtCore/qlist.h:172
#1 0x7fbc0fb8538d in QList<KWin::Rules*>::begin() /usr/include/qt5/QtCore/qlist.h:324
#2 0x7fbc0fb808b6 in KWin::RuleBook::discardUsed(KWin::AbstractClient*, bool) /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/rules.cpp:1144
#3 0x7fbc0fe36e32 in KWin::ShellClient::destroyClient() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/shell_client.cpp:435
#4 0x7fbc0fe7a726 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (KWin::ShellClient::*)()>::call(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
#5 0x7fbc0fe784c3 in void QtPrivate::FunctionPointer<void (KWin::ShellClient::*)()>::call<QtPrivate::List<>, void>(void (KWin::ShellClient::*)(), KWin::ShellClient*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
#6 0x7fbc0fe74de9 in QtPrivate::QSlotObject<void (KWin::ShellClient::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (/home/jenkins/install-prefix/lib64/libkwin.so.5+0x1677de9)
#7 0x7fbc04f27357 in QMetaObject::activate(QObject*, int, int, void**) (/usr/lib64/libQt5Core.so.5+0x2b3357)
#8 0x7fbc074e1970 in KWayland::Server::Resource::unbound() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/build/src/server/KF5WaylandServer_autogen/EWIEGA46WW/moc_resource.cpp:142
#9 0x7fbc0766b4b4 in KWayland::Server::Resource::Private::unbind(wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:68
#10 0x7fbc00bdc2ae (/usr/lib64/libwayland-server.so.0+0x92ae)
#11 0x7fbc00bdc32f in wl_resource_destroy (/usr/lib64/libwayland-server.so.0+0x932f)
#12 0x7fbc0766b53f in KWayland::Server::Resource::Private::resourceDestroyedCallback(wl_client*, wl_resource*) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/resource.cpp:76
#13 0x7fbbff481d8c (/usr/lib64/libffi.so.7+0x6d8c)
#14 0x7fbbff481179 (/usr/lib64/libffi.so.7+0x6179)
#15 0x7fbc00bdfa5f (/usr/lib64/libwayland-server.so.0+0xca5f)
#16 0x7fbc00bdc6d1 (/usr/lib64/libwayland-server.so.0+0x96d1)
#17 0x7fbc00bddc71 in wl_event_loop_dispatch (/usr/lib64/libwayland-server.so.0+0xac71)
#18 0x7fbc07541e50 in KWayland::Server::Display::Private::dispatch() /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:148
#19 0x7fbc075432de in KWayland::Server::Display::dispatchEvents(int) /home/jenkins/workspace/Administration/Dependency Build Plasma kf5-qt5 SUSEQt5.12/kwayland/src/server/display.cpp:220
#20 0x7fbc0fe864ca in KWin::WaylandServer::dispatch() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/wayland_server.cpp:616
#21 0x451ce0 in KWin::WaylandTestApplication::~WaylandTestApplication() /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/kwin_wayland_test.cpp:91
#22 0x42faa1 in main /home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/autotests/integration/globalshortcuts_test.cpp:381
#23 0x7fbc04796bca in __libc_start_main (/lib64/libc.so.6+0x26bca)
#24 0x413ea9 in _start (/home/jenkins/workspace/Plasma/kwin/kf5-qt5 SUSEQt5.12/build/bin/testGlobalShortcuts+0x413ea9)
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22821
2019-07-30 08:40:18 +00:00
|
|
|
|
2016-11-03 10:00:08 +00:00
|
|
|
if (QStyle *s = style()) {
|
|
|
|
s->unpolish(this);
|
|
|
|
}
|
2019-08-07 08:21:30 +00:00
|
|
|
waylandServer()->terminateClientConnections();
|
2015-11-10 07:52:40 +00:00
|
|
|
destroyCompositor();
|
2014-08-12 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationWayland::performStartup()
|
|
|
|
{
|
2017-09-30 13:09:06 +00:00
|
|
|
if (m_startXWayland) {
|
|
|
|
setOperationMode(OperationModeXwayland);
|
|
|
|
}
|
2015-02-23 14:57:00 +00:00
|
|
|
// first load options - done internally by a different thread
|
|
|
|
createOptions();
|
2015-04-02 12:37:23 +00:00
|
|
|
waylandServer()->createInternalConnection();
|
2015-02-20 13:57:06 +00:00
|
|
|
|
|
|
|
// try creating the Wayland Backend
|
|
|
|
createInput();
|
2017-09-30 07:36:30 +00:00
|
|
|
// now libinput thread has been created, adjust scheduler to not leak into other processes
|
|
|
|
gainRealTime(RealTimeFlags::ResetOnFork);
|
|
|
|
|
2016-04-29 13:05:03 +00:00
|
|
|
VirtualKeyboard::create(this);
|
2015-03-23 11:45:21 +00:00
|
|
|
createBackend();
|
A basic TabletModeManager
Summary:
depends from D9521
listens to switch events and updates the tablet mode status
which is exposed to dbus in the org.kde.KWin.TabletModeManager
interface
Test Plan:
as hardware support is limited, testing of clients
so far is done by the setter in the dbus property,
which should be removed from the final version.
It has been tested to successfully work on a Thinkpad.
Reviewers: #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: graesslin, davidedmundson, plasma-devel, kwin, #kwin
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D9764
2018-01-11 12:09:43 +00:00
|
|
|
TabletModeManager::create(this);
|
2020-07-23 21:33:30 +00:00
|
|
|
#ifdef PipeWire_FOUND
|
2020-07-22 17:29:23 +00:00
|
|
|
new ScreencastManager(this);
|
2020-07-23 21:33:30 +00:00
|
|
|
#endif
|
2015-02-20 13:57:06 +00:00
|
|
|
}
|
2015-02-20 10:53:25 +00:00
|
|
|
|
2015-03-23 11:45:21 +00:00
|
|
|
void ApplicationWayland::createBackend()
|
|
|
|
{
|
2016-04-07 07:18:10 +00:00
|
|
|
connect(platform(), &Platform::screensQueried, this, &ApplicationWayland::continueStartupWithScreens);
|
|
|
|
connect(platform(), &Platform::initFailed, this,
|
2015-05-05 15:58:09 +00:00
|
|
|
[] () {
|
|
|
|
std::cerr << "FATAL ERROR: backend failed to initialize, exiting now" << std::endl;
|
2016-07-11 12:34:24 +00:00
|
|
|
QCoreApplication::exit(1);
|
2015-03-23 11:45:21 +00:00
|
|
|
}
|
2015-05-05 15:58:09 +00:00
|
|
|
);
|
2016-04-07 07:18:10 +00:00
|
|
|
platform()->init();
|
2015-03-23 11:45:21 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 13:57:06 +00:00
|
|
|
void ApplicationWayland::continueStartupWithScreens()
|
|
|
|
{
|
2016-04-07 07:18:10 +00:00
|
|
|
disconnect(kwinApp()->platform(), &Platform::screensQueried, this, &ApplicationWayland::continueStartupWithScreens);
|
2015-02-20 13:57:06 +00:00
|
|
|
createScreens();
|
2019-08-07 17:33:20 +00:00
|
|
|
WaylandCompositor::create();
|
2019-02-23 12:17:50 +00:00
|
|
|
connect(Compositor::self(), &Compositor::sceneCreated, this, &ApplicationWayland::continueStartupWithScene);
|
2015-02-20 10:53:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 12:17:50 +00:00
|
|
|
void ApplicationWayland::finalizeStartup()
|
2017-10-01 07:06:51 +00:00
|
|
|
{
|
2019-02-23 12:17:50 +00:00
|
|
|
if (m_xwayland) {
|
2020-09-08 08:18:31 +00:00
|
|
|
disconnect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &ApplicationWayland::finalizeStartup);
|
2020-07-20 08:07:08 +00:00
|
|
|
disconnect(m_xwayland, &Xwl::Xwayland::started, this, &ApplicationWayland::finalizeStartup);
|
2019-02-23 12:17:50 +00:00
|
|
|
}
|
2017-10-01 07:06:51 +00:00
|
|
|
startSession();
|
2020-07-07 09:32:29 +00:00
|
|
|
notifyStarted();
|
2017-10-01 07:06:51 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 12:17:50 +00:00
|
|
|
void ApplicationWayland::continueStartupWithScene()
|
2015-02-20 10:53:25 +00:00
|
|
|
{
|
2019-02-23 12:17:50 +00:00
|
|
|
disconnect(Compositor::self(), &Compositor::sceneCreated, this, &ApplicationWayland::continueStartupWithScene);
|
|
|
|
|
2020-07-07 09:45:55 +00:00
|
|
|
// Note that we start accepting client connections after creating the Workspace.
|
|
|
|
createWorkspace();
|
|
|
|
|
|
|
|
if (!waylandServer()->start()) {
|
|
|
|
qFatal("Failed to initialze the Wayland server, exiting now");
|
|
|
|
}
|
|
|
|
|
2019-02-23 12:17:50 +00:00
|
|
|
if (operationMode() == OperationModeWaylandOnly) {
|
|
|
|
finalizeStartup();
|
|
|
|
return;
|
|
|
|
}
|
2019-02-19 08:50:20 +00:00
|
|
|
|
|
|
|
m_xwayland = new Xwl::Xwayland(this);
|
2020-09-08 08:18:31 +00:00
|
|
|
connect(m_xwayland, &Xwl::Xwayland::errorOccurred, this, &ApplicationWayland::finalizeStartup);
|
2020-07-20 08:07:08 +00:00
|
|
|
connect(m_xwayland, &Xwl::Xwayland::started, this, &ApplicationWayland::finalizeStartup);
|
|
|
|
m_xwayland->start();
|
2017-09-21 16:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationWayland::startSession()
|
|
|
|
{
|
2015-06-13 02:06:12 +00:00
|
|
|
if (!m_inputMethodServerToStart.isEmpty()) {
|
2020-04-28 12:45:34 +00:00
|
|
|
QStringList arguments = KShell::splitArgs(m_inputMethodServerToStart);
|
|
|
|
if (!arguments.isEmpty()) {
|
|
|
|
QString program = arguments.takeFirst();
|
|
|
|
int socket = dup(waylandServer()->createInputMethodConnection());
|
|
|
|
if (socket >= 0) {
|
|
|
|
QProcessEnvironment environment = processStartupEnvironment();
|
|
|
|
environment.insert(QStringLiteral("WAYLAND_SOCKET"), QByteArray::number(socket));
|
|
|
|
environment.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("wayland"));
|
|
|
|
environment.remove("DISPLAY");
|
|
|
|
environment.remove("WAYLAND_DISPLAY");
|
|
|
|
QProcess *p = new Process(this);
|
|
|
|
p->setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
|
|
|
connect(p, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this,
|
|
|
|
[p] {
|
|
|
|
if (waylandServer()) {
|
|
|
|
waylandServer()->destroyInputMethodConnection();
|
|
|
|
}
|
|
|
|
p->deleteLater();
|
2015-11-10 13:38:45 +00:00
|
|
|
}
|
2020-04-28 12:45:34 +00:00
|
|
|
);
|
|
|
|
p->setProcessEnvironment(environment);
|
|
|
|
p->setProgram(program);
|
|
|
|
p->setArguments(arguments);
|
|
|
|
p->start();
|
2020-08-10 11:22:01 +00:00
|
|
|
connect(waylandServer(), &WaylandServer::terminatingInternalClientConnection, p, [p] {
|
|
|
|
p->kill();
|
|
|
|
p->waitForFinished();
|
|
|
|
});
|
2020-04-28 12:45:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qWarning("Failed to launch the input method server: %s is an invalid command",
|
|
|
|
qPrintable(m_inputMethodServerToStart));
|
2015-06-13 02:06:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-19 08:16:23 +00:00
|
|
|
// start session
|
|
|
|
if (!m_sessionArgument.isEmpty()) {
|
2020-04-28 12:45:34 +00:00
|
|
|
QStringList arguments = KShell::splitArgs(m_sessionArgument);
|
|
|
|
if (!arguments.isEmpty()) {
|
|
|
|
QString program = arguments.takeFirst();
|
|
|
|
QProcess *p = new Process(this);
|
|
|
|
p->setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
|
|
|
p->setProcessEnvironment(processStartupEnvironment());
|
|
|
|
connect(p, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, [p] (int code, QProcess::ExitStatus status) {
|
|
|
|
p->deleteLater();
|
|
|
|
if (status == QProcess::CrashExit) {
|
|
|
|
qWarning() << "Session process has crashed";
|
|
|
|
QCoreApplication::exit(-1);
|
|
|
|
return;
|
|
|
|
}
|
2019-05-28 16:42:55 +00:00
|
|
|
|
2020-04-28 12:45:34 +00:00
|
|
|
if (code) {
|
|
|
|
qWarning() << "Session process exited with code" << code;
|
|
|
|
}
|
2019-05-28 16:42:55 +00:00
|
|
|
|
2020-04-28 12:45:34 +00:00
|
|
|
QCoreApplication::exit(code);
|
|
|
|
});
|
|
|
|
p->setProgram(program);
|
|
|
|
p->setArguments(arguments);
|
|
|
|
p->start();
|
|
|
|
} else {
|
|
|
|
qWarning("Failed to launch the session process: %s is an invalid command",
|
|
|
|
qPrintable(m_sessionArgument));
|
|
|
|
}
|
2015-11-19 08:16:23 +00:00
|
|
|
}
|
2015-04-21 09:21:28 +00:00
|
|
|
// start the applications passed to us as command line arguments
|
|
|
|
if (!m_applicationsToStart.isEmpty()) {
|
|
|
|
for (const QString &application: m_applicationsToStart) {
|
2020-04-28 12:45:34 +00:00
|
|
|
QStringList arguments = KShell::splitArgs(application);
|
|
|
|
if (arguments.isEmpty()) {
|
|
|
|
qWarning("Failed to launch application: %s is an invalid command",
|
|
|
|
qPrintable(application));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QString program = arguments.takeFirst();
|
2015-04-21 09:21:28 +00:00
|
|
|
// note: this will kill the started process when we exit
|
|
|
|
// this is going to happen anyway as we are the wayland and X server the app connects to
|
2015-12-15 09:22:03 +00:00
|
|
|
QProcess *p = new Process(this);
|
2015-12-15 09:08:36 +00:00
|
|
|
p->setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
2018-08-22 00:20:16 +00:00
|
|
|
p->setProcessEnvironment(processStartupEnvironment());
|
2020-04-28 12:45:34 +00:00
|
|
|
p->setProgram(program);
|
|
|
|
p->setArguments(arguments);
|
2020-03-15 19:59:29 +00:00
|
|
|
p->startDetached();
|
|
|
|
p->deleteLater();
|
2015-04-21 09:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-12 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 09:59:27 +00:00
|
|
|
static const QString s_waylandPlugin = QStringLiteral("KWinWaylandWaylandBackend");
|
|
|
|
static const QString s_x11Plugin = QStringLiteral("KWinWaylandX11Backend");
|
|
|
|
static const QString s_fbdevPlugin = QStringLiteral("KWinWaylandFbdevBackend");
|
|
|
|
#if HAVE_DRM
|
|
|
|
static const QString s_drmPlugin = QStringLiteral("KWinWaylandDrmBackend");
|
|
|
|
#endif
|
|
|
|
#if HAVE_LIBHYBRIS
|
|
|
|
static const QString s_hwcomposerPlugin = QStringLiteral("KWinWaylandHwcomposerBackend");
|
|
|
|
#endif
|
2015-10-02 08:44:29 +00:00
|
|
|
static const QString s_virtualPlugin = QStringLiteral("KWinWaylandVirtualBackend");
|
2015-06-29 09:59:27 +00:00
|
|
|
|
|
|
|
static QString automaticBackendSelection()
|
|
|
|
{
|
|
|
|
if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) {
|
|
|
|
return s_waylandPlugin;
|
|
|
|
}
|
|
|
|
if (qEnvironmentVariableIsSet("DISPLAY")) {
|
|
|
|
return s_x11Plugin;
|
|
|
|
}
|
|
|
|
#if HAVE_LIBHYBRIS
|
|
|
|
if (qEnvironmentVariableIsSet("ANDROID_ROOT")) {
|
|
|
|
return s_hwcomposerPlugin;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if HAVE_DRM
|
|
|
|
return s_drmPlugin;
|
|
|
|
#endif
|
|
|
|
return s_fbdevPlugin;
|
|
|
|
}
|
|
|
|
|
2015-12-08 10:42:48 +00:00
|
|
|
static void disablePtrace()
|
|
|
|
{
|
|
|
|
#if HAVE_PR_SET_DUMPABLE
|
|
|
|
// check whether we are running under a debugger
|
|
|
|
const QFileInfo parent(QStringLiteral("/proc/%1/exe").arg(getppid()));
|
2017-06-11 19:16:56 +00:00
|
|
|
if (parent.isSymLink() &&
|
|
|
|
(parent.symLinkTarget().endsWith(QLatin1String("/gdb")) ||
|
2019-08-28 19:19:50 +00:00
|
|
|
parent.symLinkTarget().endsWith(QLatin1String("/gdbserver")) ||
|
|
|
|
parent.symLinkTarget().endsWith(QLatin1String("/lldb-server")))) {
|
2015-12-08 10:42:48 +00:00
|
|
|
// debugger, don't adjust
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// disable ptrace in kwin_wayland
|
|
|
|
prctl(PR_SET_DUMPABLE, 0);
|
|
|
|
#endif
|
Disallow ptrace on greeter and kwin_wayland process on FreeBSD [... for the future]
Summary:
Similar to[[ https://phabricator.kde.org/D1216 | D1216 ]] add procctl call to disable ptrace on FreeBSD.
We cannot do the procfs-lookup to check whether the process is already being run inside gdb -- however, on FreeBSD, we could use the P_TRACED flag of the process to figure this out:
> sys/proc.h:#define P_TRACED 0x00800 /* Debugged process being traced. */
And the code would look something similar to
```
pid_t pid = getpid();
struct procstat *prstat = procstat_open_sysctl();
struct kinfo_proc *procinfo;
unsigned int cnt;
procinfo = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt);
long p_flags = procinfo->ki_flag;
int p_traced = p_flags & P_TRACED;
if (p_traced != P_TRACED) {
mode = PROC_TRACE_CTL_DISABLE;
procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode);
}
procstat_freeprocs(prstat,procinfo);
procstat_close(prstat);
```
But as wayland is [far] in the future on FreeBSD, and that check above is a bit lengthy, I think it is enough if we add it once it is needed.
Reviewers: rakuco, graesslin
Reviewed By: graesslin
Subscribers: plasma-devel
Projects: #plasma
Differential Revision: https://phabricator.kde.org/D1425
2016-05-10 06:49:58 +00:00
|
|
|
#if HAVE_PROC_TRACE_CTL
|
|
|
|
// FreeBSD's rudimentary procfs does not support /proc/<pid>/exe
|
|
|
|
// We could use the P_TRACED flag of the process to find out
|
|
|
|
// if the process is being debugged ond FreeBSD.
|
|
|
|
int mode = PROC_TRACE_CTL_DISABLE;
|
|
|
|
procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode);
|
|
|
|
#endif
|
|
|
|
|
2015-12-08 10:42:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-25 12:47:41 +00:00
|
|
|
static void unsetDumpable(int sig)
|
|
|
|
{
|
|
|
|
#if HAVE_PR_SET_DUMPABLE
|
|
|
|
prctl(PR_SET_DUMPABLE, 1);
|
|
|
|
#endif
|
|
|
|
signal(sig, SIG_IGN);
|
|
|
|
raise(sig);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-10 10:05:29 +00:00
|
|
|
void dropNiceCapability()
|
|
|
|
{
|
|
|
|
#if HAVE_LIBCAP
|
|
|
|
cap_t caps = cap_get_proc();
|
|
|
|
if (!caps) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cap_value_t capList[] = { CAP_SYS_NICE };
|
|
|
|
if (cap_set_flag(caps, CAP_PERMITTED, 1, capList, CAP_CLEAR) == -1) {
|
|
|
|
cap_free(caps);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cap_set_flag(caps, CAP_EFFECTIVE, 1, capList, CAP_CLEAR) == -1) {
|
|
|
|
cap_free(caps);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cap_set_proc(caps);
|
|
|
|
cap_free(caps);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-07-06 07:57:30 +00:00
|
|
|
int main(int argc, char * argv[])
|
2014-08-12 07:08:48 +00:00
|
|
|
{
|
2018-05-20 19:45:51 +00:00
|
|
|
if (getuid() == 0) {
|
|
|
|
std::cerr << "kwin_wayland does not support running as root." << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2015-12-08 10:42:48 +00:00
|
|
|
KWin::disablePtrace();
|
2014-08-12 07:08:48 +00:00
|
|
|
KWin::Application::setupMalloc();
|
|
|
|
KWin::Application::setupLocalizedString();
|
2017-09-10 10:05:29 +00:00
|
|
|
KWin::gainRealTime();
|
|
|
|
KWin::dropNiceCapability();
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2014-08-13 11:13:44 +00:00
|
|
|
if (signal(SIGTERM, KWin::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGTERM, SIG_IGN);
|
|
|
|
if (signal(SIGINT, KWin::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
if (signal(SIGHUP, KWin::sighandler) == SIG_IGN)
|
|
|
|
signal(SIGHUP, SIG_IGN);
|
2016-06-25 12:47:41 +00:00
|
|
|
signal(SIGABRT, KWin::unsetDumpable);
|
|
|
|
signal(SIGSEGV, KWin::unsetDumpable);
|
2016-11-18 09:02:04 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2015-03-31 07:30:19 +00:00
|
|
|
// ensure that no thread takes SIGUSR
|
2016-01-30 11:31:19 +00:00
|
|
|
sigset_t userSignals;
|
|
|
|
sigemptyset(&userSignals);
|
|
|
|
sigaddset(&userSignals, SIGUSR1);
|
|
|
|
sigaddset(&userSignals, SIGUSR2);
|
|
|
|
pthread_sigmask(SIG_BLOCK, &userSignals, nullptr);
|
2014-08-13 11:13:44 +00:00
|
|
|
|
2015-06-29 08:51:37 +00:00
|
|
|
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
|
|
|
|
|
2015-08-18 06:05:08 +00:00
|
|
|
// enforce our internal qpa plugin, unfortunately command line switch has precedence
|
|
|
|
setenv("QT_QPA_PLATFORM", "wayland-org.kde.kwin.qpa", true);
|
2015-03-17 09:31:18 +00:00
|
|
|
|
2015-04-17 16:13:39 +00:00
|
|
|
qunsetenv("QT_DEVICE_PIXEL_RATIO");
|
2016-04-29 13:05:03 +00:00
|
|
|
qputenv("QT_IM_MODULE", "qtvirtualkeyboard");
|
2015-07-10 06:57:56 +00:00
|
|
|
qputenv("QSG_RENDER_LOOP", "basic");
|
2019-01-11 22:48:04 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
2014-08-12 07:08:48 +00:00
|
|
|
KWin::ApplicationWayland a(argc, argv);
|
|
|
|
a.setupTranslator();
|
2015-11-03 15:52:55 +00:00
|
|
|
// reset QT_QPA_PLATFORM to a sane value for any processes started from KWin
|
|
|
|
setenv("QT_QPA_PLATFORM", "wayland", true);
|
2015-02-09 12:28:37 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
KWin::Application::createAboutData();
|
2017-11-01 15:45:05 +00:00
|
|
|
KQuickAddons::QtQuickSettings::init();
|
2014-08-12 07:08:48 +00:00
|
|
|
|
2015-10-02 07:31:47 +00:00
|
|
|
const auto availablePlugins = KPluginLoader::findPlugins(QStringLiteral("org.kde.kwin.waylandbackends"));
|
2015-10-02 07:47:27 +00:00
|
|
|
auto hasPlugin = [&availablePlugins] (const QString &name) {
|
|
|
|
return std::any_of(availablePlugins.begin(), availablePlugins.end(),
|
|
|
|
[name] (const KPluginMetaData &plugin) {
|
|
|
|
return plugin.pluginId() == name;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2015-10-03 18:14:16 +00:00
|
|
|
const bool hasSizeOption = hasPlugin(KWin::s_x11Plugin) || hasPlugin(KWin::s_virtualPlugin);
|
2015-11-24 12:11:29 +00:00
|
|
|
const bool hasOutputCountOption = hasPlugin(KWin::s_x11Plugin);
|
2015-10-03 18:14:16 +00:00
|
|
|
const bool hasX11Option = hasPlugin(KWin::s_x11Plugin);
|
|
|
|
const bool hasVirtualOption = hasPlugin(KWin::s_virtualPlugin);
|
|
|
|
const bool hasWaylandOption = hasPlugin(KWin::s_waylandPlugin);
|
|
|
|
const bool hasFramebufferOption = hasPlugin(KWin::s_fbdevPlugin);
|
|
|
|
#if HAVE_DRM
|
|
|
|
const bool hasDrmOption = hasPlugin(KWin::s_drmPlugin);
|
|
|
|
#endif
|
|
|
|
#if HAVE_LIBHYBRIS
|
|
|
|
const bool hasHwcomposerOption = hasPlugin(KWin::s_hwcomposerPlugin);
|
|
|
|
#endif
|
2015-10-02 07:31:47 +00:00
|
|
|
|
2015-01-09 15:00:16 +00:00
|
|
|
QCommandLineOption xwaylandOption(QStringLiteral("xwayland"),
|
2015-02-09 12:40:01 +00:00
|
|
|
i18n("Start a rootless Xwayland server."));
|
2015-02-09 12:28:37 +00:00
|
|
|
QCommandLineOption waylandSocketOption(QStringList{QStringLiteral("s"), QStringLiteral("socket")},
|
|
|
|
i18n("Name of the Wayland socket to listen on. If not set \"wayland-0\" is used."),
|
|
|
|
QStringLiteral("socket"));
|
2015-03-31 09:00:46 +00:00
|
|
|
QCommandLineOption framebufferOption(QStringLiteral("framebuffer"),
|
|
|
|
i18n("Render to framebuffer."));
|
|
|
|
QCommandLineOption framebufferDeviceOption(QStringLiteral("fb-device"),
|
|
|
|
i18n("The framebuffer device to render to."),
|
|
|
|
QStringLiteral("fbdev"));
|
2015-03-19 07:29:34 +00:00
|
|
|
QCommandLineOption x11DisplayOption(QStringLiteral("x11-display"),
|
|
|
|
i18n("The X11 Display to use in windowed mode on platform X11."),
|
|
|
|
QStringLiteral("display"));
|
2015-03-23 11:45:21 +00:00
|
|
|
QCommandLineOption waylandDisplayOption(QStringLiteral("wayland-display"),
|
|
|
|
i18n("The Wayland Display to use in windowed mode on platform Wayland."),
|
|
|
|
QStringLiteral("display"));
|
2015-10-02 08:44:29 +00:00
|
|
|
QCommandLineOption virtualFbOption(QStringLiteral("virtual"), i18n("Render to a virtual framebuffer."));
|
2015-03-19 07:29:34 +00:00
|
|
|
QCommandLineOption widthOption(QStringLiteral("width"),
|
|
|
|
i18n("The width for windowed mode. Default width is 1024."),
|
|
|
|
QStringLiteral("width"));
|
|
|
|
widthOption.setDefaultValue(QString::number(1024));
|
|
|
|
QCommandLineOption heightOption(QStringLiteral("height"),
|
|
|
|
i18n("The height for windowed mode. Default height is 768."),
|
|
|
|
QStringLiteral("height"));
|
|
|
|
heightOption.setDefaultValue(QString::number(768));
|
2016-10-25 23:36:02 +00:00
|
|
|
|
|
|
|
QCommandLineOption scaleOption(QStringLiteral("scale"),
|
|
|
|
i18n("The scale for windowed mode. Default value is 1."),
|
|
|
|
QStringLiteral("scale"));
|
|
|
|
scaleOption.setDefaultValue(QString::number(1));
|
|
|
|
|
2015-11-24 12:11:29 +00:00
|
|
|
QCommandLineOption outputCountOption(QStringLiteral("output-count"),
|
|
|
|
i18n("The number of windows to open as outputs in windowed mode. Default value is 1"),
|
2019-03-20 14:12:45 +00:00
|
|
|
QStringLiteral("count"));
|
2015-11-24 12:11:29 +00:00
|
|
|
outputCountOption.setDefaultValue(QString::number(1));
|
2014-08-12 13:27:35 +00:00
|
|
|
|
2014-08-12 07:08:48 +00:00
|
|
|
QCommandLineParser parser;
|
|
|
|
a.setupCommandLine(&parser);
|
2015-01-09 15:00:16 +00:00
|
|
|
parser.addOption(xwaylandOption);
|
2015-02-09 12:28:37 +00:00
|
|
|
parser.addOption(waylandSocketOption);
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasX11Option) {
|
2015-10-02 07:47:27 +00:00
|
|
|
parser.addOption(x11DisplayOption);
|
|
|
|
}
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasWaylandOption) {
|
2015-10-02 07:47:27 +00:00
|
|
|
parser.addOption(waylandDisplayOption);
|
|
|
|
}
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasFramebufferOption) {
|
2015-10-02 07:47:27 +00:00
|
|
|
parser.addOption(framebufferOption);
|
|
|
|
parser.addOption(framebufferDeviceOption);
|
|
|
|
}
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasVirtualOption) {
|
2015-10-02 08:44:29 +00:00
|
|
|
parser.addOption(virtualFbOption);
|
|
|
|
}
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasSizeOption) {
|
2015-10-02 07:47:27 +00:00
|
|
|
parser.addOption(widthOption);
|
|
|
|
parser.addOption(heightOption);
|
2016-10-25 23:36:02 +00:00
|
|
|
parser.addOption(scaleOption);
|
2015-10-02 07:47:27 +00:00
|
|
|
}
|
2015-11-24 12:11:29 +00:00
|
|
|
if (hasOutputCountOption) {
|
|
|
|
parser.addOption(outputCountOption);
|
|
|
|
}
|
2015-05-06 15:47:07 +00:00
|
|
|
#if HAVE_LIBHYBRIS
|
|
|
|
QCommandLineOption hwcomposerOption(QStringLiteral("hwcomposer"), i18n("Use libhybris hwcomposer"));
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasHwcomposerOption) {
|
2015-10-02 07:47:27 +00:00
|
|
|
parser.addOption(hwcomposerOption);
|
|
|
|
}
|
2015-05-06 15:47:07 +00:00
|
|
|
#endif
|
2014-08-15 12:03:52 +00:00
|
|
|
QCommandLineOption libinputOption(QStringLiteral("libinput"),
|
2020-06-26 11:48:47 +00:00
|
|
|
i18n("Enable libinput support for input events processing. Note: never use in a nested session. (deprecated)"));
|
2014-08-15 12:03:52 +00:00
|
|
|
parser.addOption(libinputOption);
|
2015-04-09 12:49:32 +00:00
|
|
|
#if HAVE_DRM
|
|
|
|
QCommandLineOption drmOption(QStringLiteral("drm"), i18n("Render through drm node."));
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasDrmOption) {
|
2015-10-02 07:47:27 +00:00
|
|
|
parser.addOption(drmOption);
|
|
|
|
}
|
2014-08-15 12:03:52 +00:00
|
|
|
#endif
|
2015-06-13 02:06:12 +00:00
|
|
|
|
|
|
|
QCommandLineOption inputMethodOption(QStringLiteral("inputmethod"),
|
|
|
|
i18n("Input method that KWin starts."),
|
|
|
|
QStringLiteral("path/to/imserver"));
|
|
|
|
parser.addOption(inputMethodOption);
|
|
|
|
|
2015-10-02 07:31:47 +00:00
|
|
|
QCommandLineOption listBackendsOption(QStringLiteral("list-backends"),
|
|
|
|
i18n("List all available backends and quit."));
|
|
|
|
parser.addOption(listBackendsOption);
|
|
|
|
|
2015-11-05 13:09:23 +00:00
|
|
|
QCommandLineOption screenLockerOption(QStringLiteral("lockscreen"),
|
|
|
|
i18n("Starts the session in locked mode."));
|
|
|
|
parser.addOption(screenLockerOption);
|
|
|
|
|
2018-12-01 12:17:02 +00:00
|
|
|
QCommandLineOption noScreenLockerOption(QStringLiteral("no-lockscreen"),
|
|
|
|
i18n("Starts the session without lock screen support."));
|
|
|
|
parser.addOption(noScreenLockerOption);
|
|
|
|
|
2018-12-02 12:09:37 +00:00
|
|
|
QCommandLineOption noGlobalShortcutsOption(QStringLiteral("no-global-shortcuts"),
|
|
|
|
i18n("Starts the session without global shortcuts support."));
|
2019-02-01 14:29:04 +00:00
|
|
|
parser.addOption(noGlobalShortcutsOption);
|
2018-12-02 12:09:37 +00:00
|
|
|
|
2015-11-19 08:16:23 +00:00
|
|
|
QCommandLineOption exitWithSessionOption(QStringLiteral("exit-with-session"),
|
|
|
|
i18n("Exit after the session application, which is started by KWin, closed."),
|
|
|
|
QStringLiteral("/path/to/session"));
|
|
|
|
parser.addOption(exitWithSessionOption);
|
|
|
|
|
2015-04-21 09:21:28 +00:00
|
|
|
parser.addPositionalArgument(QStringLiteral("applications"),
|
|
|
|
i18n("Applications to start once Wayland and Xwayland server are started"),
|
|
|
|
QStringLiteral("[/path/to/application...]"));
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
parser.process(a);
|
|
|
|
a.processCommandLine(&parser);
|
|
|
|
|
2015-11-24 08:01:46 +00:00
|
|
|
#ifdef KWIN_BUILD_ACTIVITIES
|
2018-01-13 15:45:42 +00:00
|
|
|
a.setUseKActivities(false);
|
2015-11-24 08:01:46 +00:00
|
|
|
#endif
|
|
|
|
|
2015-10-02 07:31:47 +00:00
|
|
|
if (parser.isSet(listBackendsOption)) {
|
|
|
|
for (const auto &plugin: availablePlugins) {
|
|
|
|
std::cout << std::setw(40) << std::left << qPrintable(plugin.name()) << qPrintable(plugin.description()) << std::endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-19 08:16:23 +00:00
|
|
|
if (parser.isSet(exitWithSessionOption)) {
|
|
|
|
a.setSessionArgument(parser.value(exitWithSessionOption));
|
|
|
|
}
|
|
|
|
|
2014-08-15 12:03:52 +00:00
|
|
|
KWin::Application::setUseLibinput(parser.isSet(libinputOption));
|
|
|
|
|
2015-05-05 15:58:09 +00:00
|
|
|
QString pluginName;
|
|
|
|
QSize initialWindowSize;
|
|
|
|
QByteArray deviceIdentifier;
|
2015-11-24 12:11:29 +00:00
|
|
|
int outputCount = 1;
|
2016-10-25 23:36:02 +00:00
|
|
|
qreal outputScale = 1;
|
2015-10-03 18:14:16 +00:00
|
|
|
|
2015-04-09 12:49:32 +00:00
|
|
|
#if HAVE_DRM
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasDrmOption && parser.isSet(drmOption)) {
|
2015-06-29 09:59:27 +00:00
|
|
|
pluginName = KWin::s_drmPlugin;
|
2015-05-05 15:58:09 +00:00
|
|
|
}
|
2015-04-09 12:49:32 +00:00
|
|
|
#endif
|
2015-03-31 09:00:46 +00:00
|
|
|
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasSizeOption) {
|
|
|
|
bool ok = false;
|
|
|
|
const int width = parser.value(widthOption).toInt(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
std::cerr << "FATAL ERROR incorrect value for width" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const int height = parser.value(heightOption).toInt(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
std::cerr << "FATAL ERROR incorrect value for height" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-10-25 23:36:02 +00:00
|
|
|
const qreal scale = parser.value(scaleOption).toDouble(&ok);
|
2020-05-27 17:51:03 +00:00
|
|
|
if (!ok || scale <= 0) {
|
2016-10-25 23:36:02 +00:00
|
|
|
std::cerr << "FATAL ERROR incorrect value for scale" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
outputScale = scale;
|
2015-10-03 18:14:16 +00:00
|
|
|
initialWindowSize = QSize(width, height);
|
2015-06-29 09:59:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 12:11:29 +00:00
|
|
|
if (hasOutputCountOption) {
|
|
|
|
bool ok = false;
|
|
|
|
const int count = parser.value(outputCountOption).toInt(&ok);
|
|
|
|
if (ok) {
|
|
|
|
outputCount = qMax(1, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 09:20:57 +00:00
|
|
|
if (hasX11Option && parser.isSet(x11DisplayOption)) {
|
|
|
|
deviceIdentifier = parser.value(x11DisplayOption).toUtf8();
|
|
|
|
pluginName = KWin::s_x11Plugin;
|
|
|
|
} else if (hasWaylandOption && parser.isSet(waylandDisplayOption)) {
|
|
|
|
deviceIdentifier = parser.value(waylandDisplayOption).toUtf8();
|
|
|
|
pluginName = KWin::s_waylandPlugin;
|
2015-03-19 07:29:34 +00:00
|
|
|
}
|
2018-09-13 09:20:57 +00:00
|
|
|
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasFramebufferOption && parser.isSet(framebufferOption)) {
|
2015-06-29 09:59:27 +00:00
|
|
|
pluginName = KWin::s_fbdevPlugin;
|
2015-05-05 15:58:09 +00:00
|
|
|
deviceIdentifier = parser.value(framebufferDeviceOption).toUtf8();
|
|
|
|
}
|
2015-05-06 15:47:07 +00:00
|
|
|
#if HAVE_LIBHYBRIS
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasHwcomposerOption && parser.isSet(hwcomposerOption)) {
|
2015-06-29 09:59:27 +00:00
|
|
|
pluginName = KWin::s_hwcomposerPlugin;
|
2015-05-06 15:47:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-10-03 18:14:16 +00:00
|
|
|
if (hasVirtualOption && parser.isSet(virtualFbOption)) {
|
2015-10-02 08:44:29 +00:00
|
|
|
pluginName = KWin::s_virtualPlugin;
|
|
|
|
}
|
2015-05-05 15:58:09 +00:00
|
|
|
|
2015-06-29 09:59:27 +00:00
|
|
|
if (pluginName.isEmpty()) {
|
|
|
|
std::cerr << "No backend specified through command line argument, trying auto resolution" << std::endl;
|
|
|
|
pluginName = KWin::automaticBackendSelection();
|
|
|
|
}
|
|
|
|
|
2015-10-02 07:31:47 +00:00
|
|
|
auto pluginIt = std::find_if(availablePlugins.begin(), availablePlugins.end(),
|
2015-05-05 15:58:09 +00:00
|
|
|
[&pluginName] (const KPluginMetaData &plugin) {
|
|
|
|
return plugin.pluginId() == pluginName;
|
|
|
|
}
|
|
|
|
);
|
2015-10-02 07:31:47 +00:00
|
|
|
if (pluginIt == availablePlugins.end()) {
|
2015-05-05 15:58:09 +00:00
|
|
|
std::cerr << "FATAL ERROR: could not find a backend" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2015-08-20 10:54:23 +00:00
|
|
|
|
|
|
|
// TODO: create backend without having the server running
|
|
|
|
KWin::WaylandServer *server = KWin::WaylandServer::create(&a);
|
2015-11-05 13:09:23 +00:00
|
|
|
|
2020-03-17 05:48:05 +00:00
|
|
|
KWin::WaylandServer::InitializationFlags flags;
|
2015-11-05 13:09:23 +00:00
|
|
|
if (parser.isSet(screenLockerOption)) {
|
2020-03-17 05:48:05 +00:00
|
|
|
flags = KWin::WaylandServer::InitializationFlag::LockScreen;
|
2018-12-01 12:17:02 +00:00
|
|
|
} else if (parser.isSet(noScreenLockerOption)) {
|
2020-03-17 05:48:05 +00:00
|
|
|
flags = KWin::WaylandServer::InitializationFlag::NoLockScreenIntegration;
|
2015-11-05 13:09:23 +00:00
|
|
|
}
|
2018-12-02 12:09:37 +00:00
|
|
|
if (parser.isSet(noGlobalShortcutsOption)) {
|
2020-03-17 05:48:05 +00:00
|
|
|
flags |= KWin::WaylandServer::InitializationFlag::NoGlobalShortcuts;
|
2018-12-02 12:09:37 +00:00
|
|
|
}
|
2016-07-04 07:09:03 +00:00
|
|
|
if (!server->init(parser.value(waylandSocketOption).toUtf8(), flags)) {
|
|
|
|
std::cerr << "FATAL ERROR: could not create Wayland server" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2015-08-20 10:54:23 +00:00
|
|
|
|
2016-04-06 15:30:00 +00:00
|
|
|
a.initPlatform(*pluginIt);
|
|
|
|
if (!a.platform()) {
|
2015-05-05 15:58:09 +00:00
|
|
|
std::cerr << "FATAL ERROR: could not instantiate a backend" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!deviceIdentifier.isEmpty()) {
|
2016-04-07 06:28:35 +00:00
|
|
|
a.platform()->setDeviceIdentifier(deviceIdentifier);
|
2015-05-05 15:58:09 +00:00
|
|
|
}
|
|
|
|
if (initialWindowSize.isValid()) {
|
2016-04-07 06:28:35 +00:00
|
|
|
a.platform()->setInitialWindowSize(initialWindowSize);
|
2015-03-31 09:00:46 +00:00
|
|
|
}
|
2016-10-25 23:36:02 +00:00
|
|
|
a.platform()->setInitialOutputScale(outputScale);
|
2016-04-07 06:28:35 +00:00
|
|
|
a.platform()->setInitialOutputCount(outputCount);
|
2015-03-19 07:29:34 +00:00
|
|
|
|
2015-06-12 23:48:11 +00:00
|
|
|
QObject::connect(&a, &KWin::Application::workspaceCreated, server, &KWin::WaylandServer::initWorkspace);
|
2015-08-20 10:54:23 +00:00
|
|
|
environment.insert(QStringLiteral("WAYLAND_DISPLAY"), server->display()->socketName());
|
|
|
|
a.setProcessStartupEnvironment(environment);
|
2015-02-20 10:53:25 +00:00
|
|
|
a.setStartXwayland(parser.isSet(xwaylandOption));
|
2015-04-21 09:21:28 +00:00
|
|
|
a.setApplicationsToStart(parser.positionalArguments());
|
2015-06-13 02:06:12 +00:00
|
|
|
a.setInputMethodServerToStart(parser.value(inputMethodOption));
|
2015-02-20 10:53:25 +00:00
|
|
|
a.start();
|
2014-08-12 07:08:48 +00:00
|
|
|
|
|
|
|
return a.exec();
|
|
|
|
}
|