Files
Nebula-OS/core/windows/WindowService.hpp
T
andrew 4321209e92 Add floating traffic-light window chrome
Introduces a dedicated layer-shell `WindowChromeSurface` that renders macOS-style traffic-light controls over the focused Sway window titlebar, replacing the old top-bar window controls. Adds theme tokens and a reusable `TrafficLightButton` component, updates shell QML/CMake wiring, and adjusts Sway titlebar padding/title format so window titles do not overlap the overlay. Window tracking was extended with focused-window geometry/deco/fullscreen properties plus backend refresh support so the chrome follows window movement and state changes in near real time.
2026-08-26 22:38:33 +12:00

123 lines
5.1 KiB
C++

#pragma once
#include "WindowBackend.hpp"
#include "WindowModel.hpp"
#include "WorkspaceModel.hpp"
#include <QJSEngine>
#include <QObject>
#include <QQmlEngine>
#include <QTimer>
#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)
Q_PROPERTY(bool focusedWindowFullscreen READ focusedWindowFullscreen NOTIFY focusChanged)
Q_PROPERTY(int focusedWindowX READ focusedWindowX NOTIFY focusedWindowGeometryChanged)
Q_PROPERTY(int focusedWindowY READ focusedWindowY NOTIFY focusedWindowGeometryChanged)
Q_PROPERTY(int focusedWindowWidth READ focusedWindowWidth NOTIFY focusedWindowGeometryChanged)
Q_PROPERTY(int focusedWindowHeight READ focusedWindowHeight NOTIFY focusedWindowGeometryChanged)
Q_PROPERTY(int focusedWindowDecoX READ focusedWindowDecoX NOTIFY focusedWindowGeometryChanged)
Q_PROPERTY(int focusedWindowDecoY READ focusedWindowDecoY NOTIFY focusedWindowGeometryChanged)
Q_PROPERTY(int focusedWindowDecoWidth READ focusedWindowDecoWidth NOTIFY focusedWindowGeometryChanged)
Q_PROPERTY(int focusedWindowDecoHeight READ focusedWindowDecoHeight NOTIFY focusedWindowGeometryChanged)
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;
bool focusedWindowFullscreen() const;
int focusedWindowX() const;
int focusedWindowY() const;
int focusedWindowWidth() const;
int focusedWindowHeight() const;
int focusedWindowDecoX() const;
int focusedWindowDecoY() const;
int focusedWindowDecoWidth() const;
int focusedWindowDecoHeight() 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();
void focusedWindowGeometryChanged();
private:
void syncFromBackend();
void syncFocusedGeometry();
void publishFocusedGeometry(const WindowInfo *focused);
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;
bool m_focusedWindowFullscreen = false;
int m_focusedWindowX = 0;
int m_focusedWindowY = 0;
int m_focusedWindowWidth = 0;
int m_focusedWindowHeight = 0;
int m_focusedWindowDecoX = 0;
int m_focusedWindowDecoY = 0;
int m_focusedWindowDecoWidth = 0;
int m_focusedWindowDecoHeight = 0;
QTimer *m_geometryTimer = nullptr;
};