aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2021-07-06 22:56:26 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2021-07-06 22:56:26 (GMT)
commitb0663bc167f34b9796f98406329317f7bee15b00 (patch)
tree24e59202b08ab96d7539f56d14aeb15617739658 /src
parentf76720d918d1a2c72811a6ec5b3a1fc4b52f768c (diff)
downloadfluxbox-b0663bc167f34b9796f98406329317f7bee15b00.zip
fluxbox-b0663bc167f34b9796f98406329317f7bee15b00.tar.bz2
Patch from Bo Simonsen.
Max size per client (setMaxSizePerClient) was computed for iconbar.alignment = Relative not taking into account that a fixed size can be given when iconbar.alignment = Left/Right. In a "recent" change, relative alignment was changed, to better handle items with long titles. This is breaking existing behavior, the new behavior is (with this commit) now denoted RelativeSmart.
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/Container.cc7
-rw-r--r--src/FbTk/Container.hh2
-rw-r--r--src/IconbarTool.cc31
-rw-r--r--src/IconbarTool.hh1
4 files changed, 28 insertions, 13 deletions
diff --git a/src/FbTk/Container.cc b/src/FbTk/Container.cc
index 6270c6a..cea761b 100644
--- a/src/FbTk/Container.cc
+++ b/src/FbTk/Container.cc
@@ -324,7 +324,7 @@ void Container::repositionItems() {
324 // if we have a max total size, then we must also resize ourself 324 // if we have a max total size, then we must also resize ourself
325 // within that bound 325 // within that bound
326 Alignment align = alignment(); 326 Alignment align = alignment();
327 if (m_max_total_size && align != RELATIVE) { 327 if (m_max_total_size && (align != RELATIVE && align != RELATIVE_SMART)) {
328 total_width = (max_width_per_client + borderW) * num_items - borderW; 328 total_width = (max_width_per_client + borderW) * num_items - borderW;
329 if (total_width > m_max_total_size) { 329 if (total_width > m_max_total_size) {
330 total_width = m_max_total_size; 330 total_width = m_max_total_size;
@@ -379,7 +379,7 @@ void Container::repositionItems() {
379 unsigned int totalDemands = 0; 379 unsigned int totalDemands = 0;
380 std::vector<unsigned int> buttonDemands; 380 std::vector<unsigned int> buttonDemands;
381 381
382 if (align == RELATIVE || total_width == m_max_total_size) { 382 if (align == RELATIVE_SMART && total_width == m_max_total_size) {
383 buttonDemands.reserve(num_items); 383 buttonDemands.reserve(num_items);
384 for (it = begin(); it != it_end; ++it) { 384 for (it = begin(); it != it_end; ++it) {
385 buttonDemands.push_back((*it)->preferredWidth()); 385 buttonDemands.push_back((*it)->preferredWidth());
@@ -440,7 +440,7 @@ void Container::repositionItems() {
440 // rotate the x and y coords 440 // rotate the x and y coords
441 tmpx = next_x; 441 tmpx = next_x;
442 tmpy = -borderW; 442 tmpy = -borderW;
443 if (align == RELATIVE && totalDemands) { 443 if ((align == RELATIVE || align == RELATIVE_SMART) && totalDemands) {
444 tmpw = buttonDemands.at(i)*total_width/totalDemands + extra; 444 tmpw = buttonDemands.at(i)*total_width/totalDemands + extra;
445 } else { 445 } else {
446 tmpw = max_width_per_client + extra; 446 tmpw = max_width_per_client + extra;
@@ -469,6 +469,7 @@ unsigned int Container::maxWidthPerClient() const {
469 case LEFT: 469 case LEFT:
470 return m_max_size_per_client; 470 return m_max_size_per_client;
471 break; 471 break;
472 case RELATIVE_SMART:
472 case RELATIVE: 473 case RELATIVE:
473 if (size() == 0) 474 if (size() == 0)
474 return width(); 475 return width();
diff --git a/src/FbTk/Container.hh b/src/FbTk/Container.hh
index 0f8ac08..2dc6475 100644
--- a/src/FbTk/Container.hh
+++ b/src/FbTk/Container.hh
@@ -39,7 +39,7 @@ class Container: public FbWindow, public EventHandler, private NotCopyable {
39public: 39public:
40 // LEFT, RIGHT => fixed total width, fixed icon size 40 // LEFT, RIGHT => fixed total width, fixed icon size
41 // RELATIVE => fixed total width, relative/variable icon size 41 // RELATIVE => fixed total width, relative/variable icon size
42 enum Alignment { LEFT, CENTER, RIGHT, RELATIVE }; 42 enum Alignment { LEFT, CENTER, RIGHT, RELATIVE, RELATIVE_SMART };
43 typedef Button * Item; 43 typedef Button * Item;
44 typedef const Button * ConstItem; 44 typedef const Button * ConstItem;
45 typedef std::list<Item> ItemList; 45 typedef std::list<Item> ItemList;
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc
index 8f8f128..027ab1c 100644
--- a/src/IconbarTool.cc
+++ b/src/IconbarTool.cc
@@ -73,6 +73,8 @@ string FbTk::Resource<FbTk::Container::Alignment>::getString() const {
73 return string("Left"); 73 return string("Left");
74 if (m_value == FbTk::Container::RIGHT) 74 if (m_value == FbTk::Container::RIGHT)
75 return string("Right"); 75 return string("Right");
76 if (m_value == FbTk::Container::RELATIVE_SMART)
77 return string("RelativeSmart");
76 return string("Relative"); 78 return string("Relative");
77} 79}
78 80
@@ -84,6 +86,8 @@ void FbTk::Resource<FbTk::Container::Alignment>::setFromString(const char *str)
84 m_value = FbTk::Container::RIGHT; 86 m_value = FbTk::Container::RIGHT;
85 else if (strcasecmp(str, "Relative") == 0) 87 else if (strcasecmp(str, "Relative") == 0)
86 m_value = FbTk::Container::RELATIVE; 88 m_value = FbTk::Container::RELATIVE;
89 else if (strcasecmp(str, "RelativeSmart") == 0)
90 m_value = FbTk::Container::RELATIVE_SMART;
87 else 91 else
88 setDefaultValue(); 92 setDefaultValue();
89} 93}
@@ -143,6 +147,7 @@ enum {
143 147
144 L_LEFT, 148 L_LEFT,
145 L_RELATIVE, 149 L_RELATIVE,
150 L_RELATIVE_SMART,
146 L_RIGHT, 151 L_RIGHT,
147}; 152};
148 153
@@ -163,6 +168,7 @@ void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) {
163 168
164 _FB_XTEXT(Align, Left, "Left", "Align to the left"), 169 _FB_XTEXT(Align, Left, "Left", "Align to the left"),
165 _FB_XTEXT(Align, Relative, "Relative", "Align relative to the width"), 170 _FB_XTEXT(Align, Relative, "Relative", "Align relative to the width"),
171 _FB_XTEXT(Align, RelativeSmart, "Relative (Smart)", "Align relative to the width, but let elements vary according to size of title"),
166 _FB_XTEXT(Align, Right, "Right", "Align to the right"), 172 _FB_XTEXT(Align, Right, "Right", "Align to the right"),
167 }; 173 };
168 174
@@ -181,6 +187,7 @@ void setupModeMenu(FbTk::Menu &menu, IconbarTool &handler) {
181 187
182 menu.insertItem(new ToolbarAlignMenuItem(_labels[L_LEFT], handler, FbTk::Container::LEFT, saverc_cmd)); 188 menu.insertItem(new ToolbarAlignMenuItem(_labels[L_LEFT], handler, FbTk::Container::LEFT, saverc_cmd));
183 menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RELATIVE], handler, FbTk::Container::RELATIVE, saverc_cmd)); 189 menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RELATIVE], handler, FbTk::Container::RELATIVE, saverc_cmd));
190 menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RELATIVE_SMART], handler, FbTk::Container::RELATIVE_SMART, saverc_cmd));
184 menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RIGHT], handler, FbTk::Container::RIGHT, saverc_cmd)); 191 menu.insertItem(new ToolbarAlignMenuItem(_labels[L_RIGHT], handler, FbTk::Container::RIGHT, saverc_cmd));
185 192
186 menu.insertItem(new FbTk::MenuSeparator()); 193 menu.insertItem(new FbTk::MenuSeparator());
@@ -304,11 +311,21 @@ void IconbarTool::move(int x, int y) {
304 m_icon_container.move(x, y); 311 m_icon_container.move(x, y);
305} 312}
306 313
307void IconbarTool::resize(unsigned int width, unsigned int height) { 314void IconbarTool::updateMaxSizes(unsigned int width, unsigned int height) {
308 m_icon_container.resize(width, height);
309 const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height : width; 315 const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height : width;
310 m_icon_container.setMaxTotalSize(maxsize); 316 m_icon_container.setMaxTotalSize(maxsize);
311 m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size())); 317
318 if(*m_rc_alignment == FbTk::Container::LEFT || *m_rc_alignment == FbTk::Container::RIGHT) {
319 *m_rc_client_width = FbTk::Util::clamp(*m_rc_client_width, 10, 400);
320 m_icon_container.setMaxSizePerClient(*m_rc_client_width);
321 } else {
322 m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size()));
323 }
324}
325
326void IconbarTool::resize(unsigned int width, unsigned int height) {
327 m_icon_container.resize(width, height);
328 updateMaxSizes(width, height);
312 renderTheme(); 329 renderTheme();
313} 330}
314 331
@@ -316,9 +333,7 @@ void IconbarTool::moveResize(int x, int y,
316 unsigned int width, unsigned int height) { 333 unsigned int width, unsigned int height) {
317 334
318 m_icon_container.moveResize(x, y, width, height); 335 m_icon_container.moveResize(x, y, width, height);
319 const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height : width; 336 updateMaxSizes(width, height);
320 m_icon_container.setMaxTotalSize(maxsize);
321 m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size()));
322 renderTheme(); 337 renderTheme();
323} 338}
324 339
@@ -438,10 +453,8 @@ void IconbarTool::update(UpdateReason reason, Focusable *win) {
438 } 453 }
439 454
440 m_resizeSig_timer.start(); 455 m_resizeSig_timer.start();
441 const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height() : width();
442 m_icon_container.setMaxTotalSize(maxsize);
443 m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size()));
444 456
457 updateMaxSizes(width(), height());
445 // unlock container and update graphics 458 // unlock container and update graphics
446 m_icon_container.setUpdateLock(false); 459 m_icon_container.setUpdateLock(false);
447 m_icon_container.update(); 460 m_icon_container.update();
diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh
index a461ce5..df6d9a6 100644
--- a/src/IconbarTool.hh
+++ b/src/IconbarTool.hh
@@ -98,6 +98,7 @@ private:
98 /// add icons to the list 98 /// add icons to the list
99 void updateList(); 99 void updateList();
100 100
101 void updateMaxSizes(unsigned int width, unsigned int height);
101 /// called when the list emits a signal 102 /// called when the list emits a signal
102 void update(UpdateReason reason, Focusable *win); 103 void update(UpdateReason reason, Focusable *win);
103 104