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-06-15 23:12:52 (GMT)
commitfe4b924bcb7d059e5ca059f88ba863a74c0d8760 (patch)
tree23b2fb89b1301b586a67edb17bac43b8b0df73f7 /src
parentba6a65c3d020e2a57eb805da6ed30d796b383060 (diff)
downloadfluxbox_pavel-fe4b924bcb7d059e5ca059f88ba863a74c0d8760.zip
fluxbox_pavel-fe4b924bcb7d059e5ca059f88ba863a74c0d8760.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.cc9
6 files changed, 45 insertions, 38 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 0dc958d..590a946 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -233,28 +233,28 @@ Fluxbox::Fluxbox(int argc, char **argv,
233 const std::string& rc_path, const std::string& rc_filename, bool xsync) 233 const std::string& rc_path, const std::string& rc_filename, bool xsync)
234 : FbTk::App(dpy_name.c_str()), 234 : FbTk::App(dpy_name.c_str()),
235 m_fbatoms(FbAtoms::instance()), 235 m_fbatoms(FbAtoms::instance()),
236 m_resourcemanager(rc_filename.c_str(), true), 236 m_resourcemanager("session", "Session", rc_filename.c_str(), true),
237 // TODO: shouldn't need a separate one for screen 237 // TODO: shouldn't need a separate one for screen
238 m_screen_rm(m_resourcemanager), 238 m_screen_rm(m_resourcemanager),
239 239
240 m_RC_PATH(rc_path), 240 m_RC_PATH(rc_path),
241 m_RC_INIT_FILE("init"), 241 m_RC_INIT_FILE("init"),
242 m_rc_ignoreborder(m_resourcemanager, false, "session.ignoreBorder", "Session.IgnoreBorder"), 242 m_rc_ignoreborder(m_resourcemanager, false, "ignoreBorder", "IgnoreBorder"),
243 m_rc_pseudotrans(m_resourcemanager, false, "session.forcePseudoTransparency", "Session.forcePseudoTransparency"), 243 m_rc_pseudotrans(m_resourcemanager, false, "forcePseudoTransparency", "forcePseudoTransparency"),
244 m_rc_colors_per_channel(m_resourcemanager, 4, 244 m_rc_colors_per_channel(m_resourcemanager, 4,
245 "session.colorsPerChannel", "Session.ColorsPerChannel"), 245 "colorsPerChannel", "ColorsPerChannel"),
246 m_rc_double_click_interval(m_resourcemanager, 250, "session.doubleClickInterval", "Session.DoubleClickInterval"), 246 m_rc_double_click_interval(m_resourcemanager, 250, "doubleClickInterval", "DoubleClickInterval"),
247 m_rc_tabs_padding(m_resourcemanager, 0, "session.tabPadding", "Session.TabPadding"), 247 m_rc_tabs_padding(m_resourcemanager, 0, "tabPadding", "TabPadding"),
248 m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "session.styleFile", "Session.StyleFile"), 248 m_rc_stylefile(m_resourcemanager, DEFAULTSTYLE, "styleFile", "StyleFile"),
249 m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "session.styleOverlay", "Session.StyleOverlay"), 249 m_rc_styleoverlayfile(m_resourcemanager, m_RC_PATH + "/overlay", "styleOverlay", "StyleOverlay"),
250 m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu", "session.menuFile", "Session.MenuFile"), 250 m_rc_menufile(m_resourcemanager, m_RC_PATH + "/menu", "menuFile", "MenuFile"),
251 m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "session.keyFile", "Session.KeyFile"), 251 m_rc_keyfile(m_resourcemanager, m_RC_PATH + "/keys", "keyFile", "KeyFile"),
252 m_rc_slitlistfile(m_resourcemanager, m_RC_PATH + "/slitlist", "session.slitlistFile", "Session.SlitlistFile"), 252 m_rc_slitlistfile(m_resourcemanager, m_RC_PATH + "/slitlist", "slitlistFile", "SlitlistFile"),
253 m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "session.appsFile", "Session.AppsFile"), 253 m_rc_appsfile(m_resourcemanager, m_RC_PATH + "/apps", "appsFile", "AppsFile"),
254 m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "session.tabsAttachArea", "Session.TabsAttachArea"), 254 m_rc_tabs_attach_area(m_resourcemanager, ATTACH_AREA_WINDOW, "tabsAttachArea", "TabsAttachArea"),
255 m_rc_cache_life(m_resourcemanager, 5, "session.cacheLife", "Session.CacheLife"), 255 m_rc_cache_life(m_resourcemanager, 5, "cacheLife", "CacheLife"),
256 m_rc_cache_max(m_resourcemanager, 200, "session.cacheMax", "Session.CacheMax"), 256 m_rc_cache_max(m_resourcemanager, 200, "cacheMax", "CacheMax"),
257 m_rc_auto_raise_delay(m_resourcemanager, 250, "session.autoRaiseDelay", "Session.AutoRaiseDelay"), 257 m_rc_auto_raise_delay(m_resourcemanager, 250, "autoRaiseDelay", "AutoRaiseDelay"),
258 m_masked_window(0), 258 m_masked_window(0),
259 m_mousescreen(0), 259 m_mousescreen(0),
260 m_keyscreen(0), 260 m_keyscreen(0),
@@ -399,8 +399,8 @@ Fluxbox::Fluxbox(int argc, char **argv,
399 for (size_t s = 0; s < screens.size(); s++) { 399 for (size_t s = 0; s < screens.size(); s++) {
400 std::string sc_nr = FbTk::StringUtil::number2String(screens[s]); 400 std::string sc_nr = FbTk::StringUtil::number2String(screens[s]);
401 BScreen *screen = new BScreen(m_screen_rm.lock(), 401 BScreen *screen = new BScreen(m_screen_rm.lock(),
402 std::string("session.screen") + sc_nr, 402 std::string("screen") + sc_nr,
403 std::string("session.Screen") + sc_nr, 403 std::string("Screen") + sc_nr,
404 screens[s], ::ResourceLayer::NUM_LAYERS); 404 screens[s], ::ResourceLayer::NUM_LAYERS);
405 405
406 // already handled 406 // already handled
@@ -1147,7 +1147,7 @@ void Fluxbox::save_rc() {
1147 for (; it != it_end; ++it) { 1147 for (; it != it_end; ++it) {
1148 BScreen *screen = *it; 1148 BScreen *screen = *it;
1149 1149
1150 std::string workspaces_string("session.screen"); 1150 std::string workspaces_string("screen");
1151 workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber()); 1151 workspaces_string += FbTk::StringUtil::number2String(screen->screenNumber());
1152 workspaces_string += ".workspaceNames: "; 1152 workspaces_string += ".workspaceNames: ";
1153 1153
@@ -1240,10 +1240,10 @@ void Fluxbox::load_rc(BScreen &screen) {
1240 1240
1241 std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber()); 1241 std::string screen_number = FbTk::StringUtil::number2String(screen.screenNumber());
1242 1242
1243 std::string name_lookup("session.screen"); 1243 std::string name_lookup("screen");
1244 name_lookup += screen_number; 1244 name_lookup += screen_number;
1245 name_lookup += ".workspaceNames"; 1245 name_lookup += ".workspaceNames";
1246 std::string class_lookup("session.screen"); 1246 std::string class_lookup("screen");
1247 class_lookup += screen_number; 1247 class_lookup += screen_number;
1248 class_lookup += ".WorkspaceNames"; 1248 class_lookup += ".WorkspaceNames";
1249 1249
diff --git a/src/main.cc b/src/main.cc
index a18ae56..4723c09 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -383,8 +383,8 @@ void updateConfigFilesIfNeeded(const std::string& rc_file) {
383 383
384 const int CONFIG_VERSION = 13; // TODO: move this to 'defaults.hh' or 'config.h' 384 const int CONFIG_VERSION = 13; // TODO: move this to 'defaults.hh' or 'config.h'
385 385
386 FbTk::ResourceManager r_mgr(rc_file.c_str(), false); 386 FbTk::ResourceManager r_mgr("session", "Session", rc_file.c_str(), false);
387 FbTk::IntResource c_version(r_mgr, 0, "session.configVersion", "Session.ConfigVersion"); 387 FbTk::IntResource c_version(r_mgr, 0, "configVersion", "ConfigVersion");
388 388
389 if (!r_mgr.load(rc_file.c_str())) { 389 if (!r_mgr.load(rc_file.c_str())) {
390 _FB_USES_NLS; 390 _FB_USES_NLS;
@@ -416,9 +416,10 @@ void updateConfigFilesIfNeeded(const std::string& rc_file) {
416#include "WinButton.hh" 416#include "WinButton.hh"
417int main(int argc, char **argv) { 417int main(int argc, char **argv) {
418 418
419#if 0
419 lua::state l; 420 lua::state l;
420 FbTk::LResourceManager::initState(l); 421 FbTk::LResourceManager::initState(l);
421 FbTk::LResourceManager man(l, "session"); 422 FbTk::LResourceManager man("session", l);
422 l.loadstring("session.asdf = {'close', 'close'}; session.q={{1,2,{3,4}},{{z={{5}}}}};"); 423 l.loadstring("session.asdf = {'close', 'close'}; session.q={{1,2,{3,4}},{{z={{5}}}}};");
423 l.call(0,0); 424 l.call(0,0);
424 man.save("/dev/stdout", NULL); 425 man.save("/dev/stdout", NULL);
@@ -426,7 +427,7 @@ int main(int argc, char **argv) {
426 cout << "asdf: " << asdf.getString() << endl; 427 cout << "asdf: " << asdf.getString() << endl;
427 man.save("/dev/stdout", NULL); 428 man.save("/dev/stdout", NULL);
428 return 0; 429 return 0;
429 430#endif
430 431
431 FbTk::NLSInit("fluxbox.cat"); 432 FbTk::NLSInit("fluxbox.cat");
432 433