aboutsummaryrefslogtreecommitdiff
path: root/include/RegionSelector.hpp
blob: 0465302d709642b10925152de60f30a43bbbb4f8 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include "WindowUtils.hpp"
#include <mglpp/system/vec.hpp>
#include <mglpp/graphics/Color.hpp>
#include <vector>

#include <X11/Xlib.h>

namespace gsr {
    struct Region {
        mgl::vec2i pos;
        mgl::vec2i size;
    };

    class RegionSelector {
    public:
        RegionSelector();
        RegionSelector(const RegionSelector&) = delete;
        RegionSelector& operator=(const RegionSelector&) = delete;
        ~RegionSelector();

        bool start(mgl::Color border_color);
        void stop();
        bool is_started() const;

        bool failed() const;
        bool poll_events();
        bool is_selected() const;
        bool take_selection();
        bool take_canceled();
        Region get_selection() const;
    private:
        void on_button_press(const void *de);
        void on_button_release(const void *de);
        void on_mouse_motion(const void *de);
    private:
        Display *dpy = nullptr;
        unsigned long region_window = 0;
        unsigned long cursor_window = 0;
        unsigned long region_window_colormap = 0;
        int xi_opcode = 0;
        GC region_gc = nullptr;
        GC cursor_gc = nullptr;

        Region region;
        bool selecting_region = false;
        bool selected = false;
        bool canceled = false;
        bool is_wayland = false;
        std::vector<Monitor> monitors;
        mgl::vec2i cursor_pos;
    };
}