From b405d36151d3a6d3074eb6bafb541a1d6228d85e Mon Sep 17 00:00:00 2001
From: Tomas Janousek <tomi@nomi.cz>
Date: Thu, 1 Mar 2007 23:18:18 +0100
Subject: Move windows out of inactive heads upon layout change.

Signed-off-by: Tomas Janousek <tomi@nomi.cz>
---
 src/Screen.cc | 19 +++++++++++++++++++
 src/Screen.hh |  1 +
 2 files changed, 20 insertions(+)

diff --git a/src/Screen.cc b/src/Screen.cc
index c6379a0..36b1918 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -1909,6 +1909,9 @@ void BScreen::updateSize() {
     // send resize notify
     m_resize_sig.notify();
     m_workspace_area_sig.notify();
+
+    // move windows out of inactive heads
+    clearHeads();
 }
 
 
@@ -2020,6 +2023,22 @@ notactive:
 
 }
 
+/* Move windows out of inactive heads */
+void BScreen::clearHeads() {
+    if (!hasXinerama()) return;
+
+    for (Workspaces::iterator i = m_workspaces_list.begin();
+	    i != m_workspaces_list.end(); i++) {
+	for (Workspace::Windows::iterator win = (*i)->windowList().begin();
+		win != (*i)->windowList().end(); win++) {
+	    if (getHead((*win)->fbWindow()) == 0) {
+                // first head is a safe bet here
+                (*win)->placeWindow(1);
+            }
+	}
+    }
+}
+
 int BScreen::getHead(int x, int y) const {
     if (!hasXinerama()) return 0;
 #ifdef XINERAMA
diff --git a/src/Screen.hh b/src/Screen.hh
index c95e573..f0dbcc6 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -406,6 +406,7 @@ public:
     int numHeads() const { return m_xinerama_num_heads; }
 
     void initXinerama();
+    void clearHeads();
     /**
      * Determines head number for a position
      * @param x position in pixels on the screen
-- 
cgit v0.11.2