From d232e10f8fadfbaae834c0ba124cef16cd0bc356 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 12 Jul 2011 14:52:18 +0200 Subject: Add RangeTraits class which automatically clamps the value of resources and start using it. --- src/FbTk/ResTraits.hh | 36 ++++++++++++++++++++++++++++++++++++ src/FbTk/Resource.hh | 3 +++ src/Screen.cc | 14 ++------------ src/Screen.hh | 5 +++-- src/fluxbox.cc | 33 ++++++++++++++------------------- 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 @@ #include "FbString.hh" #include "Luamm.hh" #include "StringUtil.hh" +#include "Util.hh" namespace FbTk { @@ -226,6 +227,41 @@ private: std::string m_delim; }; +template +class RangeTraits: private Traits { +public: + typedef typename Traits::Type Type; + + RangeTraits(const Type &min, const Type &max, const Traits &traits = Traits()) + : Traits(traits), m_min(min), m_max(max) + { assert(m_min <= m_max); } + + std::string toString(const Type &x) const { + assert(x >= m_min); + assert(x <= m_max); + + return Traits::toString(x); + } + + void toLua(const Type &x, lua::state &l) const { + assert(x >= m_min); + assert(x <= m_max); + + Traits::toLua(x, l); + } + + Type fromString(const std::string &x) const { + return FbTk::Util::clamp(Traits::fromString(x), m_min, m_max); + } + + Type fromLua(lua::state &l) const { + return FbTk::Util::clamp(Traits::fromLua(l), m_min, m_max); + } + +private: + Type m_min, m_max; +}; + } // end namespace FbTk #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 > IntResource; typedef Resource > UIntResource; typedef Resource StringResource; +typedef RangeTraits > RangedIntTraits; +typedef Resource RangedIntResource; + } // end namespace FbTk #endif // FBTK_RESOURCE_HH diff --git a/src/Screen.cc b/src/Screen.cc index 4c05fe3..37381cd 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -204,11 +204,6 @@ private: FbWinFrame::TabPlacement m_place; }; -void clampMenuDelay(int& delay) { - delay = FbTk::Util::clamp(delay, 0, 5000); -} - - struct TabPlacementString { FbWinFrame::TabPlacement placement; const char* str; @@ -264,7 +259,7 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, focused_alpha(rm, 255, scrname+".window.focus.alpha"), unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha"), menu_alpha(rm, 255, scrname+".menu.alpha"), - menu_delay(rm, 200, scrname + ".menuDelay"), + menu_delay(rm, 200, scrname + ".menuDelay", FbTk::RangedIntTraits(0, 5000)), tab_width(rm, 64, scrname + ".tab.width"), tooltip_delay(rm, 500, scrname + ".tooltipDelay"), allow_remote_actions(rm, false, scrname+".allowRemoteActions"), @@ -403,8 +398,6 @@ BScreen::BScreen(FbTk::ResourceManager_base &rm, unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); m_menutheme->setAlpha(*resource.menu_alpha); - clampMenuDelay(*resource.menu_delay); - m_menutheme->setDelay(*resource.menu_delay); m_tracker.join(focusedWinFrameTheme()->reconfigSig(), @@ -818,8 +811,6 @@ void BScreen::reconfigure() { unfocusedWinFrameTheme()->setAlpha(*resource.unfocused_alpha); m_menutheme->setAlpha(*resource.menu_alpha); - clampMenuDelay(*resource.menu_delay); - m_menutheme->setDelay(*resource.menu_delay); // realize the number of workspaces from the init-file @@ -1678,11 +1669,10 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { FbTk::RefCount alpha_menu( createMenu(alphamenu_label) ); if (FbTk::Transparent::haveComposite(true)) { - static FbTk::SimpleAccessor s_pseudo(Fluxbox::instance()->getPseudoTrans()); alpha_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, ForcePseudoTrans, "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), - s_pseudo, save_and_reconfigure)); + Fluxbox::instance()->getPseudoTransResource(), save_and_reconfigure)); } // 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: FbTk::StringResource windowmenufile; FbTk::UIntResource typing_delay; FbTk::IntResource workspaces, edge_snap_threshold, focused_alpha, - unfocused_alpha, menu_alpha, menu_delay, - tab_width, tooltip_delay; + unfocused_alpha, menu_alpha; + FbTk::RangedIntResource menu_delay; + FbTk::IntResource tab_width, tooltip_delay; FbTk::BoolResource allow_remote_actions; FbTk::BoolResource clientmenu_use_pixmap; FbTk::BoolResource tabs_use_pixmap; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 78741b5..e735773 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -234,21 +234,20 @@ Fluxbox::Fluxbox(int argc, char **argv, m_RC_PATH(rc_path), m_RC_INIT_FILE("init"), - m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder", "IgnoreBorder"), - m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency", "forcePseudoTransparency"), - m_rc_colors_per_channel(m_resourcemanager, 4, - "colorsPerChannel", "ColorsPerChannel"), - m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval", "DoubleClickInterval"), - m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding", "TabPadding"), - m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile", "StyleFile"), - m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"), - m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile", "MenuFile"), - m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"), - m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"), - m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"), - m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"), - m_rc_cache_max(m_resourcemanager, 200, "cacheMax", "CacheMax"), - m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay", "AutoRaiseDelay"), + m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder"), + m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency"), + m_rc_colors_per_channel(m_resourcemanager, 4, "colorsPerChannel", RangedIntTraits(2, 6)), + m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval"), + m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding"), + m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile"), + m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay"), + m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu2", "menuFile"), + m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile"), + m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile"), + m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea"), + m_rc_cache_life(m_resourcemanager, 5, "cacheLife"), + m_rc_cache_max(m_resourcemanager, 200, "cacheMax"), + m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay"), m_masked_window(0), m_mousescreen(0), m_keyscreen(0), @@ -1175,10 +1174,6 @@ void Fluxbox::load_rc() { if (m_rc_menufile->empty()) m_rc_menufile.setDefaultValue(); - FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); - - *m_rc_colors_per_channel = FbTk::Util::clamp(*m_rc_colors_per_channel, 2, 6); - if (m_rc_stylefile->empty()) *m_rc_stylefile = DEFAULTSTYLE; } 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: bool getIgnoreBorder() const { return *m_rc_ignoreborder; } - bool &getPseudoTrans() { return *m_rc_pseudotrans; } + FbTk::BoolResource &getPseudoTransResource() { return m_rc_pseudotrans; } Fluxbox::TabsAttachArea getTabsAttachArea() const { return *m_rc_tabs_attach_area; } const std::string &getStyleFilename() const { return *m_rc_stylefile; } @@ -238,8 +238,8 @@ private: FbTk::BoolResource m_rc_ignoreborder; FbTk::BoolResource m_rc_pseudotrans; - FbTk::IntResource m_rc_colors_per_channel, - m_rc_double_click_interval, + FbTk::RangedIntResource m_rc_colors_per_channel; + FbTk::IntResource m_rc_double_click_interval, m_rc_tabs_padding; FbTk::StringResource m_rc_stylefile, m_rc_styleoverlayfile, -- cgit v0.11.2