From 734280f3042a1b2d08764599d1decdee2d4d3132 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 24 Nov 2024 18:25:58 +0100 Subject: Use linux /dev/input for global hotkeys instead of x11. This also works on wayland on any compositor --- include/GlobalHotkeys.hpp | 7 ++++--- include/GlobalHotkeysLinux.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 include/GlobalHotkeysLinux.hpp (limited to 'include') diff --git a/include/GlobalHotkeys.hpp b/include/GlobalHotkeys.hpp index 020f5a5..662113e 100644 --- a/include/GlobalHotkeys.hpp +++ b/include/GlobalHotkeys.hpp @@ -19,9 +19,10 @@ namespace gsr { GlobalHotkeys& operator=(const GlobalHotkeys&) = delete; virtual ~GlobalHotkeys() = default; - virtual bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) = 0; - virtual void unbind_key_press(const std::string &id) = 0; - virtual void unbind_all_keys() = 0; + 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; }; } \ No newline at end of file diff --git a/include/GlobalHotkeysLinux.hpp b/include/GlobalHotkeysLinux.hpp new file mode 100644 index 0000000..62da74e --- /dev/null +++ b/include/GlobalHotkeysLinux.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "GlobalHotkeys.hpp" +#include +#include + +namespace gsr { + class GlobalHotkeysLinux : public GlobalHotkeys { + public: + GlobalHotkeysLinux(); + GlobalHotkeysLinux(const GlobalHotkeysLinux&) = delete; + GlobalHotkeysLinux& operator=(const GlobalHotkeysLinux&) = delete; + ~GlobalHotkeysLinux() override; + + bool start(); + bool bind_action(const std::string &id, GlobalHotkeyCallback callback) override; + void poll_events() override; + private: + pid_t process_id = 0; + int pipes[2]; + FILE *read_file = nullptr; + std::unordered_map bound_actions_by_id; + }; +} \ No newline at end of file -- cgit v1.2.3