From 5e3217441ad0f97bff1e946fb93a9673ac806052 Mon Sep 17 00:00:00 2001 From: Peter Hercek Date: Tue, 26 Feb 2013 20:15:44 +0100 Subject: fix head detection for adjacent heads of too different sizes and window placement based on apps file * if you have e.g a 1920x1200 monitor and a small 800x600 monitor to the right of the bigger one and a small window at the right side of the big monitor (but still the whole window area at the big monitor) then the original head detection would claim the window is on the small monitor because (800/2+windowWidth/2 < 1920/2+windowWidth/2) is true for small windows; but that is obviously wrong, the window is entirely on the big monitor * these incorrect head detections did lead to incorrect window placements as they were required in the apps file --- src/Screen.cc | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Screen.cc b/src/Screen.cc index 725d4b5..507a58f 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -2115,17 +2115,20 @@ int BScreen::getHead(const FbTk::FbWindow &win) const { 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; + head = getHead(cx, cy); + if ( head == 0 ) { + // if the center of the window is not on any head then select + // the head which center is nearest to the window center + 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; + } } } } -- cgit v0.11.2