diff options
author | markt <markt> | 2007-12-13 05:48:00 (GMT) |
---|---|---|
committer | markt <markt> | 2007-12-13 05:48:00 (GMT) |
commit | 8b7464046cea5e521ac46811591b0fce0c45aca1 (patch) | |
tree | 09df752f426a249ae15375a626a98436c8727593 /src/FbCommands.cc | |
parent | daca07edafc2e75eb9ee04d35fe80759308a8583 (diff) | |
download | fluxbox_pavel-8b7464046cea5e521ac46811591b0fce0c45aca1.zip fluxbox_pavel-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.cc | 110 |
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 | ||
121 | namespace FbCommands { | 124 | namespace FbCommands { |
122 | 125 | ||
126 | REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(exec, FbCommands::ExecuteCmd); | ||
127 | REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(execute, FbCommands::ExecuteCmd); | ||
128 | REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(execcommand, FbCommands::ExecuteCmd); | ||
129 | |||
123 | ExecuteCmd::ExecuteCmd(const string &cmd, int screen_num):m_cmd(cmd), m_screen_num(screen_num) { | 130 | ExecuteCmd::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 | ||
179 | FbTk::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 | |||
196 | REGISTER_COMMAND_PARSER(setenv, ExportCmd::parse); | ||
197 | REGISTER_COMMAND_PARSER(export, ExportCmd::parse); | ||
198 | REGISTER_COMMAND_PARSER(setresourcevalue, ExportCmd::parse); | ||
199 | |||
172 | ExportCmd::ExportCmd(const string& name, const string& value) : | 200 | ExportCmd::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 | ||
236 | REGISTER_COMMAND(exit, FbCommands::ExitFluxboxCmd); | ||
237 | REGISTER_COMMAND(quit, FbCommands::ExitFluxboxCmd); | ||
208 | 238 | ||
209 | void ExitFluxboxCmd::execute() { | 239 | void ExitFluxboxCmd::execute() { |
210 | Fluxbox::instance()->shutdown(); | 240 | Fluxbox::instance()->shutdown(); |
211 | } | 241 | } |
212 | 242 | ||
243 | REGISTER_COMMAND(saverc, FbCommands::SaveResources); | ||
244 | |||
213 | void SaveResources::execute() { | 245 | void SaveResources::execute() { |
214 | Fluxbox::instance()->save_rc(); | 246 | Fluxbox::instance()->save_rc(); |
215 | } | 247 | } |
216 | 248 | ||
249 | REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(restart, FbCommands::RestartFluxboxCmd); | ||
250 | |||
217 | RestartFluxboxCmd::RestartFluxboxCmd(const string &cmd):m_cmd(cmd){ | 251 | RestartFluxboxCmd::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 | ||
261 | REGISTER_COMMAND(reconfigure, FbCommands::ReconfigureFluxboxCmd); | ||
262 | REGISTER_COMMAND(reconfig, FbCommands::ReconfigureFluxboxCmd); | ||
263 | |||
227 | void ReconfigureFluxboxCmd::execute() { | 264 | void ReconfigureFluxboxCmd::execute() { |
228 | Fluxbox::instance()->reconfigure(); | 265 | Fluxbox::instance()->reconfigure(); |
229 | } | 266 | } |
230 | 267 | ||
268 | REGISTER_COMMAND(reloadstyle, FbCommands::ReloadStyleCmd); | ||
231 | 269 | ||
232 | void ReloadStyleCmd::execute() { | 270 | void ReloadStyleCmd::execute() { |
233 | SetStyleCmd cmd(Fluxbox::instance()->getStyleFilename()); | 271 | SetStyleCmd cmd(Fluxbox::instance()->getStyleFilename()); |
234 | cmd.execute(); | 272 | cmd.execute(); |
235 | } | 273 | } |
236 | 274 | ||
275 | REGISTER_COMMAND_WITH_ARGS(setstyle, FbCommands::SetStyleCmd); | ||
276 | |||
237 | SetStyleCmd::SetStyleCmd(const string &filename):m_filename(filename) { | 277 | SetStyleCmd::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 | ||
288 | REGISTER_COMMAND_WITH_ARGS(keymode, FbCommands::KeyModeCmd); | ||
289 | |||
248 | KeyModeCmd::KeyModeCmd(const string &arguments):m_keymode(arguments),m_end_args("None Escape") { | 290 | KeyModeCmd::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 | ||
305 | REGISTER_COMMAND(hidemenus, FbCommands::HideMenuCmd); | ||
306 | |||
263 | void HideMenuCmd::execute() { | 307 | void HideMenuCmd::execute() { |
264 | FbTk::Menu::hideShownMenu(); | 308 | FbTk::Menu::hideShownMenu(); |
265 | } | 309 | } |
266 | 310 | ||
311 | FbTk::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 | |||
319 | REGISTER_COMMAND_PARSER(clientmenu, ShowClientMenuCmd::parse); | ||
320 | |||
267 | void ShowClientMenuCmd::execute() { | 321 | void 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 | ||
342 | REGISTER_COMMAND_WITH_ARGS(custommenu, FbCommands::ShowCustomMenuCmd); | ||
343 | |||
288 | ShowCustomMenuCmd::ShowCustomMenuCmd(const string &arguments) : custom_menu_file(arguments) {} | 344 | ShowCustomMenuCmd::ShowCustomMenuCmd(const string &arguments) : custom_menu_file(arguments) {} |
289 | 345 | ||
290 | void ShowCustomMenuCmd::execute() { | 346 | void ShowCustomMenuCmd::execute() { |
@@ -298,6 +354,8 @@ void ShowCustomMenuCmd::execute() { | |||
298 | ::showMenu(*screen, **m_menu); | 354 | ::showMenu(*screen, **m_menu); |
299 | } | 355 | } |
300 | 356 | ||
357 | REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd); | ||
358 | |||
301 | void ShowRootMenuCmd::execute() { | 359 | void 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 | ||
367 | REGISTER_COMMAND(workspacemenu, FbCommands::ShowWorkspaceMenuCmd); | ||
368 | |||
309 | void ShowWorkspaceMenuCmd::execute() { | 369 | void 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 | 377 | REGISTER_COMMAND_WITH_ARGS(setworkspacename, FbCommands::SetWorkspaceNameCmd); | |
318 | 378 | ||
319 | SetWorkspaceNameCmd::SetWorkspaceNameCmd(const string &name, int spaceid): | 379 | SetWorkspaceNameCmd::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 | ||
322 | void SetWorkspaceNameCmd::execute() { | 385 | void 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 | ||
406 | REGISTER_COMMAND(setworkspacenamedialog, FbCommands::WorkspaceNameDialogCmd); | ||
407 | |||
343 | void WorkspaceNameDialogCmd::execute() { | 408 | void 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 | ||
419 | REGISTER_COMMAND(commanddialog, FbCommands::CommandDialogCmd); | ||
420 | |||
354 | void CommandDialogCmd::execute() { | 421 | void 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 | ||
446 | REGISTER_COMMAND(setresourcevaluedialog, FbCommands::SetResourceValueDialogCmd); | ||
447 | |||
379 | void SetResourceValueDialogCmd::execute() { | 448 | void 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 | ||
457 | REGISTER_UNTRUSTED_COMMAND_WITH_ARGS(bindkey, FbCommands::BindKeyCmd); | ||
458 | |||
388 | BindKeyCmd::BindKeyCmd(const string &keybind):m_keybind(keybind) { } | 459 | BindKeyCmd::BindKeyCmd(const string &keybind):m_keybind(keybind) { } |
389 | 460 | ||
390 | void BindKeyCmd::execute() { | 461 | void BindKeyCmd::execute() { |
@@ -398,6 +469,41 @@ void BindKeyCmd::execute() { | |||
398 | } | 469 | } |
399 | } | 470 | } |
400 | 471 | ||
472 | FbTk::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 | |||
505 | REGISTER_COMMAND_PARSER(deiconify, DeiconifyCmd::parse); | ||
506 | |||
401 | DeiconifyCmd::DeiconifyCmd(Mode mode, | 507 | DeiconifyCmd::DeiconifyCmd(Mode mode, |
402 | Destination dest) : m_mode(mode), m_dest(dest) { } | 508 | Destination dest) : m_mode(mode), m_dest(dest) { } |
403 | 509 | ||