From f16cd594575b198df8451431951960677dd81b66 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Mon, 20 Oct 2025 08:10:00 +0300
Subject: kicker: change the internal layout of systray

This makes clocks embedded into systray unaffected by systray's margin
value.

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 kicker/applets/systemtray/systemtrayapplet.cpp | 111 +++++++++----------------
 kicker/applets/systemtray/systemtrayapplet.h   |   2 +-
 2 files changed, 40 insertions(+), 73 deletions(-)

diff --git a/kicker/applets/systemtray/systemtrayapplet.cpp b/kicker/applets/systemtray/systemtrayapplet.cpp
index c2fc55989..0175bd689 100644
--- a/kicker/applets/systemtray/systemtrayapplet.cpp
+++ b/kicker/applets/systemtray/systemtrayapplet.cpp
@@ -93,8 +93,7 @@ SystemTrayApplet::SystemTrayApplet(const TQString& configFile, Type type, int ac
     m_iconMargin(1),
     m_iconMarginSB(nullptr),
     m_iconSpacing(1),
-    m_iconSpacingSB(nullptr),
-    m_layout(nullptr)
+    m_iconSpacingSB(nullptr)
 {
     DCOPObject::setObjId("SystemTrayApplet");
     loadSettings();
@@ -969,8 +968,6 @@ void SystemTrayApplet::layoutTray()
 
     int i = 0;
     bool showExpandButton = m_expandButton && m_expandButton->isVisibleTo(this);
-    delete m_layout;
-    m_layout = new TQGridLayout(this, 1, 1, m_iconMargin, m_iconSpacing);
 
     if (m_expandButton)
     {
@@ -984,6 +981,32 @@ void SystemTrayApplet::layoutTray()
         }
     }
 
+    // delete and recreate the tray layout from scratch
+    delete layout();
+
+    TQBoxLayout *mainLayout;
+
+    if (orientation() == TQt::Vertical) {
+        mainLayout = new TQVBoxLayout(this);
+    } else {
+        mainLayout = new TQHBoxLayout(this);
+    }
+
+    mainLayout->addWidget(m_leftSpacer);
+
+    if (showExpandButton) {
+        mainLayout->addWidget(m_expandButton, TQt::AlignHCenter | TQt::AlignVCenter);
+    }
+
+    TQGridLayout *iconLayout = new TQGridLayout(mainLayout, 1, 1, m_iconSpacing);
+    iconLayout->setMargin(m_iconMargin);
+
+    mainLayout->addWidget(m_rightSpacer);
+
+    if (m_clockApplet) {
+        mainLayout->addWidget(m_clockApplet);
+    }
+
     // col = column or row, depends on orientation(),
     // the opposite direction of line
     int col = 0;
@@ -1009,22 +1032,7 @@ void SystemTrayApplet::layoutTray()
                          (maxIconWidth() + m_iconSpacing);
         if (nbrOfLines < 1) {
             nbrOfLines = 1;  // avoid nbrOfLines==0 or negative (in case m_iconMargin is unreasonably large)
-            m_layout->setMargin( (width() - maxIconWidth()) / 2); // also adjust the margins, so the icons won't get shifted beyond visibility
-        }
-
-        m_layout->addMultiCellWidget(m_leftSpacer,
-                                     0, 0,
-                                     0, nbrOfLines - 1,
-                                     TQt::AlignHCenter | TQt::AlignVCenter);
-        col = 1;
-
-        if (showExpandButton)
-        {
-            m_layout->addMultiCellWidget(m_expandButton,
-                                         1, 1,
-                                         0, nbrOfLines - 1,
-                                         TQt::AlignHCenter | TQt::AlignVCenter);
-            col = 2;
+            iconLayout->setMargin( (width() - maxIconWidth()) / 2); // also adjust the margins, so the icons won't get shifted beyond visibility
         }
 
         if (m_showHidden)
@@ -1035,7 +1043,7 @@ void SystemTrayApplet::layoutTray()
             {
                 int line = i % nbrOfLines;
                 (*emb)->show();
-                m_layout->addWidget((*emb), col, line,
+                iconLayout->addWidget((*emb), col, line,
                                     TQt::AlignHCenter | TQt::AlignVCenter);
 
                 if ((line + 1) == nbrOfLines)
@@ -1053,7 +1061,7 @@ void SystemTrayApplet::layoutTray()
         {
             int line = i % nbrOfLines;
             (*emb)->show();
-            m_layout->addWidget((*emb), col, line,
+            iconLayout->addWidget((*emb), col, line,
                                 TQt::AlignHCenter | TQt::AlignVCenter);
 
             if ((line + 1) == nbrOfLines)
@@ -1064,22 +1072,6 @@ void SystemTrayApplet::layoutTray()
             ++i;
         }
 
-        m_layout->addMultiCellWidget(m_rightSpacer,
-                                     col, col,
-                                     0, nbrOfLines - 1,
-                                     TQt::AlignHCenter | TQt::AlignVCenter);
-
-        if (m_clockApplet) {
-            if (m_showClockInTray)
-                m_clockApplet->show();
-            else
-                m_clockApplet->hide();
-
-            m_layout->addMultiCellWidget(m_clockApplet,
-                                     col+1, col+1,
-                                     0, nbrOfLines - 1,
-                                     TQt::AlignHCenter | TQt::AlignVCenter);
-        }
     }
     else // horizontal
     {
@@ -1087,22 +1079,7 @@ void SystemTrayApplet::layoutTray()
                          (maxIconHeight() + m_iconSpacing);
         if (nbrOfLines < 1) {
             nbrOfLines = 1;  // avoid nbrOfLines==0 or negative (in case m_iconMargin is unreasonably large)
-            m_layout->setMargin( (height() - maxIconHeight()) / 2); // also adjust the margins, so the icons won't shift beyond viability
-        }
-
-        m_layout->addMultiCellWidget(m_leftSpacer,
-                                     0, nbrOfLines - 1,
-                                     0, 0,
-                                     TQt::AlignHCenter | TQt::AlignVCenter);
-        col = 1;
-
-        if (showExpandButton)
-        {
-            m_layout->addMultiCellWidget(m_expandButton,
-                                         0, nbrOfLines - 1,
-                                         1, 1,
-                                         TQt::AlignHCenter | TQt::AlignVCenter);
-            col = 2;
+            iconLayout->setMargin( (height() - maxIconHeight()) / 2); // also adjust the margins, so the icons won't shift beyond viability
         }
 
         if (m_showHidden)
@@ -1112,7 +1089,7 @@ void SystemTrayApplet::layoutTray()
             {
                 int line = i % nbrOfLines;
                 (*emb)->show();
-                m_layout->addWidget((*emb), line, col,
+                iconLayout->addWidget((*emb), line, col,
                                     TQt::AlignHCenter | TQt::AlignVCenter);
 
                 if ((line + 1) == nbrOfLines)
@@ -1130,7 +1107,7 @@ void SystemTrayApplet::layoutTray()
         {
             int line = i % nbrOfLines;
             (*emb)->show();
-            m_layout->addWidget((*emb), line, col,
+            iconLayout->addWidget((*emb), line, col,
                                 TQt::AlignHCenter | TQt::AlignVCenter);
 
             if ((line + 1) == nbrOfLines)
@@ -1140,23 +1117,13 @@ void SystemTrayApplet::layoutTray()
 
             ++i;
         }
+    }
 
-        m_layout->addMultiCellWidget(m_rightSpacer,
-                                     0, nbrOfLines - 1,
-                                     col, col,
-                                     TQt::AlignHCenter | TQt::AlignVCenter);
-
-        if (m_clockApplet) {
-            if (m_showClockInTray)
-                m_clockApplet->show();
-            else
-                m_clockApplet->hide();
-
-            m_layout->addMultiCellWidget(m_clockApplet,
-                                         0, nbrOfLines - 1,
-                                         col+1, col+1,
-                                         TQt::AlignHCenter | TQt::AlignVCenter);
-        }
+    if (m_clockApplet) {
+        if (m_showClockInTray)
+            m_clockApplet->show();
+        else
+            m_clockApplet->hide();
     }
 
     setUpdatesEnabled(true);
diff --git a/kicker/applets/systemtray/systemtrayapplet.h b/kicker/applets/systemtray/systemtrayapplet.h
index 581cd10b0..26a02de1c 100644
--- a/kicker/applets/systemtray/systemtrayapplet.h
+++ b/kicker/applets/systemtray/systemtrayapplet.h
@@ -124,7 +124,7 @@ private:
     TQSpinBox *m_iconMarginSB;
     int m_iconSpacing;
     TQSpinBox *m_iconSpacingSB;
-    TQGridLayout* m_layout;
+    TQLayout* m_layout;
 };
 
 class TrayEmbed : public QXEmbed
-- 
cgit v1.2.3

