aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-06-12 13:17:47 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:55:30 (GMT)
commit7a46f95d0ce4e249812fb5c2685308cd7283b37d (patch)
tree51f1bb9b88d4499a487b42b6bf17512a56d987c7 /src
parent7817fd254e9bd1529fa6e98cdba249b7c0b8a6f8 (diff)
downloadfluxbox_paul-7a46f95d0ce4e249812fb5c2685308cd7283b37d.zip
fluxbox_paul-7a46f95d0ce4e249812fb5c2685308cd7283b37d.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/LResource.cc4
-rw-r--r--src/FbTk/LResource.hh3
-rw-r--r--src/FbTk/Resource.cc18
-rw-r--r--src/FbTk/Resource.hh7
-rw-r--r--src/fluxbox.cc42
-rw-r--r--src/main.cc4
6 files changed, 42 insertions, 36 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) {
82 l.setfield(lua::REGISTRYINDEX, make_root); 82 l.setfield(lua::REGISTRYINDEX, make_root);
83} 83}
84 84
85LResourceManager::LResourceManager(lua::state &l, const std::string &root) 85LResourceManager::LResourceManager(const std::string &root, lua::state &l)
86 : m_l(&l), m_root(root) { 86 : ResourceManager_base(root), m_l(&l) {
87 l.checkstack(2); 87 l.checkstack(2);
88 lua::stack_sentry s(l); 88 lua::stack_sentry s(l);
89 89
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 {
39public: 39public:
40 static void initState(lua::state &l); 40 static void initState(lua::state &l);
41 41
42 LResourceManager(lua::state &l, const std::string &root); 42 LResourceManager(const std::string &root, lua::state &l);
43 virtual bool save(const char *filename, const char *); 43 virtual bool save(const char *filename, const char *);
44 virtual void addResource(Resource_base &r); 44 virtual void addResource(Resource_base &r);
45 virtual void removeResource(Resource_base &r); 45 virtual void removeResource(Resource_base &r);
@@ -47,7 +47,6 @@ public:
47private: 47private:
48 48
49 lua::state *m_l; 49 lua::state *m_l;
50 std::string m_root;
51}; 50};
52 51
53} // end namespace FbTk 52} // 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
82 82
83} 83}
84 84
85ResourceManager::ResourceManager(const char *filename, bool lock_db) : 85ResourceManager::ResourceManager(const std::string &root, const std::string &alt_root,
86 const char *filename, bool lock_db) :
87 ResourceManager_base(root),
86 m_db_lock(0), 88 m_db_lock(0),
87 m_database(0), 89 m_database(0),
88 m_filename(filename ? filename : "") 90 m_filename(filename ? filename : ""),
91 m_alt_root(alt_root)
89{ 92{
90 static bool xrm_initialized = false; 93 static bool xrm_initialized = false;
91 if (!xrm_initialized) { 94 if (!xrm_initialized) {
@@ -131,8 +134,8 @@ bool ResourceManager::load(const char *filename) {
131 for (; i != i_end; ++i) { 134 for (; i != i_end; ++i) {
132 135
133 Resource_base *resource = *i; 136 Resource_base *resource = *i;
134 if (XrmGetResource(**m_database, resource->name().c_str(), 137 if (XrmGetResource(**m_database, (m_root + '.' + resource->name()).c_str(),
135 resource->altName().c_str(), &value_type, &value)) 138 (m_alt_root + '.' + resource->altName()).c_str(), &value_type, &value))
136 resource->setFromString(value.addr); 139 resource->setFromString(value.addr);
137 else { 140 else {
138 _FB_USES_NLS; 141 _FB_USES_NLS;
@@ -166,13 +169,12 @@ bool ResourceManager::save(const char *filename, const char *mergefilename) {
166 // empty database 169 // empty database
167 XrmDatabaseHelper database; 170 XrmDatabaseHelper database;
168 171
169 string rc_string;
170 ResourceList::iterator i = m_resourcelist.begin(); 172 ResourceList::iterator i = m_resourcelist.begin();
171 ResourceList::iterator i_end = m_resourcelist.end(); 173 ResourceList::iterator i_end = m_resourcelist.end();
172 //write all resources to database 174 //write all resources to database
173 for (; i != i_end; ++i) { 175 for (; i != i_end; ++i) {
174 Resource_base *resource = *i; 176 Resource_base *resource = *i;
175 rc_string = resource->name() + string(": ") + resource->getString(); 177 const string &rc_string = m_root + '.' + resource->name() + ": " + resource->getString();
176 XrmPutLineResource(&*database, rc_string.c_str()); 178 XrmPutLineResource(&*database, rc_string.c_str());
177 } 179 }
178 180
@@ -248,8 +250,8 @@ void ResourceManager::addResource(Resource_base &r) {
248 char *value_type; 250 char *value_type;
249 251
250 // now, load the value for this resource 252 // now, load the value for this resource
251 if (XrmGetResource(**m_database, r.name().c_str(), 253 if (XrmGetResource(**m_database, (m_root + '.' + r.name()).c_str(),
252 r.altName().c_str(), &value_type, &value)) { 254 (m_alt_root + '.' + r.altName()).c_str(), &value_type, &value)) {
253 r.setFromString(value.addr); 255 r.setFromString(value.addr);
254 } else { 256 } else {
255 std::cerr<<"Failed to read: "<<r.name()<<std::endl; 257 std::cerr<<"Failed to read: "<<r.name()<<std::endl;
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh
index 33a6bb2..744178b 100644
--- a/src/FbTk/Resource.hh
+++ b/src/FbTk/Resource.hh
@@ -87,6 +87,8 @@ class ResourceManager_base
87public: 87public:
88 typedef std::list<Resource_base *> ResourceList; 88 typedef std::list<Resource_base *> ResourceList;
89 89
90 ResourceManager_base(const std::string &root) : m_root(root) {}
91
90 virtual ~ResourceManager_base() {} 92 virtual ~ResourceManager_base() {}
91 93
92 /// Save all resouces registered to this class 94 /// Save all resouces registered to this class
@@ -123,6 +125,7 @@ public:
123 125
124protected: 126protected:
125 ResourceList m_resourcelist; 127 ResourceList m_resourcelist;
128 const std::string m_root;
126}; 129};
127 130
128class ResourceManager: public ResourceManager_base 131class ResourceManager: public ResourceManager_base
@@ -130,7 +133,8 @@ class ResourceManager: public ResourceManager_base
130public: 133public:
131 // lock specifies if the database should be opened with one level locked 134 // lock specifies if the database should be opened with one level locked
132 // (useful for constructing inside initial set of constructors) 135 // (useful for constructing inside initial set of constructors)
133 ResourceManager(const char *filename, bool lock_db); 136 ResourceManager(const std::string &root, const std::string &alt_root,
137 const char *filename, bool lock_db);
134 virtual ~ResourceManager(); 138 virtual ~ResourceManager();
135 139
136 /// Load all resources registered to this class 140 /// Load all resources registered to this class
@@ -169,6 +173,7 @@ private:
169 XrmDatabaseHelper *m_database; 173 XrmDatabaseHelper *m_database;
170 174
171 std::string m_filename; 175 std::string m_filename;
176 std::string m_alt_root;
172}; 177};
173 178
174 179
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,
228 const std::string& rc_path, const std::string& rc_filename, bool xsync) 228 const std::string& rc_path, const std::string& rc_filename, bool xsync)
229 : FbTk::App(dpy_name.c_str()), 229 : FbTk::App(dpy_name.c_str()),
230 m_fbatoms(FbAtoms::instance()), 230 m_fbatoms(FbAtoms::instance()),
231 m_resourcemanager(rc_filename.c_str(), true), 231 m_resourcemanager("session", "Session", rc_filename.c_str(), true),
232 // TODO: shouldn't need a separate one for screen 232 // TODO: shouldn't need a separate one for screen
233 m_screen_rm(m_resourcemanager), 233 m_screen_rm(m_resourcemanager),
234 234
235 m_RC_PATH(rc_path), 235 m_RC_PATH(rc_path),
236 m_RC_INIT_FILE("init"), 236 m_RC_INIT_FILE("init"),
237 m_rc_ignoreborder(m_resourcemanager, false, "session.ignoreBorder", "Session.IgnoreBorder"), 237 m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder", "IgnoreBorder"),
238 m_rc_pseudotrans(m_resourcemanager, false, "session.forcePseudoTransparency", "Session.forcePseudoTransparency"), 238 m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency", "forcePseudoTransparency"),
239 m_rc_colors_per_channel(m_resourcemanager, 4, 239 m_rc_colors_per_channel(m_resourcemanager, 4,
240 "session.colorsPerChannel", "Session.ColorsPerChannel"), 240 "colorsPerChannel", "ColorsPerChannel"),
241 m_rc_double_click_interval(m_resourcemanager, 250, "session.doubleClickInterval", "Session.DoubleClickInterval"), 241 m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval", "DoubleClickInterval"),
242 m_rc_tabs_padding(m_resourcemanager, 0, "session.tabPadding", "Session.TabPadding"), 242 m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding", "TabPadding"),
243 m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "session.styleFile", "Session.StyleFile"), 243 m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile", "StyleFile"),
244 m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "session.styleOverlay", "Session.StyleOverlay"), 244 m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"),
245 m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu", "session.menuFile", "Session.MenuFile"), 245 m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu", "menuFile", "MenuFile"),
246 m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "session.keyFile", "Session.KeyFile"), 246 m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"),
247 m_rc_slitlistfile(m_resourcemanager, m_RC_PATH + "/slitlist", "session.slitlistFile", "Session.SlitlistFile"), 247 m_rc_slitlistfile(m_resourcemanager, m_RC_PATH + "/slitlist", "slitlistFile", "SlitlistFile"),
248 m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "session.appsFile", "Session.AppsFile"), 248 m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"),
249 m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "session.tabsAttachArea", "Session.TabsAttachArea"), 249 m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"),
250 m_rc_cache_life(m_resourcemanager, 5, "session.cacheLife", "Session.CacheLife"), 250 m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"),
251 m_rc_cache_max(m_resourcemanager, 200, "session.cacheMax", "Session.CacheMax"), 251 m_rc_cache_max(m_resourcemanager, 200, "cacheMax", "CacheMax"),
252 m_rc_auto_raise_delay(m_resourcemanager, 250, "session.autoRaiseDelay", "Session.AutoRaiseDelay"), 252 m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay", "AutoRaiseDelay"),
253 m_masked_window(0), 253 m_masked_window(0),
254 m_mousescreen(0), 254 m_mousescreen(0),
255 m_keyscreen(0), 255 m_keyscreen(0),
@@ -397,8 +397,8 @@ Fluxbox::Fluxbox(int argc, char **argv,
397 for (size_t s = 0; s < screens.size(); s++) { 397 for (size_t s = 0; s < screens.size(); s++) {
398 std::string sc_nr = FbTk::StringUtil::number2String(screens[s]); 398 std::string sc_nr = FbTk::StringUtil::number2String(screens[s]);
399 BScreen *screen = new BScreen(m_screen_rm.lock(), 399 BScreen *screen = new BScreen(m_screen_rm.lock(),
400 std::string("session.screen") + sc_nr, 400 std::string("screen") + sc_nr,
401 std::string("session.Screen") + sc_nr, 401 std::string("Screen") + sc_nr,
402 screens[s], ::ResourceLayer::NUM_LAYERS); 402 screens[s], ::ResourceLayer::NUM_LAYERS);
403 403
404 // already handled 404 // already handled
@@ -1146,7 +1146,7 @@ void Fluxbox::save_rc() {
1146 for (; it != it_end; ++it) { 1146 for (; it != it_end; ++it) {
1147 BScreen *screen = *it; 1147 BScreen *screen = *it;
1148 1148
1149 std::string workspaces_string("session.screen"); 1149 std::string workspaces_string("screen");
1150 workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber()); 1150 workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber());
1151 workspaces_string += ".workspaceNames: "; 1151 workspaces_string += ".workspaceNames: ";
1152 1152
@@ -1239,10 +1239,10 @@ void Fluxbox::load_rc(BScreen &screen) {
1239 1239
1240 std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber()); 1240 std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber());
1241 1241
1242 std::string name_lookup("session.screen"); 1242 std::string name_lookup("screen");
1243 name_lookup += screen_number; 1243 name_lookup += screen_number;
1244 name_lookup += ".workspaceNames"; 1244 name_lookup += ".workspaceNames";
1245 std::string class_lookup("session.screen"); 1245 std::string class_lookup("screen");
1246 class_lookup += screen_number; 1246 class_lookup += screen_number;
1247 class_lookup += ".WorkspaceNames"; 1247 class_lookup += ".WorkspaceNames";
1248 1248
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) {
399 399
400 const int CONFIG_VERSION = 13; // TODO: move this to 'defaults.hh' or 'config.h' 400 const int CONFIG_VERSION = 13; // TODO: move this to 'defaults.hh' or 'config.h'
401 401
402 FbTk::ResourceManager r_mgr(rc_file.c_str(), false); 402 FbTk::ResourceManager r_mgr("session", "Session", rc_file.c_str(), false);
403 FbTk::IntResource c_version(r_mgr, 0, "session.configVersion", "Session.ConfigVersion"); 403 FbTk::IntResource c_version(r_mgr, 0, "configVersion", "ConfigVersion");
404 404
405 if (!r_mgr.load(rc_file.c_str())) { 405 if (!r_mgr.load(rc_file.c_str())) {
406 _FB_USES_NLS; 406 _FB_USES_NLS;