diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-12 12:52:18 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-07-12 12:52:18 (GMT) |
commit | c63a2294d884151d5538d6ead319a76dc41abba6 (patch) | |
tree | 1a5400ee46020b965842fb4107d25a6b07c0a6b9 /src | |
parent | d03f47e861140e93e7edea61e6276bc22b406559 (diff) | |
download | fluxbox_pavel-c63a2294d884151d5538d6ead319a76dc41abba6.zip fluxbox_pavel-c63a2294d884151d5538d6ead319a76dc41abba6.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.hh | 36 | ||||
-rw-r--r-- | src/FbTk/Resource.hh | 3 | ||||
-rw-r--r-- | src/Screen.cc | 14 | ||||
-rw-r--r-- | src/Screen.hh | 5 | ||||
-rw-r--r-- | src/fluxbox.cc | 33 | ||||
-rw-r--r-- | src/fluxbox.hh | 6 |
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 | ||
32 | namespace FbTk { | 33 | namespace FbTk { |
33 | 34 | ||
@@ -226,6 +227,41 @@ private: | |||
226 | std::string m_delim; | 227 | std::string m_delim; |
227 | }; | 228 | }; |
228 | 229 | ||
230 | template<typename Traits> | ||
231 | class RangeTraits: private Traits { | ||
232 | public: | ||
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 | |||
261 | private: | ||
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; | |||
281 | typedef Resource<unsigned int, IntTraits<unsigned int> > UIntResource; | 281 | typedef Resource<unsigned int, IntTraits<unsigned int> > UIntResource; |
282 | typedef Resource<std::string, StringTraits> StringResource; | 282 | typedef Resource<std::string, StringTraits> StringResource; |
283 | 283 | ||
284 | typedef RangeTraits<IntTraits<int> > RangedIntTraits; | ||
285 | typedef 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 e4eca07..edfd298 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 | ||
207 | void clampMenuDelay(int& delay) { | ||
208 | delay = FbTk::Util::clamp(delay, 0, 5000); | ||
209 | } | ||
210 | |||
211 | |||
212 | struct TabPlacementString { | 207 | struct 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(), |
@@ -826,8 +819,6 @@ void BScreen::reconfigure() { | |||
826 | unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); | 819 | unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); |
827 | m_menutheme->setAlpha(*resource.menu_alpha); | 820 | m_menutheme->setAlpha(*resource.menu_alpha); |
828 | 821 | ||
829 | clampMenuDelay(*resource.menu_delay); | ||
830 | |||
831 | m_menutheme->setDelay(*resource.menu_delay); | 822 | m_menutheme->setDelay(*resource.menu_delay); |
832 | 823 | ||
833 | // realize the number of workspaces from the init-file | 824 | // realize the number of workspaces from the init-file |
@@ -1637,11 +1628,10 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { | |||
1637 | FbTk::RefCount<FbTk::Menu> alpha_menu( createMenu(alphamenu_label) ); | 1628 | FbTk::RefCount<FbTk::Menu> alpha_menu( createMenu(alphamenu_label) ); |
1638 | 1629 | ||
1639 | if (FbTk::Transparent::haveComposite(true)) { | 1630 | if (FbTk::Transparent::haveComposite(true)) { |
1640 | static FbTk::SimpleAccessor<bool> s_pseudo(Fluxbox::instance()->getPseudoTrans()); | ||
1641 | alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, | 1631 | alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, |
1642 | "Force Pseudo-Transparency", | 1632 | "Force Pseudo-Transparency", |
1643 | "When composite is available, still use old pseudo-transparency"), | 1633 | "When composite is available, still use old pseudo-transparency"), |
1644 | s_pseudo, save_and_reconfigure)); | 1634 | Fluxbox::instance()->getPseudoTransResource(), save_and_reconfigure)); |
1645 | } | 1635 | } |
1646 | 1636 | ||
1647 | // in order to save system resources, don't save or reconfigure alpha | 1637 | // 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 4f41e4d..d7907be 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc | |||
@@ -239,21 +239,20 @@ Fluxbox::Fluxbox(int argc, char **argv, | |||
239 | 239 | ||
240 | m_RC_PATH(rc_path), | 240 | m_RC_PATH(rc_path), |
241 | m_RC_INIT_FILE("init"), | 241 | m_RC_INIT_FILE("init"), |
242 | m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder", "IgnoreBorder"), | 242 | m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder"), |
243 | m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency", "forcePseudoTransparency"), | 243 | m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency"), |
244 | m_rc_colors_per_channel(m_resourcemanager, 4, | 244 | m_rc_colors_per_channel(m_resourcemanager, 4, "colorsPerChannel", RangedIntTraits(2, 6)), |
245 | "colorsPerChannel", "ColorsPerChannel"), | 245 | m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval"), |
246 | m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval", "DoubleClickInterval"), | 246 | m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding"), |
247 | m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding", "TabPadding"), | 247 | m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile"), |
248 | m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile", "StyleFile"), | 248 | m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay"), |
249 | m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"), | 249 | m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile"), |
250 | m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile", "MenuFile"), | 250 | m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile"), |
251 | m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"), | 251 | m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile"), |
252 | m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"), | 252 | m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea"), |
253 | m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"), | 253 | m_rc_cache_life(m_resourcemanager, 5, "cacheLife"), |
254 | m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"), | 254 | m_rc_cache_max(m_resourcemanager, 200, "cacheMax"), |
255 | m_rc_cache_max(m_resourcemanager, 200, "cacheMax", "CacheMax"), | 255 | m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay"), |
256 | m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay", "AutoRaiseDelay"), | ||
257 | m_masked_window(0), | 256 | m_masked_window(0), |
258 | m_mousescreen(0), | 257 | m_mousescreen(0), |
259 | m_keyscreen(0), | 258 | m_keyscreen(0), |
@@ -1176,10 +1175,6 @@ void Fluxbox::load_rc() { | |||
1176 | if (m_rc_menufile->empty()) | 1175 | if (m_rc_menufile->empty()) |
1177 | m_rc_menufile.setDefaultValue(); | 1176 | m_rc_menufile.setDefaultValue(); |
1178 | 1177 | ||
1179 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); | ||
1180 | |||
1181 | *m_rc_colors_per_channel = FbTk::Util::clamp(*m_rc_colors_per_channel, 2, 6); | ||
1182 | |||
1183 | if (m_rc_stylefile->empty()) | 1178 | if (m_rc_stylefile->empty()) |
1184 | *m_rc_stylefile = DEFAULTSTYLE; | 1179 | *m_rc_stylefile = DEFAULTSTYLE; |
1185 | } | 1180 | } |
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, |