forked from quickshell/quickshell
feat: expose ProxyWindowBase.screen
This commit is contained in:
parent
6ad4fffc17
commit
a361930865
|
@ -12,10 +12,8 @@
|
||||||
#include <qwindow.h>
|
#include <qwindow.h>
|
||||||
|
|
||||||
#include "proxywindow.hpp"
|
#include "proxywindow.hpp"
|
||||||
#include "qmlscreen.hpp"
|
|
||||||
|
|
||||||
void ProxyShellWindow::setupWindow() {
|
void ProxyShellWindow::setupWindow() {
|
||||||
QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyShellWindow::screenChanged);
|
|
||||||
this->shellWindow = LayerShellQt::Window::get(this->window);
|
this->shellWindow = LayerShellQt::Window::get(this->window);
|
||||||
|
|
||||||
this->ProxyWindowBase::setupWindow();
|
this->ProxyWindowBase::setupWindow();
|
||||||
|
@ -32,7 +30,6 @@ void ProxyShellWindow::setupWindow() {
|
||||||
QObject::connect(this, &ProxyShellWindow::marginsChanged, this, &ProxyShellWindow::updateExclusionZone);
|
QObject::connect(this, &ProxyShellWindow::marginsChanged, this, &ProxyShellWindow::updateExclusionZone);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
this->window->setScreen(this->mScreen);
|
|
||||||
this->setAnchors(this->mAnchors);
|
this->setAnchors(this->mAnchors);
|
||||||
this->setMargins(this->mMargins);
|
this->setMargins(this->mMargins);
|
||||||
this->setExclusionMode(this->mExclusionMode); // also sets exclusion zone
|
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);
|
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) {
|
void ProxyShellWindow::setAnchors(Anchors anchors) {
|
||||||
if (this->window == nullptr) {
|
if (this->window == nullptr) {
|
||||||
this->mAnchors = anchors;
|
this->mAnchors = anchors;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include <qwindow.h>
|
#include <qwindow.h>
|
||||||
|
|
||||||
#include "proxywindow.hpp"
|
#include "proxywindow.hpp"
|
||||||
#include "qmlscreen.hpp"
|
|
||||||
|
|
||||||
class Anchors {
|
class Anchors {
|
||||||
Q_GADGET;
|
Q_GADGET;
|
||||||
|
@ -134,10 +133,6 @@ Q_ENUM_NS(Enum);
|
||||||
class ProxyShellWindow: public ProxyWindowBase {
|
class ProxyShellWindow: public ProxyWindowBase {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
Q_OBJECT;
|
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.
|
/// 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.
|
/// 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 setHeight(qint32 height) override;
|
||||||
|
|
||||||
void setScreen(QuickShellScreenInfo* screen);
|
|
||||||
[[nodiscard]] QuickShellScreenInfo* screen() const;
|
|
||||||
|
|
||||||
void setAnchors(Anchors anchors);
|
void setAnchors(Anchors anchors);
|
||||||
[[nodiscard]] Anchors anchors() const;
|
[[nodiscard]] Anchors anchors() const;
|
||||||
|
|
||||||
|
@ -203,7 +195,6 @@ public:
|
||||||
[[nodiscard]] ScreenConfiguration::Enum screenConfiguration() const;
|
[[nodiscard]] ScreenConfiguration::Enum screenConfiguration() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void screenChanged();
|
|
||||||
void anchorsChanged();
|
void anchorsChanged();
|
||||||
void marginsChanged();
|
void marginsChanged();
|
||||||
void exclusionZoneChanged();
|
void exclusionZoneChanged();
|
||||||
|
@ -213,11 +204,9 @@ signals:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateExclusionZone();
|
void updateExclusionZone();
|
||||||
void onScreenDestroyed();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LayerShellQt::Window* shellWindow = nullptr;
|
LayerShellQt::Window* shellWindow = nullptr;
|
||||||
QScreen* mScreen = nullptr;
|
|
||||||
ExclusionMode::Enum mExclusionMode = ExclusionMode::Normal;
|
ExclusionMode::Enum mExclusionMode = ExclusionMode::Normal;
|
||||||
qint32 mExclusionZone = 0;
|
qint32 mExclusionZone = 0;
|
||||||
Anchors mAnchors;
|
Anchors mAnchors;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <qtypes.h>
|
#include <qtypes.h>
|
||||||
#include <qwindow.h>
|
#include <qwindow.h>
|
||||||
|
|
||||||
|
#include "qmlscreen.hpp"
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
#include "reload.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::visibilityChanged, this, &ProxyWindowBase::visibleChanged);
|
||||||
QObject::connect(this->window, &QWindow::widthChanged, this, &ProxyWindowBase::widthChanged);
|
QObject::connect(this->window, &QWindow::widthChanged, this, &ProxyWindowBase::widthChanged);
|
||||||
QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyWindowBase::heightChanged);
|
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->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged);
|
||||||
|
|
||||||
QObject::connect(this, &ProxyWindowBase::maskChanged, this, &ProxyWindowBase::onMaskChanged);
|
QObject::connect(this, &ProxyWindowBase::maskChanged, this, &ProxyWindowBase::onMaskChanged);
|
||||||
|
@ -60,6 +62,7 @@ void ProxyWindowBase::setupWindow() {
|
||||||
QObject::connect(this, &ProxyWindowBase::heightChanged, this, &ProxyWindowBase::onMaskChanged);
|
QObject::connect(this, &ProxyWindowBase::heightChanged, this, &ProxyWindowBase::onMaskChanged);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
this->window->setScreen(this->mScreen);
|
||||||
this->setWidth(this->mWidth);
|
this->setWidth(this->mWidth);
|
||||||
this->setHeight(this->mHeight);
|
this->setHeight(this->mHeight);
|
||||||
this->setColor(this->mColor);
|
this->setColor(this->mColor);
|
||||||
|
@ -115,6 +118,37 @@ void ProxyWindowBase::setHeight(qint32 height) {
|
||||||
} else this->window->setHeight(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 {
|
QColor ProxyWindowBase::color() const {
|
||||||
if (this->window == nullptr) return this->mColor;
|
if (this->window == nullptr) return this->mColor;
|
||||||
else return this->window->color();
|
else return this->window->color();
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <qtmetamacros.h>
|
#include <qtmetamacros.h>
|
||||||
#include <qtypes.h>
|
#include <qtypes.h>
|
||||||
|
|
||||||
|
#include "qmlscreen.hpp"
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
#include "reload.hpp"
|
#include "reload.hpp"
|
||||||
|
|
||||||
|
@ -38,6 +39,10 @@ class ProxyWindowBase: public Reloadable {
|
||||||
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
|
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
|
||||||
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
|
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
|
||||||
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
|
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.
|
/// The background color of the window. Defaults to white.
|
||||||
///
|
///
|
||||||
/// > [!WARNING] This seems to behave weirdly when using transparent colors on some systems.
|
/// > [!WARNING] This seems to behave weirdly when using transparent colors on some systems.
|
||||||
|
@ -129,6 +134,9 @@ public:
|
||||||
[[nodiscard]] virtual qint32 height() const;
|
[[nodiscard]] virtual qint32 height() const;
|
||||||
virtual void setHeight(qint32 height);
|
virtual void setHeight(qint32 height);
|
||||||
|
|
||||||
|
virtual void setScreen(QuickShellScreenInfo* screen);
|
||||||
|
[[nodiscard]] QuickShellScreenInfo* screen() const;
|
||||||
|
|
||||||
[[nodiscard]] QColor color() const;
|
[[nodiscard]] QColor color() const;
|
||||||
void setColor(QColor color);
|
void setColor(QColor color);
|
||||||
|
|
||||||
|
@ -142,6 +150,7 @@ signals:
|
||||||
void visibleChanged();
|
void visibleChanged();
|
||||||
void widthChanged();
|
void widthChanged();
|
||||||
void heightChanged();
|
void heightChanged();
|
||||||
|
void screenChanged();
|
||||||
void colorChanged();
|
void colorChanged();
|
||||||
void maskChanged();
|
void maskChanged();
|
||||||
|
|
||||||
|
@ -149,11 +158,13 @@ private slots:
|
||||||
void onMaskChanged();
|
void onMaskChanged();
|
||||||
void onWidthChanged();
|
void onWidthChanged();
|
||||||
void onHeightChanged();
|
void onHeightChanged();
|
||||||
|
void onScreenDestroyed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool mVisible = true;
|
bool mVisible = true;
|
||||||
qint32 mWidth = 100;
|
qint32 mWidth = 100;
|
||||||
qint32 mHeight = 100;
|
qint32 mHeight = 100;
|
||||||
|
QScreen* mScreen = nullptr;
|
||||||
QColor mColor = Qt::white;
|
QColor mColor = Qt::white;
|
||||||
PendingRegion* mMask = nullptr;
|
PendingRegion* mMask = nullptr;
|
||||||
QQuickWindow* window = nullptr;
|
QQuickWindow* window = nullptr;
|
||||||
|
|
Loading…
Reference in a new issue