From d6bc8d753e85ece940f5ec932fb71ba44b3d297b Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sat, 1 May 2010 14:27:45 +0200 Subject: bugfix: moving (the center of) a maximized window out of a xinerama head could result in maximizing it over all heads the old way of deciding which head to (re)maximize the current window was to just test if the center of the window is INSIDE which head. now we calculate the closest head which fixes the problem --- src/Screen.cc | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Screen.cc b/src/Screen.cc index e3df8a0..17615fe 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -175,6 +175,10 @@ int anotherWMRunning(Display *display, XErrorEvent *) { } +int calcSquareDistance(int x1, int y1, int x2, int y2) { + return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1); +} + class TabPlacementMenuItem: public FbTk::RadioMenuItem { public: TabPlacementMenuItem(FbTk::FbString & label, BScreen &screen, @@ -2022,11 +2026,36 @@ int BScreen::getHead(int x, int y) const { return 0; } + int BScreen::getHead(const FbTk::FbWindow &win) const { - if (hasXinerama()) - return getHead(win.x() + win.width()/2, win.y() + win.height()/2); - else - return 0; + + int head = 0; // whole screen + +#if XINERAMA + if (hasXinerama()) { + + // cast needed to prevent win.x() become "unsigned int" which is bad + // since it might become negative + int cx = win.x() + static_cast(win.width() / 2); + int cy = win.y() + static_cast(win.height() / 2); + + long dist = -1; + + int i; + for (i = 0; i < m_xinerama_num_heads; ++i) { + + XineramaHeadInfo& hi = m_xinerama_headinfo[i]; + int d = calcSquareDistance(cx, cy, hi.x + (hi.width / 2), hi.y + (hi.height / 2)); + + if (dist == -1 || d < dist) { // found a closer head + head = i + 1; + dist = d; + } + } + } +#endif + + return head; } -- cgit v0.11.2