From 6c4d1123c07f8fe265bbb38920b0ae3d90879d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Mon, 29 Aug 2016 22:15:20 +0200 Subject: Relative aligmment when changing window head So far, altering the head would potentially move the window out of the workspace area (by moving a far right/bottom window from a HUUUUUGE to a small screen) This preserves edge alignments (w/ topleft preference), otherwise moves the window to it's relative topleft position on the new head (ie. if it was 10% left and 3% top into the screen, it will still be) --- src/Window.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Window.cc b/src/Window.cc index 56c78c7..7855f68 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -3926,8 +3926,21 @@ void FluxboxWindow::setOnHead(int head) { if (head > 0 && head <= screen().numHeads()) { int cur = screen().getHead(fbWindow()); bool placed = m_placed; - move(screen().getHeadX(head) + frame().x() - screen().getHeadX(cur), - screen().getHeadY(head) + frame().y() - screen().getHeadY(cur)); + int x = frame().x(), y = frame().y(); + const int w = frame().width(), h = frame().height(), bw = frame().window().borderWidth(); + const int sx = screen().getHeadX(cur), sw = screen().getHeadWidth(cur), + sy = screen().getHeadY(cur), sh = screen().getHeadHeight(cur); + int d = sx + sw - (x + bw + w); + if (std::abs(sx - x) > bw && std::abs(d) <= bw) // right aligned + x = screen().getHeadX(head) + screen().getHeadWidth(head) - (w + bw + d); + else // calc top-left relative position + x = screen().getHeadWidth(head) * (x - sx) / sw + screen().getHeadX(head); + d = sy + sh - (y + bw + h); + if (std::abs(sy - y) > bw && std::abs(d) <= bw) // bottom aligned + y = screen().getHeadY(head) + screen().getHeadHeight(head) - (h + bw + d); + else // calc top-left relative position + y = screen().getHeadHeight(head) * (y - sy) / sh + screen().getHeadY(head); + move(x, y); m_placed = placed; } -- cgit v0.11.2