all repos — fluxbox @ 8e96ffb74b98b08ac35dcd1c861421c65a55cbe6

custom fork of the fluxbox windowmanager

moved DelayedCmd from Screen.cc to FbTk/Timer.cc, added it to the keys file
Mark Tiefenbruck mark@fluxbox.org
commit

8e96ffb74b98b08ac35dcd1c861421c65a55cbe6

parent

0f6b73f36abb1fd31893ef16413f010e78ed84ab

5 files changed, 63 insertions(+), 27 deletions(-)

jump to
M ChangeLogChangeLog

@@ -1,5 +1,9 @@

(Format: Year/Month/Day) Changes for 1.0.1: +*07/12/28: + * Added new key command :Delay {<command>} [<int>], which runs the command + after a delay of <int> microseconds (default is 200 milliseconds) (Mark) + FbTk/Timer.cc/hh *07/12/25: * Updated german translations for maximization menu (thanks Christian Loosli) nls/de_*/Translation.m
M src/FbTk/StringUtil.hhsrc/FbTk/StringUtil.hh

@@ -26,6 +26,8 @@ #define FBTK_STRINGUTIL_HH

#include <string> +#include "stringstream.hh" + namespace FbTk { namespace StringUtil {

@@ -66,6 +68,12 @@ std::string::size_type removeTrailingWhitespace(std::string &str);

/// splits input at first non-leading whitespace and returns both parts void getFirstWord(const std::string &in, std::string &first, std::string &rest); + +template <typename T> +void fromString(const char *in, T &out) { + FbTk_istringstream iss(in); + iss >> out; +} template <typename Container> static void stringTokensBetween(Container &container, const std::string &in,
M src/FbTk/Timer.ccsrc/FbTk/Timer.cc

@@ -24,7 +24,8 @@ // DEALINGS IN THE SOFTWARE.

#include "Timer.hh" -#include "Command.hh" +#include "ObjectRegistry.hh" +#include "StringUtil.hh" //use GNU extensions #ifndef _GNU_SOURCE

@@ -244,6 +245,41 @@ }

} m_timerlist.insert(it, timer); +} + +Command *DelayedCmd::parse(const std::string &command, + const std::string &args, bool trusted) { + + std::string cmd_str; + int err = StringUtil::getStringBetween(cmd_str, args.c_str(), '{', '}'); + if (err == 0) + return 0; + + RefCount<Command> cmd(ObjectRegistry<Command>::instance().parse(cmd_str, trusted)); + if (*cmd == 0) + return 0; + + int delay = 200000; + StringUtil::fromString<int>(args.c_str() + err, delay); + + return new DelayedCmd(cmd, delay); +} + +REGISTER_OBJECT_PARSER(delay, DelayedCmd::parse, Command); + +DelayedCmd::DelayedCmd(RefCount<Command> &cmd, unsigned int timeout) { + timeval to; // defaults to 200ms + to.tv_sec = timeout/1000000; + to.tv_usec = timeout % 1000000; + m_timer.setTimeout(to); + m_timer.setCommand(cmd); + m_timer.fireOnce(true); +} + +void DelayedCmd::execute() { + if (m_timer.isTiming()) + m_timer.stop(); + m_timer.start(); } void Timer::removeTimer(Timer *timer) {
M src/FbTk/Timer.hhsrc/FbTk/Timer.hh

@@ -26,6 +26,7 @@ #ifndef FBTK_TIMER_HH

#define FBTK_TIMER_HH #include "RefCount.hh" +#include "Command.hh" #ifdef HAVE_CTIME #include <ctime>

@@ -33,6 +34,7 @@ #else

#include <time.h> #endif #include <list> +#include <string> #ifdef HAVE_CONFIG_H #include "config.h"

@@ -48,8 +50,6 @@ #include <sys/time.h>

#include <unistd.h> namespace FbTk { - -class Command; /** Handles Timeout

@@ -107,7 +107,17 @@ timeval m_start; ///< start time

timeval m_timeout; ///< time length }; +/// executes a command after a specified timeout +class DelayedCmd: public Command { +public: + DelayedCmd(RefCount<Command> &cmd, unsigned int timeout = 200000); + void execute(); + static Command *parse(const std::string &command, + const std::string &args, bool trusted); +private: + Timer m_timer; +}; + } // end namespace FbTk #endif // FBTK_TIMER_HH -
M src/Screen.ccsrc/Screen.cc

@@ -196,28 +196,6 @@ BScreen &m_screen;

FbWinFrame::TabPlacement m_place; }; -// this might be useful elsewhere, but I'll leave it here for now -class DelayedCmd: public FbTk::Command { -public: - DelayedCmd(FbTk::RefCount<FbTk::Command> &cmd) { - timeval to; - to.tv_sec = 0; - to.tv_usec = 500000; // 1/2 second - m_timer.setTimeout(to); - m_timer.setCommand(cmd); - m_timer.fireOnce(true); - } - void execute() { - // if it's already started, restart it; otherwise, just start it - // we want this to execute 1/2 second after the last click - if (m_timer.isTiming()) - m_timer.stop(); - m_timer.start(); - } -private: - FbTk::Timer m_timer; -}; - } // end anonymous namespace

@@ -1724,7 +1702,7 @@

// in order to save system resources, don't save or reconfigure alpha // settings until after the user is done changing them FbTk::RefCount<FbTk::Command> delayed_save_and_reconf( - new ::DelayedCmd(save_and_reconfigure)); + new FbTk::DelayedCmd(save_and_reconfigure)); FbTk::MenuItem *focused_alpha_item = new FbTk::IntMenuItem(_FB_XTEXT(Configmenu, FocusedAlpha,