moved DelayedCmd from Screen.cc to FbTk/Timer.cc, added it to the keys file
This commit is contained in:
parent
0f6b73f36a
commit
8e96ffb74b
5 changed files with 63 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "stringstream.hh"
|
||||
|
||||
namespace FbTk {
|
||||
|
||||
namespace StringUtil {
|
||||
|
@ -67,6 +69,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,
|
||||
std::string &rest, char first, char last,
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
#include "Timer.hh"
|
||||
|
||||
#include "Command.hh"
|
||||
#include "ObjectRegistry.hh"
|
||||
#include "StringUtil.hh"
|
||||
|
||||
//use GNU extensions
|
||||
#ifndef _GNU_SOURCE
|
||||
|
@ -246,6 +247,41 @@ void Timer::addTimer(Timer *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) {
|
||||
assert(timer);
|
||||
m_timerlist.remove(timer);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define FBTK_TIMER_HH
|
||||
|
||||
#include "RefCount.hh"
|
||||
#include "Command.hh"
|
||||
|
||||
#ifdef HAVE_CTIME
|
||||
#include <ctime>
|
||||
|
@ -33,6 +34,7 @@
|
|||
#include <time.h>
|
||||
#endif
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
|
@ -49,8 +51,6 @@
|
|||
|
||||
namespace FbTk {
|
||||
|
||||
class Command;
|
||||
|
||||
/**
|
||||
Handles Timeout
|
||||
*/
|
||||
|
@ -107,7 +107,17 @@ private:
|
|||
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
|
||||
|
||||
|
|
|
@ -196,28 +196,6 @@ private:
|
|||
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 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) {
|
|||
// 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,
|
||||
|
|
Loading…
Reference in a new issue