aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Timer.cc
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2007-12-28 09:19:33 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2007-12-28 09:19:33 (GMT)
commit8e96ffb74b98b08ac35dcd1c861421c65a55cbe6 (patch)
tree6c2da67d383d126892708ced362b569af9178db4 /src/FbTk/Timer.cc
parent0f6b73f36abb1fd31893ef16413f010e78ed84ab (diff)
downloadfluxbox_pavel-8e96ffb74b98b08ac35dcd1c861421c65a55cbe6.zip
fluxbox_pavel-8e96ffb74b98b08ac35dcd1c861421c65a55cbe6.tar.bz2
moved DelayedCmd from Screen.cc to FbTk/Timer.cc, added it to the keys file
Diffstat (limited to 'src/FbTk/Timer.cc')
-rw-r--r--src/FbTk/Timer.cc38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc
index 9492ac6..ff568dc 100644
--- a/src/FbTk/Timer.cc
+++ b/src/FbTk/Timer.cc
@@ -24,7 +24,8 @@
24 24
25#include "Timer.hh" 25#include "Timer.hh"
26 26
27#include "Command.hh" 27#include "ObjectRegistry.hh"
28#include "StringUtil.hh"
28 29
29//use GNU extensions 30//use GNU extensions
30#ifndef _GNU_SOURCE 31#ifndef _GNU_SOURCE
@@ -246,6 +247,41 @@ void Timer::addTimer(Timer *timer) {
246 247
247} 248}
248 249
250Command *DelayedCmd::parse(const std::string &command,
251 const std::string &args, bool trusted) {
252
253 std::string cmd_str;
254 int err = StringUtil::getStringBetween(cmd_str, args.c_str(), '{', '}');
255 if (err == 0)
256 return 0;
257
258 RefCount<Command> cmd(ObjectRegistry<Command>::instance().parse(cmd_str, trusted));
259 if (*cmd == 0)
260 return 0;
261
262 int delay = 200000;
263 StringUtil::fromString<int>(args.c_str() + err, delay);
264
265 return new DelayedCmd(cmd, delay);
266}
267
268REGISTER_OBJECT_PARSER(delay, DelayedCmd::parse, Command);
269
270DelayedCmd::DelayedCmd(RefCount<Command> &cmd, unsigned int timeout) {
271 timeval to; // defaults to 200ms
272 to.tv_sec = timeout/1000000;
273 to.tv_usec = timeout % 1000000;
274 m_timer.setTimeout(to);
275 m_timer.setCommand(cmd);
276 m_timer.fireOnce(true);
277}
278
279void DelayedCmd::execute() {
280 if (m_timer.isTiming())
281 m_timer.stop();
282 m_timer.start();
283}
284
249void Timer::removeTimer(Timer *timer) { 285void Timer::removeTimer(Timer *timer) {
250 assert(timer); 286 assert(timer);
251 m_timerlist.remove(timer); 287 m_timerlist.remove(timer);