From 29291eac7427669a8981b884e783e4669568d8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Tue, 14 Nov 2023 19:46:01 +0100 Subject: [PATCH] Fix harbour placement on the right edge Commit b780659 (Fix max line-length and too many space indents, 2022-07-16) factors out the code inside Harbour::placeDockApp() into placeDockAppX and placeDockAppY but never calls the latter. Later on placeDockAppY() is deleted in another cleanup commit. I do not understand how I only noticed this now [1] but with default harbor setting (on the right edge), all the dock apps are now moved to the left edge. And this seems to fix this, but to be honest I don't really know what I'm doing. [1] well not now, a few months but I was too lazy to go check --- src/Harbour.cc | 39 ++++++++++++++++++++++++++++++++++++++- src/Harbour.hh | 2 ++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Harbour.cc b/src/Harbour.cc index fead82dd..620869a4 100644 --- a/src/Harbour.cc +++ b/src/Harbour.cc @@ -396,7 +396,7 @@ Harbour::placeDockApp(DockApp *da) if (x_place) { placeDockAppX(da, head, x, y); } else { - placeDockAppX(da, head, x, y); + placeDockAppY(da, head, x, y); } da->move(x, y); @@ -440,6 +440,43 @@ Harbour::placeDockAppX(DockApp* da, const Geometry& head, int& x, const int y) } } +void +Harbour::placeDockAppY(DockApp *da, const Geometry& head, const int x, int &y) +{ + int test; + bool placed = false, increase = false; + bool bottom = (_cfg->getHarbourOrientation() == BOTTOM_TO_TOP); + y = test = bottom ? head.y + head.height - da->getHeight() : head.y; + + while (! placed + && (bottom + ? (test >= 0) + : ((test + da->getHeight()) < (head.y + head.height)))) { + placed = increase = true; + + std::vector::const_iterator it = _dapps.begin(); + for (; placed && it != _dapps.end(); ++it) { + if ((*it) == da) { + continue; // exclude ourselves + } + + int ty = static_cast(test + da->getHeight()); + if (((*it)->getY() < ty) && ((*it)->getBY() > test)) { + placed = increase = false; + test = bottom + ? (*it)->getY() - da->getHeight() + : (*it)->getBY(); + } + } + + if (placed) { + y = test; + } else if (increase) { + test += bottom ? -1 : 1; + } + } +} + //! @brief Inserts DockApp and places all dockapps in sorted order //! @todo Screen boundary checking void diff --git a/src/Harbour.hh b/src/Harbour.hh index 326c678d..8d681f48 100644 --- a/src/Harbour.hh +++ b/src/Harbour.hh @@ -57,6 +57,8 @@ private: void placeDockApp(DockApp *da); void placeDockAppX(DockApp *da, const Geometry& head, int& x, const int y); + void placeDockAppY(DockApp *da, const Geometry& head, + const int x, int &y); void placeDockAppsSorted(void); void placeDockAppInsideScreen(DockApp *da);