aboutsummaryrefslogtreecommitdiff
path: root/src/FbCommands.cc
diff options
context:
space:
mode:
authormarkt <markt>2007-12-13 05:48:00 (GMT)
committermarkt <markt>2007-12-13 05:48:00 (GMT)
commit8b7464046cea5e521ac46811591b0fce0c45aca1 (patch)
tree09df752f426a249ae15375a626a98436c8727593 /src/FbCommands.cc
parentdaca07edafc2e75eb9ee04d35fe80759308a8583 (diff)
downloadfluxbox-8b7464046cea5e521ac46811591b0fce0c45aca1.zip
fluxbox-8b7464046cea5e521ac46811591b0fce0c45aca1.tar.bz2
added FbTk::CommandRegistry, decentralized command parsing, and made them auto-register
Diffstat (limited to 'src/FbCommands.cc')
-rw-r--r--src/FbCommands.cc110
1 files changed, 108 insertions, 2 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index de14f73..0d4e0e3 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -33,6 +33,9 @@
33 33
34#include "FbTk/Theme.hh" 34#include "FbTk/Theme.hh"
35#include "FbTk/Menu.hh" 35#include "FbTk/Menu.hh"
36#include "FbTk/CommandRegistry.hh"
37#include "FbTk/StringUtil.hh"
38#include "FbTk/stringstream.hh"
36 39
37#include <sys/types.h> 40#include <sys/types.h>
38#include <unistd.h> 41#include <unistd.h>
@@ -120,6 +123,10 @@ void showMenu(const BScreen &screen, FbTk::Menu &menu) {
120 123
121namespace FbCommands { 124namespace FbCommands {
122 125
126REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(exec, FbCommands::ExecuteCmd);
127REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(execute, FbCommands::ExecuteCmd);
128REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(execcommand, FbCommands::ExecuteCmd);
129
123ExecuteCmd::ExecuteCmd(const string &cmd, int screen_num):m_cmd(cmd), m_screen_num(screen_num) { 130ExecuteCmd::ExecuteCmd(const string &cmd, int screen_num):m_cmd(cmd), m_screen_num(screen_num) {
124 131
125} 132}
@@ -169,6 +176,27 @@ int ExecuteCmd::run() {
169 return pid; // compiler happy -> we are happy ;) 176 return pid; // compiler happy -> we are happy ;)
170} 177}
171 178
179FbTk::Command *ExportCmd::parse(const string &command, const string &args,
180 bool trusted) {
181 string name = args;
182 FbTk::StringUtil::removeFirstWhitespace(name);
183 if (command != "setresourcevalue")
184 FbTk::StringUtil::removeTrailingWhitespace(name);
185 size_t pos = name.find_first_of(command == "export" ? "=" : " \t");
186 if (pos == string::npos || pos == name.size() || !trusted)
187 return 0;
188
189 string value = name.substr(pos + 1);
190 name = name.substr(0, pos);
191 if (command == "setresourcevalue")
192 return new SetResourceValueCmd(name, value);
193 return new ExportCmd(name, value);
194}
195
196REGISTER_COMMAND_PARSER(setenv, ExportCmd::parse);
197REGISTER_COMMAND_PARSER(export, ExportCmd::parse);
198REGISTER_COMMAND_PARSER(setresourcevalue, ExportCmd::parse);
199
172ExportCmd::ExportCmd(const string& name, const string& value) : 200ExportCmd::ExportCmd(const string& name, const string& value) :
173 m_name(name), m_value(value) { 201 m_name(name), m_value(value) {
174} 202}
@@ -205,15 +233,21 @@ void ExportCmd::execute() {
205 } 233 }
206} 234}
207 235
236REGISTER_COMMAND(exit, FbCommands::ExitFluxboxCmd);
237REGISTER_COMMAND(quit, FbCommands::ExitFluxboxCmd);
208 238
209void ExitFluxboxCmd::execute() { 239void ExitFluxboxCmd::execute() {
210 Fluxbox::instance()->shutdown(); 240 Fluxbox::instance()->shutdown();
211} 241}
212 242
243REGISTER_COMMAND(saverc, FbCommands::SaveResources);
244
213void SaveResources::execute() { 245void SaveResources::execute() {
214 Fluxbox::instance()->save_rc(); 246 Fluxbox::instance()->save_rc();
215} 247}
216 248
249REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(restart, FbCommands::RestartFluxboxCmd);
250
217RestartFluxboxCmd::RestartFluxboxCmd(const string &cmd):m_cmd(cmd){ 251RestartFluxboxCmd::RestartFluxboxCmd(const string &cmd):m_cmd(cmd){
218} 252}
219 253
@@ -224,16 +258,22 @@ void RestartFluxboxCmd::execute() {
224 Fluxbox::instance()->restart(m_cmd.c_str()); 258 Fluxbox::instance()->restart(m_cmd.c_str());
225} 259}
226 260
261REGISTER_COMMAND(reconfigure, FbCommands::ReconfigureFluxboxCmd);
262REGISTER_COMMAND(reconfig, FbCommands::ReconfigureFluxboxCmd);
263
227void ReconfigureFluxboxCmd::execute() { 264void ReconfigureFluxboxCmd::execute() {
228 Fluxbox::instance()->reconfigure(); 265 Fluxbox::instance()->reconfigure();
229} 266}
230 267
268REGISTER_COMMAND(reloadstyle, FbCommands::ReloadStyleCmd);
231 269
232void ReloadStyleCmd::execute() { 270void ReloadStyleCmd::execute() {
233 SetStyleCmd cmd(Fluxbox::instance()->getStyleFilename()); 271 SetStyleCmd cmd(Fluxbox::instance()->getStyleFilename());
234 cmd.execute(); 272 cmd.execute();
235} 273}
236 274
275REGISTER_COMMAND_WITH_ARGS(setstyle, FbCommands::SetStyleCmd);
276
237SetStyleCmd::SetStyleCmd(const string &filename):m_filename(filename) { 277SetStyleCmd::SetStyleCmd(const string &filename):m_filename(filename) {
238 278
239} 279}
@@ -245,6 +285,8 @@ void SetStyleCmd::execute() {
245 Fluxbox::instance()->getStyleOverlayFilename()); 285 Fluxbox::instance()->getStyleOverlayFilename());
246} 286}
247 287
288REGISTER_COMMAND_WITH_ARGS(keymode, FbCommands::KeyModeCmd);
289
248KeyModeCmd::KeyModeCmd(const string &arguments):m_keymode(arguments),m_end_args("None Escape") { 290KeyModeCmd::KeyModeCmd(const string &arguments):m_keymode(arguments),m_end_args("None Escape") {
249 string::size_type second_pos = m_keymode.find_first_of(" \t", 0); 291 string::size_type second_pos = m_keymode.find_first_of(" \t", 0);
250 if (second_pos != string::npos) { 292 if (second_pos != string::npos) {
@@ -260,10 +302,22 @@ void KeyModeCmd::execute() {
260 Fluxbox::instance()->keys()->keyMode(m_keymode); 302 Fluxbox::instance()->keys()->keyMode(m_keymode);
261} 303}
262 304
305REGISTER_COMMAND(hidemenus, FbCommands::HideMenuCmd);
306
263void HideMenuCmd::execute() { 307void HideMenuCmd::execute() {
264 FbTk::Menu::hideShownMenu(); 308 FbTk::Menu::hideShownMenu();
265} 309}
266 310
311FbTk::Command *ShowClientMenuCmd::parse(const string &command,
312 const string &args, bool trusted) {
313 int opts;
314 string pat;
315 FocusableList::parseArgs(args, opts, pat);
316 return new ShowClientMenuCmd(opts, pat);
317}
318
319REGISTER_COMMAND_PARSER(clientmenu, ShowClientMenuCmd::parse);
320
267void ShowClientMenuCmd::execute() { 321void ShowClientMenuCmd::execute() {
268 BScreen *screen = Fluxbox::instance()->mouseScreen(); 322 BScreen *screen = Fluxbox::instance()->mouseScreen();
269 if (screen == 0) 323 if (screen == 0)
@@ -285,6 +339,8 @@ void ShowClientMenuCmd::execute() {
285 ::showMenu(*screen, **m_menu); 339 ::showMenu(*screen, **m_menu);
286} 340}
287 341
342REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd);
343
288ShowCustomMenuCmd::ShowCustomMenuCmd(const string &arguments) : custom_menu_file(arguments) {} 344ShowCustomMenuCmd::ShowCustomMenuCmd(const string &arguments) : custom_menu_file(arguments) {}
289 345
290void ShowCustomMenuCmd::execute() { 346void ShowCustomMenuCmd::execute() {
@@ -298,6 +354,8 @@ void ShowCustomMenuCmd::execute() {
298 ::showMenu(*screen, **m_menu); 354 ::showMenu(*screen, **m_menu);
299} 355}
300 356
357REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd);
358
301void ShowRootMenuCmd::execute() { 359void ShowRootMenuCmd::execute() {
302 BScreen *screen = Fluxbox::instance()->mouseScreen(); 360 BScreen *screen = Fluxbox::instance()->mouseScreen();
303 if (screen == 0) 361 if (screen == 0)
@@ -306,6 +364,8 @@ void ShowRootMenuCmd::execute() {
306 ::showMenu(*screen, screen->rootMenu()); 364 ::showMenu(*screen, screen->rootMenu());
307} 365}
308 366
367REGISTER_COMMAND(workspacemenu, FbCommands::ShowWorkspaceMenuCmd);
368
309void ShowWorkspaceMenuCmd::execute() { 369void ShowWorkspaceMenuCmd::execute() {
310 BScreen *screen = Fluxbox::instance()->mouseScreen(); 370 BScreen *screen = Fluxbox::instance()->mouseScreen();
311 if (screen == 0) 371 if (screen == 0)
@@ -314,10 +374,13 @@ void ShowWorkspaceMenuCmd::execute() {
314 ::showMenu(*screen, screen->workspaceMenu()); 374 ::showMenu(*screen, screen->workspaceMenu());
315} 375}
316 376
317 377REGISTER_COMMAND_WITH_ARGS(setworkspacename, FbCommands::SetWorkspaceNameCmd);
318 378
319SetWorkspaceNameCmd::SetWorkspaceNameCmd(const string &name, int spaceid): 379SetWorkspaceNameCmd::SetWorkspaceNameCmd(const string &name, int spaceid):
320 m_name(name), m_workspace(spaceid) { } 380 m_name(name), m_workspace(spaceid) {
381 if (name.empty())
382 m_name = "empty";
383}
321 384
322void SetWorkspaceNameCmd::execute() { 385void SetWorkspaceNameCmd::execute() {
323 BScreen *screen = Fluxbox::instance()->mouseScreen(); 386 BScreen *screen = Fluxbox::instance()->mouseScreen();
@@ -340,6 +403,8 @@ void SetWorkspaceNameCmd::execute() {
340 Fluxbox::instance()->save_rc(); 403 Fluxbox::instance()->save_rc();
341} 404}
342 405
406REGISTER_COMMAND(setworkspacenamedialog, FbCommands::WorkspaceNameDialogCmd);
407
343void WorkspaceNameDialogCmd::execute() { 408void WorkspaceNameDialogCmd::execute() {
344 409
345 BScreen *screen = Fluxbox::instance()->mouseScreen(); 410 BScreen *screen = Fluxbox::instance()->mouseScreen();
@@ -351,6 +416,8 @@ void WorkspaceNameDialogCmd::execute() {
351 win->show(); 416 win->show();
352} 417}
353 418
419REGISTER_COMMAND(commanddialog, FbCommands::CommandDialogCmd);
420
354void CommandDialogCmd::execute() { 421void CommandDialogCmd::execute() {
355 BScreen *screen = Fluxbox::instance()->mouseScreen(); 422 BScreen *screen = Fluxbox::instance()->mouseScreen();
356 if (screen == 0) 423 if (screen == 0)
@@ -376,6 +443,8 @@ void SetResourceValueCmd::execute() {
376 Fluxbox::instance()->save_rc(); 443 Fluxbox::instance()->save_rc();
377} 444}
378 445
446REGISTER_COMMAND(setresourcevaluedialog, FbCommands::SetResourceValueDialogCmd);
447
379void SetResourceValueDialogCmd::execute() { 448void SetResourceValueDialogCmd::execute() {
380 BScreen *screen = Fluxbox::instance()->mouseScreen(); 449 BScreen *screen = Fluxbox::instance()->mouseScreen();
381 if (screen == 0) 450 if (screen == 0)
@@ -385,6 +454,8 @@ void SetResourceValueDialogCmd::execute() {
385 win->show(); 454 win->show();
386}; 455};
387 456
457REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(bindkey, FbCommands::BindKeyCmd);
458
388BindKeyCmd::BindKeyCmd(const string &keybind):m_keybind(keybind) { } 459BindKeyCmd::BindKeyCmd(const string &keybind):m_keybind(keybind) { }
389 460
390void BindKeyCmd::execute() { 461void BindKeyCmd::execute() {
@@ -398,6 +469,41 @@ void BindKeyCmd::execute() {
398 } 469 }
399} 470}
400 471
472FbTk::Command *DeiconifyCmd::parse(const string &command, const string &args,
473 bool trusted) {
474 FbTk_istringstream iss(args.c_str());
475 string mode;
476 string d;
477 Destination dest;
478
479 iss >> mode;
480 if (iss.fail())
481 mode="lastworkspace";
482 mode= FbTk::StringUtil::toLower(mode);
483
484 iss >> d;
485 if (iss.fail())
486 d="current";
487 d = FbTk::StringUtil::toLower(d);
488 if (d == "origin" )
489 dest = ORIGIN;
490 else if (d == "originquiet")
491 dest = ORIGINQUIET;
492 else
493 dest = CURRENT;
494
495 if (mode == "all")
496 return new DeiconifyCmd(DeiconifyCmd::ALL, dest);
497 else if (mode == "allworkspace")
498 return new DeiconifyCmd(DeiconifyCmd::ALLWORKSPACE, dest);
499 else if (mode == "last")
500 return new DeiconifyCmd(DeiconifyCmd::LAST, dest);
501 // lastworkspace, default
502 return new DeiconifyCmd(DeiconifyCmd::LASTWORKSPACE, dest);
503}
504
505REGISTER_COMMAND_PARSER(deiconify, DeiconifyCmd::parse);
506
401DeiconifyCmd::DeiconifyCmd(Mode mode, 507DeiconifyCmd::DeiconifyCmd(Mode mode,
402 Destination dest) : m_mode(mode), m_dest(dest) { } 508 Destination dest) : m_mode(mode), m_dest(dest) { }
403 509