From 815867c178688f9efd669422e4c6bcd5f796f774 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 15 Aug 2024 18:46:06 -0700 Subject: [PATCH] x11/panelwindow: fix multi monitor Previously attached panels to the virtual desktop geometry instead of the screen geometry. --- src/core/proxywindow.cpp | 6 +++++- src/x11/panel_window.cpp | 43 ++++++++++++++++++++++++++-------------- src/x11/panel_window.hpp | 4 +++- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/core/proxywindow.cpp b/src/core/proxywindow.cpp index 05fbff0a..c4b72a04 100644 --- a/src/core/proxywindow.cpp +++ b/src/core/proxywindow.cpp @@ -140,6 +140,8 @@ void ProxyWindowBase::completeWindow() { if (this->mScreen != nullptr && this->window->screen() != this->mScreen) { if (this->window->isVisible()) this->window->setVisible(false); this->window->setScreen(this->mScreen); + } else if (this->mScreen == nullptr) { + this->mScreen = this->window->screen(); } this->setWidth(this->mWidth); @@ -259,7 +261,6 @@ void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) { } if (this->window == nullptr) { - this->mScreen = qscreen; emit this->screenChanged(); } else { auto reshow = this->isVisibleDirect(); @@ -267,6 +268,9 @@ void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) { if (this->window != nullptr) this->window->setScreen(qscreen); if (reshow) this->setVisibleDirect(true); } + + if (qscreen) this->mScreen = qscreen; + else this->mScreen = this->window->screen(); } void ProxyWindowBase::onScreenDestroyed() { this->mScreen = nullptr; } diff --git a/src/x11/panel_window.cpp b/src/x11/panel_window.cpp index fab50abe..b092b7e5 100644 --- a/src/x11/panel_window.cpp +++ b/src/x11/panel_window.cpp @@ -88,10 +88,13 @@ void XPanelWindow::connectWindow() { this->window->installEventFilter(&this->eventFilter); this->connectScreen(); - // clang-format off - QObject::connect(this->window, &QQuickWindow::screenChanged, this, &XPanelWindow::connectScreen); - QObject::connect(this->window, &QQuickWindow::visibleChanged, this, &XPanelWindow::updatePanelStack); - // clang-format on + + QObject::connect( + this->window, + &QQuickWindow::visibleChanged, + this, + &XPanelWindow::updatePanelStack + ); // qt overwrites _NET_WM_STATE, so we have to use the qt api // QXcbWindow::WindowType::Dock in qplatformwindow_p.h @@ -129,6 +132,11 @@ void XPanelWindow::setHeight(qint32 height) { } } +void XPanelWindow::setScreen(QuickshellScreenInfo* screen) { + this->ProxyWindowBase::setScreen(screen); + this->connectScreen(); +} + Anchors XPanelWindow::anchors() const { return this->mAnchors; } void XPanelWindow::setAnchors(Anchors anchors) { @@ -194,14 +202,14 @@ void XPanelWindow::xInit() { // Stick to every workspace auto desktop = 0xffffffff; xcb_change_property( - conn, - XCB_PROP_MODE_REPLACE, - this->window->winId(), - XAtom::_NET_WM_DESKTOP.atom(), - XCB_ATOM_CARDINAL, - 32, - 1, - &desktop + conn, + XCB_PROP_MODE_REPLACE, + this->window->winId(), + XAtom::_NET_WM_DESKTOP.atom(), + XCB_ATOM_CARDINAL, + 32, + 1, + &desktop ); } @@ -210,7 +218,7 @@ void XPanelWindow::connectScreen() { QObject::disconnect(this->mTrackedScreen, nullptr, this, nullptr); } - this->mTrackedScreen = this->window->screen(); + this->mTrackedScreen = this->mScreen; if (this->mTrackedScreen != nullptr) { QObject::connect( @@ -220,12 +228,15 @@ void XPanelWindow::connectScreen() { &XPanelWindow::updateDimensions ); } + + this->updateDimensions(); } void XPanelWindow::updateDimensions() { - if (this->window == nullptr || this->window->handle() == nullptr) return; + if (this->window == nullptr || this->window->handle() == nullptr || this->mScreen == nullptr) + return; - auto screenGeometry = this->window->screen()->virtualGeometry(); + auto screenGeometry = this->mScreen->geometry(); if (this->mExclusionMode != ExclusionMode::Ignore) { for (auto* panel: XPanelStack::instance()->panels(this)) { @@ -235,6 +246,8 @@ void XPanelWindow::updateDimensions() { // we only care about windows in the same layer if (panel->mAboveWindows != this->mAboveWindows) continue; + if (panel->mScreen != this->mScreen) continue; + int side = -1; quint32 exclusiveZone = 0; panel->getExclusion(side, exclusiveZone); diff --git a/src/x11/panel_window.hpp b/src/x11/panel_window.hpp index db8de7d2..4cdfaaa3 100644 --- a/src/x11/panel_window.hpp +++ b/src/x11/panel_window.hpp @@ -49,6 +49,8 @@ public: void setWidth(qint32 width) override; void setHeight(qint32 height) override; + void setScreen(QuickshellScreenInfo* screen) override; + [[nodiscard]] Anchors anchors() const; void setAnchors(Anchors anchors); @@ -77,11 +79,11 @@ signals: private slots: void xInit(); - void connectScreen(); void updateDimensions(); void updatePanelStack(); private: + void connectScreen(); void getExclusion(int& side, quint32& exclusiveZone); void updateStrut(); void updateAboveWindows();