aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent0f6b73f36abb1fd31893ef16413f010e78ed84ab (diff)
downloadfluxbox-8e96ffb74b98b08ac35dcd1c861421c65a55cbe6.zip
fluxbox-8e96ffb74b98b08ac35dcd1c861421c65a55cbe6.tar.bz2
moved DelayedCmd from Screen.cc to FbTk/Timer.cc, added it to the keys file
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/StringUtil.hh8
-rw-r--r--src/FbTk/Timer.cc38
-rw-r--r--src/FbTk/Timer.hh16
-rw-r--r--src/Screen.cc24
4 files changed, 59 insertions, 27 deletions
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index bca48bc..416db0d 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -26,6 +26,8 @@
26 26
27#include <string> 27#include <string>
28 28
29#include "stringstream.hh"
30
29namespace FbTk { 31namespace FbTk {
30 32
31namespace StringUtil { 33namespace StringUtil {
@@ -67,6 +69,12 @@ std::string::size_type removeTrailingWhitespace(std::string &str);
67/// splits input at first non-leading whitespace and returns both parts 69/// splits input at first non-leading whitespace and returns both parts
68void getFirstWord(const std::string &in, std::string &first, std::string &rest); 70void getFirstWord(const std::string &in, std::string &first, std::string &rest);
69 71
72template <typename T>
73void fromString(const char *in, T &out) {
74 FbTk_istringstream iss(in);
75 iss >> out;
76}
77
70template <typename Container> 78template <typename Container>
71static void stringTokensBetween(Container &container, const std::string &in, 79static void stringTokensBetween(Container &container, const std::string &in,
72 std::string &rest, char first, char last, 80 std::string &rest, char first, char last,
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);
diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh
index bd55435..4b5be95 100644
--- a/src/FbTk/Timer.hh
+++ b/src/FbTk/Timer.hh
@@ -26,6 +26,7 @@
26#define FBTK_TIMER_HH 26#define FBTK_TIMER_HH
27 27
28#include "RefCount.hh" 28#include "RefCount.hh"
29#include "Command.hh"
29 30
30#ifdef HAVE_CTIME 31#ifdef HAVE_CTIME
31 #include <ctime> 32 #include <ctime>
@@ -33,6 +34,7 @@
33 #include <time.h> 34 #include <time.h>
34#endif 35#endif
35#include <list> 36#include <list>
37#include <string>
36 38
37#ifdef HAVE_CONFIG_H 39#ifdef HAVE_CONFIG_H
38#include "config.h" 40#include "config.h"
@@ -49,8 +51,6 @@
49 51
50namespace FbTk { 52namespace FbTk {
51 53
52class Command;
53
54/** 54/**
55 Handles Timeout 55 Handles Timeout
56*/ 56*/
@@ -107,7 +107,17 @@ private:
107 timeval m_timeout; ///< time length 107 timeval m_timeout; ///< time length
108}; 108};
109 109
110/// executes a command after a specified timeout
111class DelayedCmd: public Command {
112public:
113 DelayedCmd(RefCount<Command> &cmd, unsigned int timeout = 200000);
114 void execute();
115 static Command *parse(const std::string &command,
116 const std::string &args, bool trusted);
117private:
118 Timer m_timer;
119};
120
110} // end namespace FbTk 121} // end namespace FbTk
111 122
112#endif // FBTK_TIMER_HH 123#endif // FBTK_TIMER_HH
113
diff --git a/src/Screen.cc b/src/Screen.cc
index a09f4d1..2d214eb 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -196,28 +196,6 @@ private:
196 FbWinFrame::TabPlacement m_place; 196 FbWinFrame::TabPlacement m_place;
197}; 197};
198 198
199// this might be useful elsewhere, but I'll leave it here for now
200class DelayedCmd: public FbTk::Command {
201public:
202 DelayedCmd(FbTk::RefCount<FbTk::Command> &cmd) {
203 timeval to;
204 to.tv_sec = 0;
205 to.tv_usec = 500000; // 1/2 second
206 m_timer.setTimeout(to);
207 m_timer.setCommand(cmd);
208 m_timer.fireOnce(true);
209 }
210 void execute() {
211 // if it's already started, restart it; otherwise, just start it
212 // we want this to execute 1/2 second after the last click
213 if (m_timer.isTiming())
214 m_timer.stop();
215 m_timer.start();
216 }
217private:
218 FbTk::Timer m_timer;
219};
220
221} // end anonymous namespace 199} // end anonymous namespace
222 200
223 201
@@ -1724,7 +1702,7 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
1724 // in order to save system resources, don't save or reconfigure alpha 1702 // in order to save system resources, don't save or reconfigure alpha
1725 // settings until after the user is done changing them 1703 // settings until after the user is done changing them
1726 FbTk::RefCount<FbTk::Command> delayed_save_and_reconf( 1704 FbTk::RefCount<FbTk::Command> delayed_save_and_reconf(
1727 new ::DelayedCmd(save_and_reconfigure)); 1705 new FbTk::DelayedCmd(save_and_reconfigure));
1728 1706
1729 FbTk::MenuItem *focused_alpha_item = 1707 FbTk::MenuItem *focused_alpha_item =
1730 new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha, 1708 new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha,