Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
WindowsProvider.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3#pragma once
4
6#include <PhosphorShellLauncher/phosphorshelllauncher_export.h>
7
8#include <QList>
9#include <QPointer>
10#include <QSet>
11#include <QString>
12#include <QVariantList>
13
14QT_BEGIN_NAMESPACE
15class QAbstractItemModel;
16QT_END_NAMESPACE
17
18namespace PhosphorShellLauncher {
19
20// Open windows, for switching. Lists every toplevel on an empty query
21// and fuzzy-matches title and app id otherwise. Enter activates the
22// window.
23//
24// Reads the shell's toplevel model duck-typed: any QAbstractItemModel
25// with a `toplevel` role whose objects expose `title` and `appId`
26// properties and an invokable `activate()`. That is the shape of
27// Phosphor.Shell's Toplevels model, and it is also exactly how QML would
28// consume the same objects, so this library stays free of the Wayland
29// stack for the sake of one provider. A host on a compositor that does
30// not advertise foreign-toplevel simply gets an empty model here, and
31// the provider lists nothing.
32//
33// Rows are addressed by the toplevel object itself (its address), not
34// its index: windows open and close while the launcher is up, and an
35// index captured at query time would activate the wrong one.
36class PHOSPHORSHELLLAUNCHER_EXPORT WindowsProvider : public PhosphorRegistry::ILauncherProvider
37{
38 Q_OBJECT
39
40public:
41 // Null makes the provider inert (no rows), never a crash.
47 explicit WindowsProvider(QAbstractItemModel* toplevels, QObject* parent = nullptr);
48 ~WindowsProvider() override;
49
50 [[nodiscard]] QString id() const override;
51 [[nodiscard]] QString displayName() const override;
52 [[nodiscard]] QString iconName() const override;
53 [[nodiscard]] bool listsOnEmptyQuery() const override;
54
55 void setQuery(const QString& query) override;
56 [[nodiscard]] QList<PhosphorRegistry::LauncherResult> results() const override;
57 [[nodiscard]] bool activate(const QString& resultId, Activation activation) override;
58
59 // A host without foreign-toplevel can supply stable native window IDs.
60 // Each row carries windowId, title, appId and an optional subtitle.
61 void setNativeWindows(const QVariantList& windows);
62
63Q_SIGNALS:
64 void nativeWindowActivated(const QString& windowId);
65
66private Q_SLOTS:
67 // A slot, not a plain method: watchToplevels connects to each toplevel's
68 // titleChanged / appIdChanged by NAME, since this library does not link
69 // the Wayland toplevel type, and a name-based connect needs a name on
70 // this side too.
71 void recompute();
72
73private:
80 void watchToplevels();
81 [[nodiscard]] QObject* toplevelAt(int row) const;
82 [[nodiscard]] QObject* toplevelFor(const QString& resultId) const;
83
84 QPointer<QAbstractItemModel> m_toplevels;
85 int m_toplevelRole = -1;
86 bool m_native = false;
87 QVariantList m_nativeWindows;
88 QString m_query;
89 QList<PhosphorRegistry::LauncherResult> m_results;
90 // Toplevels already subscribed to, so a rescan does not stack a second
91 // connection on each one. Entries are dropped as the objects die.
92 QSet<QObject*> m_watched;
93};
94
95} // namespace PhosphorShellLauncher
Definition ILauncherProvider.h:106
Activation
Definition ILauncherProvider.h:112
QString iconName() const override
QString displayName() const override
bool listsOnEmptyQuery() const override
WindowsProvider(QAbstractItemModel *toplevels, QObject *parent=nullptr)
The model is resolved ONCE, here, and so is its "toplevel" role.
bool activate(const QString &resultId, Activation activation) override
void nativeWindowActivated(const QString &windowId)
void setNativeWindows(const QVariantList &windows)
QList< PhosphorRegistry::LauncherResult > results() const override
void setQuery(const QString &query) override
Definition AppsProvider.h:19