aboutsummaryrefslogtreecommitdiff
path: root/include/GlobalHotkeys/GlobalHotkeys.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-05-03 12:03:43 +0200
committerdec05eba <dec05eba@protonmail.com>2025-05-03 12:03:43 +0200
commitd08ea692771caa8e385412c2f992089672773e30 (patch)
tree994c05673d90b130e25d8bc25c6c365f607134db /include/GlobalHotkeys/GlobalHotkeys.hpp
parent180a3b73dbab2f586c53f9e5f044ab88aca95014 (diff)
Keep keyboard led when turning on global hotkeys, move files
Diffstat (limited to 'include/GlobalHotkeys/GlobalHotkeys.hpp')
-rw-r--r--include/GlobalHotkeys/GlobalHotkeys.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/GlobalHotkeys/GlobalHotkeys.hpp b/include/GlobalHotkeys/GlobalHotkeys.hpp
new file mode 100644
index 0000000..2927fa7
--- /dev/null
+++ b/include/GlobalHotkeys/GlobalHotkeys.hpp
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <stdint.h>
+#include <functional>
+#include <string>
+
+namespace mgl {
+ class Event;
+}
+
+namespace gsr {
+ enum HotkeyModifier : uint32_t {
+ HOTKEY_MOD_LSHIFT = 1 << 0,
+ HOTKEY_MOD_RSHIFT = 1 << 1,
+ HOTKEY_MOD_LCTRL = 1 << 2,
+ HOTKEY_MOD_RCTRL = 1 << 3,
+ HOTKEY_MOD_LALT = 1 << 4,
+ HOTKEY_MOD_RALT = 1 << 5,
+ HOTKEY_MOD_LSUPER = 1 << 6,
+ HOTKEY_MOD_RSUPER = 1 << 7
+ };
+
+ struct Hotkey {
+ uint32_t key = 0; // X11 keysym
+ uint32_t modifiers = 0; // HotkeyModifier
+ };
+
+ using GlobalHotkeyCallback = std::function<void(const std::string &id)>;
+
+ class GlobalHotkeys {
+ public:
+ GlobalHotkeys() = default;
+ GlobalHotkeys(const GlobalHotkeys&) = delete;
+ GlobalHotkeys& operator=(const GlobalHotkeys&) = delete;
+ virtual ~GlobalHotkeys() = default;
+
+ virtual bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) { (void)hotkey; (void)id; (void)callback; return false; }
+ virtual void unbind_key_press(const std::string &id) { (void)id; }
+ virtual void unbind_all_keys() {}
+ virtual bool bind_action(const std::string &id, GlobalHotkeyCallback callback) { (void)id; (void)callback; return false; };
+ virtual void poll_events() = 0;
+ // Returns true if the event wasn't consumed (if the event didn't match a key that has been bound)
+ virtual bool on_event(mgl::Event &event) { (void)event; return true; }
+ };
+} \ No newline at end of file