diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-05-03 12:03:43 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-05-03 12:03:43 +0200 |
commit | d08ea692771caa8e385412c2f992089672773e30 (patch) | |
tree | 994c05673d90b130e25d8bc25c6c365f607134db /include/GlobalHotkeys/GlobalHotkeysX11.hpp | |
parent | 180a3b73dbab2f586c53f9e5f044ab88aca95014 (diff) |
Keep keyboard led when turning on global hotkeys, move files
Diffstat (limited to 'include/GlobalHotkeys/GlobalHotkeysX11.hpp')
-rw-r--r-- | include/GlobalHotkeys/GlobalHotkeysX11.hpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/GlobalHotkeys/GlobalHotkeysX11.hpp b/include/GlobalHotkeys/GlobalHotkeysX11.hpp new file mode 100644 index 0000000..610399a --- /dev/null +++ b/include/GlobalHotkeys/GlobalHotkeysX11.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "GlobalHotkeys.hpp" +#include <unordered_map> +#include <X11/Xlib.h> + +namespace gsr { + class GlobalHotkeysX11 : public GlobalHotkeys { + public: + GlobalHotkeysX11(); + GlobalHotkeysX11(const GlobalHotkeysX11&) = delete; + GlobalHotkeysX11& operator=(const GlobalHotkeysX11&) = delete; + ~GlobalHotkeysX11() override; + + // Hotkey key is a KeySym (XK_z for example) and modifiers is a bitmask of X11 modifier masks (for example ShiftMask | Mod1Mask) + bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) override; + void unbind_key_press(const std::string &id) override; + void unbind_all_keys() override; + void poll_events() override; + bool on_event(mgl::Event &event) override; + private: + // Returns true if a key bind has been registered for the hotkey + bool call_hotkey_callback(Hotkey hotkey) const; + private: + struct HotkeyData { + Hotkey hotkey; + GlobalHotkeyCallback callback; + }; + + Display *dpy = nullptr; + XEvent xev; + std::unordered_map<std::string, HotkeyData> bound_keys_by_id; + }; +}
\ No newline at end of file |