aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2007-12-20 20:23:56 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2007-12-20 20:23:56 (GMT)
commit03dce043b78103a977bd6c48b81bb1b462aaac5f (patch)
tree6cc49956acf8c4049f7d6702058534d29c1c15c2 /src
parentb90a7e21a9f56f8e9f92c7ec357cbf683e6fd712 (diff)
downloadfluxbox-03dce043b78103a977bd6c48b81bb1b462aaac5f.zip
fluxbox-03dce043b78103a977bd6c48b81bb1b462aaac5f.tar.bz2
added ForEach key command
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/StringUtil.hh21
-rw-r--r--src/FocusableList.cc5
-rw-r--r--src/WorkspaceCmd.cc47
-rw-r--r--src/WorkspaceCmd.hh10
4 files changed, 69 insertions, 14 deletions
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index d3c131e..bca48bc 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -67,6 +67,27 @@ std::string::size_type removeTrailingWhitespace(std::string &str);
67/// splits input at first non-leading whitespace and returns both parts 67/// splits input at first non-leading whitespace and returns both parts
68void getFirstWord(const std::string &in, std::string &first, std::string &rest); 68void getFirstWord(const std::string &in, std::string &first, std::string &rest);
69 69
70template <typename Container>
71static void stringTokensBetween(Container &container, const std::string &in,
72 std::string &rest, char first, char last,
73 const char *ok_chars = " \t\n", bool allow_nesting = true) {
74
75 std::string token;
76 int err = 0, pos = 0;
77
78 while (true) {
79 err = getStringBetween(token, in.c_str() + pos, first, last, ok_chars,
80 allow_nesting);
81 if (err == 0)
82 break;
83 container.push_back(token);
84 pos += err;
85 }
86
87 rest = in.c_str() + pos;
88
89}
90
70/// Breaks a string into tokens 91/// Breaks a string into tokens
71template <typename Container> 92template <typename Container>
72static void 93static void
diff --git a/src/FocusableList.cc b/src/FocusableList.cc
index 8c43181..366ef8a 100644
--- a/src/FocusableList.cc
+++ b/src/FocusableList.cc
@@ -38,10 +38,11 @@ using std::vector;
38 38
39void FocusableList::parseArgs(const string &in, int &opts, string &pat) { 39void FocusableList::parseArgs(const string &in, int &opts, string &pat) {
40 string options; 40 string options;
41 int err = FbTk::StringUtil::getStringBetween(options, in.c_str(), '{', '}'); 41 int err = FbTk::StringUtil::getStringBetween(options, in.c_str(), '{', '}',
42 " \t\n");
42 43
43 // the rest of the string is a ClientPattern 44 // the rest of the string is a ClientPattern
44 pat = in.c_str() + err; 45 pat = in.c_str() + (err > 0 ? err : 0);
45 46
46 // now parse the options 47 // now parse the options
47 vector<string> args; 48 vector<string> args;
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index 2d2964e..bb1537e 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -35,6 +35,7 @@
35#include "FbTk/KeyUtil.hh" 35#include "FbTk/KeyUtil.hh"
36#include "FbTk/ObjectRegistry.hh" 36#include "FbTk/ObjectRegistry.hh"
37#include "FbTk/stringstream.hh" 37#include "FbTk/stringstream.hh"
38#include "FbTk/StringUtil.hh"
38 39
39#ifdef HAVE_CMATH 40#ifdef HAVE_CMATH
40 #include <cmath> 41 #include <cmath>
@@ -43,30 +44,58 @@
43#endif 44#endif
44#include <algorithm> 45#include <algorithm>
45#include <functional> 46#include <functional>
47#include <vector>
46 48
47using std::string; 49using std::string;
48using FbTk::Command; 50using FbTk::Command;
49using FbTk::BoolCommand; 51using FbTk::BoolCommand;
50 52
51void WindowListCmd::execute() { 53REGISTER_OBJECT_PARSER(map, WindowListCmd::parse, Command);
52 if (m_pat.error()) { 54REGISTER_OBJECT_PARSER(foreach, WindowListCmd::parse, Command);
53 m_cmd->execute(); 55
54 return; 56FbTk::Command *WindowListCmd::parse(const string &command, const string &args,
57 bool trusted) {
58 FbTk::Command *cmd = 0;
59 FbTk::BoolCommand *filter = 0;
60 std::vector<string> tokens;
61 int opts;
62 string pat;
63
64 FbTk::StringUtil::stringTokensBetween(tokens, args, pat, '{', '}');
65 if (tokens.empty())
66 return 0;
67
68 cmd = FbTk::ObjectRegistry<Command>::instance().parse(tokens[0], trusted);
69 if (!cmd)
70 return 0;
71
72 if (tokens.size() > 1) {
73 FocusableList::parseArgs(tokens[1], opts, pat);
74
75 filter = FbTk::ObjectRegistry<BoolCommand>::instance().parse(pat,
76 trusted);
55 } 77 }
56 78
79 return new WindowListCmd(FbTk::RefCount<Command>(cmd), opts,
80 FbTk::RefCount<BoolCommand>(filter));
81}
82
83void WindowListCmd::execute() {
57 BScreen *screen = Fluxbox::instance()->keyScreen(); 84 BScreen *screen = Fluxbox::instance()->keyScreen();
58 if (screen != 0) { 85 if (screen != 0) {
59 FocusControl::Focusables win_list(screen->focusControl().creationOrderWinList().clientList()); 86 FocusableList::Focusables win_list(FocusableList::getListFromOptions(*screen, m_opts)->clientList());
60 87
61 FocusControl::Focusables::iterator it = win_list.begin(), 88 FocusableList::Focusables::iterator it = win_list.begin(),
62 it_end = win_list.end(); 89 it_end = win_list.end();
63 // save old value, so we can restore it later 90 // save old value, so we can restore it later
64 WinClient *old = WindowCmd<void>::client(); 91 WinClient *old = WindowCmd<void>::client();
65 for (; it != it_end; ++it) { 92 for (; it != it_end; ++it) {
66 if (m_pat.match(**it) && (*it)->fbwindow()) { 93 if (typeid(**it) == typeid(FluxboxWindow))
67 WindowCmd<void>::setWindow((*it)->fbwindow()); 94 WindowCmd<void>::setWindow((*it)->fbwindow());
95 else if (typeid(**it) == typeid(WinClient))
96 WindowCmd<void>::setClient(dynamic_cast<WinClient *>(*it));
97 if (!*m_filter || m_filter->bool_execute())
68 m_cmd->execute(); 98 m_cmd->execute();
69 }
70 } 99 }
71 WindowCmd<void>::setClient(old); 100 WindowCmd<void>::setClient(old);
72 } 101 }
diff --git a/src/WorkspaceCmd.hh b/src/WorkspaceCmd.hh
index fa8cb58..13adec3 100644
--- a/src/WorkspaceCmd.hh
+++ b/src/WorkspaceCmd.hh
@@ -36,14 +36,18 @@
36 36
37class WindowListCmd: public FbTk::Command { 37class WindowListCmd: public FbTk::Command {
38public: 38public:
39 WindowListCmd(FbTk::RefCount<FbTk::Command> cmd, const std::string &pat): 39 WindowListCmd(FbTk::RefCount<FbTk::Command> cmd, int opts,
40 m_cmd(cmd), m_pat(pat.c_str()) { } 40 FbTk::RefCount<FbTk::BoolCommand> filter):
41 m_cmd(cmd), m_opts(opts), m_filter(filter) { }
41 42
42 void execute(); 43 void execute();
44 static FbTk::Command *parse(const std::string &command,
45 const std::string &args, bool trusted);
43 46
44private: 47private:
45 FbTk::RefCount<FbTk::Command> m_cmd; 48 FbTk::RefCount<FbTk::Command> m_cmd;
46 ClientPattern m_pat; 49 int m_opts;
50 FbTk::RefCount<FbTk::BoolCommand> m_filter;
47}; 51};
48 52
49class SomeCmd: public FbTk::BoolCommand { 53class SomeCmd: public FbTk::BoolCommand {