KWin
Loading...
Searching...
No Matches
killprompt.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <kde@broulik.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "killprompt.h"
8
9#include "client_machine.h"
10#include "wayland/display.h"
11#include "wayland/seat.h"
13#include "wayland_server.h"
14#include "x11window.h"
15#include "xdgactivationv1.h"
16#include "xdgshellwindow.h"
17
18#include <QDir>
19#include <QFileInfo>
20#include <QString>
21
22namespace KWin
23{
24
26 : m_window(window)
27{
28 Q_ASSERT(qobject_cast<X11Window *>(window) || qobject_cast<XdgToplevelWindow *>(window));
29
30 m_process.setProcessChannelMode(QProcess::ForwardedChannels);
31
32 const QFileInfo binaryInfo(KWIN_KILLER_BIN);
33 const QFileInfo buildDirBinary{QDir{QCoreApplication::applicationDirPath()}, binaryInfo.fileName()};
34
35 if (buildDirBinary.exists()) {
36 m_process.setProgram(buildDirBinary.absoluteFilePath());
37 } else {
38 m_process.setProgram(KWIN_KILLER_BIN);
39 }
40}
41
43{
44 return m_process.state() == QProcess::Running;
45}
46
47void KillPrompt::start(quint32 timestamp)
48{
49 if (isRunning()) {
50 return;
51 }
52
53 QProcessEnvironment env = kwinApp()->processStartupEnvironment();
54
55 QString wid;
56 QString timestampString;
57 QString hostname = QStringLiteral("localhost");
58 QString appId = !m_window->desktopFileName().isEmpty() ? m_window->desktopFileName() : m_window->resourceClass();
59 QString platform;
60
61 if (auto *x11Window = qobject_cast<X11Window *>(m_window)) {
62 platform = QStringLiteral("xcb");
63 wid = QString::number(x11Window->window());
64 timestampString = QString::number(timestamp);
65 if (!x11Window->clientMachine()->isLocal()) {
66 hostname = x11Window->clientMachine()->hostName();
67 }
68 } else if (auto *xdgToplevel = qobject_cast<XdgToplevelWindow *>(m_window)) {
69 platform = QStringLiteral("wayland");
70 auto *exported = waylandServer()->exportAsForeign(xdgToplevel->surface());
71 wid = exported->handle();
72
73 auto *seat = waylandServer()->seat();
74 const QString token = waylandServer()->xdgActivationIntegration()->requestPrivilegedToken(nullptr, seat->display()->serial(), seat, QStringLiteral("org.kde.kwin.killer"));
75 env.insert(QStringLiteral("XDG_ACTIVATION_TOKEN"), token);
76
77 env.remove(QStringLiteral("QT_WAYLAND_RECONNECT"));
78 }
79
80 QStringList args{
81 QStringLiteral("-platform"),
82 platform,
83 QStringLiteral("--pid"),
84 QString::number(m_window->pid()),
85 QStringLiteral("--windowname"),
86 m_window->captionNormal(),
87 QStringLiteral("--applicationname"),
88 appId,
89 QStringLiteral("--wid"),
90 wid,
91 QStringLiteral("--hostname"),
92 hostname,
93 QStringLiteral("--timestamp"),
94 timestampString,
95 };
96
97 m_process.setArguments(args);
98 m_process.setProcessEnvironment(env);
99 m_process.start();
100}
101
103{
104 m_process.terminate();
105}
106
107} // namespace KWin
bool isRunning() const
Whether the kill helper process is currently running.
void quit()
Terminate the kill helper process.
KillPrompt(Window *window)
Creates a kill helper process.
void start(quint32 timestamp=0)
Starts the kill helper process.
XdgExportedSurface * exportAsForeign(SurfaceInterface *surface)
SeatInterface * seat() const
XdgActivationV1Integration * xdgActivationIntegration() const
QString desktopFileName
Definition window.h:501
QString resourceClass
Definition window.h:115
virtual QString captionNormal() const =0
QString requestPrivilegedToken(SurfaceInterface *surface, uint serial, SeatInterface *seat, const QString &appId)
WaylandServer * waylandServer()