diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-30 10:21:53 (GMT) |
---|---|---|
committer | Paul Tagliamonte <paultag@fluxbox.org> | 2012-04-07 02:12:16 (GMT) |
commit | f614d641a4abb2b1926c7327a3242cd95e1fcfdc (patch) | |
tree | bfa0e93d167140c0ec30f6ccf1d67e5b5e9c5b1e /src | |
parent | 6cf46efc6ae4415833e54a795ff630c9faf4b9ce (diff) | |
download | fluxbox_paul-f614d641a4abb2b1926c7327a3242cd95e1fcfdc.zip fluxbox_paul-f614d641a4abb2b1926c7327a3242cd95e1fcfdc.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.cc | 52 | ||||
-rw-r--r-- | src/FbTk/LResource.hh | 3 | ||||
-rw-r--r-- | src/fluxbox.cc | 17 | ||||
-rw-r--r-- | src/fluxbox.hh | 4 |
4 files changed, 48 insertions, 28 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 | ||
103 | LResourceManager::LResourceManager(const std::string &root, Lua &l) | 103 | LResourceManager::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 | ||
117 | bool LResourceManager::save(const char *filename, const char *) { | 108 | bool LResourceManager::save(const char *filename, const char *) { |
@@ -127,11 +118,20 @@ bool LResourceManager::save(const char *filename, const char *) { | |||
127 | } | 118 | } |
128 | 119 | ||
129 | void LResourceManager::addResource(Resource_base &r) { | 120 | void 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 | |||
131 | void 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 | ||
145 | void LResourceManager::removeResource(Resource_base &r) { | 145 | void LResourceManager::removeResource(Resource_base &r) { |
146 | m_l->checkstack(5); | 146 | doRemoveResource(r); |
147 | ResourceManager_base::removeResource(r); | ||
148 | } | ||
149 | |||
150 | void 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); | 163 | void 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 | ||
45 | private: | 46 | private: |
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 4692a1f..224c7f0 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: |
@@ -1248,11 +1246,12 @@ BScreen *Fluxbox::findScreen(int id) { | |||
1248 | return result; | 1246 | return result; |
1249 | } | 1247 | } |
1250 | 1248 | ||
1251 | void Fluxbox::timed_reconfigure() { | 1249 | void Fluxbox::reconfigure() { |
1252 | if (m_reconfigure_wait) | 1250 | std::auto_ptr<FbTk::Lua> t = m_l; |
1253 | real_reconfigure(); | 1251 | m_l.reset(new Lua); |
1254 | 1252 | m_resourcemanager.setLua(*m_l); | |
1255 | m_reconfigure_wait = false; | 1253 | load_rc(); |
1254 | STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); | ||
1256 | } | 1255 | } |
1257 | 1256 | ||
1258 | void Fluxbox::revertFocus() { | 1257 | void 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 |