aboutsummaryrefslogtreecommitdiff
path: root/include/GlobalHotkeysX11.hpp
blob: 427e9f0e238626bcd93fdb4aaca81eaf761afa91 (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
#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;

        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;
    private:
        void 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;
    };
}