This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaylandPointer.hpp
82 lines (66 loc) · 1.78 KB
/
WaylandPointer.hpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef _WAYLANDPOINTER_H
#define _WAYLANDPOINTER_H
#include <iostream>
#include <vector>
#include <functional>
#include <wayland-client.h>
#include <wayland-cursor.h>
#include <WaylandRegistry.hpp>
class WaylandSeatListener
{
public:
virtual void handle_capabilities(struct wl_seat *wl_seat, uint32_t caps){};
void handle_name(struct wl_seat *wl_seat, const char *name){};
virtual ~WaylandSeatListener() = default;
};
class WaylandPointer;
class WaylandPointerDelegate
{
public:
int x, y;
virtual void on_mouse_motion(int x, int y)
{
this->x = x;
this->y = y;
}
virtual void on_mouse_click(){};
virtual void on_mouse_up(){};
virtual void on_mouse_scroll(bool up){};
};
class WaylandPointer : public WaylandSeatListener
{
public:
WaylandPointerDelegate *delegate;
WaylandXDGRegistry *registry;
WaylandPointer(WaylandXDGRegistry *registry);
struct wl_pointer *wl_pointer;
struct wl_surface *cursor_surface;
virtual void handle_capabilities(struct wl_seat *wl_seat, uint32_t caps);
void handle_name(struct wl_seat *wl_seat, const char *name)
{
}
};
class WaylandSeat
{
struct wl_seat *wl_seat;
std::vector<WaylandSeatListener *> listeners;
public:
WaylandSeat(struct wl_seat *wl_seat);
void handle_capabilities(struct wl_seat *wl_seat, uint32_t caps)
{
for (WaylandSeatListener *listener : this->listeners)
{
listener->handle_capabilities(wl_seat, caps);
}
}
void handle_name(struct wl_seat *wl_seat, const char *name)
{
// std::cout << "Name: " << name << "\n";
}
void add_listener(WaylandSeatListener *listener)
{
// std::cout << "Adding listener\n";
this->listeners.emplace_back(listener);
}
};
#endif