1 /********************************************************************
2 Copyright © 2020 Roman Gilg <subdiff@gmail.com>
3 
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11 
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library.  If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #pragma once
21 
22 #include "seat.h"
23 
24 #include "drag_pool.h"
25 #include "keyboard_pool.h"
26 #include "pointer_pool.h"
27 #include "selection_pool.h"
28 #include "text_input_pool.h"
29 #include "touch_pool.h"
30 
31 #include "wayland/global.h"
32 
33 #include <QHash>
34 #include <QMap>
35 #include <QPointer>
36 #include <QVector>
37 
38 #include <map>
39 #include <optional>
40 #include <string>
41 #include <vector>
42 #include <wayland-server.h>
43 
44 namespace Wrapland::Server
45 {
46 
47 constexpr uint32_t SeatVersion = 5;
48 using SeatGlobal = Wayland::Global<Seat, SeatVersion>;
49 using SeatBind = Wayland::Bind<SeatGlobal>;
50 
51 class Seat::Private : public SeatGlobal
52 {
53 public:
54     Private(Seat* q, Display* d);
55 
56     void bindInit(SeatBind* bind) override;
57 
58     void sendCapabilities();
59     void sendName();
60 
61     uint32_t getCapabilities() const;
62 
63     template<typename Dev>
set_capability(uint32_t cap,std::optional<Dev> & dev,bool has)64     void set_capability(uint32_t cap, std::optional<Dev>& dev, bool has)
65     {
66         if (static_cast<bool>(dev) == has) {
67             return;
68         }
69         if (has) {
70             prior_caps |= cap;
71             dev = Dev(q_ptr);
72         } else {
73             dev.reset();
74         }
75         sendCapabilities();
76     }
77 
78     std::string name;
79     uint32_t timestamp = 0;
80 
81     std::optional<pointer_pool> pointers;
82     std::optional<keyboard_pool> keyboards;
83     std::optional<touch_pool> touches;
84     uint32_t prior_caps{0};
85 
86     drag_pool drags;
87     selection_pool<DataDevice, &Seat::selectionChanged> data_devices;
88     selection_pool<PrimarySelectionDevice, &Seat::primarySelectionChanged>
89         primary_selection_devices;
90     input_method_v2* input_method{nullptr};
91     text_input_pool text_inputs;
92 
93     // legacy
94     friend class SeatInterface;
95     //
96 
97     Seat* q_ptr;
98 
99 private:
100     static void getPointerCallback(SeatBind* bind, uint32_t id);
101     static void getKeyboardCallback(SeatBind* bind, uint32_t id);
102     static void getTouchCallback(SeatBind* bind, uint32_t id);
103 
104     static const struct wl_seat_interface s_interface;
105 };
106 
107 }
108