compress resize signals

typically buttons will call for this quite some, eg. when switching
workspace or (now) when altering the focused window. This compresses
various changes happening at the same time and re-layout the toolbar
only once for them
This commit is contained in:
Thomas Lübking 2016-09-24 19:36:09 +02:00
parent 7d30d0007d
commit 93a91904e6
2 changed files with 17 additions and 3 deletions

View file

@ -287,6 +287,12 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme,
FbTk::MemFun(*this, &IconbarTool::themeReconfigured));
m_tracker.join(screen.reconfigureSig(),
FbTk::MemFunIgnoreArgs(*this, &IconbarTool::updateIconifiedPattern));
m_resizeSig_timer.setTimeout(100 * FbTk::FbTime::IN_MILLISECONDS);
m_resizeSig_timer.fireOnce(true);
FbTk::RefCount<FbTk::Command<void> > ers(new FbTk::SimpleCommand<IconbarTool>(*this, &IconbarTool::emitResizeSig));
m_resizeSig_timer.setCommand(ers);
themeReconfigured();
}
@ -360,7 +366,7 @@ void IconbarTool::setMode(string mode) {
}
reset();
resizeSig().emit();
m_resizeSig_timer.start();
// unlock graphics update
m_icon_container.setUpdateLock(false);
@ -372,6 +378,10 @@ void IconbarTool::setMode(string mode) {
m_menu.reconfigure();
}
void IconbarTool::emitResizeSig() {
resizeSig().emit();
}
unsigned int IconbarTool::width() const {
return m_icon_container.width();
}
@ -427,7 +437,7 @@ void IconbarTool::update(UpdateReason reason, Focusable *win) {
break;
}
resizeSig().emit();
m_resizeSig_timer.start();
const unsigned int maxsize = (m_icon_container.orientation() & 1) ? height() : width();
m_icon_container.setMaxTotalSize(maxsize);
m_icon_container.setMaxSizePerClient(maxsize/std::max(1, m_icon_container.size()));
@ -482,7 +492,7 @@ void IconbarTool::insertWindow(Focusable &win, int pos) {
}
m_icon_container.insertItem(button, pos);
m_tracker.join(button->titleChanged(), FbTk::MemFun(resizeSig(), &FbTk::Signal<>::emit));
m_tracker.join(button->titleChanged(), FbTk::MemFun(m_resizeSig_timer, &FbTk::Timer::start));
}
void IconbarTool::reset() {

View file

@ -29,6 +29,7 @@
#include "FbTk/Container.hh"
#include "FbTk/CachedPixmap.hh"
#include "FbTk/Resource.hh"
#include "FbTk/Timer.hh"
#include <map>
@ -104,6 +105,9 @@ private:
void themeReconfigured();
FbTk::Timer m_resizeSig_timer;
void emitResizeSig();
BScreen &m_screen;
FbTk::Container m_icon_container;
IconbarTheme &m_theme;