From 8c208459910f1dddcfdeb00567b990eebfc218b8 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sat, 11 Jun 2011 13:00:45 +0200 Subject: Simplify FbTk::Resource template class by outsourcing the conversion from string/lua to the specific type (and back) to a separate class. This change touches a lot of files because the interface of FbTk::Resource changed slightly. However, the changes are minor. --- src/AttentionNoticeHandler.cc | 4 +- src/ClockTool.hh | 2 +- src/FbTk/ResTraits.hh | 208 +++++++++++++++++++++++ src/FbTk/Resource.hh | 60 ++++--- src/FocusControl.cc | 89 ++-------- src/FocusControl.hh | 6 +- src/IconbarTool.cc | 45 +---- src/IconbarTool.hh | 11 +- src/Layer.hh | 8 +- src/Resources.cc | 372 ++++------------------------------------- src/Screen.cc | 66 ++------ src/Screen.hh | 22 +-- src/ScreenPlacement.cc | 143 +++------------- src/ScreenPlacement.hh | 9 +- src/Slit.cc | 109 +++--------- src/Slit.hh | 8 +- src/Toolbar.cc | 81 ++------- src/Toolbar.hh | 16 +- src/Window.cc | 9 +- src/fluxbox.hh | 14 +- src/main.cc | 2 +- util/fluxbox-update_configs.cc | 42 ++--- 22 files changed, 449 insertions(+), 877 deletions(-) create mode 100644 src/FbTk/ResTraits.hh diff --git a/src/AttentionNoticeHandler.cc b/src/AttentionNoticeHandler.cc index 0aaf266..3ed9bf3 100644 --- a/src/AttentionNoticeHandler.cc +++ b/src/AttentionNoticeHandler.cc @@ -67,10 +67,10 @@ void AttentionNoticeHandler::addAttention(Focusable &client) { ResourceManager &res = client.screen().resourceManager(); std::string res_name = client.screen().name() + ".demandsAttentionTimeout"; std::string res_alt_name = client.screen().name() + ".DemandsAttentionTimeout"; - Resource *timeout_res = dynamic_cast* >(res.findResource(res_name)); + IntResource *timeout_res = dynamic_cast(res.findResource(res_name)); if (timeout_res == 0) { // no resource, create one and add it to managed resources - timeout_res = new FbTk::Resource(res, 500, res_name, res_alt_name); + timeout_res = new FbTk::IntResource(res, 500, res_name, res_alt_name); client.screen().addManagedResource(timeout_res); } // disable if timeout is zero diff --git a/src/ClockTool.hh b/src/ClockTool.hh index 4f89b36..80dde97 100644 --- a/src/ClockTool.hh +++ b/src/ClockTool.hh @@ -79,7 +79,7 @@ private: Pixmap m_pixmap; FbTk::Timer m_timer; - FbTk::Resource m_timeformat; + FbTk::StringResource m_timeformat; FbTk::StringConvertor m_stringconvertor; diff --git a/src/FbTk/ResTraits.hh b/src/FbTk/ResTraits.hh new file mode 100644 index 0000000..32be48d --- /dev/null +++ b/src/FbTk/ResTraits.hh @@ -0,0 +1,208 @@ +// ResTraits.hh +// Copyright (c) 2011 Pavel Labath (pavelo at centrum dot sk) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef FBTK_RESTRAITS_HH +#define FBTK_RESTRAITS_HH + +#include +#include + +#include "Luamm.hh" +#include "StringUtil.hh" + +namespace FbTk { + +struct ConversionError: public std::runtime_error { + ConversionError(const std::string &msg) : std::runtime_error(msg) {} +}; + +/* Classes that "know" how to convert from string and lua representations + * into corresponding C++ types + */ + +template +struct IntTraits { + typedef T Type; + static std::string toString(T x) { return StringUtil::number2String(x); } + static void toLua(T x, lua::state &l) { l.pushnumber(x); } + + static T fromString(const std::string &x) { + T t; + if(StringUtil::extractNumber(x, t)) + return t; + throw ConversionError("Cannot convert to integer from '" + x + "'"); + } + + static T fromLua(lua::state &l) { + lua::stack_sentry s(l, -1); + + if(l.isnumber(-1)) + return l.tonumber(-1); + else if(l.isstring(-1)) + return fromString(l.tostring(-1)); + throw ConversionError( std::string("Cannot convert to integer from lua type ") + + l.type_name(l.type(-1)) ); + } +}; + +struct StringTraits { + typedef std::string Type; + static std::string toString(const std::string &x) { return x; } + static void toLua(const std::string &x, lua::state &l) { l.pushstring(x); } + static std::string fromString(const std::string &x) { return x; } + + static std::string fromLua(lua::state &l) { + lua::stack_sentry s(l, -1); + + if(l.isstring(-1) || l.isnumber(-1)) + return fromString(l.tostring(-1)); + throw ConversionError( std::string("Cannot convert to string from lua type ") + + l.type_name(l.type(-1)) ); + } +}; + +struct BoolTraits { + typedef bool Type; + static std::string toString(bool x) { return x ? "true" : "false"; } + static void toLua(bool x, lua::state &l) { l.pushboolean(x); } + static bool fromString(const std::string &x) { + return strcasecmp(x.c_str(), "true") == 0; + } + + static bool fromLua(lua::state &l) { + lua::stack_sentry s(l, -1); + + if(l.isstring(-1)) + return fromString(l.tostring(-1)); + else if(l.isnumber(-1)) + return l.tointeger(-1) != 0; + else + return l.toboolean(-1); + } +}; + +/** + * To use this class, one must first define a mapping between enum values and their names using + * the s_map array. A NULL value for name signals the end of the array. E.g., + * + * template<> + * EnumTraits::Pair EnumTraits::s_map[] = { {"Bar", Bar}, {"Baz", Baz} {NULL, Baz} }; + */ +template +struct EnumTraits { + typedef T Type; + struct Pair { + const char *name; + T value; + }; + static const Pair s_map[]; + + static std::string toString(T x) { + for(const Pair *p = s_map; p->name; ++p) { + if(p->value == x) + return p->name; + } + throw ConversionError("Unknown value for enum"); + } + + static void toLua(T x, lua::state &l) { l.pushstring(toString(x)); } + + static T fromString(const std::string &x) { + for(const Pair *p = s_map; p->name; ++p) { + if(strcasecmp(p->name, x.c_str()) == 0) + return p->value; + } + throw ConversionError("Cannot convert to enum from '" + x + "'"); + } + + static T fromLua(lua::state &l) { + lua::stack_sentry s(l, -1); + + if(l.isstring(-1) || l.isnumber(-1)) + return fromString(l.tostring(-1)); + throw ConversionError( std::string("Cannot convert to enum from lua type ") + + l.type_name(l.type(-1)) ); + } +}; + +template +struct VectorTraits { + typedef std::vector Type; + static std::string toString(const Type &x) { + std::string retval; + for(size_t i = 0; i < x.size(); ++i) { + retval.append(Traits::toString(x[i])); + retval.append(" "); + } + + return retval; + } + + static void toLua(const Type &x, lua::state &l) { + l.checkstack(2); + l.createtable(x.size()); + lua::stack_sentry s(l); + + for(size_t i = 0; i < x.size(); ++i) { + Traits::toLua(x[i], l); + l.rawseti(-2, i); + } + } + + static Type fromString(const std::string &x) { + std::vector val; + StringUtil::stringtok(val, x); + Type retval; + + for(size_t i = 0; i < val.size(); i++) { + try { + retval.push_back(Traits::fromString(val[i])); + } + catch(std::runtime_error &) { + } + } + + return retval; + } + + static Type fromLua(lua::state &l) { + l.checkstack(1); + lua::stack_sentry s(l, -1); + Type retval; + + if(l.type(-1) == lua::TTABLE) { + for(size_t i = 0; l.rawgeti(-1, i), !l.isnil(-1); ++i) { + try { + retval.push_back(Traits::fromLua(l)); + } + catch(std::runtime_error &) { + } + } + return retval; + } + throw ConversionError( std::string("Cannot convert to vector from lua type ") + + l.type_name(l.type(-1)) ); + } +}; + +} // end namespace FbTk + +#endif // FBTK_RESTRAITS_HH diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 1c53bff..fb05426 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh @@ -31,12 +31,9 @@ #include #include +#include "ResTraits.hh" #include "XrmDatabaseHelper.hh" -namespace lua { - class state; -} - namespace FbTk { class ResourceException: public std::exception { @@ -82,7 +79,7 @@ private: std::string m_altname; ///< alternative name }; -template +template class Resource; class ResourceManager_base @@ -119,8 +116,8 @@ public: * it will throw exception if it fails * @return reference to resource type */ - template - Resource &getResource(const std::string &resource); + template + Resource &getResource(const std::string &resource); }; class ResourceManager: public ResourceManager_base @@ -189,15 +186,10 @@ private: /// Real resource class /** - * usage: Resource someresource(resourcemanager, 10, "someresourcename", "somealternativename"); - * and then implement setFromString and getString - * example: - * template <> - * void Resource::setFromString(const char *str) { - * *(*this) = atoi(str); - * } + * usage: Resource > someresource(resourcemanager, 10, "someresourcename", "somealternativename"); + * If there is no traits class for your type, you have to implement one. */ -template +template class Resource:public Resource_base, public Accessor { public: typedef T Type; @@ -211,14 +203,30 @@ public: void setDefaultValue() { m_value = m_defaultval; } /// sets resource from string, specialized, must be implemented - void setFromString(const char *strval); + void setFromString(const char *strval) { + try { + m_value = Traits::fromString(strval); + } + catch(ConversionError &e) { + std::cerr << name() << ": " << e.what() << std::endl; + setDefaultValue(); + } + } Accessor &operator =(const T& newvalue) { m_value = newvalue; return *this;} /// specialized, must be implemented /// @return string value of resource - std::string getString() const; + std::string getString() const { return Traits::toString(m_value); } - virtual void setFromLua(lua::state &l); - virtual void pushToLua(lua::state &l) const; + virtual void setFromLua(lua::state &l) { + try { + m_value = Traits::fromLua(l); + } + catch(ConversionError &e) { + std::cerr << name() << ": " << e.what() << std::endl; + setDefaultValue(); + } + } + virtual void pushToLua(lua::state &l) const { Traits::toLua(m_value, l); } operator T() const { return m_value; } T& get() { return m_value; } @@ -232,17 +240,16 @@ private: }; - -template -Resource &ResourceManager_base::getResource(const std::string &resname) { +template +Resource &ResourceManager_base::getResource(const std::string &resname) { Resource_base *res = findResource(resname); if (res == 0) { throw ResourceException("Could not find resource \"" + resname + "\""); } - Resource *res_type = - dynamic_cast *>(res); + Resource *res_type = + dynamic_cast *>(res); if (res_type == 0) { throw ResourceException("Could not convert resource \"" + resname + @@ -252,6 +259,11 @@ Resource &ResourceManager_base::getResource(const std::string &res return *res_type; } +typedef Resource BoolResource; +typedef Resource > IntResource; +typedef Resource > UIntResource; +typedef Resource StringResource; + } // end namespace FbTk #endif // FBTK_RESOURCE_HH diff --git a/src/FocusControl.cc b/src/FocusControl.cc index abedcf2..4f3b390 100644 --- a/src/FocusControl.cc +++ b/src/FocusControl.cc @@ -599,86 +599,19 @@ void FocusControl::setFocusedWindow(WinClient *client) { namespace FbTk { template<> -std::string FbTk::Resource::getString() const { - switch (m_value) { - case FocusControl::MOUSEFOCUS: - return string("MouseFocus"); - case FocusControl::STRICTMOUSEFOCUS: - return string("StrictMouseFocus"); - case FocusControl::CLICKFOCUS: - return string("ClickFocus"); - } - // default string - return string("ClickFocus"); -} - -template<> -void FbTk::Resource:: -setFromString(char const *strval) { - if (strcasecmp(strval, "MouseFocus") == 0) - m_value = FocusControl::MOUSEFOCUS; - else if (strcasecmp(strval, "StrictMouseFocus") == 0) - m_value = FocusControl::STRICTMOUSEFOCUS; - else if (strcasecmp(strval, "ClickToFocus") == 0) - m_value = FocusControl::CLICKFOCUS; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} - +const EnumTraits::Pair EnumTraits::s_map[] = { + { "MouseFocus", FocusControl::MOUSEFOCUS }, + { "StrictMouseFocus", FocusControl::STRICTMOUSEFOCUS }, + { "ClickFocus", FocusControl::CLICKFOCUS }, + { NULL, FocusControl::CLICKFOCUS } +}; template<> -std::string FbTk::Resource::getString() const { - switch (m_value) { - case FocusControl::MOUSETABFOCUS: - return string("SloppyTabFocus"); - case FocusControl::CLICKTABFOCUS: - return string("ClickToTabFocus"); - } - // default string - return string("ClickToTabFocus"); -} - -template<> -void FbTk::Resource:: -setFromString(char const *strval) { - - if (strcasecmp(strval, "SloppyTabFocus") == 0 ) - m_value = FocusControl::MOUSETABFOCUS; - else if (strcasecmp(strval, "ClickToTabFocus") == 0) - m_value = FocusControl::CLICKTABFOCUS; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "SloppyTabFocus", FocusControl::MOUSETABFOCUS }, + { "ClickToTabFocus", FocusControl::CLICKTABFOCUS }, + { NULL, FocusControl::CLICKTABFOCUS } +}; } // end namespace FbTk diff --git a/src/FocusControl.hh b/src/FocusControl.hh index c265253..19059da 100644 --- a/src/FocusControl.hh +++ b/src/FocusControl.hh @@ -158,9 +158,9 @@ private: BScreen &m_screen; - FbTk::Resource m_focus_model; - FbTk::Resource m_tab_focus_model; - FbTk::Resource m_focus_new; + FbTk::Resource > m_focus_model; + FbTk::Resource > m_tab_focus_model; + FbTk::BoolResource m_focus_new; // This list keeps the order of window focusing for this screen // Screen global so it works for sticky windows too. diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 0f3aeb7..1452080 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -68,45 +68,12 @@ using std::endl; namespace FbTk { template<> -void FbTk::Resource::setDefaultValue() { - m_value = FbTk::Container::RELATIVE; -} - -template<> -string FbTk::Resource::getString() const { - if (m_value == FbTk::Container::LEFT) - return string("Left"); - if (m_value == FbTk::Container::RIGHT) - return string("Right"); - return string("Relative"); -} - -template<> -void FbTk::Resource::setFromString(const char *str) { - if (strcasecmp(str, "Left") == 0) - m_value = FbTk::Container::LEFT; - else if (strcasecmp(str, "Right") == 0) - m_value = FbTk::Container::RIGHT; - else if (strcasecmp(str, "Relative") == 0) - m_value = FbTk::Container::RELATIVE; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "Left", Container::LEFT }, + { "Right", Container::RIGHT }, + { "Relative", Container::RELATIVE }, + { NULL, Container::RELATIVE } +}; } // end namespace FbTk diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index 118eacf..90df5cf 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -110,11 +110,12 @@ private: std::auto_ptr m_winlist; IconMap m_icons; std::string m_mode; - FbTk::Resource m_rc_mode; - FbTk::Resource m_rc_alignment; ///< alignment of buttons - FbTk::Resource m_rc_client_width; ///< size of client button in LEFT/RIGHT mode - FbTk::Resource m_rc_client_padding; ///< padding of the text - FbTk::Resource m_rc_use_pixmap; ///< if iconbar should use win pixmap or not + FbTk::StringResource m_rc_mode; + /// alignment of buttons + FbTk::Resource > m_rc_alignment; + FbTk::IntResource m_rc_client_width; ///< size of client button in LEFT/RIGHT mode + FbTk::UIntResource m_rc_client_padding; ///< padding of the text + FbTk::BoolResource m_rc_use_pixmap; ///< if iconbar should use win pixmap or not FbMenu m_menu; int m_alpha; }; diff --git a/src/Layer.hh b/src/Layer.hh index ac4102b..34dd350 100644 --- a/src/Layer.hh +++ b/src/Layer.hh @@ -32,13 +32,19 @@ */ class ResourceLayer { public: - enum { + enum Type { MENU = 0, + LAYER1 = 1, ABOVE_DOCK = 2, + LAYER3 = 3, DOCK = 4, + LAYER5 = 5, TOP = 6, + LAYER7 = 7, NORMAL = 8, + LAYER9 = 9, BOTTOM = 10, + LAYER11 = 11, DESKTOP = 12, NUM_LAYERS = 13 }; diff --git a/src/Resources.cc b/src/Resources.cc index cdc142d..cf09543 100644 --- a/src/Resources.cc +++ b/src/Resources.cc @@ -48,343 +48,39 @@ using std::vector; namespace FbTk { template<> -string FbTk::Resource:: -getString() const { - return FbTk::StringUtil::number2String(**this); -} - -template<> -void FbTk::Resource:: -setFromString(const char* strval) { - FbTk::StringUtil::extractNumber(strval, get()); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isnumber(-1)) - *this = l.tonumber(-1); - else if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushnumber(*this); -} - - -template<> -string FbTk::Resource:: -getString() const { return **this; } - -template<> -void FbTk::Resource:: -setFromString(const char *strval) { - *this = strval; -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - *this = l.tostring(-1); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(*this); -} - - -template<> -string FbTk::Resource:: -getString() const { - return string(**this == true ? "true" : "false"); -} - -template<> -void FbTk::Resource:: -setFromString(char const *strval) { - *this = (bool)!strcasecmp(strval, "true"); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else if(l.isnumber(-1)) - *this = l.tointeger(-1) != 0; - else - *this = l.toboolean(-1); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushboolean(*this); -} - - -namespace { - struct ButtonPair { - WinButton::Type type; - const char *name; - }; - const ButtonPair button_map[] = { - { WinButton::SHADE, "Shade" }, - { WinButton::MINIMIZE, "Minimize" }, - { WinButton::MAXIMIZE, "Maximize" }, - { WinButton::CLOSE, "Close" }, - { WinButton::STICK, "Stick" }, - { WinButton::MENUICON, "MenuIcon" } - }; - - const char *buttonToStr(WinButton::Type t) { - for(size_t i = 0; i < sizeof(button_map)/sizeof(button_map[0]); ++i) { - if(button_map[i].type == t) - return button_map[i].name; - } - assert(0); - } - - WinButton::Type strToButton(const char *v) { - for(size_t i = 0; i < sizeof(button_map)/sizeof(button_map[0]); ++i) { - if(strcasecmp(v, button_map[i].name) == 0) - return button_map[i].type; - } - throw std::runtime_error("bad button"); - } -} - -template<> -string FbTk::Resource >:: -getString() const { - string retval; - for (size_t i = 0; i < m_value.size(); i++) { - retval.append(buttonToStr(m_value[i])); - retval.append(" "); - } - - return retval; -} - -template<> -void FbTk::Resource >:: -setFromString(char const *strval) { - vector val; - StringUtil::stringtok(val, strval); - //clear old values - m_value.clear(); - - for (size_t i = 0; i < val.size(); i++) { - try { - m_value.push_back(strToButton(val[i].c_str())); - } - catch(std::runtime_error &) { - } - } -} - -template<> -void FbTk::Resource >::setFromLua(lua::state &l) { - l.checkstack(1); - lua::stack_sentry s(l, -1); - - if(l.type(-1) == lua::TTABLE) { - for(size_t i = 0; l.rawgeti(-1, i), !l.isnil(-1); l.pop(), ++i) { - if(l.isstring(-1)) { - try { - m_value.push_back(strToButton(l.tostring(-1).c_str())); - } - catch(std::runtime_error &) { - } - } - } - l.pop(); - } - l.pop(); -} - -template<> -void FbTk::Resource >::pushToLua(lua::state &l) const { - l.checkstack(2); - l.newtable(); - lua::stack_sentry s(l); - - for (size_t i = 0; i < m_value.size(); ++i) { - l.pushstring(buttonToStr(m_value[i])); - l.rawseti(-2, i); - } -} - - -template<> -string FbTk::Resource:: -getString() const { - if (m_value == Fluxbox::ATTACH_AREA_TITLEBAR) - return "Titlebar"; - else - return "Window"; -} - -template<> -void FbTk::Resource:: -setFromString(char const *strval) { - if (strcasecmp(strval, "Titlebar")==0) - m_value= Fluxbox::ATTACH_AREA_TITLEBAR; - else - m_value= Fluxbox::ATTACH_AREA_WINDOW; -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - - if(l.isstring(-1) && strcasecmp(l.tostring(-1).c_str(), "Titlebar") == 0) - m_value = Fluxbox::ATTACH_AREA_TITLEBAR; - else - m_value = Fluxbox::ATTACH_AREA_WINDOW; - - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.checkstack(1); - - l.pushstring(getString()); -} - - -template<> -string FbTk::Resource:: -getString() const { - return FbTk::StringUtil::number2String(m_value); -} - -template<> -void FbTk::Resource:: -setFromString(const char *strval) { - if (!FbTk::StringUtil::extractNumber(strval, m_value)) - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isnumber(-1)) - *this = l.tonumber(-1); - else if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushnumber(*this); -} - - -template<> -string FbTk::Resource:: -getString() const { - return FbTk::StringUtil::number2String(m_value); -} - -template<> -void FbTk::Resource:: -setFromString(const char *strval) { - if (!FbTk::StringUtil::extractNumber(strval, m_value)) - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isnumber(-1)) - *this = l.tonumber(-1); - else if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushnumber(*this); -} - - -template<> -string FbTk::Resource:: -getString() const { - return ::ResourceLayer::getString(m_value.getNum()); -} - -template<> -void FbTk::Resource:: -setFromString(const char *strval) { - string str(strval); - int tempnum = ::ResourceLayer::getNumFromString(str); - if (tempnum >= 0 && tempnum < ::ResourceLayer::NUM_LAYERS) - m_value = tempnum; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - - int tempnum = -1; - if(l.isnumber(-1)) - tempnum = l.tonumber(-1); - else if(l.isstring(-1)) - tempnum = ::ResourceLayer::getNumFromString(l.tostring(-1)); - - if (tempnum >= 0 && tempnum < ::ResourceLayer::NUM_LAYERS) - m_value = tempnum; - else - setDefaultValue(); - - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} - - -template<> -string FbTk::Resource:: -getString() const { - return FbTk::StringUtil::number2String(m_value); -} - -template<> -void FbTk::Resource:: -setFromString(const char *strval) { - if (!FbTk::StringUtil::extractNumber(strval, m_value)) - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isnumber(-1)) - *this = l.tonumber(-1); - else if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushnumber(*this); -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "Shade", WinButton::SHADE }, + { "Minimize", WinButton::MINIMIZE }, + { "Maximize", WinButton::MAXIMIZE }, + { "Close", WinButton::CLOSE }, + { "Stick", WinButton::STICK }, + { "MenuIcon", WinButton::MENUICON }, + { NULL, WinButton::MENUICON } +}; + +template<> +const EnumTraits::Pair EnumTraits::s_map[] = { + { "Titlebar", Fluxbox::ATTACH_AREA_TITLEBAR }, + { "Window", Fluxbox::ATTACH_AREA_WINDOW }, + { NULL, Fluxbox::ATTACH_AREA_WINDOW } +}; + +template<> +const EnumTraits::Pair EnumTraits::s_map[] = { + { "Menu", ResourceLayer::MENU }, + { "1", ResourceLayer::LAYER1 }, + { "AboveDock",ResourceLayer::ABOVE_DOCK }, + { "3", ResourceLayer::LAYER3 }, + { "Dock", ResourceLayer::DOCK }, + { "5", ResourceLayer::LAYER5 }, + { "Top", ResourceLayer::TOP }, + { "7", ResourceLayer::LAYER7 }, + { "Normal", ResourceLayer::NORMAL }, + { "9", ResourceLayer::LAYER9 }, + { "Bottom", ResourceLayer::BOTTOM }, + { "11", ResourceLayer::LAYER11 }, + { "Desktop", ResourceLayer::DESKTOP }, + { NULL, ResourceLayer::DESKTOP } +}; } // end namespace FbTk diff --git a/src/Screen.cc b/src/Screen.cc index 3435843..be65ac8 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -215,20 +215,6 @@ struct TabPlacementString { const char* str; }; -const TabPlacementString placement_strings[] = { - { FbWinFrame::TOPLEFT, "TopLeft" }, - { FbWinFrame::TOP, "Top" }, - { FbWinFrame::TOPRIGHT, "TopRight" }, - { FbWinFrame::BOTTOMLEFT, "BottomLeft" }, - { FbWinFrame::BOTTOM, "Bottom" }, - { FbWinFrame::BOTTOMRIGHT, "BottomRight" }, - { FbWinFrame::LEFTBOTTOM, "LeftBottom" }, - { FbWinFrame::LEFT, "Left" }, - { FbWinFrame::LEFTTOP, "LeftTop" }, - { FbWinFrame::RIGHTBOTTOM, "RightBottom" }, - { FbWinFrame::RIGHT, "Right" }, - { FbWinFrame::RIGHTTOP, "RightTop" } -}; } // end anonymous namespace @@ -238,41 +224,21 @@ const TabPlacementString placement_strings[] = { namespace FbTk { template<> -string FbTk::Resource:: -getString() const { - - size_t i = (m_value == FbTk::Util::clamp(m_value, FbWinFrame::TOPLEFT, FbWinFrame::RIGHTTOP) - ? m_value - : FbWinFrame::DEFAULT) - 1; - return placement_strings[i].str; -} - -template<> -void FbTk::Resource:: -setFromString(const char *strval) { - - size_t i; - for (i = 0; i < sizeof(placement_strings)/sizeof(TabPlacementString); ++i) { - if (strcasecmp(strval, placement_strings[i].str) == 0) { - m_value = placement_strings[i].placement; - return; - } - } - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - - setFromString(l.isstring(-1) ? l.tostring(-1).c_str() : ""); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "TopLeft", FbWinFrame::TOPLEFT }, + { "Top", FbWinFrame::TOP }, + { "TopRight", FbWinFrame::TOPRIGHT }, + { "BottomLeft", FbWinFrame::BOTTOMLEFT }, + { "Bottom", FbWinFrame::BOTTOM }, + { "BottomRight", FbWinFrame::BOTTOMRIGHT }, + { "LeftBottom", FbWinFrame::LEFTBOTTOM }, + { "Left", FbWinFrame::LEFT }, + { "LeftTop", FbWinFrame::LEFTTOP }, + { "RightBottom", FbWinFrame::RIGHTBOTTOM }, + { "Right", FbWinFrame::RIGHT }, + { "RightTop", FbWinFrame::RIGHTTOP }, + { NULL, FbWinFrame::RIGHTTOP } +}; } // end namespace FbTk @@ -1560,7 +1526,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { try { focus_menu->insert(new FbTk::BoolMenuItem(_FB_XTEXT(Configmenu, FocusNew, "Focus New Windows", "Focus newly created windows"), - m_resource_manager.getResource(name() + ".focusNewWindows"), + m_resource_manager.getResource(name() + ".focusNewWindows"), saverc_cmd)); } catch (FbTk::ResourceException e) { cerr< opaque_move, full_max, + FbTk::BoolResource opaque_move, full_max, max_ignore_inc, max_disable_move, max_disable_resize, workspace_warping, show_window_pos, auto_raise, click_raises; - FbTk::Resource default_deco; - FbTk::Resource tab_placement; - FbTk::Resource windowmenufile; - FbTk::Resource typing_delay; - FbTk::Resource workspaces, edge_snap_threshold, focused_alpha, + FbTk::StringResource default_deco; + FbTk::Resource > tab_placement; + 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; - FbTk::Resource allow_remote_actions; - FbTk::Resource clientmenu_use_pixmap; - FbTk::Resource tabs_use_pixmap; - FbTk::Resource max_over_tabs; - FbTk::Resource default_internal_tabs; + FbTk::BoolResource allow_remote_actions; + FbTk::BoolResource clientmenu_use_pixmap; + FbTk::BoolResource tabs_use_pixmap; + FbTk::BoolResource max_over_tabs; + FbTk::BoolResource default_internal_tabs; } resource; diff --git a/src/ScreenPlacement.cc b/src/ScreenPlacement.cc index cd7ce15..2a743ce 100644 --- a/src/ScreenPlacement.cc +++ b/src/ScreenPlacement.cc @@ -182,133 +182,28 @@ void ScreenPlacement::placeAndShowMenu(FbTk::Menu& menu, int x, int y, bool resp namespace FbTk { template <> -std::string FbTk::Resource::getString() const { - switch (*(*this)) { - case ScreenPlacement::ROWSMARTPLACEMENT: - return "RowSmartPlacement"; - case ScreenPlacement::COLSMARTPLACEMENT: - return "ColSmartPlacement"; - case ScreenPlacement::ROWMINOVERLAPPLACEMENT: - return "RowMinOverlapPlacement"; - case ScreenPlacement::COLMINOVERLAPPLACEMENT: - return "ColMinOverlapPlacement"; - case ScreenPlacement::UNDERMOUSEPLACEMENT: - return "UnderMousePlacement"; - case ScreenPlacement::CASCADEPLACEMENT: - return "CascadePlacement"; - } - - return "RowSmartPlacement"; -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "RowSmartPlacement", ScreenPlacement::ROWSMARTPLACEMENT }, + { "ColSmartPlacement", ScreenPlacement::COLSMARTPLACEMENT }, + { "RowMinOverlapPlacement", ScreenPlacement::ROWMINOVERLAPPLACEMENT }, + { "ColMinOverlapPlacement", ScreenPlacement::COLMINOVERLAPPLACEMENT }, + { "UnderMousePlacement", ScreenPlacement::UNDERMOUSEPLACEMENT }, + { "CascadePlacement", ScreenPlacement::CASCADEPLACEMENT }, + { NULL, ScreenPlacement::CASCADEPLACEMENT } +}; template <> -void FbTk::Resource::setFromString(const char *str) { - if (strcasecmp("RowSmartPlacement", str) == 0) - *(*this) = ScreenPlacement::ROWSMARTPLACEMENT; - else if (strcasecmp("ColSmartPlacement", str) == 0) - *(*this) = ScreenPlacement::COLSMARTPLACEMENT; - else if (strcasecmp("RowMinOverlapPlacement", str) == 0) - *(*this) = ScreenPlacement::ROWMINOVERLAPPLACEMENT; - else if (strcasecmp("ColMinOverlapPlacement", str) == 0) - *(*this) = ScreenPlacement::COLMINOVERLAPPLACEMENT; - else if (strcasecmp("UnderMousePlacement", str) == 0) - *(*this) = ScreenPlacement::UNDERMOUSEPLACEMENT; - else if (strcasecmp("CascadePlacement", str) == 0) - *(*this) = ScreenPlacement::CASCADEPLACEMENT; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} - +const EnumTraits::Pair EnumTraits::s_map[] = { + { "LeftToRight", ScreenPlacement::LEFTRIGHT }, + { "RightToLeft", ScreenPlacement::RIGHTLEFT }, + { NULL, ScreenPlacement::RIGHTLEFT }, +}; template <> -std::string FbTk::Resource::getString() const { - switch (*(*this)) { - case ScreenPlacement::LEFTRIGHT: - return "LeftToRight"; - case ScreenPlacement::RIGHTLEFT: - return "RightToLeft"; - } - - return "LeftToRight"; -} - - -template <> -void FbTk::Resource::setFromString(const char *str) { - if (strcasecmp("LeftToRight", str) == 0) - *(*this) = ScreenPlacement::LEFTRIGHT; - else if (strcasecmp("RightToLeft", str) == 0) - *(*this) = ScreenPlacement::RIGHTLEFT; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} - -template <> -std::string FbTk::Resource::getString() const { - switch (*(*this)) { - case ScreenPlacement::TOPBOTTOM: - return "TopToBottom"; - case ScreenPlacement::BOTTOMTOP: - return "BottomToTop"; - } - - return "TopToBottom"; -} - - -template <> -void FbTk::Resource::setFromString(const char *str) { - if (strcasecmp("TopToBottom", str) == 0) - *(*this) = ScreenPlacement::TOPBOTTOM; - else if (strcasecmp("BottomToTop", str) == 0) - *(*this) = ScreenPlacement::BOTTOMTOP; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "TopToBottom", ScreenPlacement::TOPBOTTOM }, + { "BottomToTop", ScreenPlacement::BOTTOMTOP }, + { NULL, ScreenPlacement::BOTTOMTOP }, +}; } // end namespace FbTk diff --git a/src/ScreenPlacement.hh b/src/ScreenPlacement.hh index 05db90d..cbe1528 100644 --- a/src/ScreenPlacement.hh +++ b/src/ScreenPlacement.hh @@ -76,9 +76,12 @@ public: ColumnDirection colDirection() const { return *m_col_direction; } private: - FbTk::Resource m_row_direction; ///< row direction resource - FbTk::Resource m_col_direction; ///< column direction resource - FbTk::Resource m_placement_policy; ///< placement policy resource + /// row direction resource + FbTk::Resource > m_row_direction; + /// column direction resource + FbTk::Resource > m_col_direction; + /// placement policy resource + FbTk::Resource > m_placement_policy; PlacementPolicy m_old_policy; ///< holds old policy, used to determine if resources has changed std::auto_ptr m_strategy; ///< main strategy std::auto_ptr m_fallback_strategy; ///< a fallback strategy if the main strategy fails diff --git a/src/Slit.cc b/src/Slit.cc index d950ce9..7224bb5 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -92,95 +92,24 @@ using std::dec; namespace FbTk { template<> -string FbTk::Resource::getString() const { - switch (m_value) { - case Slit::TOPLEFT: - return string("TopLeft"); - break; - case Slit::LEFTCENTER: - return string("LeftCenter"); - break; - case Slit::BOTTOMLEFT: - return string("BottomLeft"); - break; - case Slit::TOPCENTER: - return string("TopCenter"); - break; - case Slit::BOTTOMCENTER: - return string("BottomCenter"); - break; - case Slit::TOPRIGHT: - return string("TopRight"); - break; - case Slit::RIGHTCENTER: - return string("RightCenter"); - break; - case Slit::BOTTOMRIGHT: - return string("BottomRight"); - break; - case Slit::LEFTTOP: - return string("LeftTop"); - break; - case Slit::RIGHTTOP: - return string("RightTop"); - break; - case Slit::LEFTBOTTOM: - return string("LeftBottom"); - break; - case Slit::RIGHTBOTTOM: - return string("RightBottom"); - break; - } - //default string - return string("RightBottom"); -} - -template<> -void FbTk::Resource::setFromString(const char *strval) { - if (strcasecmp(strval, "TopLeft")==0) - m_value = Slit::TOPLEFT; - else if (strcasecmp(strval, "LeftCenter")==0) - m_value = Slit::LEFTCENTER; - else if (strcasecmp(strval, "BottomLeft")==0) - m_value = Slit::BOTTOMLEFT; - else if (strcasecmp(strval, "TopCenter")==0) - m_value = Slit::TOPCENTER; - else if (strcasecmp(strval, "BottomCenter")==0) - m_value = Slit::BOTTOMCENTER; - else if (strcasecmp(strval, "TopRight")==0) - m_value = Slit::TOPRIGHT; - else if (strcasecmp(strval, "RightCenter")==0) - m_value = Slit::RIGHTCENTER; - else if (strcasecmp(strval, "BottomRight")==0) - m_value = Slit::BOTTOMRIGHT; - else if (strcasecmp(strval, "LeftTop")==0) - m_value = Slit::LEFTTOP; - else if (strcasecmp(strval, "LeftBottom")==0) - m_value = Slit::LEFTBOTTOM; - else if (strcasecmp(strval, "RightTop")==0) - m_value = Slit::RIGHTTOP; - else if (strcasecmp(strval, "RightBottom")==0) - m_value = Slit::RIGHTBOTTOM; - else - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "TopLeft", Slit::TOPLEFT }, + { "LeftCenter", Slit::LEFTCENTER }, + { "BottomLeft", Slit::BOTTOMLEFT }, + { "TopCenter", Slit::TOPCENTER }, + { "BottomCenter", Slit::BOTTOMCENTER }, + { "TopRight", Slit::TOPRIGHT }, + { "RightCenter", Slit::RIGHTCENTER }, + { "BottomRight", Slit::BOTTOMRIGHT }, + { "LeftTop", Slit::LEFTTOP }, + { "RightTop", Slit::RIGHTTOP }, + { "LeftBottom", Slit::LEFTBOTTOM }, + { "RightBottom", Slit::RIGHTBOTTOM }, + { NULL, Slit::RIGHTBOTTOM }, +}; } // end namespace FbTk + namespace { class SlitClientMenuItem: public FbTk::MenuItem{ @@ -273,7 +202,7 @@ Slit::Slit(BScreen &scr, FbTk::Layer &layer, const char *filename) scr.name() + ".slit.alpha", scr.altName() + ".Slit.Alpha"), m_rc_on_head(scr.resourceManager(), 0, scr.name() + ".slit.onhead", scr.altName() + ".Slit.onHead"), - m_rc_layernum(scr.resourceManager(), ResourceLayer(ResourceLayer::DOCK), + m_rc_layernum(scr.resourceManager(), ResourceLayer::DOCK, scr.name() + ".slit.layer", scr.altName() + ".Slit.Layer") { _FB_USES_NLS; @@ -319,7 +248,7 @@ Slit::Slit(BScreen &scr, FbTk::Layer &layer, const char *filename) true)); m_layermenu->setLabel(_FB_XTEXT(Slit, Layer, "Slit Layer", "Title of Slit Layer Menu")); - moveToLayer((*m_rc_layernum).getNum()); + moveToLayer(static_cast(*m_rc_layernum)); @@ -1287,7 +1216,7 @@ void Slit::setupMenu() { void Slit::moveToLayer(int layernum) { m_layeritem->moveToLayer(layernum); - *m_rc_layernum = layernum; + *m_rc_layernum = static_cast(layernum); } void Slit::saveOnHead(int head) { diff --git a/src/Slit.hh b/src/Slit.hh index 5753565..5c69a8c 100644 --- a/src/Slit.hh +++ b/src/Slit.hh @@ -179,10 +179,10 @@ private: static unsigned int s_eventmask; Strut *m_strut; - FbTk::Resource m_rc_kde_dockapp, m_rc_auto_hide, m_rc_maximize_over; - FbTk::Resource m_rc_placement; - FbTk::Resource m_rc_alpha, m_rc_on_head; - FbTk::Resource m_rc_layernum; + FbTk::BoolResource m_rc_kde_dockapp, m_rc_auto_hide, m_rc_maximize_over; + FbTk::Resource > m_rc_placement; + FbTk::IntResource m_rc_alpha, m_rc_on_head; + FbTk::Resource > m_rc_layernum; }; diff --git a/src/Toolbar.cc b/src/Toolbar.cc index fe4c591..603ed08 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -84,69 +84,24 @@ using std::list; using FbTk::STLUtil::forAll; -namespace { - -struct ToolbarPlacementString { - Toolbar::Placement placement; - const char* str; -}; - -const ToolbarPlacementString placement_strings[] = { - { Toolbar::TOPLEFT, "TopLeft" }, - { Toolbar::TOPCENTER, "TopCenter" }, - { Toolbar::TOPRIGHT, "TopRight" }, - { Toolbar::BOTTOMLEFT, "BottomLeft" }, - { Toolbar::BOTTOMCENTER, "BottomCenter" }, - { Toolbar::BOTTOMRIGHT, "BottomRight" }, - { Toolbar::LEFTBOTTOM, "LeftBottom" }, - { Toolbar::LEFTCENTER, "LeftCenter" }, - { Toolbar::LEFTTOP, "LeftTop" }, - { Toolbar::RIGHTBOTTOM, "RightBottom" }, - { Toolbar::RIGHTCENTER, "RightCenter" }, - { Toolbar::RIGHTTOP, "RightTop" } -}; - -} - namespace FbTk { template<> -string FbTk::Resource:: -getString() const { - - size_t i = (m_value == FbTk::Util::clamp(m_value, Toolbar::TOPLEFT, Toolbar::RIGHTTOP) - ? m_value - : Toolbar::DEFAULT) - Toolbar::TOPLEFT; - return placement_strings[i].str; -} - -template<> -void FbTk::Resource:: -setFromString(const char *strval) { - size_t i; - for (i = 0; i < sizeof(placement_strings)/sizeof(ToolbarPlacementString); ++i) { - if (strcasecmp(strval, placement_strings[i].str) == 0) { - m_value = placement_strings[i].placement; - return; - } - } - setDefaultValue(); -} - -template<> -void FbTk::Resource::setFromLua(lua::state &l) { - lua::stack_sentry s(l, -1); - if(l.isstring(-1)) - setFromString(l.tostring(-1).c_str()); - else - setDefaultValue(); - l.pop(); -} - -template<> -void FbTk::Resource::pushToLua(lua::state &l) const { - l.pushstring(getString()); -} +const EnumTraits::Pair EnumTraits::s_map[] = { + { "TopLeft", Toolbar::TOPLEFT }, + { "TopCenter", Toolbar::TOPCENTER }, + { "TopRight", Toolbar::TOPRIGHT }, + { "BottomLeft", Toolbar::BOTTOMLEFT }, + { "BottomCenter", Toolbar::BOTTOMCENTER }, + { "BottomRight", Toolbar::BOTTOMRIGHT }, + { "LeftBottom", Toolbar::LEFTBOTTOM }, + { "LeftCenter", Toolbar::LEFTCENTER }, + { "LeftTop", Toolbar::LEFTTOP }, + { "RightBottom", Toolbar::RIGHTBOTTOM }, + { "RightCenter", Toolbar::RIGHTCENTER }, + { "RightTop", Toolbar::RIGHTTOP }, + { NULL, Toolbar::RIGHTTOP } +}; } // end namespace FbTk @@ -230,7 +185,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width): scrn.name() + ".toolbar.widthPercent", scrn.altName() + ".Toolbar.WidthPercent"), m_rc_alpha(scrn.resourceManager(), 255, scrn.name() + ".toolbar.alpha", scrn.altName() + ".Toolbar.Alpha"), - m_rc_layernum(scrn.resourceManager(), ResourceLayer(ResourceLayer::DOCK), + m_rc_layernum(scrn.resourceManager(), ResourceLayer::DOCK, scrn.name() + ".toolbar.layer", scrn.altName() + ".Toolbar.Layer"), m_rc_on_head(scrn.resourceManager(), 1, scrn.name() + ".toolbar.onhead", scrn.altName() + ".Toolbar.onHead"), @@ -255,7 +210,7 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::Layer &layer, size_t width): FbTk::MemFun(*this, &Toolbar::screenChanged)); - moveToLayer((*m_rc_layernum).getNum()); + moveToLayer(static_cast(*m_rc_layernum)); m_layermenu.setLabel(_FB_XTEXT(Toolbar, Layer, "Toolbar Layer", "Title of toolbar layer menu")); m_placementmenu.setLabel(_FB_XTEXT(Toolbar, Placement, "Toolbar Placement", "Title of toolbar placement menu")); @@ -785,7 +740,7 @@ void Toolbar::toggleHidden() { void Toolbar::moveToLayer(int layernum) { m_layeritem.moveToLayer(layernum); - *m_rc_layernum = layernum; + *m_rc_layernum = static_cast(layernum); } void Toolbar::setupMenus(bool skip_new_placement) { diff --git a/src/Toolbar.hh b/src/Toolbar.hh index 9f737b4..eca379b 100644 --- a/src/Toolbar.hh +++ b/src/Toolbar.hh @@ -184,14 +184,14 @@ private: Strut *m_strut; ///< created and destroyed by BScreen // resources - FbTk::Resource m_rc_auto_hide, m_rc_maximize_over, m_rc_visible; - FbTk::Resource m_rc_width_percent; - FbTk::Resource m_rc_alpha; - FbTk::Resource m_rc_layernum; - FbTk::Resource m_rc_on_head; - FbTk::Resource m_rc_placement; - FbTk::Resource m_rc_height; - FbTk::Resource m_rc_tools; + FbTk::BoolResource m_rc_auto_hide, m_rc_maximize_over, m_rc_visible; + FbTk::IntResource m_rc_width_percent; + FbTk::IntResource m_rc_alpha; + FbTk::Resource > m_rc_layernum; + FbTk::IntResource m_rc_on_head; + FbTk::Resource > m_rc_placement; + FbTk::IntResource m_rc_height; + FbTk::StringResource m_rc_tools; std::auto_ptr m_shape; typedef std::list StringList; StringList m_tools; diff --git a/src/Window.cc b/src/Window.cc index db5bacc..551836c 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -251,6 +251,11 @@ private: int m_mode; }; +typedef FbTk::Resource< + vector, + FbTk::VectorTraits > +> WinButtonsResource; + } @@ -3430,9 +3435,6 @@ void FluxboxWindow::setupWindow() { // sets up our window // we allow both to be done at once to share the commands - using namespace FbTk; - typedef FbTk::Resource > WinButtonsResource; - string titlebar_name[2]; string titlebar_alt_name[2]; titlebar_name[0] = screen().name() + ".titlebar.left"; @@ -3495,7 +3497,6 @@ void FluxboxWindow::updateButtons() { titlebar_name[0] = screen().name() + ".titlebar.left"; titlebar_name[1] = screen().name() + ".titlebar.right"; - typedef FbTk::Resource > WinButtonsResource; WinButtonsResource *titlebar_side[2]; ResourceManager &rm = screen().resourceManager(); diff --git a/src/fluxbox.hh b/src/fluxbox.hh index d1e8e93..dad58f8 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -234,20 +234,20 @@ private: //--- Resources - FbTk::Resource m_rc_ignoreborder; - FbTk::Resource m_rc_pseudotrans; - FbTk::Resource m_rc_colors_per_channel, + FbTk::BoolResource m_rc_ignoreborder; + FbTk::BoolResource m_rc_pseudotrans; + FbTk::IntResource m_rc_colors_per_channel, m_rc_double_click_interval, m_rc_tabs_padding; - FbTk::Resource m_rc_stylefile, + FbTk::StringResource m_rc_stylefile, m_rc_styleoverlayfile, m_rc_menufile, m_rc_keyfile, m_rc_slitlistfile, m_rc_appsfile; - FbTk::Resource m_rc_tabs_attach_area; - FbTk::Resource m_rc_cache_life, m_rc_cache_max; - FbTk::Resource m_rc_auto_raise_delay; + FbTk::Resource > m_rc_tabs_attach_area; + FbTk::UIntResource m_rc_cache_life, m_rc_cache_max; + FbTk::Resource > m_rc_auto_raise_delay; typedef std::map WinClientMap; WinClientMap m_window_search; diff --git a/src/main.cc b/src/main.cc index 8aea835..7fba919 100644 --- a/src/main.cc +++ b/src/main.cc @@ -400,7 +400,7 @@ void updateConfigFilesIfNeeded(const std::string& rc_file) { const int CONFIG_VERSION = 13; // TODO: move this to 'defaults.hh' or 'config.h' FbTk::ResourceManager r_mgr(rc_file.c_str(), false); - FbTk::Resource c_version(r_mgr, 0, "session.configVersion", "Session.ConfigVersion"); + FbTk::IntResource c_version(r_mgr, 0, "session.configVersion", "Session.ConfigVersion"); if (!r_mgr.load(rc_file.c_str())) { _FB_USES_NLS; diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc index a8052a2..93acb04 100644 --- a/util/fluxbox-update_configs.cc +++ b/util/fluxbox-update_configs.cc @@ -89,10 +89,10 @@ void update_add_mouse_evens_to_keys(FbTk::ResourceManager& rm, // hmmm, what are the odds that somebody wants this to be different on // different screens? the ability is going away until we make per-screen // keys files, anyway, so let's just use the first screen's setting - FbTk::Resource rc_wheeling(rm, true, + FbTk::BoolResource rc_wheeling(rm, true, "session.screen0.desktopwheeling", "Session.Screen0.DesktopWheeling"); - FbTk::Resource rc_reverse(rm, false, + FbTk::BoolResource rc_reverse(rm, false, "session.screen0.reversewheeling", "Session.Screen0.ReverseWheeling"); if (*rc_wheeling) { @@ -114,7 +114,7 @@ void update_add_mouse_evens_to_keys(FbTk::ResourceManager& rm, void update_move_groups_entries_to_apps_file(FbTk::ResourceManager& rm, const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { - FbTk::Resource rc_groupfile(rm, "~/.fluxbox/groups", + FbTk::StringResource rc_groupfile(rm, "~/.fluxbox/groups", "session.groupFile", "Session.GroupFile"); string groupfilename = FbTk::StringUtil::expandFilename(*rc_groupfile); string whole_groupfile = read_file(groupfilename); @@ -158,13 +158,13 @@ void update_move_toolbar_wheeling_to_keys_file(FbTk::ResourceManager& rm, bool keep_changes = false; // scrolling on toolbar needs to match user's toolbar wheeling settings - FbTk::Resource rc_wheeling(rm, "Off", + FbTk::StringResource rc_wheeling(rm, "Off", "session.screen0.iconbar.wheelMode", "Session.Screen0.Iconbar.WheelMode"); - FbTk::Resource rc_screen(rm, true, + FbTk::BoolResource rc_screen(rm, true, "session.screen0.desktopwheeling", "Session.Screen0.DesktopWheeling"); - FbTk::Resource rc_reverse(rm, false, + FbTk::BoolResource rc_reverse(rm, false, "session.screen0.reversewheeling", "Session.Screen0.ReverseWheeling"); if (strcasecmp((*rc_wheeling).c_str(), "On") == 0 || @@ -195,10 +195,10 @@ void update_move_modkey_to_keys_file(FbTk::ResourceManager& rm, new_keyfile += "!mouse actions added by fluxbox-update_configs\n"; // need to match user's resize model - FbTk::Resource rc_mode(rm, "Bottom", + FbTk::StringResource rc_mode(rm, "Bottom", "session.screen0.resizeMode", "Session.Screen0.ResizeMode"); - FbTk::Resource rc_modkey(rm, "Mod1", + FbTk::StringResource rc_modkey(rm, "Mod1", "session.modKey", "Session.ModKey"); @@ -227,8 +227,8 @@ void update_window_patterns_for_iconbar(FbTk::ResourceManager& rm, // this needs to survive after going out of scope // it won't get freed, but that's ok - FbTk::Resource *rc_mode = - new FbTk::Resource(rm, "Workspace", + FbTk::StringResource *rc_mode = + new FbTk::StringResource(rm, "Workspace", "session.screen0.iconbar.mode", "Session.Screen0.Iconbar.Mode"); @@ -260,8 +260,8 @@ void update_move_titlebar_actions_to_keys_file(FbTk::ResourceManager& rm, new_keyfile += "OnTitlebar Double Mouse1 :Shade\n"; new_keyfile += "OnTitlebar Mouse3 :WindowMenu\n"; - FbTk::Resource rc_reverse(rm, false,"session.screen0.reversewheeling", "Session.Screen0.ReverseWheeling"); - FbTk::Resource scroll_action(rm, "", "session.screen0.windowScrollAction", "Session.Screen0.WindowScrollAction"); + FbTk::BoolResource rc_reverse(rm, false,"session.screen0.reversewheeling", "Session.Screen0.ReverseWheeling"); + FbTk::StringResource scroll_action(rm, "", "session.screen0.windowScrollAction", "Session.Screen0.WindowScrollAction"); if (strcasecmp((*scroll_action).c_str(), "shade") == 0) { if (*rc_reverse) { new_keyfile += "OnTitlebar Mouse5 :ShadeOn\n"; @@ -305,8 +305,8 @@ void update_added_starttabbing_command(FbTk::ResourceManager& rm, void update_disable_icons_in_tabs_for_backwards_compatibility(FbTk::ResourceManager& rm, const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { - FbTk::Resource *show = - new FbTk::Resource(rm, false, + FbTk::BoolResource *show = + new FbTk::BoolResource(rm, false, "session.screen0.tabs.usePixmap", "Session.Screen0.Tabs.UsePixmap"); if (!*show) // only change if the setting didn't already exist @@ -319,13 +319,13 @@ void update_disable_icons_in_tabs_for_backwards_compatibility(FbTk::ResourceMana void update_change_format_of_split_placement_menu(FbTk::ResourceManager& rm, const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { - FbTk::Resource *placement = - new FbTk::Resource(rm, "BottomRight", + FbTk::StringResource *placement = + new FbTk::StringResource(rm, "BottomRight", "session.screen0.slit.placement", "Session.Screen0.Slit.Placement"); - FbTk::Resource *direction = - new FbTk::Resource(rm, "Vertical", + FbTk::StringResource *direction = + new FbTk::StringResource(rm, "Vertical", "session.screen0.slit.direction", "Session.Screen0.Slit.Direction"); @@ -555,9 +555,9 @@ const Update UPDATES[] = { int run_updates(int old_version, FbTk::ResourceManager &rm) { int new_version = old_version; - FbTk::Resource rc_keyfile(rm, "~/.fluxbox/keys", + FbTk::StringResource rc_keyfile(rm, "~/.fluxbox/keys", "session.keyFile", "Session.KeyFile"); - FbTk::Resource rc_appsfile(rm, "~/.fluxbox/apps", + FbTk::StringResource rc_appsfile(rm, "~/.fluxbox/apps", "session.appsFile", "Session.AppsFile"); string appsfilename = FbTk::StringUtil::expandFilename(*rc_appsfile); @@ -633,7 +633,7 @@ int main(int argc, char **argv) { // run updates here // I feel like putting this in a separate function for no apparent reason - FbTk::Resource config_version(resource_manager, 0, + FbTk::IntResource config_version(resource_manager, 0, "session.configVersion", "Session.ConfigVersion"); if (check) { -- cgit v0.11.2