aboutsummaryrefslogtreecommitdiff
path: root/include/GlobalHotkeysLinux.hpp
blob: c9428de52fe1d0eb93dc4c49a4f73c8f4e1c4301 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

#include "GlobalHotkeys.hpp"
#include <unordered_map>
#include <sys/types.h>

namespace gsr {
    class GlobalHotkeysLinux : public GlobalHotkeys {
    public:
        enum class GrabType {
            ALL,
            VIRTUAL
        };

        GlobalHotkeysLinux(GrabType grab_type);
        GlobalHotkeysLinux(const GlobalHotkeysLinux&) = delete;
        GlobalHotkeysLinux& operator=(const GlobalHotkeysLinux&) = delete;
        ~GlobalHotkeysLinux() override;

        bool start();
        bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) override;
        void unbind_all_keys() override;
        void poll_events() override;
    private:
        pid_t process_id = 0;
        int read_pipes[2];
        int write_pipes[2];
        FILE *read_file = nullptr;
        std::unordered_map<std::string, GlobalHotkeyCallback> bound_actions_by_id;
        GrabType grab_type;
    };
}