aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-08-09 08:25:28 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-08-09 08:28:31 (GMT)
commit75c2d19358daba345d9e298c78041eea4a8f2116 (patch)
tree2e994f7fec2377150198fed4c40930a5459126ee
parent2741ca1fceda384500e1c5b6781c167353b19092 (diff)
downloadfluxbox_pavel-75c2d19358daba345d9e298c78041eea4a8f2116.zip
fluxbox_pavel-75c2d19358daba345d9e298c78041eea4a8f2116.tar.bz2
Make AutoReloadHelper truly "automatic"
by adding the ability to automatically check for modifications at specified intervals. Using inotify() would be better, but that's not always present.
-rw-r--r--src/FbTk/AutoReloadHelper.cc8
-rw-r--r--src/FbTk/AutoReloadHelper.hh8
-rw-r--r--src/Keys.cc2
3 files changed, 16 insertions, 2 deletions
diff --git a/src/FbTk/AutoReloadHelper.cc b/src/FbTk/AutoReloadHelper.cc
index 17124d4..a9f2f5c 100644
--- a/src/FbTk/AutoReloadHelper.cc
+++ b/src/FbTk/AutoReloadHelper.cc
@@ -22,10 +22,18 @@
22#include "AutoReloadHelper.hh" 22#include "AutoReloadHelper.hh"
23 23
24#include "FileUtil.hh" 24#include "FileUtil.hh"
25#include "MemFun.hh"
25#include "StringUtil.hh" 26#include "StringUtil.hh"
26 27
27namespace FbTk { 28namespace FbTk {
28 29
30AutoReloadHelper::AutoReloadHelper(int interval) {
31 m_timer.setFunctor(MemFun(*this, &AutoReloadHelper::checkReload));
32 m_timer.setInterval(interval);
33 if(interval > 0)
34 m_timer.start();
35}
36
29void AutoReloadHelper::checkReload() { 37void AutoReloadHelper::checkReload() {
30 if (!m_reload_cmd.get()) 38 if (!m_reload_cmd.get())
31 return; 39 return;
diff --git a/src/FbTk/AutoReloadHelper.hh b/src/FbTk/AutoReloadHelper.hh
index b337a4a..216b3f5 100644
--- a/src/FbTk/AutoReloadHelper.hh
+++ b/src/FbTk/AutoReloadHelper.hh
@@ -28,11 +28,16 @@
28 28
29#include "Command.hh" 29#include "Command.hh"
30#include "RefCount.hh" 30#include "RefCount.hh"
31#include "Timer.hh"
31 32
32namespace FbTk { 33namespace FbTk {
33 34
34class AutoReloadHelper { 35class AutoReloadHelper: private NotCopyable {
35public: 36public:
37 /**
38 * @param interval time interval (in seconds) between automatic reload checks
39 */
40 AutoReloadHelper(int interval = 0);
36 41
37 void setMainFile(const std::string& filename); 42 void setMainFile(const std::string& filename);
38 void addFile(const std::string& filename); 43 void addFile(const std::string& filename);
@@ -44,6 +49,7 @@ public:
44private: 49private:
45 RefCount<Command<void> > m_reload_cmd; 50 RefCount<Command<void> > m_reload_cmd;
46 std::string m_main_file; 51 std::string m_main_file;
52 Timer m_timer;
47 53
48 typedef std::map<std::string, time_t> TimestampMap; 54 typedef std::map<std::string, time_t> TimestampMap;
49 TimestampMap m_timestamps; 55 TimestampMap m_timestamps;
diff --git a/src/Keys.cc b/src/Keys.cc
index 14a5d0f..a9a5ad2 100644
--- a/src/Keys.cc
+++ b/src/Keys.cc
@@ -459,7 +459,7 @@ Keys::t_key::FindPair Keys::t_key::findBinding(vector<string> val, bool insert )
459 459
460 460
461Keys::Keys(): 461Keys::Keys():
462 m_reloader(new FbTk::AutoReloadHelper()), 462 m_reloader(new FbTk::AutoReloadHelper(5)),
463 m_keylist(0), 463 m_keylist(0),
464 next_key(0), saved_keymode(0) { 464 next_key(0), saved_keymode(0) {
465 465