diff --git a/src/window/FloatingWindow.cpp b/src/window/FloatingWindow.cpp index 95ca263..8c881fd 100644 --- a/src/window/FloatingWindow.cpp +++ b/src/window/FloatingWindow.cpp @@ -36,6 +36,20 @@ FloatingWindow::FloatingWindow(QWindow *window, QObject *parent) } m_position = defaultPosition(); apply(); + followScreen(window->screen()); + connect(window, &QWindow::screenChanged, this, &FloatingWindow::followScreen); +} + +// Re-fits the window (not saved: the stored geometry is the user's choice). +void FloatingWindow::followScreen(QScreen *screen) +{ + if (m_screen) + disconnect(m_screen, nullptr, this, nullptr); + m_screen = screen; + if (!m_screen) + return; + connect(m_screen, &QScreen::geometryChanged, this, [this] { setGeometry(geometry()); }); + setGeometry(geometry()); } QRect FloatingWindow::geometry() const diff --git a/src/window/FloatingWindow.h b/src/window/FloatingWindow.h index 79b8e25..0a11d8e 100644 --- a/src/window/FloatingWindow.h +++ b/src/window/FloatingWindow.h @@ -4,13 +4,15 @@ #include #include +class QScreen; class QWindow; namespace LayerShellQt { class Window; } // Places a keyboard window as a free-floating overlay that never takes focus. // On Wayland: a layer-shell surface anchored top-left, positioned via margins. // On X11: a frameless, non-focusable, always-on-top tool window. -// Geometry is relative to the window's screen and always kept on it. +// Geometry is relative to the window's screen and always kept on it, also +// when the screen's resolution changes or the window moves to another one. class FloatingWindow : public QObject { Q_OBJECT @@ -42,8 +44,10 @@ private: QPoint clamped(QPoint position, QSize size) const; QPoint defaultPosition() const; void apply(); + void followScreen(QScreen *screen); QWindow *m_window; LayerShellQt::Window *m_layerSurface = nullptr; QPoint m_position; + QScreen *m_screen = nullptr; };