From ff2b5b5468fcfce0a2277cb2baad494344144ad8 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 13 Aug 2017 12:00:08 +0200 Subject: democompositor: Provide an example to detect unknown apps When a new wlShellSurface is created we can check the identity of the client and if it is belongs to an application launched by the democompositor. In the future such apps might be killed and their surface not displayed. Introduce appStateForPid to find the AppState and return it as a QVariant to easily use it in QML. Use int as type as one can not easily use Q_PID in QML. Change-Id: Ibb9ac004a8016bd76f61679f5c837c99783fa7e8 Reviewed-by: Paul Olav Tvete --- wayland/democompositor/processlauncher.cpp | 13 +++++++++++++ wayland/democompositor/processlauncher.h | 1 + wayland/democompositor/qml/Screen.qml | 1 + wayland/democompositor/qml/main.qml | 8 ++++++++ 4 files changed, 23 insertions(+) diff --git a/wayland/democompositor/processlauncher.cpp b/wayland/democompositor/processlauncher.cpp index c8fe15c..bb11cb9 100644 --- a/wayland/democompositor/processlauncher.cpp +++ b/wayland/democompositor/processlauncher.cpp @@ -74,6 +74,19 @@ WaylandProcessLauncher::~WaylandProcessLauncher() { } +QVariant WaylandProcessLauncher::appStateForPid(int pid) const +{ + for (auto state : m_appStates) { + if (state.process->pid() == pid) { + qCDebug(procs) << "Found state for" << pid << state.appEntry.executableName; + return QVariant::fromValue(state); + } + } + + qCDebug(procs) << "Couldn't find entry for" << pid; + return QVariant(); +} + bool WaylandProcessLauncher::isRunning(const AppEntry& entry) const { for (auto state : m_appStates) { diff --git a/wayland/democompositor/processlauncher.h b/wayland/democompositor/processlauncher.h index 84f9cb8..f21be98 100644 --- a/wayland/democompositor/processlauncher.h +++ b/wayland/democompositor/processlauncher.h @@ -81,6 +81,7 @@ public: ~WaylandProcessLauncher(); Q_INVOKABLE void launch(const AppEntry &entry); + Q_INVOKABLE QVariant appStateForPid(int pid) const; Q_INVOKABLE bool isRunning(const AppEntry& entry) const; Q_SIGNALS: diff --git a/wayland/democompositor/qml/Screen.qml b/wayland/democompositor/qml/Screen.qml index fb8d4ea..ffb8490 100644 --- a/wayland/democompositor/qml/Screen.qml +++ b/wayland/democompositor/qml/Screen.qml @@ -59,6 +59,7 @@ import com.theqtcompany.wlapplistmodel 1.0 WaylandOutput { id: output property alias surfaceArea: background + property alias appLauncher: launcher property var windowList: [ ] property int hiddenWindowCount diff --git a/wayland/democompositor/qml/main.qml b/wayland/democompositor/qml/main.qml index 8c0c621..75d1adc 100644 --- a/wayland/democompositor/qml/main.qml +++ b/wayland/democompositor/qml/main.qml @@ -57,6 +57,7 @@ WaylandCompositor { property var primarySurfacesArea: null Screen { + id: mainScreen compositor: comp } @@ -69,6 +70,13 @@ WaylandCompositor { WlShell { id: defaultShell onWlShellSurfaceCreated: { + const pid = shellSurface.surface.client.processId; + const appState = mainScreen.appLauncher.appStateForPid(pid); + if (!appState) { + console.log("shellSurface of unknown application. Continuing. PID=" + pid); + } else { + console.log("shellSurface belonging to " + appState.appEntry.executableName); + } chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": shellSurface } ); defaultOutput.relayout(); } -- cgit v1.2.3