feat: expose ProxyWindowBase.screen

This commit is contained in:
outfoxxed 2024-02-18 19:23:20 -08:00
parent 6ad4fffc17
commit a361930865
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 45 additions and 45 deletions

View file

@ -12,10 +12,8 @@
#include <qwindow.h>
#include "proxywindow.hpp"
#include "qmlscreen.hpp"
void ProxyShellWindow::setupWindow() {
QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyShellWindow::screenChanged);
this->shellWindow = LayerShellQt::Window::get(this->window);
this->ProxyWindowBase::setupWindow();
@ -32,7 +30,6 @@ void ProxyShellWindow::setupWindow() {
QObject::connect(this, &ProxyShellWindow::marginsChanged, this, &ProxyShellWindow::updateExclusionZone);
// clang-format on
this->window->setScreen(this->mScreen);
this->setAnchors(this->mAnchors);
this->setMargins(this->mMargins);
this->setExclusionMode(this->mExclusionMode); // also sets exclusion zone
@ -64,37 +61,6 @@ void ProxyShellWindow::setHeight(qint32 height) {
if (!anchors.mTop || !anchors.mBottom) this->ProxyWindowBase::setHeight(height);
}
void ProxyShellWindow::setScreen(QuickShellScreenInfo* screen) {
if (this->mScreen != nullptr) {
QObject::disconnect(this->mScreen, nullptr, this, nullptr);
}
auto* qscreen = screen == nullptr ? nullptr : screen->screen;
if (qscreen != nullptr) {
QObject::connect(qscreen, &QObject::destroyed, this, &ProxyShellWindow::onScreenDestroyed);
}
if (this->window == nullptr) this->mScreen = qscreen;
else this->window->setScreen(qscreen);
}
void ProxyShellWindow::onScreenDestroyed() { this->mScreen = nullptr; }
QuickShellScreenInfo* ProxyShellWindow::screen() const {
QScreen* qscreen = nullptr;
if (this->window == nullptr) {
if (this->mScreen != nullptr) qscreen = this->mScreen;
} else {
qscreen = this->window->screen();
}
return new QuickShellScreenInfo(
const_cast<ProxyShellWindow*>(this), // NOLINT
qscreen
);
}
void ProxyShellWindow::setAnchors(Anchors anchors) {
if (this->window == nullptr) {
this->mAnchors = anchors;

View file

@ -12,7 +12,6 @@
#include <qwindow.h>
#include "proxywindow.hpp"
#include "qmlscreen.hpp"
class Anchors {
Q_GADGET;
@ -134,10 +133,6 @@ Q_ENUM_NS(Enum);
class ProxyShellWindow: public ProxyWindowBase {
// clang-format off
Q_OBJECT;
/// The screen that the shell window currently occupies.
///
/// > [!INFO] This cannot be changed while the shell window is visible.
Q_PROPERTY(QuickShellScreenInfo* screen READ screen WRITE setScreen NOTIFY screenChanged);
/// Anchors attach a shell window to the sides of the screen.
/// By default all anchors are disabled to avoid blocking the entire screen due to a misconfiguration.
///
@ -175,9 +170,6 @@ public:
void setHeight(qint32 height) override;
void setScreen(QuickShellScreenInfo* screen);
[[nodiscard]] QuickShellScreenInfo* screen() const;
void setAnchors(Anchors anchors);
[[nodiscard]] Anchors anchors() const;
@ -203,7 +195,6 @@ public:
[[nodiscard]] ScreenConfiguration::Enum screenConfiguration() const;
signals:
void screenChanged();
void anchorsChanged();
void marginsChanged();
void exclusionZoneChanged();
@ -213,11 +204,9 @@ signals:
private slots:
void updateExclusionZone();
void onScreenDestroyed();
private:
LayerShellQt::Window* shellWindow = nullptr;
QScreen* mScreen = nullptr;
ExclusionMode::Enum mExclusionMode = ExclusionMode::Normal;
qint32 mExclusionZone = 0;
Anchors mAnchors;

View file

@ -9,6 +9,7 @@
#include <qtypes.h>
#include <qwindow.h>
#include "qmlscreen.hpp"
#include "region.hpp"
#include "reload.hpp"
@ -53,6 +54,7 @@ void ProxyWindowBase::setupWindow() {
QObject::connect(this->window, &QWindow::visibilityChanged, this, &ProxyWindowBase::visibleChanged);
QObject::connect(this->window, &QWindow::widthChanged, this, &ProxyWindowBase::widthChanged);
QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyWindowBase::heightChanged);
QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged);
QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged);
QObject::connect(this, &ProxyWindowBase::maskChanged, this, &ProxyWindowBase::onMaskChanged);
@ -60,6 +62,7 @@ void ProxyWindowBase::setupWindow() {
QObject::connect(this, &ProxyWindowBase::heightChanged, this, &ProxyWindowBase::onMaskChanged);
// clang-format on
this->window->setScreen(this->mScreen);
this->setWidth(this->mWidth);
this->setHeight(this->mHeight);
this->setColor(this->mColor);
@ -115,6 +118,37 @@ void ProxyWindowBase::setHeight(qint32 height) {
} else this->window->setHeight(height);
}
void ProxyWindowBase::setScreen(QuickShellScreenInfo* screen) {
if (this->mScreen != nullptr) {
QObject::disconnect(this->mScreen, nullptr, this, nullptr);
}
auto* qscreen = screen == nullptr ? nullptr : screen->screen;
if (qscreen != nullptr) {
QObject::connect(qscreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed);
}
if (this->window == nullptr) this->mScreen = qscreen;
else this->window->setScreen(qscreen);
}
void ProxyWindowBase::onScreenDestroyed() { this->mScreen = nullptr; }
QuickShellScreenInfo* ProxyWindowBase::screen() const {
QScreen* qscreen = nullptr;
if (this->window == nullptr) {
if (this->mScreen != nullptr) qscreen = this->mScreen;
} else {
qscreen = this->window->screen();
}
return new QuickShellScreenInfo(
const_cast<ProxyWindowBase*>(this), // NOLINT
qscreen
);
}
QColor ProxyWindowBase::color() const {
if (this->window == nullptr) return this->mColor;
else return this->window->color();

View file

@ -12,6 +12,7 @@
#include <qtmetamacros.h>
#include <qtypes.h>
#include "qmlscreen.hpp"
#include "region.hpp"
#include "reload.hpp"
@ -38,6 +39,10 @@ class ProxyWindowBase: public Reloadable {
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
/// The screen that the window currently occupies.
///
/// > [!INFO] This cannot be changed while the window is visible.
Q_PROPERTY(QuickShellScreenInfo* screen READ screen WRITE setScreen NOTIFY screenChanged);
/// The background color of the window. Defaults to white.
///
/// > [!WARNING] This seems to behave weirdly when using transparent colors on some systems.
@ -129,6 +134,9 @@ public:
[[nodiscard]] virtual qint32 height() const;
virtual void setHeight(qint32 height);
virtual void setScreen(QuickShellScreenInfo* screen);
[[nodiscard]] QuickShellScreenInfo* screen() const;
[[nodiscard]] QColor color() const;
void setColor(QColor color);
@ -142,6 +150,7 @@ signals:
void visibleChanged();
void widthChanged();
void heightChanged();
void screenChanged();
void colorChanged();
void maskChanged();
@ -149,11 +158,13 @@ private slots:
void onMaskChanged();
void onWidthChanged();
void onHeightChanged();
void onScreenDestroyed();
protected:
bool mVisible = true;
qint32 mWidth = 100;
qint32 mHeight = 100;
QScreen* mScreen = nullptr;
QColor mColor = Qt::white;
PendingRegion* mMask = nullptr;
QQuickWindow* window = nullptr;