From b8dc91871e116f51a061597e40e60d89d9f715cb Mon Sep 17 00:00:00 2001
From: simonb <simonb>
Date: Sat, 10 Jun 2006 16:31:47 +0000
Subject: couple of alignment fixes, esp for external tabs

---
 ChangeLog         |  5 +++++
 src/Container.cc  | 40 ++++++++++++----------------------------
 src/FbWinFrame.cc | 12 +++++++++++-
 3 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e779121..a48ff34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
  (Format: Year/Month/Day)
 Changes for 0.9.16:
+*06/06/10:
+   * Fix some external tab alignment on shade (Simon)
+     FbWinFrame.cc
+   * Fix container size rounding for right alignment (Simon)
+     Container.cc
 *06/06/01:
    * Update of new manpage (thanx Guillermo Patterer)
 *06/05/23:
diff --git a/src/Container.cc b/src/Container.cc
index 4cd0fa8..5e7cb7d 100644
--- a/src/Container.cc
+++ b/src/Container.cc
@@ -272,35 +272,10 @@ void Container::setMaxTotalSize(unsigned int size) {
     if (m_max_total_size == size)
         return;
 
-    unsigned int old = m_max_total_size;
     m_max_total_size = size;
 
     repositionItems();
     return;
-
-    if (m_max_total_size && width() > m_max_total_size) {
-        resize(m_max_total_size, height());
-    } else if (!m_max_total_size && old) { // going from restricted to unrestricted
-        repositionItems();
-    } else {
-        // this is a bit of duplication from repositionItems
-        // for when we are allowed to grow ourself
-        Alignment align = alignment();
-        size_t num_items = m_item_list.size();
-        if (m_max_total_size && (align == RIGHT || align == LEFT) &&
-            num_items) { 
-            unsigned int max_width_per_client = maxWidthPerClient();
-            unsigned int borderW = m_item_list.front()->borderWidth();
-            
-            unsigned int preferred_width = (max_width_per_client + borderW) * num_items - borderW;
-
-            if (preferred_width > m_max_total_size)
-                preferred_width = m_max_total_size;
-
-            if (preferred_width != width())
-                repositionItems();
-        }
-    }
 }
 
 void Container::setAlignment(Container::Alignment a) {
@@ -401,7 +376,6 @@ void Container::repositionItems() {
             total_width = m_max_total_size;
             if (m_max_total_size > ((num_items - 1)*borderW)) { // don't go negative with unsigned nums
                 max_width_per_client = ( m_max_total_size - (num_items - 1)*borderW ) / num_items;
-                total_width = (max_width_per_client + borderW) * num_items - borderW;
             } else
                 max_width_per_client = 1;
         }
@@ -429,7 +403,11 @@ void Container::repositionItems() {
     ItemList::iterator it = m_item_list.begin();
     const ItemList::iterator it_end = m_item_list.end();
 
-    int rounding_error = total_width - ((max_width_per_client + borderW)* num_items - borderW);
+    int rounding_error = 0;
+
+    if (align == RELATIVE || total_width == m_max_total_size) {
+        rounding_error = total_width - ((max_width_per_client + borderW)* num_items - borderW);
+    }
 
     int next_x = -borderW; // zero so the border of the first shows
     int extra = 0;
@@ -443,10 +421,16 @@ void Container::repositionItems() {
     unsigned int tmpw, tmph;
     for (; it != it_end; ++it, next_x += direction*(max_width_per_client + borderW + extra)) {
         // we only need to do error stuff with alignment RELATIVE
-        if (rounding_error != 0 && align == RELATIVE) {
+        // OR with max_total_size triggered
+        if (rounding_error) {
             --rounding_error;
             extra = 1;
+            //counter for different direction
+            if (align == RIGHT && !extra)
+                --next_x;
         } else {
+            if (extra && align == RIGHT) // last extra
+                ++next_x;
             extra = 0;
         }
         // rotate the x and y coords
diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc
index d3dd682..00583d7 100644
--- a/src/FbWinFrame.cc
+++ b/src/FbWinFrame.cc
@@ -348,6 +348,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT0) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT0);
         m_tab_container.setAlignment(Container::LEFT);
+        m_tab_container.setMaxTotalSize(m_window.width());
         tabx = x();
         taby = y() - yOffset();
         break;
@@ -355,6 +356,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT0) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT0);
         m_tab_container.setAlignment(Container::RIGHT);
+        m_tab_container.setMaxTotalSize(m_window.width());
         tabx = x() + width() - m_tab_container.width();
         taby = y() - yOffset();
         break;
@@ -362,6 +364,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT270) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT270);
         m_tab_container.setAlignment(Container::RIGHT);
+        m_tab_container.setMaxTotalSize(m_window.height());
         tabx = x() - xOffset();
         taby = y();
         break;
@@ -369,6 +372,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT270) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT270);
         m_tab_container.setAlignment(Container::LEFT);
+        m_tab_container.setMaxTotalSize(m_window.height());
         tabx = x() - xOffset();
         taby = y() + height() - m_tab_container.height();
         break;
@@ -376,6 +380,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT90) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT90);
         m_tab_container.setAlignment(Container::LEFT);
+        m_tab_container.setMaxTotalSize(m_window.height());
         tabx = x() + width() + m_window.borderWidth();
         taby = y();
         break;
@@ -383,6 +388,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT90) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT90);
         m_tab_container.setAlignment(Container::RIGHT);
+        m_tab_container.setMaxTotalSize(m_window.height());
         tabx = x() + width() + m_window.borderWidth();
         taby = y() + height() - m_tab_container.height();
         break;
@@ -390,6 +396,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT0) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT0);
         m_tab_container.setAlignment(Container::LEFT);
+        m_tab_container.setMaxTotalSize(m_window.width());
         tabx = x();
         taby = y() + height() + m_window.borderWidth();
         break;
@@ -397,6 +404,7 @@ void FbWinFrame::alignTabs() {
         if (orig_orient != FbTk::ROT0) m_tab_container.hide();
         m_tab_container.setOrientation(FbTk::ROT0);
         m_tab_container.setAlignment(Container::RIGHT);
+        m_tab_container.setMaxTotalSize(m_window.width());
         tabx = x() + width() - m_tab_container.width();
         taby = y() + height() + m_window.borderWidth();
         break;
@@ -404,7 +412,6 @@ void FbWinFrame::alignTabs() {
 
     unsigned int w = m_window.width(), h = m_window.height();
     translateSize(m_tab_container.orientation(), w, h);
-    m_tab_container.setMaxTotalSize(w);
 
     if (m_tab_container.orientation() != orig_orient ||
         m_tab_container.maxWidthPerClient() != orig_tabwidth) {
@@ -417,6 +424,9 @@ void FbWinFrame::alignTabs() {
     }
 
     if (m_tab_container.parent()->window() != m_screen.rootWindow().window()) {
+        // because the label might be using the same cached pixmap as tab container!
+        renderTitlebar();
+        applyTitlebar();
         m_tab_container.reparent(m_screen.rootWindow(), tabx, taby);
         m_layeritem.addWindow(m_tab_container);
     } else {
-- 
cgit v0.11.2