Introduces a new `WindowControls` component in the desktop top bar with minimize, maximize/restore, and close actions for the focused window. `WindowService` now exposes focused-window presence/maximized state plus focused-window convenience actions to support this UI. Also extends Nebula UI with a reusable `NebulaToolTip`, keyboard/pressed-state support in `NebulaIconButton`, new window-control glyphs in `NebulaIcon`, and theme tokens for pressed/danger hover states, with CMake and README updates to register/document the new components.
91 lines
3.4 KiB
C++
91 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include "WindowBackend.hpp"
|
|
#include "WindowModel.hpp"
|
|
#include "WorkspaceModel.hpp"
|
|
|
|
#include <QJSEngine>
|
|
#include <QObject>
|
|
#include <QQmlEngine>
|
|
#include <QVector>
|
|
#include <QtQml/qqmlregistration.h>
|
|
|
|
class ApplicationService;
|
|
|
|
class WindowService : public QObject
|
|
{
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
QML_SINGLETON
|
|
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
|
|
Q_PROPERTY(WindowModel *model READ model CONSTANT)
|
|
Q_PROPERTY(WorkspaceModel *workspaceModel READ workspaceModel CONSTANT)
|
|
Q_PROPERTY(int windowCount READ windowCount NOTIFY windowCountChanged)
|
|
Q_PROPERTY(bool hasFocusedWindow READ hasFocusedWindow NOTIFY focusChanged)
|
|
Q_PROPERTY(QString focusedWindowId READ focusedWindowId NOTIFY focusChanged)
|
|
Q_PROPERTY(QString focusedWindowTitle READ focusedWindowTitle NOTIFY focusChanged)
|
|
Q_PROPERTY(QString focusedApplicationId READ focusedApplicationId NOTIFY focusChanged)
|
|
Q_PROPERTY(QString focusedApplicationName READ focusedApplicationName NOTIFY focusChanged)
|
|
Q_PROPERTY(bool focusedWindowMaximized READ focusedWindowMaximized NOTIFY focusChanged)
|
|
|
|
public:
|
|
enum SnapEdge {
|
|
SnapLeft = WindowBackend::SnapLeft,
|
|
SnapRight = WindowBackend::SnapRight,
|
|
SnapMaximize = WindowBackend::SnapMaximize
|
|
};
|
|
Q_ENUM(SnapEdge)
|
|
|
|
explicit WindowService(QObject *parent = nullptr);
|
|
static WindowService *create(QQmlEngine *engine, QJSEngine *scriptEngine);
|
|
|
|
bool connected() const;
|
|
WindowModel *model() const;
|
|
WorkspaceModel *workspaceModel() const;
|
|
int windowCount() const;
|
|
|
|
bool hasFocusedWindow() const;
|
|
QString focusedWindowId() const;
|
|
QString focusedWindowTitle() const;
|
|
QString focusedApplicationId() const;
|
|
QString focusedApplicationName() const;
|
|
bool focusedWindowMaximized() const;
|
|
|
|
Q_INVOKABLE bool focusWindow(const QString &windowId);
|
|
Q_INVOKABLE bool closeWindow(const QString &windowId);
|
|
Q_INVOKABLE bool maximizeWindow(const QString &windowId);
|
|
Q_INVOKABLE bool restoreWindow(const QString &windowId);
|
|
Q_INVOKABLE bool minimizeWindow(const QString &windowId);
|
|
Q_INVOKABLE bool minimizeFocusedWindow();
|
|
Q_INVOKABLE bool toggleMaximizeFocusedWindow();
|
|
Q_INVOKABLE bool closeFocusedWindow();
|
|
Q_INVOKABLE bool setWindowFloating(const QString &windowId, bool floating);
|
|
Q_INVOKABLE bool moveWindow(const QString &windowId, int x, int y);
|
|
Q_INVOKABLE bool resizeWindow(const QString &windowId, int width, int height);
|
|
Q_INVOKABLE bool snapWindow(const QString &windowId, SnapEdge edge);
|
|
Q_INVOKABLE bool switchWorkspace(const QString &workspaceId);
|
|
|
|
signals:
|
|
void connectedChanged();
|
|
void windowCountChanged();
|
|
void focusChanged();
|
|
|
|
private:
|
|
void syncFromBackend();
|
|
void resolveNames(QVector<WindowInfo> &windows) const;
|
|
void bindApplicationService();
|
|
static qint64 parseWindowId(const QString &windowId);
|
|
static QString humanizeIdentifier(const QString &appId, const QString &windowClass);
|
|
static QString titleCaseIdentifier(QString id);
|
|
|
|
WindowBackend *m_backend = nullptr;
|
|
WindowModel *m_model = nullptr;
|
|
WorkspaceModel *m_workspaces = nullptr;
|
|
ApplicationService *m_applications = nullptr;
|
|
QString m_focusedWindowId;
|
|
QString m_focusedWindowTitle;
|
|
QString m_focusedApplicationId;
|
|
QString m_focusedApplicationName;
|
|
bool m_focusedWindowMaximized = false;
|
|
};
|