aboutsummaryrefslogtreecommitdiff
path: root/src/ShortcutManager.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/ShortcutManager.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/ShortcutManager.cc')
-rw-r--r--src/ShortcutManager.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ShortcutManager.cc b/src/ShortcutManager.cc
new file mode 100644
index 0000000..52e94af
--- /dev/null
+++ b/src/ShortcutManager.cc
@@ -0,0 +1,45 @@
1#include "ShortcutManager.hh"
2#include "Debug.hh"
3
4#include <iostream>
5
6ShortcutManager::ShortcutManager() : m_last_placeholder_key(0) { }
7
8void ShortcutManager::setLastPlaceHolderKey(unsigned int lastPlaceHolderKey_)
9{
10 m_last_placeholder_key = lastPlaceHolderKey_;
11}
12
13unsigned int ShortcutManager::getLastPlaceHolderKey()
14{
15 return m_last_placeholder_key;
16}
17
18void ShortcutManager::mapKeyToWindow(unsigned int key, FluxboxWindow* window)
19{
20 m_key_to_window_map.insert(std::make_pair(key, window));
21}
22
23void ShortcutManager::removeWindow(FluxboxWindow* window)
24{
25 KeyToWindowMap::const_iterator it;
26 for (it = m_key_to_window_map.begin(); it != m_key_to_window_map.end(); ++it) {
27 if (it->second == window){
28 fbdbg << "Remove mapping window[" << window
29 << "] key [" << it->first << "]" << std::endl;
30 m_key_to_window_map.erase(it);
31 return;
32 }
33 }
34}
35
36FluxboxWindow* ShortcutManager::getWindowForKey(unsigned int key)
37{
38 KeyToWindowMap::const_iterator it = m_key_to_window_map.find(key);
39 if (it != m_key_to_window_map.end()) {
40 return it->second;
41 }
42 else {
43 return nullptr;
44 }
45}