diff options
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/Makefile.am | 1 | ||||
-rw-r--r-- | src/FbTk/MultLayers.cc | 15 | ||||
-rw-r--r-- | src/FbTk/Util.hh | 43 |
3 files changed, 48 insertions, 11 deletions
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index 67be7a0..45a24b3 100644 --- a/src/FbTk/Makefile.am +++ b/src/FbTk/Makefile.am | |||
@@ -64,6 +64,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ | |||
64 | Select2nd.hh STLUtil.hh \ | 64 | Select2nd.hh STLUtil.hh \ |
65 | CachedPixmap.hh CachedPixmap.cc \ | 65 | CachedPixmap.hh CachedPixmap.cc \ |
66 | Slot.hh Signal.hh MemFun.hh RelaySignal.hh SelectArg.hh \ | 66 | Slot.hh Signal.hh MemFun.hh RelaySignal.hh SelectArg.hh \ |
67 | Util.hh \ | ||
67 | ${xpm_SOURCE} \ | 68 | ${xpm_SOURCE} \ |
68 | ${xft_SOURCE} \ | 69 | ${xft_SOURCE} \ |
69 | ${xmb_SOURCE} \ | 70 | ${xmb_SOURCE} \ |
diff --git a/src/FbTk/MultLayers.cc b/src/FbTk/MultLayers.cc index a9135e3..6469a14 100644 --- a/src/FbTk/MultLayers.cc +++ b/src/FbTk/MultLayers.cc | |||
@@ -26,6 +26,8 @@ | |||
26 | #include "App.hh" | 26 | #include "App.hh" |
27 | #include "FbWindow.hh" | 27 | #include "FbWindow.hh" |
28 | 28 | ||
29 | #include "Util.hh" | ||
30 | |||
29 | using namespace FbTk; | 31 | using namespace FbTk; |
30 | 32 | ||
31 | MultLayers::MultLayers(int numlayers) : | 33 | MultLayers::MultLayers(int numlayers) : |
@@ -56,11 +58,7 @@ XLayerItem *MultLayers::getLowestItemAboveLayer(int layernum) { | |||
56 | } | 58 | } |
57 | 59 | ||
58 | void MultLayers::addToTop(XLayerItem &item, int layernum) { | 60 | void MultLayers::addToTop(XLayerItem &item, int layernum) { |
59 | if (layernum < 0) | 61 | layernum = FbTk::Util::clamp(layernum, 0, static_cast<signed>(m_layers.size()) - 1); |
60 | layernum = 0; | ||
61 | else if (layernum >= static_cast<signed>(m_layers.size())) | ||
62 | layernum = m_layers.size()-1; | ||
63 | |||
64 | m_layers[layernum]->insert(item); | 62 | m_layers[layernum]->insert(item); |
65 | restack(); | 63 | restack(); |
66 | } | 64 | } |
@@ -108,12 +106,7 @@ void MultLayers::moveToLayer(XLayerItem &item, int layernum) { | |||
108 | if (curr_layer.getLayerNum() == layernum) | 106 | if (curr_layer.getLayerNum() == layernum) |
109 | return; | 107 | return; |
110 | 108 | ||
111 | // clamp layer number | 109 | layernum = FbTk::Util::clamp(layernum, 0, static_cast<signed>(m_layers.size()) - 1); |
112 | if (layernum < 0) | ||
113 | layernum = 0; | ||
114 | else if (layernum >= static_cast<signed>(m_layers.size())) | ||
115 | layernum = m_layers.size()-1; | ||
116 | // remove item from old layer and insert it into the | ||
117 | item.setLayer(*m_layers[layernum]); | 110 | item.setLayer(*m_layers[layernum]); |
118 | } | 111 | } |
119 | 112 | ||
diff --git a/src/FbTk/Util.hh b/src/FbTk/Util.hh new file mode 100644 index 0000000..5e5a986 --- /dev/null +++ b/src/FbTk/Util.hh | |||
@@ -0,0 +1,43 @@ | |||
1 | // Util.hh for fluxbox | ||
2 | // Copyright (c) 2010 Mathias Gumz (akira at fluxbox org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | #ifndef FBTK_UTIL_HH | ||
23 | #define FBTK_UTIL_HH | ||
24 | |||
25 | namespace FbTk { | ||
26 | |||
27 | namespace Util { | ||
28 | |||
29 | template<typename T> | ||
30 | inline T clamp(const T& value, const T& lower, const T& upper) { | ||
31 | if (value < lower) | ||
32 | return lower; | ||
33 | else if (value > upper) | ||
34 | return upper; | ||
35 | return value; | ||
36 | } | ||
37 | |||
38 | } // end namespace Util | ||
39 | |||
40 | } // end namespace FbTk | ||
41 | |||
42 | |||
43 | #endif // FBTK_UTIL_HH | ||