From 384603e962dcbd34bc05a220d8fbf3e88a980e80 Mon Sep 17 00:00:00 2001
From: rathnor <rathnor>
Date: Fri, 25 Apr 2003 09:07:14 +0000
Subject: add UnderMousePlacement placement policy, plus a little fix for
 window positioning (Simon)

---
 ChangeLog        |  4 ++++
 src/Screen.hh    |  6 +++---
 src/Window.cc    | 14 +++++++-------
 src/Workspace.cc | 44 ++++++++++++++++++++++++++++++++++++++++++--
 src/fluxbox.cc   |  8 +++++++-
 5 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 856370f..111653a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 (Format: Year/Month/Day)
 Changes for 0.9.2:
+*03/04/25:
+   * Add UnderMousePlacement policy, plus minor positioning fix (Simon)
+     -> Patch originally contributed by "Mike" (lgn@users.sf)
+     Screen.hh Workspace.cc fluxbox.cc Window.cc
 *03/04/21:
    * Fix toolbar startup and reconfigure things (Simon)
      (Thanks Brian Sea)
diff --git a/src/Screen.hh b/src/Screen.hh
index 5b5f0de..1e010ab 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Screen.hh,v 1.82 2003/04/20 13:45:07 fluxgen Exp $
+// $Id: Screen.hh,v 1.83 2003/04/25 09:07:08 rathnor Exp $
 
 #ifndef	 SCREEN_HH
 #define	 SCREEN_HH
@@ -309,8 +309,8 @@ public:
     FluxboxWindow *createWindow(WinClient &client);
     void setupWindowActions(FluxboxWindow &win);
 
-    enum { ROWSMARTPLACEMENT = 1, COLSMARTPLACEMENT, CASCADEPLACEMENT, LEFTRIGHT,
-           RIGHTLEFT, TOPBOTTOM, BOTTOMTOP };
+    enum { ROWSMARTPLACEMENT = 1, COLSMARTPLACEMENT, CASCADEPLACEMENT,
+           UNDERMOUSEPLACEMENT, LEFTRIGHT, RIGHTLEFT, TOPBOTTOM, BOTTOMTOP };
     enum { LEFTJUSTIFY = 1, RIGHTJUSTIFY, CENTERJUSTIFY };
 
     /// obsolete
diff --git a/src/Window.cc b/src/Window.cc
index 890a4e0..15f7e0e 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Window.cc,v 1.144 2003/04/20 02:47:14 rathnor Exp $
+// $Id: Window.cc,v 1.145 2003/04/25 09:07:09 rathnor Exp $
 
 #include "Window.hh"
 
