monitor: fix centered floating windows off-screen in special workspace (#14203)

Signed-off-by: Zebra2711 <zebra2711t@gmail.com>
This commit is contained in:
Zebra2711 2026-05-01 01:38:05 +07:00 committed by GitHub
parent 859bbb11e1
commit bac49db9a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -588,6 +588,28 @@ TEST_CASE(issue14038) {
// this should not crash hyprland. If we are alive, we good.
}
TEST_CASE(specialFloatRecenters) {
if (!spawnKitty("kitty_special_float_recenter"))
FAIL_TEST("Could not spawn kitty");
OK(getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:kitty_special_float_recenter' })"));
OK(getFromSocket("/dispatch hl.dsp.window.resize({ x = 10, y = 10, window = 'class:kitty_special_float_recenter' })"));
OK(getFromSocket("/dispatch hl.dsp.window.move({ workspace = 'special:recenter', follow = false, window = 'class:kitty_special_float_recenter' })"));
OK(getFromSocket("/dispatch hl.dsp.window.move({ x = 50000, y = 50000, window = 'class:kitty_special_float_recenter' })"));
OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('recenter')"));
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kitty_special_float_recenter' })"));
const auto active = getFromSocket("/activewindow");
EXPECT_CONTAINS(active, "class: kitty_special_float_recenter");
EXPECT_CONTAINS(active, "size: 10,10");
EXPECT_CONTAINS(active, "at: 955,535");
OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('recenter')"));
Tests::killAllWindows();
ASSERT(Tests::windowCount(), 0);
}
// TODO: decompose this into multiple test cases
TEST_CASE(windows) {
// test on workspace "window"

View file

@ -1564,7 +1564,7 @@ void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) {
if (VECNOTINRECT(MIDDLE, PMONFROMMIDDLE->m_position.x, PMONFROMMIDDLE->m_position.y, PMONFROMMIDDLE->m_position.x + PMONFROMMIDDLE->m_size.x,
PMONFROMMIDDLE->m_position.y + PMONFROMMIDDLE->m_size.y)) {
// not on any monitor, center
pos = middle() / 2.f - w->m_realSize->goal() / 2.f;
pos = middle() - w->m_realSize->goal() / 2.f;
} else
pos = pos - PMONFROMMIDDLE->m_position + m_position;