aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ArrowButton.cc6
-rw-r--r--src/CurrentWindowCmd.cc33
-rw-r--r--src/FbTk/Makefile.am1
-rw-r--r--src/FbTk/MultLayers.cc15
-rw-r--r--src/FbTk/Util.hh43
-rw-r--r--src/FbWinFrameTheme.cc13
-rw-r--r--src/IconbarTool.cc7
-rw-r--r--src/Remember.cc31
-rw-r--r--src/Screen.cc29
-rw-r--r--src/WindowState.cc6
10 files changed, 92 insertions, 92 deletions
diff --git a/src/ArrowButton.cc b/src/ArrowButton.cc
index b764a8f..e46ffc4 100644
--- a/src/ArrowButton.cc
+++ b/src/ArrowButton.cc
@@ -22,6 +22,8 @@
22#include "ArrowButton.hh" 22#include "ArrowButton.hh"
23#include "ButtonTheme.hh" 23#include "ButtonTheme.hh"
24 24
25#include "FbTk/Util.hh"
26
25ArrowButton::ArrowButton(FbTk::FbDrawable::TriangleType arrow_type, 27ArrowButton::ArrowButton(FbTk::FbDrawable::TriangleType arrow_type,
26 const FbTk::FbWindow &parent, 28 const FbTk::FbWindow &parent,
27 int x, int y, 29 int x, int y,
@@ -92,6 +94,6 @@ void ArrowButton::updateTheme(const FbTk::Theme &theme) {
92 94
93 m_arrowscale = btheme.scale(); 95 m_arrowscale = btheme.scale();
94 if (m_arrowscale == 0) m_arrowscale = 250; // default is 0 => 300 96 if (m_arrowscale == 0) m_arrowscale = 250; // default is 0 => 300
95 else if (m_arrowscale < 100) m_arrowscale = 100; // otherwise clamp 97
96 else if (m_arrowscale > 100000) m_arrowscale = 100000; // clamp below overflow when *100 98 m_arrowscale = FbTk::Util::clamp(m_arrowscale, 100, 100000);
97} 99}
diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc
index 4d25d54..e2fdb94 100644
--- a/src/CurrentWindowCmd.cc
+++ b/src/CurrentWindowCmd.cc
@@ -35,6 +35,7 @@
35#include "FbTk/I18n.hh" 35#include "FbTk/I18n.hh"
36#include "FbTk/stringstream.hh" 36#include "FbTk/stringstream.hh"
37#include "FbTk/StringUtil.hh" 37#include "FbTk/StringUtil.hh"
38#include "FbTk/Util.hh"
38 39
39#ifdef HAVE_CONFIG_H 40#ifdef HAVE_CONFIG_H
40#include "config.h" 41#include "config.h"
@@ -250,8 +251,7 @@ void SetHeadCmd::real_execute() {
250 int num = m_head; 251 int num = m_head;
251 int total = fbwindow().screen().numHeads(); 252 int total = fbwindow().screen().numHeads();
252 if (num < 0) num += total + 1; 253 if (num < 0) num += total + 1;
253 if (num < 1) num = 1; 254 num = FbTk::Util::clamp(num, 1, total);
254 if (num > total) num = total;
255 fbwindow().setOnHead(num); 255 fbwindow().setOnHead(num);
256} 256}
257 257
@@ -259,8 +259,7 @@ void SendToWorkspaceCmd::real_execute() {
259 int num = m_workspace_num; 259 int num = m_workspace_num;
260 int total = fbwindow().screen().numberOfWorkspaces(); 260 int total = fbwindow().screen().numberOfWorkspaces();
261 if (num < 0) num += total + 1; 261 if (num < 0) num += total + 1;
262 if (num < 1) num = 1; 262 num = FbTk::Util::clamp(num, 1, total);
263 if (num > total) num = total;
264 fbwindow().screen().sendToWorkspace(num-1, &fbwindow(), m_take); 263 fbwindow().screen().sendToWorkspace(num-1, &fbwindow(), m_take);
265} 264}
266 265
@@ -281,8 +280,7 @@ void SendToNextHeadCmd::real_execute() {
281void GoToTabCmd::real_execute() { 280void GoToTabCmd::real_execute() {
282 int num = m_tab_num; 281 int num = m_tab_num;
283 if (num < 0) num += fbwindow().numClients() + 1; 282 if (num < 0) num += fbwindow().numClients() + 1;
284 if (num < 1) num = 1; 283 num = FbTk::Util::clamp(num, 1, fbwindow().numClients());
285 if (num > fbwindow().numClients()) num = fbwindow().numClients();
286 284
287 FluxboxWindow::ClientList::iterator it = fbwindow().clientList().begin(); 285 FluxboxWindow::ClientList::iterator it = fbwindow().clientList().begin();
288 286
@@ -670,22 +668,13 @@ void SetAlphaCmd::real_execute() {
670 return; 668 return;
671 } 669 }
672 670
673 int new_alpha; 671 fbwindow().setFocusedAlpha(m_relative
674 if (m_relative) { 672 ? FbTk::Util::clamp(fbwindow().getFocusedAlpha() + m_focus, 0, 255)
675 new_alpha = fbwindow().getFocusedAlpha() + m_focus; 673 : m_focus);
676 if (new_alpha < 0) new_alpha = 0; 674
677 if (new_alpha > 255) new_alpha = 255; 675 fbwindow().setUnfocusedAlpha(m_un_relative
678 fbwindow().setFocusedAlpha(new_alpha); 676 ? FbTk::Util::clamp(fbwindow().getUnfocusedAlpha() + m_unfocus, 0, 255)
679 } else 677 : m_unfocus);
680 fbwindow().setFocusedAlpha(m_focus);
681
682 if (m_un_relative) {
683 new_alpha = fbwindow().getUnfocusedAlpha() + m_unfocus;
684 if (new_alpha < 0) new_alpha = 0;
685 if (new_alpha > 255) new_alpha = 255;
686 fbwindow().setUnfocusedAlpha(new_alpha);
687 } else
688 fbwindow().setUnfocusedAlpha(m_unfocus);
689} 678}
690 679
691REGISTER_COMMAND_WITH_ARGS(matches, MatchCmd, bool); 680REGISTER_COMMAND_WITH_ARGS(matches, MatchCmd, bool);
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
29using namespace FbTk; 31using namespace FbTk;
30 32
31MultLayers::MultLayers(int numlayers) : 33MultLayers::MultLayers(int numlayers) :
@@ -56,11 +58,7 @@ XLayerItem *MultLayers::getLowestItemAboveLayer(int layernum) {
56} 58}
57 59
58void MultLayers::addToTop(XLayerItem &item, int layernum) { 60void 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
25namespace FbTk {
26
27namespace Util {
28
29template<typename T>
30inline 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
diff --git a/src/FbWinFrameTheme.cc b/src/FbWinFrameTheme.cc
index 92cb134..f01c546 100644
--- a/src/FbWinFrameTheme.cc
+++ b/src/FbWinFrameTheme.cc
@@ -21,6 +21,7 @@
21 21
22#include "FbWinFrameTheme.hh" 22#include "FbWinFrameTheme.hh"
23#include "FbTk/App.hh" 23#include "FbTk/App.hh"
24#include "FbTk/Util.hh"
24 25
25#include "IconbarTheme.hh" 26#include "IconbarTheme.hh"
26 27
@@ -88,16 +89,10 @@ bool FbWinFrameTheme::fallback(FbTk::ThemeItem_base &item) {
88} 89}
89 90
90void FbWinFrameTheme::reconfigTheme() { 91void FbWinFrameTheme::reconfigTheme() {
91 if (*m_bevel_width > 20) 92 *m_bevel_width = FbTk::Util::clamp(*m_bevel_width, 0, 20);
92 *m_bevel_width = 20; 93 if (*m_handle_width < 0)
93 else if (*m_bevel_width < 0)
94 *m_bevel_width = 0;
95
96 if (*m_handle_width > 200)
97 *m_handle_width = 200;
98 else if (*m_handle_width < 0)
99 *m_handle_width = 1; 94 *m_handle_width = 1;
100 95 *m_handle_width = FbTk::Util::clamp(*m_handle_width, 0, 200);
101 m_button_pic_gc.setForeground(*m_button_color); 96 m_button_pic_gc.setForeground(*m_button_color);
102 m_iconbar_theme.reconfigTheme(); 97 m_iconbar_theme.reconfigTheme();
103} 98}
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc
index 85997ed..14835cb 100644
--- a/src/IconbarTool.cc
+++ b/src/IconbarTool.cc
@@ -47,6 +47,7 @@
47#include "FbTk/ImageControl.hh" 47#include "FbTk/ImageControl.hh"
48#include "FbTk/MacroCommand.hh" 48#include "FbTk/MacroCommand.hh"
49#include "FbTk/MenuSeparator.hh" 49#include "FbTk/MenuSeparator.hh"
50#include "FbTk/Util.hh"
50 51
51#include <typeinfo> 52#include <typeinfo>
52#include <iterator> 53#include <iterator>
@@ -389,12 +390,8 @@ void IconbarTool::update(FbTk::Subject *subj) {
389 } 390 }
390 391
391 m_icon_container.setAlignment(*m_rc_alignment); 392 m_icon_container.setAlignment(*m_rc_alignment);
392 // clamp to normal values
393 if (*m_rc_client_width < 1)
394 *m_rc_client_width = 10;
395 else if (*m_rc_client_width > 400)
396 *m_rc_client_width = 400;
397 393
394 *m_rc_client_width = FbTk::Util::clamp(*m_rc_client_width, 10, 400);
398 m_icon_container.setMaxSizePerClient(*m_rc_client_width); 395 m_icon_container.setMaxSizePerClient(*m_rc_client_width);
399 396
400 if (subj == &m_focused_theme.reconfigSig() || 397 if (subj == &m_focused_theme.reconfigSig() ||
diff --git a/src/Remember.cc b/src/Remember.cc
index f70217e..54b5b0d 100644
--- a/src/Remember.cc
+++ b/src/Remember.cc
@@ -41,6 +41,7 @@
41#include "FbTk/Transparent.hh" 41#include "FbTk/Transparent.hh"
42#include "FbTk/AutoReloadHelper.hh" 42#include "FbTk/AutoReloadHelper.hh"
43#include "FbTk/RefCount.hh" 43#include "FbTk/RefCount.hh"
44#include "FbTk/Util.hh"
44 45
45#ifdef HAVE_CSTRING 46#ifdef HAVE_CSTRING
46 #include <cstring> 47 #include <cstring>
@@ -512,28 +513,18 @@ int parseApp(ifstream &file, Application &app, string *first_line = 0) {
512 app.rememberDecostate((unsigned int)deco); 513 app.rememberDecostate((unsigned int)deco);
513 } else if (str_key == "alpha") { 514 } else if (str_key == "alpha") {
514 int focused_a, unfocused_a; 515 int focused_a, unfocused_a;
515 if (sscanf(str_label.c_str(), "%i %i", &focused_a, &unfocused_a) == 2) 516 switch (sscanf(str_label.c_str(), "%i %i", &focused_a, &unfocused_a)) {
516 { 517 case 1: // 'alpha <focus>'
517 // clamp; 518 unfocused_a = focused_a;
518 if (focused_a > 255) 519 case 2: // 'alpha <focus> <unfocus>'
519 focused_a = 255; 520 focused_a = FbTk::Util::clamp(focused_a, 0, 255);
520 if (unfocused_a > 255) 521 unfocused_a = FbTk::Util::clamp(unfocused_a, 0, 255);
521 unfocused_a = 255;
522 if (focused_a <= 0)
523 focused_a = 0;
524 if (unfocused_a <= 0)
525 unfocused_a = 0;
526
527 app.rememberAlpha(focused_a, unfocused_a); 522 app.rememberAlpha(focused_a, unfocused_a);
528 } else if (sscanf(str_label.c_str(), "%i", &focused_a) == 1) { 523 break;
529 if (focused_a > 255) 524 default:
530 focused_a = 255; 525 had_error = true;
531 if (focused_a <= 0) 526 break;
532 focused_a = 0;
533 app.rememberAlpha(focused_a, focused_a);
534 } 527 }
535 else
536 had_error = 1;
537 } else if (str_key == "sticky") { 528 } else if (str_key == "sticky") {
538 app.rememberStuckstate((strcasecmp(str_label.c_str(), "yes") == 0)); 529 app.rememberStuckstate((strcasecmp(str_label.c_str(), "yes") == 0));
539 } else if (str_key == "minimized") { 530 } else if (str_key == "minimized") {
diff --git a/src/Screen.cc b/src/Screen.cc
index ad24503..58aec0d 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -73,6 +73,7 @@
73#include "FbTk/FbString.hh" 73#include "FbTk/FbString.hh"
74#include "FbTk/STLUtil.hh" 74#include "FbTk/STLUtil.hh"
75#include "FbTk/KeyUtil.hh" 75#include "FbTk/KeyUtil.hh"
76#include "FbTk/Util.hh"
76 77
77//use GNU extensions 78//use GNU extensions
78#ifndef _GNU_SOURCE 79#ifndef _GNU_SOURCE
@@ -203,6 +204,10 @@ private:
203 FbWinFrame::TabPlacement m_place; 204 FbWinFrame::TabPlacement m_place;
204}; 205};
205 206
207void clampMenuDelay(int& delay) {
208 delay = FbTk::Util::clamp(delay, 0, 5000);
209}
210
206} // end anonymous namespace 211} // end anonymous namespace
207 212
208 213
@@ -453,11 +458,8 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
453 focusedWinFrameTheme()->setAlpha(*resource.focused_alpha); 458 focusedWinFrameTheme()->setAlpha(*resource.focused_alpha);
454 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); 459 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha);
455 m_menutheme->setAlpha(*resource.menu_alpha); 460 m_menutheme->setAlpha(*resource.menu_alpha);
456 // clamp values 461
457 if (*resource.menu_delay > 5000) 462 clampMenuDelay(*resource.menu_delay);
458 *resource.menu_delay = 5000;
459 if (*resource.menu_delay < 0)
460 *resource.menu_delay = 0;
461 463
462 m_menutheme->setDelay(*resource.menu_delay); 464 m_menutheme->setDelay(*resource.menu_delay);
463 465
@@ -905,11 +907,7 @@ void BScreen::reconfigure() {
905 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); 907 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha);
906 m_menutheme->setAlpha(*resource.menu_alpha); 908 m_menutheme->setAlpha(*resource.menu_alpha);
907 909
908 // clamp values 910 clampMenuDelay(*resource.menu_delay);
909 if (*resource.menu_delay > 5000)
910 *resource.menu_delay = 5000;
911 if (*resource.menu_delay < 0)
912 *resource.menu_delay = 0;
913 911
914 m_menutheme->setDelay(*resource.menu_delay); 912 m_menutheme->setDelay(*resource.menu_delay);
915 913
@@ -2138,15 +2136,8 @@ pair<int,int> BScreen::clampToHead(int head, int x, int y, int w, int h) const {
2138 int hw = getHeadWidth(head); 2136 int hw = getHeadWidth(head);
2139 int hh = getHeadHeight(head); 2137 int hh = getHeadHeight(head);
2140 2138
2141 if (x + w > hx + hw) 2139 x = FbTk::Util::clamp(x, hx, hx + hw - w);
2142 x = hx + hw - w; 2140 y = FbTk::Util::clamp(y, hy, hy + hh - h);
2143 if (y + h > hy + hh)
2144 y = hy + hh - h;
2145
2146 if (x < hx)
2147 x = hx;
2148 if (y < hy)
2149 y = hy;
2150 2141
2151 return make_pair(x,y); 2142 return make_pair(x,y);
2152} 2143}
diff --git a/src/WindowState.cc b/src/WindowState.cc
index 6632b66..1e650d8 100644
--- a/src/WindowState.cc
+++ b/src/WindowState.cc
@@ -246,10 +246,8 @@ void SizeHints::apply(unsigned int &width, unsigned int &height,
246 w = increaseToMultiple(h * min_aspect_x / min_aspect_y, width_inc); 246 w = increaseToMultiple(h * min_aspect_x / min_aspect_y, width_inc);
247 } 247 }
248 248
249 unsigned int max_w = make_fit && (width < max_width || max_width == 0) ? 249 unsigned int max_w = (make_fit && (width < max_width || max_width == 0)) ? width : max_width;
250 width : max_width; 250 unsigned int max_h = (make_fit && (height < max_height || max_height == 0)) ? height : max_height;
251 unsigned int max_h = make_fit && (height < max_height || max_height == 0) ?
252 height : max_height;
253 251
254 // Check maximum size 252 // Check maximum size
255 if (max_w > 0 && w + base_width > max_w) 253 if (max_w > 0 && w + base_width > max_w)