diff options
author | markt <markt> | 2007-01-15 19:00:09 (GMT) |
---|---|---|
committer | markt <markt> | 2007-01-15 19:00:09 (GMT) |
commit | a2804705db7259109232c23e9cd1ef86093237b1 (patch) | |
tree | 0d2c800aa93f0f2b6aa9c85211a78c62d78e3a7d /src/IntResMenuItem.hh | |
parent | 2a9e8e27826f57068c32c159c9b5a16824dd04b1 (diff) | |
download | fluxbox-a2804705db7259109232c23e9cd1ef86093237b1.zip fluxbox-a2804705db7259109232c23e9cd1ef86093237b1.tar.bz2 |
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
Diffstat (limited to 'src/IntResMenuItem.hh')
-rw-r--r-- | src/IntResMenuItem.hh | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh index 0be2775..768870e 100644 --- a/src/IntResMenuItem.hh +++ b/src/IntResMenuItem.hh | |||
@@ -56,20 +56,22 @@ public: | |||
56 | if (time - last_time <= 200) | 56 | if (time - last_time <= 200) |
57 | inc_val = 5; | 57 | inc_val = 5; |
58 | 58 | ||
59 | |||
60 | last_time = time; | 59 | last_time = time; |
61 | 60 | ||
62 | if ((button == 4 || button == 3)&& *m_res < m_max) // scroll up | 61 | // make sure values stay within bounds _before_ we try to set m_res |
63 | m_res.get() += inc_val; | 62 | // otherwise, this may cause bugs (say, with casting to unsigned char) |
64 | else if ((button == 5 || button == 1) && *m_res > m_min) // scroll down | 63 | if ((button == 4 || button == 3) && *m_res < m_max) { // up |
65 | m_res.get() -= inc_val; | 64 | if (*m_res + inc_val < m_max) |
66 | 65 | m_res.get() += inc_val; | |
67 | // clamp value | 66 | else |
68 | if (*m_res > m_max) | 67 | m_res.get() = m_max; |
69 | m_res.get() = m_max; | 68 | } else if ((button == 5 || button == 1) && *m_res > m_min) { // down |
70 | else if (*m_res < m_min) | 69 | if (*m_res - inc_val >= m_min) |
71 | m_res.get() = m_min; | 70 | m_res.get() -= inc_val; |
72 | 71 | else | |
72 | m_res.get() = m_min; | ||
73 | } | ||
74 | |||
73 | // update label | 75 | // update label |
74 | updateLabel(); | 76 | updateLabel(); |
75 | // call other commands | 77 | // call other commands |
@@ -86,7 +88,7 @@ public: | |||
86 | void updateLabel() { | 88 | void updateLabel() { |
87 | setLabel(appendIntValue(m_org_label, *m_res)); | 89 | setLabel(appendIntValue(m_org_label, *m_res)); |
88 | } | 90 | } |
89 | 91 | ||
90 | private: | 92 | private: |
91 | std::string m_org_label; ///< original label | 93 | std::string m_org_label; ///< original label |
92 | const int m_max; ///< maximum value the integer can have | 94 | const int m_max; ///< maximum value the integer can have |