diff options
author | Thomas Lübking <thomas.luebking@gmail.com> | 2016-07-24 14:40:03 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2016-08-26 05:33:44 (GMT) |
commit | 3bde5c8aee16f7f33e3ce7b9058fded916fe2369 (patch) | |
tree | 8c7791003a4c0196c7261db68a07313a9740bf1f /src/IconbarTool.cc | |
parent | 10e3f10b55fbd8f3ff6793a3993b8ee55f3192a2 (diff) | |
download | fluxbox-3bde5c8aee16f7f33e3ce7b9058fded916fe2369.zip fluxbox-3bde5c8aee16f7f33e3ce7b9058fded916fe2369.tar.bz2 |
Improve stretching (RELATIVE) toolbar items
The available space is distributed reg. the preferred width
of items (spacers and the iconbar ;-) instead of evenly.
The preferred width of the iconbar is calculated from its buttons.
This allows to align the iconbar using spacers and makes better use of
the available space
Diffstat (limited to 'src/IconbarTool.cc')
-rw-r--r-- | src/IconbarTool.cc | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 294d17a..4e2114d 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc | |||
@@ -292,7 +292,9 @@ void IconbarTool::move(int x, int y) { | |||
292 | 292 | ||
293 | void IconbarTool::resize(unsigned int width, unsigned int height) { | 293 | void IconbarTool::resize(unsigned int width, unsigned int height) { |
294 | m_icon_container.resize(width, height); | 294 | m_icon_container.resize(width, height); |
295 | m_icon_container.setMaxTotalSize(m_icon_container.orientation() == FbTk::ROT0 || m_icon_container.orientation() == FbTk::ROT180 ? width : height); | 295 | const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height : width; |
296 | m_icon_container.setMaxTotalSize(maxsize); | ||
297 | m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size())); | ||
296 | renderTheme(); | 298 | renderTheme(); |
297 | } | 299 | } |
298 | 300 | ||
@@ -300,7 +302,9 @@ void IconbarTool::moveResize(int x, int y, | |||
300 | unsigned int width, unsigned int height) { | 302 | unsigned int width, unsigned int height) { |
301 | 303 | ||
302 | m_icon_container.moveResize(x, y, width, height); | 304 | m_icon_container.moveResize(x, y, width, height); |
303 | m_icon_container.setMaxTotalSize(m_icon_container.orientation() == FbTk::ROT0 || m_icon_container.orientation() == FbTk::ROT180 ? width : height); | 305 | const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height : width; |
306 | m_icon_container.setMaxTotalSize(maxsize); | ||
307 | m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size())); | ||
304 | renderTheme(); | 308 | renderTheme(); |
305 | } | 309 | } |
306 | 310 | ||
@@ -362,6 +366,18 @@ unsigned int IconbarTool::width() const { | |||
362 | return m_icon_container.width(); | 366 | return m_icon_container.width(); |
363 | } | 367 | } |
364 | 368 | ||
369 | unsigned int IconbarTool::preferredWidth() const { | ||
370 | // border and paddings | ||
371 | unsigned int w = 2*borderWidth() + *m_rc_client_padding * m_icons.size(); | ||
372 | |||
373 | // the buttons | ||
374 | for (IconMap::const_iterator it = m_icons.begin(), end = m_icons.end(); it != end; ++it) { | ||
375 | w += it->second->preferredWidth(); | ||
376 | } | ||
377 | |||
378 | return w; | ||
379 | } | ||
380 | |||
365 | unsigned int IconbarTool::height() const { | 381 | unsigned int IconbarTool::height() const { |
366 | return m_icon_container.height(); | 382 | return m_icon_container.height(); |
367 | } | 383 | } |
@@ -384,9 +400,6 @@ void IconbarTool::update(UpdateReason reason, Focusable *win) { | |||
384 | 400 | ||
385 | m_icon_container.setAlignment(*m_rc_alignment); | 401 | m_icon_container.setAlignment(*m_rc_alignment); |
386 | 402 | ||
387 | *m_rc_client_width = FbTk::Util::clamp(*m_rc_client_width, 10, 400); | ||
388 | m_icon_container.setMaxSizePerClient(*m_rc_client_width); | ||
389 | |||
390 | // lock graphic update | 403 | // lock graphic update |
391 | m_icon_container.setUpdateLock(true); | 404 | m_icon_container.setUpdateLock(true); |
392 | 405 | ||
@@ -404,6 +417,11 @@ void IconbarTool::update(UpdateReason reason, Focusable *win) { | |||
404 | break; | 417 | break; |
405 | } | 418 | } |
406 | 419 | ||
420 | resizeSig().emit(); | ||
421 | const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height() : width(); | ||
422 | m_icon_container.setMaxTotalSize(maxsize); | ||
423 | m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size())); | ||
424 | |||
407 | // unlock container and update graphics | 425 | // unlock container and update graphics |
408 | m_icon_container.setUpdateLock(false); | 426 | m_icon_container.setUpdateLock(false); |
409 | m_icon_container.update(); | 427 | m_icon_container.update(); |
@@ -441,6 +459,7 @@ void IconbarTool::insertWindow(Focusable &win, int pos) { | |||
441 | } | 459 | } |
442 | 460 | ||
443 | m_icon_container.insertItem(button, pos); | 461 | m_icon_container.insertItem(button, pos); |
462 | m_tracker.join(button->titleChanged(), FbTk::MemFun(resizeSig(), &FbTk::Signal<>::emit)); | ||
444 | } | 463 | } |
445 | 464 | ||
446 | void IconbarTool::reset() { | 465 | void IconbarTool::reset() { |