From 7a46f95d0ce4e249812fb5c2685308cd7283b37d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 12 Jun 2011 15:17:47 +0200 Subject: Factor out "session." from resource names this reduces typing and it makes more sense in lua, since there the resources are implemented as hierarchical tables and the topmost table has to be handled a bit specially. --- src/FbTk/LResource.cc | 4 +-- src/FbTk/LResource.hh | 3 +-- src/FbTk/Resource.cc | 18 +++++++------ src/FbTk/Resource.hh | 7 ++++- src/fluxbox.cc | 42 +++++++++++++++--------------- src/main.cc | 4 +-- util/fluxbox-update_configs.cc | 58 +++++++++++++++++++++--------------------- 7 files changed, 71 insertions(+), 65 deletions(-) diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc index 5842b65..78511eb 100644 --- a/src/FbTk/LResource.cc +++ b/src/FbTk/LResource.cc @@ -82,8 +82,8 @@ void LResourceManager::initState(lua::state &l) { l.setfield(lua::REGISTRYINDEX, make_root); } -LResourceManager::LResourceManager(lua::state &l, const std::string &root) - : m_l(&l), m_root(root) { +LResourceManager::LResourceManager(const std::string &root, lua::state &l) + : ResourceManager_base(root), m_l(&l) { l.checkstack(2); lua::stack_sentry s(l); diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh index 0853687..185a029 100644 --- a/src/FbTk/LResource.hh +++ b/src/FbTk/LResource.hh @@ -39,7 +39,7 @@ class LResourceManager: public ResourceManager_base { public: static void initState(lua::state &l); - LResourceManager(lua::state &l, const std::string &root); + LResourceManager(const std::string &root, lua::state &l); virtual bool save(const char *filename, const char *); virtual void addResource(Resource_base &r); virtual void removeResource(Resource_base &r); @@ -47,7 +47,6 @@ public: private: lua::state *m_l; - std::string m_root; }; } // end namespace FbTk diff --git a/src/FbTk/Resource.cc b/src/FbTk/Resource.cc index fb0f595..37555b3 100644 --- a/src/FbTk/Resource.cc +++ b/src/FbTk/Resource.cc @@ -82,10 +82,13 @@ void ResourceManager_base::setResourceValue(const string &resname, const string } -ResourceManager::ResourceManager(const char *filename, bool lock_db) : +ResourceManager::ResourceManager(const std::string &root, const std::string &alt_root, + const char *filename, bool lock_db) : + ResourceManager_base(root), m_db_lock(0), m_database(0), - m_filename(filename ? filename : "") + m_filename(filename ? filename : ""), + m_alt_root(alt_root) { static bool xrm_initialized = false; if (!xrm_initialized) { @@ -131,8 +134,8 @@ bool ResourceManager::load(const char *filename) { for (; i != i_end; ++i) { Resource_base *resource = *i; - if (XrmGetResource(**m_database, resource->name().c_str(), - resource->altName().c_str(), &value_type, &value)) + if (XrmGetResource(**m_database, (m_root + '.' + resource->name()).c_str(), + (m_alt_root + '.' + resource->altName()).c_str(), &value_type, &value)) resource->setFromString(value.addr); else { _FB_USES_NLS; @@ -166,13 +169,12 @@ bool ResourceManager::save(const char *filename, const char *mergefilename) { // empty database XrmDatabaseHelper database; - string rc_string; ResourceList::iterator i = m_resourcelist.begin(); ResourceList::iterator i_end = m_resourcelist.end(); //write all resources to database for (; i != i_end; ++i) { Resource_base *resource = *i; - rc_string = resource->name() + string(": ") + resource->getString(); + const string &rc_string = m_root + '.' + resource->name() + ": " + resource->getString(); XrmPutLineResource(&*database, rc_string.c_str()); } @@ -248,8 +250,8 @@ void ResourceManager::addResource(Resource_base &r) { char *value_type; // now, load the value for this resource - if (XrmGetResource(**m_database, r.name().c_str(), - r.altName().c_str(), &value_type, &value)) { + if (XrmGetResource(**m_database, (m_root + '.' + r.name()).c_str(), + (m_alt_root + '.' + r.altName()).c_str(), &value_type, &value)) { r.setFromString(value.addr); } else { std::cerr<<"Failed to read: "< ResourceList; + ResourceManager_base(const std::string &root) : m_root(root) {} + virtual ~ResourceManager_base() {} /// Save all resouces registered to this class @@ -123,6 +125,7 @@ public: protected: ResourceList m_resourcelist; + const std::string m_root; }; class ResourceManager: public ResourceManager_base @@ -130,7 +133,8 @@ class ResourceManager: public ResourceManager_base public: // lock specifies if the database should be opened with one level locked // (useful for constructing inside initial set of constructors) - ResourceManager(const char *filename, bool lock_db); + ResourceManager(const std::string &root, const std::string &alt_root, + const char *filename, bool lock_db); virtual ~ResourceManager(); /// Load all resources registered to this class @@ -169,6 +173,7 @@ private: XrmDatabaseHelper *m_database; std::string m_filename; + std::string m_alt_root; }; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index 8260897..9ccad80 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -228,28 +228,28 @@ Fluxbox::Fluxbox(int argc, char **argv, const std::string& rc_path, const std::string& rc_filename, bool xsync) : FbTk::App(dpy_name.c_str()), m_fbatoms(FbAtoms::instance()), - m_resourcemanager(rc_filename.c_str(), true), + m_resourcemanager("session", "Session", rc_filename.c_str(), true), // TODO: shouldn't need a separate one for screen m_screen_rm(m_resourcemanager), m_RC_PATH(rc_path), m_RC_INIT_FILE("init"), - m_rc_ignoreborder(m_resourcemanager, false, "session.ignoreBorder", "Session.IgnoreBorder"), - m_rc_pseudotrans(m_resourcemanager, false, "session.forcePseudoTransparency", "Session.forcePseudoTransparency"), + m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder", "IgnoreBorder"), + m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency", "forcePseudoTransparency"), m_rc_colors_per_channel(m_resourcemanager, 4, - "session.colorsPerChannel", "Session.ColorsPerChannel"), - m_rc_double_click_interval(m_resourcemanager, 250, "session.doubleClickInterval", "Session.DoubleClickInterval"), - m_rc_tabs_padding(m_resourcemanager, 0, "session.tabPadding", "Session.TabPadding"), - m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "session.styleFile", "Session.StyleFile"), - m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "session.styleOverlay", "Session.StyleOverlay"), - m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu", "session.menuFile", "Session.MenuFile"), - m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "session.keyFile", "Session.KeyFile"), - m_rc_slitlistfile(m_resourcemanager, m_RC_PATH + "/slitlist", "session.slitlistFile", "Session.SlitlistFile"), - m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "session.appsFile", "Session.AppsFile"), - m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "session.tabsAttachArea", "Session.TabsAttachArea"), - m_rc_cache_life(m_resourcemanager, 5, "session.cacheLife", "Session.CacheLife"), - m_rc_cache_max(m_resourcemanager, 200, "session.cacheMax", "Session.CacheMax"), - m_rc_auto_raise_delay(m_resourcemanager, 250, "session.autoRaiseDelay", "Session.AutoRaiseDelay"), + "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 + "/menu", "menuFile", "MenuFile"), + m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"), + m_rc_slitlistfile(m_resourcemanager, m_RC_PATH + "/slitlist", "slitlistFile", "SlitlistFile"), + 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_masked_window(0), m_mousescreen(0), m_keyscreen(0), @@ -397,8 +397,8 @@ Fluxbox::Fluxbox(int argc, char **argv, for (size_t s = 0; s < screens.size(); s++) { std::string sc_nr = FbTk::StringUtil::number2String(screens[s]); BScreen *screen = new BScreen(m_screen_rm.lock(), - std::string("session.screen") + sc_nr, - std::string("session.Screen") + sc_nr, + std::string("screen") + sc_nr, + std::string("Screen") + sc_nr, screens[s], ::ResourceLayer::NUM_LAYERS); // already handled @@ -1146,7 +1146,7 @@ void Fluxbox::save_rc() { for (; it != it_end; ++it) { BScreen *screen = *it; - std::string workspaces_string("session.screen"); + std::string workspaces_string("screen"); workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber()); workspaces_string += ".workspaceNames: "; @@ -1239,10 +1239,10 @@ void Fluxbox::load_rc(BScreen &screen) { std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber()); - std::string name_lookup("session.screen"); + std::string name_lookup("screen"); name_lookup += screen_number; name_lookup += ".workspaceNames"; - std::string class_lookup("session.screen"); + std::string class_lookup("screen"); class_lookup += screen_number; class_lookup += ".WorkspaceNames"; diff --git a/src/main.cc b/src/main.cc index 36e258b..3d35044 100644 --- a/src/main.cc +++ b/src/main.cc @@ -399,8 +399,8 @@ 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::IntResource c_version(r_mgr, 0, "session.configVersion", "Session.ConfigVersion"); + FbTk::ResourceManager r_mgr("session", "Session", rc_file.c_str(), false); + FbTk::IntResource c_version(r_mgr, 0, "configVersion", "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 93acb04..069b112 100644 --- a/util/fluxbox-update_configs.cc +++ b/util/fluxbox-update_configs.cc @@ -90,11 +90,11 @@ void update_add_mouse_evens_to_keys(FbTk::ResourceManager& rm, // 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::BoolResource rc_wheeling(rm, true, - "session.screen0.desktopwheeling", - "Session.Screen0.DesktopWheeling"); + "screen0.desktopwheeling", + "Screen0.DesktopWheeling"); FbTk::BoolResource rc_reverse(rm, false, - "session.screen0.reversewheeling", - "Session.Screen0.ReverseWheeling"); + "screen0.reversewheeling", + "Screen0.ReverseWheeling"); if (*rc_wheeling) { if (*rc_reverse) { // if you ask me, this should have been default new_keyfile += "OnDesktop Mouse4 :PrevWorkspace\n"; @@ -115,7 +115,7 @@ void update_move_groups_entries_to_apps_file(FbTk::ResourceManager& rm, const FbTk::FbString& keyfilename, const FbTk::FbString& appsfilename) { FbTk::StringResource rc_groupfile(rm, "~/.fluxbox/groups", - "session.groupFile", "Session.GroupFile"); + "groupFile", "GroupFile"); string groupfilename = FbTk::StringUtil::expandFilename(*rc_groupfile); string whole_groupfile = read_file(groupfilename); string whole_appsfile = read_file(appsfilename); @@ -159,14 +159,14 @@ void update_move_toolbar_wheeling_to_keys_file(FbTk::ResourceManager& rm, // scrolling on toolbar needs to match user's toolbar wheeling settings FbTk::StringResource rc_wheeling(rm, "Off", - "session.screen0.iconbar.wheelMode", - "Session.Screen0.Iconbar.WheelMode"); + "screen0.iconbar.wheelMode", + "Screen0.Iconbar.WheelMode"); FbTk::BoolResource rc_screen(rm, true, - "session.screen0.desktopwheeling", - "Session.Screen0.DesktopWheeling"); + "screen0.desktopwheeling", + "Screen0.DesktopWheeling"); FbTk::BoolResource rc_reverse(rm, false, - "session.screen0.reversewheeling", - "Session.Screen0.ReverseWheeling"); + "screen0.reversewheeling", + "Screen0.ReverseWheeling"); if (strcasecmp((*rc_wheeling).c_str(), "On") == 0 || (strcasecmp((*rc_wheeling).c_str(), "Screen") == 0 && *rc_screen)) { keep_changes = true; @@ -196,11 +196,11 @@ void update_move_modkey_to_keys_file(FbTk::ResourceManager& rm, // need to match user's resize model FbTk::StringResource rc_mode(rm, "Bottom", - "session.screen0.resizeMode", - "Session.Screen0.ResizeMode"); + "screen0.resizeMode", + "Screen0.ResizeMode"); FbTk::StringResource rc_modkey(rm, "Mod1", - "session.modKey", - "Session.ModKey"); + "modKey", + "ModKey"); new_keyfile += "OnWindow " + *rc_modkey + " Mouse1 :MacroCmd {Raise} {Focus} {StartMoving}\n"; @@ -229,8 +229,8 @@ void update_window_patterns_for_iconbar(FbTk::ResourceManager& rm, // it won't get freed, but that's ok FbTk::StringResource *rc_mode = new FbTk::StringResource(rm, "Workspace", - "session.screen0.iconbar.mode", - "Session.Screen0.Iconbar.Mode"); + "screen0.iconbar.mode", + "Screen0.Iconbar.Mode"); std::string mode = FbTk::StringUtil::toLower(**rc_mode); if (mode == "none") @@ -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::BoolResource rc_reverse(rm, false,"session.screen0.reversewheeling", "Session.Screen0.ReverseWheeling"); - FbTk::StringResource scroll_action(rm, "", "session.screen0.windowScrollAction", "Session.Screen0.WindowScrollAction"); + FbTk::BoolResource rc_reverse(rm, false,"screen0.reversewheeling", "Screen0.ReverseWheeling"); + FbTk::StringResource scroll_action(rm, "", "screen0.windowScrollAction", "Screen0.WindowScrollAction"); if (strcasecmp((*scroll_action).c_str(), "shade") == 0) { if (*rc_reverse) { new_keyfile += "OnTitlebar Mouse5 :ShadeOn\n"; @@ -307,8 +307,8 @@ void update_disable_icons_in_tabs_for_backwards_compatibility(FbTk::ResourceMana FbTk::BoolResource *show = new FbTk::BoolResource(rm, false, - "session.screen0.tabs.usePixmap", - "Session.Screen0.Tabs.UsePixmap"); + "screen0.tabs.usePixmap", + "Screen0.Tabs.UsePixmap"); if (!*show) // only change if the setting didn't already exist *show = false; } @@ -321,13 +321,13 @@ void update_change_format_of_split_placement_menu(FbTk::ResourceManager& rm, FbTk::StringResource *placement = new FbTk::StringResource(rm, "BottomRight", - "session.screen0.slit.placement", - "Session.Screen0.Slit.Placement"); + "screen0.slit.placement", + "Screen0.Slit.Placement"); FbTk::StringResource *direction = new FbTk::StringResource(rm, "Vertical", - "session.screen0.slit.direction", - "Session.Screen0.Slit.Direction"); + "screen0.slit.direction", + "Screen0.Slit.Direction"); if (strcasecmp((**direction).c_str(), "vertical") == 0) { if (strcasecmp((**placement).c_str(), "BottomRight") == 0) @@ -556,9 +556,9 @@ int run_updates(int old_version, FbTk::ResourceManager &rm) { int new_version = old_version; FbTk::StringResource rc_keyfile(rm, "~/.fluxbox/keys", - "session.keyFile", "Session.KeyFile"); + "keyFile", "KeyFile"); FbTk::StringResource rc_appsfile(rm, "~/.fluxbox/apps", - "session.appsFile", "Session.AppsFile"); + "appsFile", "AppsFile"); string appsfilename = FbTk::StringUtil::expandFilename(*rc_appsfile); string keyfilename = FbTk::StringUtil::expandFilename(*rc_keyfile); @@ -617,7 +617,7 @@ int main(int argc, char **argv) { if (rc_filename.empty()) rc_filename = getenv("HOME") + string("/.fluxbox/init"); - FbTk::ResourceManager resource_manager(rc_filename.c_str(),false); + FbTk::ResourceManager resource_manager("session", "Session", rc_filename.c_str(),false); if (!resource_manager.load(rc_filename.c_str())) { // couldn't load rc file cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "Failed trying to read rc file")<<":"<