aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-08-02 10:08:58 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-09-14 17:39:11 (GMT)
commite67b9a6f833fd8af3be105ef411f8743d94e25d9 (patch)
tree980d080d476436708eb0a72a084bcad1c9cbdefd /src/FbTk
parentae252c62cb2714dc3d7f1fbdfa81e19cee3828fd (diff)
downloadfluxbox_paul-e67b9a6f833fd8af3be105ef411f8743d94e25d9.zip
fluxbox_paul-e67b9a6f833fd8af3be105ef411f8743d94e25d9.tar.bz2
Upgrade FbTk::Timer so it can take an arbitrary functor as a parameter
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Timer.cc8
-rw-r--r--src/FbTk/Timer.hh14
2 files changed, 20 insertions, 2 deletions
diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc
index 13bfc05..9b3fe8c 100644
--- a/src/FbTk/Timer.cc
+++ b/src/FbTk/Timer.cc
@@ -285,11 +285,15 @@ Command<void> *DelayedCmd::parse(const std::string &command,
285REGISTER_COMMAND_PARSER(delay, DelayedCmd::parse, void); 285REGISTER_COMMAND_PARSER(delay, DelayedCmd::parse, void);
286 286
287DelayedCmd::DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout) { 287DelayedCmd::DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout) {
288 timeval to; // defaults to 200ms 288 initTimer(timeout);
289 m_timer.setCommand(cmd);
290}
291
292void DelayedCmd::initTimer(unsigned int timeout) {
293 timeval to;
289 to.tv_sec = timeout/1000000; 294 to.tv_sec = timeout/1000000;
290 to.tv_usec = timeout % 1000000; 295 to.tv_usec = timeout % 1000000;
291 m_timer.setTimeout(to); 296 m_timer.setTimeout(to);
292 m_timer.setCommand(cmd);
293 m_timer.fireOnce(true); 297 m_timer.fireOnce(true);
294} 298}
295 299
diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh
index 4b5a10e..376eac0 100644
--- a/src/FbTk/Timer.hh
+++ b/src/FbTk/Timer.hh
@@ -66,6 +66,9 @@ public:
66 void setTimeout(const timeval &val); 66 void setTimeout(const timeval &val);
67 void setTimeout(unsigned int secs, unsigned int usecs); 67 void setTimeout(unsigned int secs, unsigned int usecs);
68 void setCommand(const RefCount<Slot<void> > &cmd); 68 void setCommand(const RefCount<Slot<void> > &cmd);
69 template<typename Functor>
70 void setFunctor(const Functor &functor)
71 { setCommand(RefCount<Slot<void> >(new SlotImpl<Functor, void>(functor))); }
69 void setInterval(int val) { m_interval = val; } 72 void setInterval(int val) { m_interval = val; }
70 /// start timing 73 /// start timing
71 void start(); 74 void start();
@@ -111,10 +114,21 @@ private:
111class DelayedCmd: public Command<void> { 114class DelayedCmd: public Command<void> {
112public: 115public:
113 DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout = 200000); 116 DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout = 200000);
117
118 // this constructor has inverted order of parameters to avoid ambiguity with the previous
119 // constructor
120 template<typename Functor>
121 DelayedCmd(unsigned int timeout, const Functor &functor) {
122 initTimer(timeout);
123 m_timer.setFunctor(functor);
124 }
125
114 void execute(); 126 void execute();
115 static Command<void> *parse(const std::string &command, 127 static Command<void> *parse(const std::string &command,
116 const std::string &args, bool trusted); 128 const std::string &args, bool trusted);
117private: 129private:
130 void initTimer(unsigned int timeout);
131
118 Timer m_timer; 132 Timer m_timer;
119}; 133};
120 134