aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-30 10:21:53 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 09:57:24 (GMT)
commitfa82f62dde8a8c43f5bac93993e5a047be14c70f (patch)
tree2e3e8bf779daae2f42bda16fe36555409ef5223c /src
parentbb5495fce6b635203ba0a9d5b4b1bc792b6f448f (diff)
downloadfluxbox_paul-fa82f62dde8a8c43f5bac93993e5a047be14c70f.zip
fluxbox_paul-fa82f62dde8a8c43f5bac93993e5a047be14c70f.tar.bz2
Create a completely new lua state upon USR2 reconfigure
This way, global variables set by the scripts don't persist between hard reconfigures. I also cleaned up the reconfig-handling code in fluxbox.cc. Instead of three reconfig functions (real_reconfig, timed_reconfig, reconfig) we have just one.
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/LResource.cc52
-rw-r--r--src/FbTk/LResource.hh3
-rw-r--r--src/fluxbox.cc28
-rw-r--r--src/fluxbox.hh4
4 files changed, 48 insertions, 39 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc
index d7627c9..0909520 100644
--- a/src/FbTk/LResource.cc
+++ b/src/FbTk/LResource.cc
@@ -101,17 +101,8 @@ void LResourceManager::convert(ResourceManager &old, const std::string &new_file
101} 101}
102 102
103LResourceManager::LResourceManager(const std::string &root, Lua &l) 103LResourceManager::LResourceManager(const std::string &root, Lua &l)
104 : ResourceManager_base(root), m_l(&l) { 104 : ResourceManager_base(root), m_l(&l) {
105 l.checkstack(2); 105 setLua(l);
106 lua::stack_sentry s(l);
107
108 l.pushstring(root);
109
110 l.getfield(lua::REGISTRYINDEX, make_root);
111 l.pushstring(root);
112 l.call(1, 1);
113
114 l.readOnlySet(lua::GLOBALSINDEX);
115} 106}
116 107
117bool LResourceManager::save(const char *filename, const char *) { 108bool LResourceManager::save(const char *filename, const char *) {
@@ -127,11 +118,20 @@ bool LResourceManager::save(const char *filename, const char *) {
127} 118}
128 119
129void LResourceManager::addResource(Resource_base &r) { 120void LResourceManager::addResource(Resource_base &r) {
121 ResourceManager_base::addResource(r);
122 try {
123 doAddResource(r);
124 }
125 catch(...) {
126 ResourceManager_base::removeResource(r);
127 throw;
128 }
129}
130
131void LResourceManager::doAddResource(Resource_base &r) {
130 m_l->checkstack(5); 132 m_l->checkstack(5);
131 lua::stack_sentry s(*m_l); 133 lua::stack_sentry s(*m_l);
132 134
133 ResourceManager_base::addResource(r);
134
135 m_l->getfield(lua::REGISTRYINDEX, register_resource); 135 m_l->getfield(lua::REGISTRYINDEX, register_resource);
136 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); 136 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str());
137 m_l->pushstring(r.name()); 137 m_l->pushstring(r.name());
@@ -143,7 +143,12 @@ void LResourceManager::addResource(Resource_base &r) {
143} 143}
144 144
145void LResourceManager::removeResource(Resource_base &r) { 145void LResourceManager::removeResource(Resource_base &r) {
146 m_l->checkstack(5); 146 doRemoveResource(r);
147 ResourceManager_base::removeResource(r);
148}
149
150void LResourceManager::doRemoveResource(Resource_base &r) {
151 m_l->checkstack(4);
147 lua::stack_sentry s(*m_l); 152 lua::stack_sentry s(*m_l);
148 153
149 m_l->getfield(lua::REGISTRYINDEX, register_resource); 154 m_l->getfield(lua::REGISTRYINDEX, register_resource);
@@ -153,8 +158,25 @@ void LResourceManager::removeResource(Resource_base &r) {
153 m_l->call(3, 1); 158 m_l->call(3, 1);
154 *static_cast<Resource_base **>(m_l->touserdata(-1)) = NULL; 159 *static_cast<Resource_base **>(m_l->touserdata(-1)) = NULL;
155 m_l->pop(); 160 m_l->pop();
161}
156 162
157 ResourceManager_base::removeResource(r); 163void LResourceManager::setLua(Lua &l) {
164 l.checkstack(2);
165 lua::stack_sentry s(l);
166
167 for(ResourceList::const_iterator i = begin(); i != end(); ++i)
168 doRemoveResource(**i);
169
170 l.getfield(lua::REGISTRYINDEX, make_root);
171 l.pushstring(m_root);
172 l.call(1, 1);
173
174 l.readOnlySetField(lua::GLOBALSINDEX, m_root.c_str());
175
176 m_l = &l;
177
178 for(ResourceList::const_iterator i = begin(); i != end(); ++i)
179 doAddResource(**i);
158} 180}
159 181
160} // end namespace FbTk 182} // end namespace FbTk
diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh
index 1567269..bb7f224 100644
--- a/src/FbTk/LResource.hh
+++ b/src/FbTk/LResource.hh
@@ -41,8 +41,11 @@ public:
41 virtual bool save(const char *filename, const char *); 41 virtual bool save(const char *filename, const char *);
42 virtual void addResource(Resource_base &r); 42 virtual void addResource(Resource_base &r);
43 virtual void removeResource(Resource_base &r); 43 virtual void removeResource(Resource_base &r);
44 void setLua(Lua &l);
44 45
45private: 46private:
47 void doAddResource(Resource_base &r);
48 void doRemoveResource(Resource_base &r);
46 49
47 Lua *m_l; 50 Lua *m_l;
48}; 51};
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 8b5d11f..c4e6559 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -303,7 +303,7 @@ Fluxbox::Fluxbox(int argc, char **argv,
303 // Because when the command is executed we shouldn't do reconfig directly 303 // Because when the command is executed we shouldn't do reconfig directly
304 // because it could affect ongoing menu stuff so we need to reconfig in 304 // because it could affect ongoing menu stuff so we need to reconfig in
305 // the next event "round". 305 // the next event "round".
306 FbTk::RefCount<FbTk::Command<void> > reconfig_cmd(new FbTk::SimpleCommand<Fluxbox>(*this, &Fluxbox::timed_reconfigure)); 306 FbTk::RefCount<FbTk::Command<void> > reconfig_cmd(new FbTk::SimpleCommand<Fluxbox>(*this, &Fluxbox::reconfigure));
307 m_reconfig_timer.setTimeout(0, 1); 307 m_reconfig_timer.setTimeout(0, 1);
308 m_reconfig_timer.setCommand(reconfig_cmd); 308 m_reconfig_timer.setCommand(reconfig_cmd);
309 m_reconfig_timer.fireOnce(true); 309 m_reconfig_timer.fireOnce(true);
@@ -435,8 +435,6 @@ Fluxbox::Fluxbox(int argc, char **argv,
435 //XSynchronize(disp, False); 435 //XSynchronize(disp, False);
436 sync(false); 436 sync(false);
437 437
438 m_reconfigure_wait = false;
439
440 ungrab(); 438 ungrab();
441 439
442 m_starting = false; 440 m_starting = false;
@@ -896,7 +894,7 @@ void Fluxbox::handleSignal(int signum) {
896 load_rc(); 894 load_rc();
897 break; 895 break;
898 case SIGUSR2: 896 case SIGUSR2:
899 reconfigure(); 897 m_reconfig_timer.start();
900 break; 898 break;
901#endif 899#endif
902 case SIGSEGV: 900 case SIGSEGV:
@@ -1181,17 +1179,6 @@ void Fluxbox::load_rc() {
1181 *m_rc_stylefile = DEFAULTSTYLE; 1179 *m_rc_stylefile = DEFAULTSTYLE;
1182} 1180}
1183 1181
1184void Fluxbox::reconfigure() {
1185 load_rc();
1186 m_reconfigure_wait = true;
1187 m_reconfig_timer.start();
1188}
1189
1190
1191void Fluxbox::real_reconfigure() {
1192 STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure));
1193}
1194
1195BScreen *Fluxbox::findScreen(int id) { 1182BScreen *Fluxbox::findScreen(int id) {
1196 1183
1197 BScreen* result = 0; 1184 BScreen* result = 0;
@@ -1204,11 +1191,12 @@ BScreen *Fluxbox::findScreen(int id) {
1204 return result; 1191 return result;
1205} 1192}
1206 1193
1207void Fluxbox::timed_reconfigure() { 1194void Fluxbox::reconfigure() {
1208 if (m_reconfigure_wait) 1195 std::auto_ptr<FbTk::Lua> t = m_l;
1209 real_reconfigure(); 1196 m_l.reset(new Lua);
1210 1197 m_resourcemanager.setLua(*m_l);
1211 m_reconfigure_wait = false; 1198 load_rc();
1199 STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure));
1212} 1200}
1213 1201
1214void Fluxbox::revertFocus() { 1202void Fluxbox::revertFocus() {
diff --git a/src/fluxbox.hh b/src/fluxbox.hh
index 6be5253..00a2e7d 100644
--- a/src/fluxbox.hh
+++ b/src/fluxbox.hh
@@ -159,7 +159,6 @@ public:
159 void attachSignals(FluxboxWindow &win); 159 void attachSignals(FluxboxWindow &win);
160 void attachSignals(WinClient &winclient); 160 void attachSignals(WinClient &winclient);
161 161
162 void timed_reconfigure();
163 void revertFocus(); 162 void revertFocus();
164 void setShowingDialog(bool value) { 163 void setShowingDialog(bool value) {
165 m_showing_dialog = value; if (!value) revertFocus(); 164 m_showing_dialog = value; if (!value) revertFocus();
@@ -193,8 +192,6 @@ private:
193 std::string getRcFilename(); 192 std::string getRcFilename();
194 void load_rc(); 193 void load_rc();
195 194
196 void real_reconfigure();
197
198 void handleEvent(XEvent *xe); 195 void handleEvent(XEvent *xe);
199 196
200 void handleUnmapNotify(XUnmapEvent &ue); 197 void handleUnmapNotify(XUnmapEvent &ue);
@@ -273,7 +270,6 @@ private:
273 270
274 Atom m_fluxbox_pid; 271 Atom m_fluxbox_pid;
275 272
276 bool m_reconfigure_wait;
277 Time m_last_time; 273 Time m_last_time;
278 Window m_masked; 274 Window m_masked;
279 std::string m_rc_file; ///< resource filename 275 std::string m_rc_file; ///< resource filename