1 /*
2     SPDX-FileCopyrightText: 2020 Roman Gilg <subdiff@gmail.com>
3     SPDX-FileCopyrightText: 2021 Francesco Sorrentino <francesco.sorr@gmail.com>
4 
5     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only
6 */
7 #pragma once
8 
9 #include <Wrapland/Server/wraplandserver_export.h>
10 
11 #include <QObject>
12 #include <QPoint>
13 
14 #include <cstdint>
15 #include <map>
16 #include <vector>
17 
18 namespace Wrapland::Server
19 {
20 class Client;
21 class Seat;
22 class Surface;
23 class Touch;
24 
25 struct touch_focus {
26     Surface* surface{nullptr};
27     std::vector<Touch*> devices;
28     QPointF offset;
29     QPointF first_touch_position;
30     QMetaObject::Connection surface_lost_notifier;
31 };
32 
33 /*
34  * Handle touch devices associated to a seat.
35  */
36 class WRAPLANDSERVER_EXPORT touch_pool
37 {
38 public:
39     explicit touch_pool(Seat* seat);
40     ~touch_pool();
41 
42     touch_focus const& get_focus() const;
43     std::vector<Touch*> const& get_devices() const;
44 
45     void set_focused_surface(Surface* surface, const QPointF& surfacePosition = QPointF());
46     void set_focused_surface_position(const QPointF& surfacePosition);
47     int32_t touch_down(const QPointF& globalPosition);
48     void touch_up(int32_t id);
49     void touch_move(int32_t id, const QPointF& globalPosition);
50     void touch_move_any(QPointF const& pos);
51     void touch_frame() const;
52     void cancel_sequence();
53     bool has_implicit_grab(uint32_t serial) const;
54     bool is_in_progress() const;
55 
56 private:
57     friend class Seat;
58     void create_device(Client* client, uint32_t version, uint32_t id);
59 
60     touch_focus focus;
61 
62     // Key: Distinct id per touch point, Value: Wayland display serial.
63     std::map<int32_t, uint32_t> ids;
64 
65     std::vector<Touch*> devices;
66     Seat* seat;
67 };
68 
69 }
70