all repos — fluxbox @ a2804705db7259109232c23e9cd1ef86093237b1

custom fork of the fluxbox windowmanager

prevent per-window alpha menu from scrolling past 0 or 255:
suppose your alpha was at 3 and then you double-clicked -- IntResMenuItem was
setting the alpha to -2, which in FbWinFrame::setAlpha got cast to an unsigned
char, or 254; then, IntResMenuItem would check if the value was less than 0,
which, of course, it wasn't
now, IntResMenuItem checks if the value will exceed the max/min before setting
markt markt
commit

a2804705db7259109232c23e9cd1ef86093237b1

parent

2a9e8e27826f57068c32c159c9b5a16824dd04b1

2 files changed, 18 insertions(+), 14 deletions(-)

jump to
M ChangeLogChangeLog

@@ -1,6 +1,8 @@

(Format: Year/Month/Day) Changes for 1.0rc3: *07/01/15: + * Prevent per-window alpha menu from scrolling past 0 or 255 (Mark) + IntResMenuItem.hh * Fix rootmenu disappearing on reconfigure (Mark) Screen.cc *07/01/14:
M src/IntResMenuItem.hhsrc/IntResMenuItem.hh

@@ -56,20 +56,22 @@ //!! TODO: must have some sort of "global" double click time in FbTk

if (time - last_time <= 200) inc_val = 5; - last_time = time; - - if ((button == 4 || button == 3)&& *m_res < m_max) // scroll up - m_res.get() += inc_val; - else if ((button == 5 || button == 1) && *m_res > m_min) // scroll down - m_res.get() -= inc_val; - - // clamp value - if (*m_res > m_max) - m_res.get() = m_max; - else if (*m_res < m_min) - m_res.get() = m_min; - + + // make sure values stay within bounds _before_ we try to set m_res + // otherwise, this may cause bugs (say, with casting to unsigned char) + if ((button == 4 || button == 3) && *m_res < m_max) { // up + if (*m_res + inc_val < m_max) + m_res.get() += inc_val; + else + m_res.get() = m_max; + } else if ((button == 5 || button == 1) && *m_res > m_min) { // down + if (*m_res - inc_val >= m_min) + m_res.get() -= inc_val; + else + m_res.get() = m_min; + } + // update label updateLabel(); // call other commands

@@ -86,7 +88,7 @@

void updateLabel() { setLabel(appendIntValue(m_org_label, *m_res)); } - + private: std::string m_org_label; ///< original label const int m_max; ///< maximum value the integer can have