From 2585aefafe99591a6d3fa20fd09f079ddfa897c1 Mon Sep 17 00:00:00 2001
From: rathnor <rathnor>
Date: Sat, 26 Jul 2003 16:17:02 +0000
Subject: fix window size when varying borderWidth

---
 ChangeLog         |  2 ++
 src/FbWinFrame.cc | 21 ++++++++++++++++++++-
 src/FbWinFrame.hh |  4 +++-
 src/Window.cc     | 25 ++++++++++---------------
 src/Window.hh     |  4 ++--
 5 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cbfa7cc..b3f115e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 (Format: Year/Month/Day)
 Changes for 0.9.5:
 *03/07/26:
+   * Fix window size when changing borderWidth [borderless wins] (Simon)
+     Window.hh/cc FbWinFrame.hh/cc
    * Fix some keybinding issues with ShadeWindow, StickWindow,
      SendToWorkspace, NextGroup, PrevGroup (Simon)  
      CurrentWindowCmd.cc FbCommandFactory.cc
diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc
index a848788..ada5f00 100644
--- a/src/FbWinFrame.cc
+++ b/src/FbWinFrame.cc
@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: FbWinFrame.cc,v 1.30 2003/07/10 11:36:21 fluxgen Exp $
+// $Id: FbWinFrame.cc,v 1.31 2003/07/26 16:17:01 rathnor Exp $
 
 #include "FbWinFrame.hh"
 #include "ImageControl.hh"
@@ -914,3 +914,22 @@ void FbWinFrame::renderLabelButtons() {
     }
     
 }
+
+void FbWinFrame::setBorderWidth(unsigned int borderW) {
+    int bw_changes = 0;
+    // we need to change the size of the window 
+    // if the border width changes...
+    if (m_use_titlebar) 
+        bw_changes += (signed) borderW - titlebar().borderWidth();
+    if (m_use_handle) 
+        bw_changes += (signed) borderW - handle().borderWidth();
+
+    window().setBorderWidth(borderW);
+    titlebar().setBorderWidth(borderW);
+    handle().setBorderWidth(borderW);
+    gripLeft().setBorderWidth(borderW);
+    gripRight().setBorderWidth(borderW);
+
+    if (bw_changes != 0)
+        resize(width(), height() + bw_changes);
+}
diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh
index 49bb452..2632311 100644
--- a/src/FbWinFrame.hh
+++ b/src/FbWinFrame.hh
@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: FbWinFrame.hh,v 1.9 2003/07/10 11:36:21 fluxgen Exp $
+// $Id: FbWinFrame.hh,v 1.10 2003/07/26 16:17:01 rathnor Exp $
 
 #ifndef FBWINFRAME_HH
 #define FBWINFRAME_HH
@@ -113,6 +113,8 @@ public:
     void hideAllDecorations();
     void showAllDecorations();
 
+    void setBorderWidth(unsigned int borderW);
+
     /**
        @name Event handlers
     */
diff --git a/src/Window.cc b/src/Window.cc
index 0ba7a4a..ba5b346 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.210 2003/07/24 03:19:02 rathnor Exp $
+// $Id: Window.cc,v 1.211 2003/07/26 16:17:01 rathnor Exp $
 
 #include "Window.hh"
 
@@ -504,7 +504,7 @@ void FluxboxWindow::init() {
 
     grabButtons();
 		
-    applyDecorations();
+    applyDecorations(true);
 
     if (m_workspace_number < 0 || m_workspace_number >= screen().getCount())
         m_workspace_number = screen().currentWorkspaceID();
@@ -2678,21 +2678,15 @@ void FluxboxWindow::setDecoration(Decoration decoration) {
 }
 
 // commit current decoration values to actual displayed things
-void FluxboxWindow::applyDecorations() {
+void FluxboxWindow::applyDecorations(bool initial) {
     frame().clientArea().setBorderWidth(0); // client area bordered by other things
 
     unsigned int borderW = 0;
     if (decorations.border) 
         borderW = screen().rootTheme().borderWidth();
 
-    if (frame().window().borderWidth() != borderW) {
-        frame().window().setBorderWidth(borderW);
-        frame().titlebar().setBorderWidth(borderW);
-        frame().handle().setBorderWidth(borderW);
-        frame().gripLeft().setBorderWidth(borderW);
-        frame().gripRight().setBorderWidth(borderW);
-        frame().reconfigure();
-    }
+    if (initial || frame().window().borderWidth() != borderW)
+        frame().setBorderWidth(borderW);
 
     // we rely on frame not doing anything if it is already shown/hidden
     if (decorations.titlebar) 
@@ -2700,9 +2694,10 @@ void FluxboxWindow::applyDecorations() {
     else
         frame().hideTitlebar();
 
-    if (decorations.handle)
+    if (decorations.handle) {
         frame().showHandle();
-    else
+        frame().reconfigure(); // show handle requires reconfigure
+    } else
         frame().hideHandle();
 
 }
@@ -2713,15 +2708,15 @@ void FluxboxWindow::toggleDecoration() {
         return;
 	
     if (decorations.enabled) { //remove decorations
-        setDecoration(DECOR_NONE); 
         decorations.enabled = false;
+        setDecoration(DECOR_NONE); 
     } else { //revert back to old decoration
+        decorations.enabled = true;
         if (m_old_decoration == DECOR_NONE) { // make sure something happens
             setDecoration(DECOR_NORMAL);
         } else {
             setDecoration(m_old_decoration);
         }
-        decorations.enabled = true;
     }
 }
 
diff --git a/src/Window.hh b/src/Window.hh
index d6eb944..573739d 100644
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -22,7 +22,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-// $Id: Window.hh,v 1.86 2003/07/24 03:19:02 rathnor Exp $
+// $Id: Window.hh,v 1.87 2003/07/26 16:17:02 rathnor Exp $
 
 #ifndef	 WINDOW_HH
 #define	 WINDOW_HH
@@ -241,7 +241,7 @@ public:
     //@}
 
     void setDecoration(Decoration decoration);
-    void applyDecorations();
+    void applyDecorations(bool initial = false);
     void toggleDecoration();
 
 
-- 
cgit v0.11.2