#pragma once #include #include #include #include #include #include #include #include #include #include "qmlscreen.hpp" class QuickshellGlobal: public QObject { Q_OBJECT; // clang-format off /// All currently connected screens. /// /// This property updates as connected screens change. /// /// #### Reusing a window on every screen /// ```qml /// ShellRoot { /// Variants { /// ShellWindow { /// // ... /// } /// /// // see Variants for details /// variants: Quickshell.screens.map(screen => ({ screen })) /// } /// } /// ``` /// /// This creates an instance of your window once on every screen. /// As screens are added or removed your window will be created or destroyed on those screens. Q_PROPERTY(QQmlListProperty screens READ screens NOTIFY screensChanged); /// Quickshell's working directory. Defaults to whereever quickshell was launched from. Q_PROPERTY(QString workingDirectory READ workingDirectory WRITE setWorkingDirectory NOTIFY workingDirectoryChanged); // clang-format on QML_SINGLETON; QML_NAMED_ELEMENT(Quickshell); public: QuickshellGlobal(QObject* parent = nullptr); QQmlListProperty screens(); /// Reload the shell from the [ShellRoot]. /// /// `hard` - perform a hard reload. If this is false, Quickshell will attempt to reuse windows /// that already exist. If true windows will be recreated. /// /// See [Reloadable] for more information on what can be reloaded and how. /// /// [Reloadable]: ../reloadable Q_INVOKABLE void reload(bool hard); /// Returns the string value of an environment variable or null if it is not set. Q_INVOKABLE QVariant env(const QString& variable); [[nodiscard]] QString workingDirectory() const; void setWorkingDirectory(const QString& workingDirectory); static QuickshellGlobal* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/); static QuickshellGlobal* instance(); static void deleteInstance(); signals: void screensChanged(); void workingDirectoryChanged(); public slots: void updateScreens(); private: static qsizetype screensCount(QQmlListProperty* prop); static QuickshellScreenInfo* screenAt(QQmlListProperty* prop, qsizetype i); QVector mScreens; };