diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-12 12:52:18 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-17 09:55:04 (GMT) |
commit | 3ba2a09692eeda90874919f248387be488581e15 (patch) | |
tree | d43b0dc3010bfc690369c17ea83e356729d64eba /src | |
parent | c9f19e88e187836aee4627d67dc7d26a1641d8ad (diff) | |
download | fluxbox_pavel-3ba2a09692eeda90874919f248387be488581e15.zip fluxbox_pavel-3ba2a09692eeda90874919f248387be488581e15.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 cf7f438..15fab9d 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -206,11 +206,6 @@ private: | |||
206 | FbWinFrame::TabPlacement m_place; | 206 | FbWinFrame::TabPlacement m_place; |
207 | }; | 207 | }; |
208 | 208 | ||
209 | void clampMenuDelay(int& delay) { | ||
210 | delay = FbTk::Util::clamp(delay, 0, 5000); | ||
211 | } | ||
212 | |||
213 | |||
214 | struct TabPlacementString { | 209 | struct TabPlacementString { |
215 | FbWinFrame::TabPlacement placement; | 210 | FbWinFrame::TabPlacement placement; |
216 | const char* str; | 211 | const char* str; |
@@ -282,7 +277,7 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, | |||
282 | focused_alpha(rm, 255, scrname+".window.focus.alpha"), | 277 | focused_alpha(rm, 255, scrname+".window.focus.alpha"), |
283 | unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha"), | 278 | unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha"), |
284 | menu_alpha(rm, 255, scrname+".menu.alpha"), | 279 | menu_alpha(rm, 255, scrname+".menu.alpha"), |
285 | menu_delay(rm, 200, scrname + ".menuDelay"), | 280 | menu_delay(rm, 200, scrname + ".menuDelay", FbTk::RangedIntTraits(0, 5000)), |
286 | tab_width(rm, 64, scrname + ".tab.width"), | 281 | tab_width(rm, 64, scrname + ".tab.width"), |
287 | tooltip_delay(rm, 500, scrname + ".tooltipDelay"), | 282 | tooltip_delay(rm, 500, scrname + ".tooltipDelay"), |
288 | allow_remote_actions(rm, false, scrname+".allowRemoteActions"), | 283 | allow_remote_actions(rm, false, scrname+".allowRemoteActions"), |
@@ -429,8 +424,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, | |||
429 | unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); | 424 | unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); |
430 | m_menutheme->setAlpha(*resource.menu_alpha); | 425 | m_menutheme->setAlpha(*resource.menu_alpha); |
431 | 426 | ||
432 | clampMenuDelay(*resource.menu_delay); | ||
433 | |||
434 | m_menutheme->setDelay(*resource.menu_delay); | 427 | m_menutheme->setDelay(*resource.menu_delay); |
435 | 428 | ||
436 | m_tracker.join(focusedWinFrameTheme()->reconfigSig(), | 429 | m_tracker.join(focusedWinFrameTheme()->reconfigSig(), |
@@ -841,8 +834,6 @@ void BScreen::reconfigure() { | |||
841 | unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); | 834 | unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); |
842 | m_menutheme->setAlpha(*resource.menu_alpha); | 835 | m_menutheme->setAlpha(*resource.menu_alpha); |
843 | 836 | ||
844 | clampMenuDelay(*resource.menu_delay); | ||
845 | |||
846 | m_menutheme->setDelay(*resource.menu_delay); | 837 | m_menutheme->setDelay(*resource.menu_delay); |
847 | 838 | ||
848 | // realize the number of workspaces from the init-file | 839 | // realize the number of workspaces from the init-file |
@@ -1710,11 +1701,10 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { | |||
1710 | FbTk::RefCount<FbTk::Menu> alpha_menu( createMenu(alphamenu_label) ); | 1701 | FbTk::RefCount<FbTk::Menu> alpha_menu( createMenu(alphamenu_label) ); |
1711 | 1702 | ||
1712 | if (FbTk::Transparent::haveComposite(true)) { | 1703 | if (FbTk::Transparent::haveComposite(true)) { |
1713 | static FbTk::SimpleAccessor<bool> s_pseudo(Fluxbox::instance()->getPseudoTrans()); | ||
1714 | alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, | 1704 | alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, |
1715 | "Force Pseudo-Transparency", | 1705 | "Force Pseudo-Transparency", |
1716 | "When composite is available, still use old pseudo-transparency"), | 1706 | "When composite is available, still use old pseudo-transparency"), |
1717 | s_pseudo, save_and_reconfigure)); | 1707 | Fluxbox::instance()->getPseudoTransResource(), save_and_reconfigure)); |
1718 | } | 1708 | } |
1719 | 1709 | ||
1720 | // in order to save system resources, don't save or reconfigure alpha | 1710 | // in order to save system resources, don't save or reconfigure alpha |
diff --git a/src/Screen.hh b/src/Screen.hh index db357d1..1057229 100644 --- a/src/Screen.hh +++ b/src/Screen.hh | |||
@@ -537,8 +537,9 @@ private: | |||
537 | FbTk::StringResource windowmenufile; | 537 | FbTk::StringResource windowmenufile; |
538 | FbTk::UIntResource typing_delay; | 538 | FbTk::UIntResource typing_delay; |
539 | FbTk::IntResource workspaces, edge_snap_threshold, focused_alpha, | 539 | FbTk::IntResource workspaces, edge_snap_threshold, focused_alpha, |
540 | unfocused_alpha, menu_alpha, menu_delay, | 540 | unfocused_alpha, menu_alpha; |
541 | tab_width, tooltip_delay; | 541 | FbTk::RangedIntResource menu_delay; |
542 | FbTk::IntResource tab_width, tooltip_delay; | ||
542 | FbTk::BoolResource allow_remote_actions; | 543 | FbTk::BoolResource allow_remote_actions; |
543 | FbTk::BoolResource clientmenu_use_pixmap; | 544 | FbTk::BoolResource clientmenu_use_pixmap; |
544 | FbTk::BoolResource tabs_use_pixmap; | 545 | FbTk::BoolResource tabs_use_pixmap; |
diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 1dfcab8..37eb0e1 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc | |||
@@ -242,21 +242,20 @@ Fluxbox::Fluxbox(int argc, char **argv, | |||
242 | m_resourcemanager("session", *m_l), | 242 | m_resourcemanager("session", *m_l), |
243 | 243 | ||
244 | m_RC_PATH(rc_path), | 244 | m_RC_PATH(rc_path), |
245 | m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder", "IgnoreBorder"), | 245 | m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder"), |
246 | m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency", "forcePseudoTransparency"), | 246 | m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency"), |
247 | m_rc_colors_per_channel(m_resourcemanager, 4, | 247 | m_rc_colors_per_channel(m_resourcemanager, 4, "colorsPerChannel", RangedIntTraits(2, 6)), |
248 | "colorsPerChannel", "ColorsPerChannel"), | 248 | m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval"), |
249 | m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval", "DoubleClickInterval"), | 249 | m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding"), |
250 | m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding", "TabPadding"), | 250 | m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile"), |
251 | m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile", "StyleFile"), | 251 | m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay"), |
252 | m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"), | 252 | m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile"), |
253 | m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile", "MenuFile"), | 253 | m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile"), |
254 | m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"), | 254 | m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile"), |
255 | m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"), | 255 | m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea"), |
256 | m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"), | 256 | m_rc_cache_life(m_resourcemanager, 5, "cacheLife"), |
257 | m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"), | 257 | m_rc_cache_max(m_resourcemanager, 200, "cacheMax"), |
258 | m_rc_cache_max(m_resourcemanager, 200, "cacheMax", "CacheMax"), | 258 | m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay"), |
259 | m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay", "AutoRaiseDelay"), | ||
260 | m_masked_window(0), | 259 | m_masked_window(0), |
261 | m_mousescreen(0), | 260 | m_mousescreen(0), |
262 | m_keyscreen(0), | 261 | m_keyscreen(0), |
@@ -1184,10 +1183,6 @@ void Fluxbox::load_rc() { | |||
1184 | if (m_rc_menufile->empty()) | 1183 | if (m_rc_menufile->empty()) |
1185 | m_rc_menufile.setDefaultValue(); | 1184 | m_rc_menufile.setDefaultValue(); |
1186 | 1185 | ||
1187 | FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); | ||
1188 | |||
1189 | *m_rc_colors_per_channel = FbTk::Util::clamp(*m_rc_colors_per_channel, 2, 6); | ||
1190 | |||
1191 | if (m_rc_stylefile->empty()) | 1186 | if (m_rc_stylefile->empty()) |
1192 | *m_rc_stylefile = DEFAULTSTYLE; | 1187 | *m_rc_stylefile = DEFAULTSTYLE; |
1193 | } | 1188 | } |
diff --git a/src/fluxbox.hh b/src/fluxbox.hh index d6e9281..47ab834 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; } |
@@ -237,8 +237,8 @@ private: | |||
237 | 237 | ||
238 | FbTk::BoolResource m_rc_ignoreborder; | 238 | FbTk::BoolResource m_rc_ignoreborder; |
239 | FbTk::BoolResource m_rc_pseudotrans; | 239 | FbTk::BoolResource m_rc_pseudotrans; |
240 | FbTk::IntResource m_rc_colors_per_channel, | 240 | FbTk::RangedIntResource m_rc_colors_per_channel; |
241 | m_rc_double_click_interval, | 241 | FbTk::IntResource m_rc_double_click_interval, |
242 | m_rc_tabs_padding; | 242 | m_rc_tabs_padding; |
243 | FbTk::StringResource m_rc_stylefile, | 243 | FbTk::StringResource m_rc_stylefile, |
244 | m_rc_styleoverlayfile, | 244 | m_rc_styleoverlayfile, |