File: primary_selection.h

package info (click to toggle)
wlcs 1.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,528 kB
  • sloc: cpp: 14,211; xml: 7,744; ansic: 952; sh: 164; makefile: 33
file content (162 lines) | stat: -rw-r--r-- 5,938 bytes parent folder | download | duplicates (4)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright © 2019 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
 */

#ifndef WLCS_PRIMARY_SELECTION_H
#define WLCS_PRIMARY_SELECTION_H

#include "generated/primary-selection-unstable-v1-client.h"

#include "active_listeners.h"
#include "wl_interface_descriptor.h"
#include "wl_handle.h"

#include <memory>
#include <mutex>
#include <set>

namespace wlcs
{
WLCS_CREATE_INTERFACE_DESCRIPTOR(zwp_primary_selection_device_manager_v1)

    class PrimarySelectionSource
    {
    public:
        using WrappedType = zwp_primary_selection_source_v1;

        PrimarySelectionSource() = default;

        explicit PrimarySelectionSource(zwp_primary_selection_device_manager_v1* manager) :
                self{zwp_primary_selection_device_manager_v1_create_source(manager), deleter} {}

        operator WrappedType*() const { return self.get(); }

        void reset() { self.reset(); }

        void reset(WrappedType* source) { self.reset(source, deleter); }

        friend void zwp_primary_selection_source_v1_destroy(PrimarySelectionSource const&) = delete;

    private:
        static void deleter(WrappedType* source) { zwp_primary_selection_source_v1_destroy(source); }

        std::shared_ptr<WrappedType> self;
    };


    class PrimarySelectionDevice
    {
    public:
        using WrappedType = zwp_primary_selection_device_v1;

        PrimarySelectionDevice() = default;

        PrimarySelectionDevice(zwp_primary_selection_device_manager_v1* manager, wl_seat* seat) :
                self{zwp_primary_selection_device_manager_v1_get_device(manager, seat), deleter} {}

        operator WrappedType*() const { return self.get(); }

        void reset() { self.reset(); }

        void reset(WrappedType* device) { self.reset(device, deleter); }

        friend void zwp_primary_selection_device_v1_destroy(PrimarySelectionDevice const&) = delete;

    private:
        static void deleter(WrappedType* device) { zwp_primary_selection_device_v1_destroy(device); }

        std::shared_ptr<WrappedType> self;
    };

    struct PrimarySelectionDeviceListener
    {
        PrimarySelectionDeviceListener(zwp_primary_selection_device_v1* device)
        {
            active_listeners.add(this);
            zwp_primary_selection_device_v1_add_listener(device, &thunks, this);
        }

        virtual ~PrimarySelectionDeviceListener() { active_listeners.del(this); }

        PrimarySelectionDeviceListener(PrimarySelectionDeviceListener const&) = delete;
        PrimarySelectionDeviceListener& operator=(PrimarySelectionDeviceListener const&) = delete;

        virtual void data_offer(zwp_primary_selection_device_v1* device, zwp_primary_selection_offer_v1* offer);

        virtual void selection(zwp_primary_selection_device_v1* device, zwp_primary_selection_offer_v1* offer);

    private:
        static void data_offer(void* data, zwp_primary_selection_device_v1* device, zwp_primary_selection_offer_v1* offer);

        static void selection(void* data, zwp_primary_selection_device_v1* device, zwp_primary_selection_offer_v1* offer);

        static ActiveListeners active_listeners;
        constexpr static zwp_primary_selection_device_v1_listener thunks =
                {
                        &data_offer,
                        &selection
                };
    };

    struct PrimarySelectionOfferListener
    {
        PrimarySelectionOfferListener() { active_listeners.add(this); }
        virtual ~PrimarySelectionOfferListener() { active_listeners.del(this); }

        PrimarySelectionOfferListener(PrimarySelectionOfferListener const&) = delete;
        PrimarySelectionOfferListener& operator=(PrimarySelectionOfferListener const&) = delete;

        void listen_to(zwp_primary_selection_offer_v1* offer)
        {
            zwp_primary_selection_offer_v1_add_listener(offer, &thunks, this);
        }

        virtual void offer(zwp_primary_selection_offer_v1* offer, const char* mime_type);

    private:
        static void offer(void* data, zwp_primary_selection_offer_v1* offer, const char* mime_type);

        static ActiveListeners active_listeners;
        constexpr static zwp_primary_selection_offer_v1_listener thunks = { &offer, };
    };

    struct PrimarySelectionSourceListener
    {
        explicit PrimarySelectionSourceListener(PrimarySelectionSource const& source)
        {
            active_listeners.add(this);
            zwp_primary_selection_source_v1_add_listener(source, &thunks, this);
        }

        virtual ~PrimarySelectionSourceListener() { active_listeners.del(this); }

        PrimarySelectionSourceListener(PrimarySelectionSourceListener const&) = delete;
        PrimarySelectionSourceListener& operator=(PrimarySelectionSourceListener const&) = delete;

        virtual void send(zwp_primary_selection_source_v1* source, const char* mime_type, int32_t fd);
        virtual void cancelled(zwp_primary_selection_source_v1* source);

    private:
        static void send(void* data, zwp_primary_selection_source_v1* source, const char* mime_type, int32_t fd);
        static void cancelled(void* data, zwp_primary_selection_source_v1* source);

        static ActiveListeners active_listeners;
        constexpr static zwp_primary_selection_source_v1_listener thunks = { &send, &cancelled };
    };
}

#endif //WLCS_PRIMARY_SELECTION_H