@@ -409,9 +409,6 @@ void FluxboxWindow::init() {
 
     upsize();
 
-    m_frame.move(wattrib.x, wattrib.y);
-    m_frame.resizeForClient(wattrib.width, wattrib.height);
-
     bool place_window = true;
     if (fluxbox->isStartup() || transient ||
         m_client->normal_hint_flags & (PPosition|USPosition)) {
@@ -444,15 +441,19 @@ void FluxboxWindow::init() {
 
     restoreAttributes();
 
+    m_frame.move(wattrib.x, wattrib.y);
+    m_frame.resizeForClient(wattrib.width, wattrib.height);
+
     // if we're a transient then we should be on the same layer as our parent
     if (isTransient())
         getLayerItem().setLayer(getTransientFor()->getLayerItem().getLayer());       
     else // if no parent then set default layer
         moveToLayer(m_layernum);
     
-    screen.getWorkspace(workspace_number)->addWindow(*this, place_window);
+    if (!place_window)
+        moveResize(m_frame.x(), m_frame.y(), m_frame.width(), m_frame.height());
 
-    moveResize(m_frame.x(), m_frame.y(), m_frame.width(), m_frame.height());
+    screen.getWorkspace(workspace_number)->addWindow(*this, place_window);
 
     if (shaded) { // start shaded
         shaded = false;
@@ -471,7 +472,6 @@ void FluxboxWindow::init() {
     }
 
     setState(current_state);
-    m_frame.resizeForClient(wattrib.width, wattrib.height);
     m_frame.reconfigure();
     sendConfigureNotify();
     // no focus default
diff --git a/src/Workspace.cc b/src/Workspace.cc
index 9ddce15..4d357b0 100644
--- a/src/Workspace.cc
+++ b/src/Workspace.cc
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Workspace.cc,v 1.53 2003/04/16 14:43:06 rathnor Exp $
+// $Id: Workspace.cc,v 1.54 2003/04/25 09:07:13 rathnor Exp $
 
 #include "Workspace.hh"
 
@@ -528,13 +528,53 @@ void Workspace::placeWindow(FluxboxWindow &win) {
     if (screen.getRowPlacementDirection() == BScreen::RIGHTLEFT)
         change_x = -1;
 
-
     int win_w = win.getWidth() + screen.getBorderWidth2x(),
         win_h = win.getHeight() + screen.getBorderWidth2x();
 
     int test_x, test_y, curr_x, curr_y, curr_w, curr_h;
 
     switch (screen.getPlacementPolicy()) {
+    case BScreen::UNDERMOUSEPLACEMENT: {
+        int root_x, root_y, min_y, min_x, max_y, max_x, ignore_i;
+
+        unsigned int ignore_ui;
+
+        Window ignore_w;
+
+        XQueryPointer(screen.getBaseDisplay()->getXDisplay(),
+            screen.getRootWindow(), &ignore_w, &ignore_w, &root_x, &root_y,
+            &ignore_i, &ignore_i, &ignore_ui);
+
+        test_x = root_x - (win_w / 2);
+        test_y = root_y - (win_h / 2);
+
+        min_x = (int) screen.getMaxLeft();
+        min_y = (int) screen.getMaxTop();
+        max_x = (int) screen.getMaxRight() - win_w;
+        max_y = (int) screen.getMaxBottom() - win_h;
+
+        // keep the window inside the screen
+
+        if (test_x < min_x)
+            test_x = min_x;
+
+        if (test_x > max_x)
+            test_x = max_x;
+
+        if (test_y < min_y)
+            test_y = min_y;
+
+        if (test_y > max_y)
+            test_y = max_y;
+
+        place_x = test_x;
+        place_y = test_y;
+
+        placed = true;
+
+        break; 
+    } // end case UNDERMOUSEPLACEMENT
+
     case BScreen::ROWSMARTPLACEMENT: {
 
         test_y = 0;
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index d2dc234..0a29fb1 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: fluxbox.cc,v 1.115 2003/04/20 12:21:35 rathnor Exp $
+// $Id: fluxbox.cc,v 1.116 2003/04/25 09:07:14 rathnor Exp $
 
 #include "fluxbox.hh"
 
@@ -1776,6 +1776,10 @@ void Fluxbox::save_rc() {
             placement = "ColSmartPlacement";
             break;
 
+        case BScreen::UNDERMOUSEPLACEMENT:
+            placement = "UnderMousePlacement";
+            break;
+
         default:
         case BScreen::ROWSMARTPLACEMENT:
             placement = "RowSmartPlacement";
@@ -2021,6 +2025,8 @@ void Fluxbox::load_rc(BScreen &screen) {
             screen.savePlacementPolicy(BScreen::ROWSMARTPLACEMENT);
         else if (! strncasecmp(value.addr, "ColSmartPlacement", value.size))
             screen.savePlacementPolicy(BScreen::COLSMARTPLACEMENT);
+        else if (! strncasecmp(value.addr, "UnderMousePlacement", value.size))
+            screen.savePlacementPolicy(BScreen::UNDERMOUSEPLACEMENT);
         else
             screen.savePlacementPolicy(BScreen::CASCADEPLACEMENT);
     } else
-- 
cgit v0.11.2