aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-12 12:52:18 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:57:22 (GMT)
commitaec059644893c1314203d501b1d80cfd439f4d2f (patch)
tree8c7eab1e3e316bf7fe0ee7a98c32fdc12d773c43 /src
parent592d306e702cac55245b8485db9a769f47584137 (diff)
downloadfluxbox_pavel-aec059644893c1314203d501b1d80cfd439f4d2f.zip
fluxbox_pavel-aec059644893c1314203d501b1d80cfd439f4d2f.tar.bz2
Add RangeTraits class which automatically clamps the value of resources
and start using it.
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/ResTraits.hh36
-rw-r--r--src/FbTk/Resource.hh3
-rw-r--r--src/Screen.cc14
-rw-r--r--src/Screen.hh5
-rw-r--r--src/fluxbox.cc33
-rw-r--r--src/fluxbox.hh6
6 files changed, 61 insertions, 36 deletions
diff --git a/src/FbTk/ResTraits.hh b/src/FbTk/ResTraits.hh
index 19decb5..e1c3871 100644
--- a/src/FbTk/ResTraits.hh
+++ b/src/FbTk/ResTraits.hh
@@ -28,6 +28,7 @@
28#include "FbString.hh" 28#include "FbString.hh"
29#include "Luamm.hh" 29#include "Luamm.hh"
30#include "StringUtil.hh" 30#include "StringUtil.hh"
31#include "Util.hh"
31 32
32namespace FbTk { 33namespace FbTk {
33 34
@@ -226,6 +227,41 @@ private:
226 std::string m_delim; 227 std::string m_delim;
227}; 228};
228 229
230template<typename Traits>
231class RangeTraits: private Traits {
232public:
233 typedef typename Traits::Type Type;
234
235 RangeTraits(const Type &min, const Type &max, const Traits &traits = Traits())
236 : Traits(traits), m_min(min), m_max(max)
237 { assert(m_min <= m_max); }
238
239 std::string toString(const Type &x) const {
240 assert(x >= m_min);
241 assert(x <= m_max);
242
243 return Traits::toString(x);
244 }
245
246 void toLua(const Type &x, lua::state &l) const {
247 assert(x >= m_min);
248 assert(x <= m_max);
249
250 Traits::toLua(x, l);
251 }
252
253 Type fromString(const std::string &x) const {
254 return FbTk::Util::clamp(Traits::fromString(x), m_min, m_max);
255 }
256
257 Type fromLua(lua::state &l) const {
258 return FbTk::Util::clamp(Traits::fromLua(l), m_min, m_max);
259 }
260
261private:
262 Type m_min, m_max;
263};
264
229} // end namespace FbTk 265} // end namespace FbTk
230 266
231#endif // FBTK_RESTRAITS_HH 267#endif // FBTK_RESTRAITS_HH
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh
index c6f12d6..37a7ed3 100644
--- a/src/FbTk/Resource.hh
+++ b/src/FbTk/Resource.hh
@@ -281,6 +281,9 @@ typedef Resource<int, IntTraits<int> > IntResource;
281typedef Resource<unsigned int, IntTraits<unsigned int> > UIntResource; 281typedef Resource<unsigned int, IntTraits<unsigned int> > UIntResource;
282typedef Resource<std::string, StringTraits> StringResource; 282typedef Resource<std::string, StringTraits> StringResource;
283 283
284typedef RangeTraits<IntTraits<int> > RangedIntTraits;
285typedef Resource<int, RangedIntTraits> RangedIntResource;
286
284} // end namespace FbTk 287} // end namespace FbTk
285 288
286#endif // FBTK_RESOURCE_HH 289#endif // FBTK_RESOURCE_HH
diff --git a/src/Screen.cc b/src/Screen.cc
index 36a4233..d4a8a0a 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -204,11 +204,6 @@ private:
204 FbWinFrame::TabPlacement m_place; 204 FbWinFrame::TabPlacement m_place;
205}; 205};
206 206
207void clampMenuDelay(int& delay) {
208 delay = FbTk::Util::clamp(delay, 0, 5000);
209}
210
211
212struct TabPlacementString { 207struct TabPlacementString {
213 FbWinFrame::TabPlacement placement; 208 FbWinFrame::TabPlacement placement;
214 const char* str; 209 const char* str;
@@ -264,7 +259,7 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm,
264 focused_alpha(rm, 255, scrname+".window.focus.alpha"), 259 focused_alpha(rm, 255, scrname+".window.focus.alpha"),
265 unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha"), 260 unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha"),
266 menu_alpha(rm, 255, scrname+".menu.alpha"), 261 menu_alpha(rm, 255, scrname+".menu.alpha"),
267 menu_delay(rm, 200, scrname + ".menuDelay"), 262 menu_delay(rm, 200, scrname + ".menuDelay", FbTk::RangedIntTraits(0, 5000)),
268 tab_width(rm, 64, scrname + ".tab.width"), 263 tab_width(rm, 64, scrname + ".tab.width"),
269 tooltip_delay(rm, 500, scrname + ".tooltipDelay"), 264 tooltip_delay(rm, 500, scrname + ".tooltipDelay"),
270 allow_remote_actions(rm, false, scrname+".allowRemoteActions"), 265 allow_remote_actions(rm, false, scrname+".allowRemoteActions"),
@@ -403,8 +398,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm,
403 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); 398 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha);
404 m_menutheme->setAlpha(*resource.menu_alpha); 399 m_menutheme->setAlpha(*resource.menu_alpha);
405 400
406 clampMenuDelay(*resource.menu_delay);
407
408 m_menutheme->setDelay(*resource.menu_delay); 401 m_menutheme->setDelay(*resource.menu_delay);
409 402
410 m_tracker.join(focusedWinFrameTheme()->reconfigSig(), 403 m_tracker.join(focusedWinFrameTheme()->reconfigSig(),
@@ -818,8 +811,6 @@ void BScreen::reconfigure() {
818 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); 811 unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha);
819 m_menutheme->setAlpha(*resource.menu_alpha); 812 m_menutheme->setAlpha(*resource.menu_alpha);
820 813
821 clampMenuDelay(*resource.menu_delay);
822
823 m_menutheme->setDelay(*resource.menu_delay); 814 m_menutheme->setDelay(*resource.menu_delay);
824 815
825 // realize the number of workspaces from the init-file 816 // realize the number of workspaces from the init-file
@@ -1629,11 +1620,10 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1629 FbTk::RefCount<FbTk::Menu> alpha_menu( createMenu(alphamenu_label) ); 1620 FbTk::RefCount<FbTk::Menu> alpha_menu( createMenu(alphamenu_label) );
1630 1621
1631 if (FbTk::Transparent::haveComposite(true)) { 1622 if (FbTk::Transparent::haveComposite(true)) {
1632 static FbTk::SimpleAccessor<bool> s_pseudo(Fluxbox::instance()->getPseudoTrans());
1633 alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, 1623 alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans,
1634 "Force Pseudo-Transparency", 1624 "Force Pseudo-Transparency",
1635 "When composite is available, still use old pseudo-transparency"), 1625 "When composite is available, still use old pseudo-transparency"),
1636 s_pseudo, save_and_reconfigure)); 1626 Fluxbox::instance()->getPseudoTransResource(), save_and_reconfigure));
1637 } 1627 }
1638 1628
1639 // in order to save system resources, don't save or reconfigure alpha 1629 // in order to save system resources, don't save or reconfigure alpha
diff --git a/src/Screen.hh b/src/Screen.hh
index 1906d67..b8d589b 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -520,8 +520,9 @@ private:
520 FbTk::StringResource windowmenufile; 520 FbTk::StringResource windowmenufile;
521 FbTk::UIntResource typing_delay; 521 FbTk::UIntResource typing_delay;
522 FbTk::IntResource workspaces, edge_snap_threshold, focused_alpha, 522 FbTk::IntResource workspaces, edge_snap_threshold, focused_alpha,
523 unfocused_alpha, menu_alpha, menu_delay, 523 unfocused_alpha, menu_alpha;
524 tab_width, tooltip_delay; 524 FbTk::RangedIntResource menu_delay;
525 FbTk::IntResource tab_width, tooltip_delay;
525 FbTk::BoolResource allow_remote_actions; 526 FbTk::BoolResource allow_remote_actions;
526 FbTk::BoolResource clientmenu_use_pixmap; 527 FbTk::BoolResource clientmenu_use_pixmap;
527 FbTk::BoolResource tabs_use_pixmap; 528 FbTk::BoolResource tabs_use_pixmap;
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index b20b589..09aca1b 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -234,21 +234,20 @@ Fluxbox::Fluxbox(int argc, char **argv,
234 234
235 m_RC_PATH(rc_path), 235 m_RC_PATH(rc_path),
236 m_RC_INIT_FILE("init"), 236 m_RC_INIT_FILE("init"),
237 m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder", "IgnoreBorder"), 237 m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder"),
238 m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency", "forcePseudoTransparency"), 238 m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency"),
239 m_rc_colors_per_channel(m_resourcemanager, 4, 239 m_rc_colors_per_channel(m_resourcemanager, 4, "colorsPerChannel", RangedIntTraits(2, 6)),
240 "colorsPerChannel", "ColorsPerChannel"), 240 m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval"),
241 m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval", "DoubleClickInterval"), 241 m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding"),
242 m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding", "TabPadding"), 242 m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile"),
243 m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile", "StyleFile"), 243 m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay"),
244 m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"), 244 m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile"),
245 m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile", "MenuFile"), 245 m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile"),
246 m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"), 246 m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile"),
247 m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"), 247 m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea"),
248 m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"), 248 m_rc_cache_life(m_resourcemanager, 5, "cacheLife"),
249 m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"), 249 m_rc_cache_max(m_resourcemanager, 200, "cacheMax"),
250 m_rc_cache_max(m_resourcemanager, 200, "cacheMax", "CacheMax"), 250 m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay"),
251 m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay", "AutoRaiseDelay"),
252 m_masked_window(0), 251 m_masked_window(0),
253 m_mousescreen(0), 252 m_mousescreen(0),
254 m_keyscreen(0), 253 m_keyscreen(0),
@@ -1175,10 +1174,6 @@ void Fluxbox::load_rc() {
1175 if (m_rc_menufile->empty()) 1174 if (m_rc_menufile->empty())
1176 m_rc_menufile.setDefaultValue(); 1175 m_rc_menufile.setDefaultValue();
1177 1176
1178 FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans);
1179
1180 *m_rc_colors_per_channel = FbTk::Util::clamp(*m_rc_colors_per_channel, 2, 6);
1181
1182 if (m_rc_stylefile->empty()) 1177 if (m_rc_stylefile->empty())
1183 *m_rc_stylefile = DEFAULTSTYLE; 1178 *m_rc_stylefile = DEFAULTSTYLE;
1184} 1179}
diff --git a/src/fluxbox.hh b/src/fluxbox.hh
index 6c82c00..22b34bb 100644
--- a/src/fluxbox.hh
+++ b/src/fluxbox.hh
@@ -114,7 +114,7 @@ public:
114 114
115 115
116 bool getIgnoreBorder() const { return *m_rc_ignoreborder; } 116 bool getIgnoreBorder() const { return *m_rc_ignoreborder; }
117 bool &getPseudoTrans() { return *m_rc_pseudotrans; } 117 FbTk::BoolResource &getPseudoTransResource() { return m_rc_pseudotrans; }
118 118
119 Fluxbox::TabsAttachArea getTabsAttachArea() const { return *m_rc_tabs_attach_area; } 119 Fluxbox::TabsAttachArea getTabsAttachArea() const { return *m_rc_tabs_attach_area; }
120 const std::string &getStyleFilename() const { return *m_rc_stylefile; } 120 const std::string &getStyleFilename() const { return *m_rc_stylefile; }
@@ -238,8 +238,8 @@ private:
238 238
239 FbTk::BoolResource m_rc_ignoreborder; 239 FbTk::BoolResource m_rc_ignoreborder;
240 FbTk::BoolResource m_rc_pseudotrans; 240 FbTk::BoolResource m_rc_pseudotrans;
241 FbTk::IntResource m_rc_colors_per_channel, 241 FbTk::RangedIntResource m_rc_colors_per_channel;
242 m_rc_double_click_interval, 242 FbTk::IntResource m_rc_double_click_interval,
243 m_rc_tabs_padding; 243 m_rc_tabs_padding;
244 FbTk::StringResource m_rc_stylefile, 244 FbTk::StringResource m_rc_stylefile,
245 m_rc_styleoverlayfile, 245 m_rc_styleoverlayfile,