summaryrefslogtreecommitdiff
path: root/src/WorkspaceCmd.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/WorkspaceCmd.cc')
-rw-r--r--src/WorkspaceCmd.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index 536019c..5498b38 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -33,6 +33,8 @@
33#include "WindowCmd.hh" 33#include "WindowCmd.hh"
34 34
35#include "FbTk/KeyUtil.hh" 35#include "FbTk/KeyUtil.hh"
36#include "FbTk/CommandRegistry.hh"
37#include "FbTk/stringstream.hh"
36 38
37#ifdef HAVE_CMATH 39#ifdef HAVE_CMATH
38 #include <cmath> 40 #include <cmath>
@@ -42,6 +44,8 @@
42#include <algorithm> 44#include <algorithm>
43#include <functional> 45#include <functional>
44 46
47using std::string;
48
45void WindowListCmd::execute() { 49void WindowListCmd::execute() {
46 if (m_pat.error()) { 50 if (m_pat.error()) {
47 m_cmd->execute(); 51 m_cmd->execute();
@@ -66,6 +70,20 @@ void WindowListCmd::execute() {
66 } 70 }
67} 71}
68 72
73FbTk::BoolCommand *SomeCmd::parse(const string &command, const string &args,
74 bool trusted) {
75 BoolCommand *boolcmd =
76 FbTk::CommandRegistry::instance().parseBoolLine(args, trusted);
77 if (!boolcmd)
78 return 0;
79 if (command == "some")
80 return new SomeCmd(FbTk::RefCount<FbTk::BoolCommand>(boolcmd));
81 return new EveryCmd(FbTk::RefCount<FbTk::BoolCommand>(boolcmd));
82}
83
84REGISTER_BOOLCOMMAND_PARSER(some, SomeCmd::parse);
85REGISTER_BOOLCOMMAND_PARSER(every, SomeCmd::parse);
86
69bool SomeCmd::bool_execute() { 87bool SomeCmd::bool_execute() {
70 BScreen *screen = Fluxbox::instance()->keyScreen(); 88 BScreen *screen = Fluxbox::instance()->keyScreen();
71 if (screen != 0) { 89 if (screen != 0) {
@@ -108,6 +126,37 @@ bool EveryCmd::bool_execute() {
108 return true; 126 return true;
109} 127}
110 128
129namespace {
130
131FbTk::Command *parseWindowList(const string &command,
132 const string &args, bool trusted) {
133 int opts;
134 string pat;
135 FocusableList::parseArgs(args, opts, pat);
136 if (command == "attach")
137 return new AttachCmd(pat);
138 else if (command == "nextwindow")
139 return new NextWindowCmd(opts, pat);
140 else if (command == "nextgroup") {
141 opts |= FocusableList::LIST_GROUPS;
142 return new NextWindowCmd(opts, pat);
143 } else if (command == "prevwindow")
144 return new PrevWindowCmd(opts, pat);
145 else if (command == "prevgroup") {
146 opts |= FocusableList::LIST_GROUPS;
147 return new PrevWindowCmd(opts, pat);
148 }
149 return 0;
150}
151
152REGISTER_COMMAND_PARSER(attach, parseWindowList);
153REGISTER_COMMAND_PARSER(nextwindow, parseWindowList);
154REGISTER_COMMAND_PARSER(nextgroup, parseWindowList);
155REGISTER_COMMAND_PARSER(prevwindow, parseWindowList);
156REGISTER_COMMAND_PARSER(prevgroup, parseWindowList);
157
158}; // end anonymous namespace
159
111void AttachCmd::execute() { 160void AttachCmd::execute() {
112 BScreen *screen = Fluxbox::instance()->keyScreen(); 161 BScreen *screen = Fluxbox::instance()->keyScreen();
113 if (screen != 0) { 162 if (screen != 0) {
@@ -140,6 +189,21 @@ void PrevWindowCmd::execute() {
140 screen->cycleFocus(m_option, &m_pat, true); 189 screen->cycleFocus(m_option, &m_pat, true);
141} 190}
142 191
192FbTk::Command *GoToWindowCmd::parse(const string &command,
193 const string &arguments, bool trusted) {
194 int num, opts;
195 string args, pat;
196 FbTk_istringstream iss(arguments.c_str());
197 iss >> num;
198 string::size_type pos = arguments.find_first_of("({");
199 if (pos != string::npos && pos != arguments.size())
200 args = arguments.c_str() + pos;
201 FocusableList::parseArgs(args, opts, pat);
202 return new GoToWindowCmd(num, opts, pat);
203}
204
205REGISTER_COMMAND_PARSER(gotowindow, GoToWindowCmd::parse);
206
143void GoToWindowCmd::execute() { 207void GoToWindowCmd::execute() {
144 BScreen *screen = Fluxbox::instance()->keyScreen(); 208 BScreen *screen = Fluxbox::instance()->keyScreen();
145 if (screen != 0) { 209 if (screen != 0) {
@@ -149,6 +213,24 @@ void GoToWindowCmd::execute() {
149 } 213 }
150} 214}
151 215
216FbTk::Command *DirFocusCmd::parse(const string &command,
217 const string &args, bool trusted) {
218 if (command == "focusup")
219 return new DirFocusCmd(FocusControl::FOCUSUP);
220 else if (command == "focusdown")
221 return new DirFocusCmd(FocusControl::FOCUSDOWN);
222 else if (command == "focusleft")
223 return new DirFocusCmd(FocusControl::FOCUSLEFT);
224 else if (command == "focusright")
225 return new DirFocusCmd(FocusControl::FOCUSRIGHT);
226 return 0;
227}
228
229REGISTER_COMMAND_PARSER(focusup, DirFocusCmd::parse);
230REGISTER_COMMAND_PARSER(focusdown, DirFocusCmd::parse);
231REGISTER_COMMAND_PARSER(focusleft, DirFocusCmd::parse);
232REGISTER_COMMAND_PARSER(focusright, DirFocusCmd::parse);
233
152void DirFocusCmd::execute() { 234void DirFocusCmd::execute() {
153 BScreen *screen = Fluxbox::instance()->keyScreen(); 235 BScreen *screen = Fluxbox::instance()->keyScreen();
154 if (screen == 0) 236 if (screen == 0)
@@ -159,18 +241,51 @@ void DirFocusCmd::execute() {
159 screen->focusControl().dirFocus(*win, m_dir); 241 screen->focusControl().dirFocus(*win, m_dir);
160} 242}
161 243
244REGISTER_COMMAND(addworkspace, AddWorkspaceCmd);
245
162void AddWorkspaceCmd::execute() { 246void AddWorkspaceCmd::execute() {
163 BScreen *screen = Fluxbox::instance()->mouseScreen(); 247 BScreen *screen = Fluxbox::instance()->mouseScreen();
164 if (screen != 0) 248 if (screen != 0)
165 screen->addWorkspace(); 249 screen->addWorkspace();
166} 250}
167 251
252REGISTER_COMMAND(removelastworkspace, RemoveLastWorkspaceCmd);
253
168void RemoveLastWorkspaceCmd::execute() { 254void RemoveLastWorkspaceCmd::execute() {
169 BScreen *screen = Fluxbox::instance()->mouseScreen(); 255 BScreen *screen = Fluxbox::instance()->mouseScreen();
170 if (screen != 0) 256 if (screen != 0)
171 screen->removeLastWorkspace(); 257 screen->removeLastWorkspace();
172} 258}
173 259
260namespace {
261
262FbTk::Command *parseIntCmd(const string &command, const string &args,
263 bool trusted) {
264 int num = 1;
265 FbTk_istringstream iss(args.c_str());
266 iss >> num;
267 if (command == "nextworkspace")
268 return new NextWorkspaceCmd(num);
269 else if (command == "prevworkspace")
270 return new PrevWorkspaceCmd(num);
271 else if (command == "rightworkspace")
272 return new RightWorkspaceCmd(num);
273 else if (command == "leftworkspace")
274 return new LeftWorkspaceCmd(num);
275 else if (command == "workspace")
276 // workspaces appear 1-indexed to the user, hence the minus 1
277 return new JumpToWorkspaceCmd(num - 1);
278 return 0;
279}
280
281REGISTER_COMMAND_PARSER(nextworkspace, parseIntCmd);
282REGISTER_COMMAND_PARSER(prevworkspace, parseIntCmd);
283REGISTER_COMMAND_PARSER(rightworkspace, parseIntCmd);
284REGISTER_COMMAND_PARSER(leftworkspace, parseIntCmd);
285REGISTER_COMMAND_PARSER(workspace, parseIntCmd);
286
287}; // end anonymous namespace
288
174void NextWorkspaceCmd::execute() { 289void NextWorkspaceCmd::execute() {
175 BScreen *screen = Fluxbox::instance()->mouseScreen(); 290 BScreen *screen = Fluxbox::instance()->mouseScreen();
176 if (screen != 0) 291 if (screen != 0)
@@ -210,6 +325,7 @@ void JumpToWorkspaceCmd::execute() {
210 } 325 }
211} 326}
212 327
328REGISTER_COMMAND(arrangewindows, ArrangeWindowsCmd);
213 329
214/** 330/**
215 try to arrange the windows on the current workspace in a 'clever' way. 331 try to arrange the windows on the current workspace in a 'clever' way.
@@ -335,6 +451,8 @@ void ArrangeWindowsCmd::execute() {
335 } 451 }
336} 452}
337 453
454REGISTER_COMMAND(showdesktop, ShowDesktopCmd);
455
338void ShowDesktopCmd::execute() { 456void ShowDesktopCmd::execute() {
339 BScreen *screen = Fluxbox::instance()->mouseScreen(); 457 BScreen *screen = Fluxbox::instance()->mouseScreen();
340 if (screen == 0) 458 if (screen == 0)
@@ -349,6 +467,8 @@ void ShowDesktopCmd::execute() {
349 } 467 }
350} 468}
351 469
470REGISTER_COMMAND(closeallwindows, CloseAllWindowsCmd);
471
352void CloseAllWindowsCmd::execute() { 472void CloseAllWindowsCmd::execute() {
353 BScreen *screen = Fluxbox::instance()->mouseScreen(); 473 BScreen *screen = Fluxbox::instance()->mouseScreen();
354 if (screen == 0) 474 if (screen == 0)