aboutsummaryrefslogtreecommitdiff
path: root/src/WorkspaceCmd.cc
diff options
context:
space:
mode:
authorRichard Tamin <richard.tamin@gmail.com>2020-08-23 04:01:43 (GMT)
committerMathias Gumz <mgumz@users.noreply.github.com>2022-04-18 19:50:06 (GMT)
commit174e62ff66fee78d83231b1f0f9ea083370ae55d (patch)
tree59168c7cc06e7a0d0ef0a3d55976db2fb733092c /src/WorkspaceCmd.cc
parent8e32f098bd94cb14ae80c3621c3db74fbdfa7bb6 (diff)
downloadfluxbox-174e62ff66fee78d83231b1f0f9ea083370ae55d.zip
fluxbox-174e62ff66fee78d83231b1f0f9ea083370ae55d.tar.bz2
Initial implementation of shortcut to windows
[PURPOSE] In editors such as vi and emacs, a user can mark a line in a file with a shortcut key and afterwards jump back to that line using the shortcut. The idea is extended to opened windows. A user can assign a keyboard shortcut to an opened window. Afterwards, the shortcut can be used to switch focus back to the marked window. Such shortcuts save the user from pressing "alt+tab" multiple times to cycle through windows until the desired one is found. [EXAMPLE USAGE] The following binding is added to file "~/.fluxbox/keys": Mod1 m ARG :MarkWindow Mod1 g ARG :GotoMarkedWindow User enters "alt+m x" to mark the currently focused window with shortcut key 'x' User enters "alt+g x" to switch focus to the marked window [IMPLEMENTATION SUMMARY] - Two new commands were added :MarkWindow and :GotoMarkedWindow - Keys.cc was modified: - addBinding() method supports parsing an argument placeholder where the user can pass in a shortcut key - doAction() method forwards the shortcut key to the command to execute - Class Keys::t_key was modified to recognize a placeholder key - New class ShortcutManager was added to maintain mapping of shortcut keys to marked windows
Diffstat (limited to 'src/WorkspaceCmd.cc')
-rw-r--r--src/WorkspaceCmd.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index 6d18b73..c2e4948 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -39,6 +39,8 @@
39#include "FbTk/stringstream.hh" 39#include "FbTk/stringstream.hh"
40#include "FbTk/StringUtil.hh" 40#include "FbTk/StringUtil.hh"
41 41
42#include "Debug.hh"
43
42#ifdef HAVE_CMATH 44#ifdef HAVE_CMATH
43 #include <cmath> 45 #include <cmath>
44#else 46#else
@@ -751,3 +753,38 @@ FbTk::Command<void> *RelabelButtonCmd::parse(const std::string &command,
751 753
752REGISTER_COMMAND_PARSER(relabelbutton, RelabelButtonCmd::parse, void); 754REGISTER_COMMAND_PARSER(relabelbutton, RelabelButtonCmd::parse, void);
753 755
756void MarkWindowCmd::execute() {
757 BScreen *screen = Fluxbox::instance()->keyScreen();
758 if (screen) {
759
760 FluxboxWindow* window = screen->focusControl().focusedFbWindow();
761 if (window) {
762 ShortcutManager &shortcutManager = Fluxbox::instance()->shortcutManager();
763 unsigned int key = shortcutManager.getLastPlaceHolderKey();
764 shortcutManager.mapKeyToWindow(key, window);
765 fbdbg << "Map window[" << window << "] to key[" << key << "]" << std::endl;
766 }
767 }
768}
769
770REGISTER_COMMAND(markwindow, MarkWindowCmd, void);
771
772void GotoMarkedWindowCmd::execute() {
773
774 ShortcutManager &shortcutManager = Fluxbox::instance()->shortcutManager();
775 unsigned int key = shortcutManager.getLastPlaceHolderKey();
776
777 FluxboxWindow *window = shortcutManager.getWindowForKey(key);
778 if (window) {
779
780 if (window->isIconic()) {
781 window->deiconify(false);
782 }
783 window->raiseAndFocus();
784
785 fbdbg << "Raise and focus window[" << window
786 << "] mapped to key[" << key << "]" << std::endl;
787 }
788}
789
790REGISTER_COMMAND(gotomarkedwindow, GotoMarkedWindowCmd, void);