Keep the window on screen after screen changes
Re-fits on a resolution change or a move to another screen, without overwriting the saved geometry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,20 @@ FloatingWindow::FloatingWindow(QWindow *window, QObject *parent)
|
|||||||
}
|
}
|
||||||
m_position = defaultPosition();
|
m_position = defaultPosition();
|
||||||
apply();
|
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
|
QRect FloatingWindow::geometry() const
|
||||||
|
|||||||
@@ -4,13 +4,15 @@
|
|||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
|
|
||||||
|
class QScreen;
|
||||||
class QWindow;
|
class QWindow;
|
||||||
namespace LayerShellQt { class Window; }
|
namespace LayerShellQt { class Window; }
|
||||||
|
|
||||||
// Places a keyboard window as a free-floating overlay that never takes focus.
|
// 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 Wayland: a layer-shell surface anchored top-left, positioned via margins.
|
||||||
// On X11: a frameless, non-focusable, always-on-top tool window.
|
// 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
|
class FloatingWindow : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -42,8 +44,10 @@ private:
|
|||||||
QPoint clamped(QPoint position, QSize size) const;
|
QPoint clamped(QPoint position, QSize size) const;
|
||||||
QPoint defaultPosition() const;
|
QPoint defaultPosition() const;
|
||||||
void apply();
|
void apply();
|
||||||
|
void followScreen(QScreen *screen);
|
||||||
|
|
||||||
QWindow *m_window;
|
QWindow *m_window;
|
||||||
LayerShellQt::Window *m_layerSurface = nullptr;
|
LayerShellQt::Window *m_layerSurface = nullptr;
|
||||||
QPoint m_position;
|
QPoint m_position;
|
||||||
|
QScreen *m_screen = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user