1 /****************************************************************************
2 Copyright 2015 Marco Martin <notmart@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 #include "slide.h"
21 #include "event_queue.h"
22 #include "surface.h"
23 #include "wayland_pointer_p.h"
24
25 #include <wayland-slide-client-protocol.h>
26
27 namespace Wrapland
28 {
29 namespace Client
30 {
31
32 class Q_DECL_HIDDEN SlideManager::Private
33 {
34 public:
35 Private() = default;
36
37 WaylandPointer<org_kde_kwin_slide_manager, org_kde_kwin_slide_manager_destroy> slidemanager;
38 EventQueue* queue = nullptr;
39 };
40
SlideManager(QObject * parent)41 SlideManager::SlideManager(QObject* parent)
42 : QObject(parent)
43 , d(new Private)
44 {
45 }
46
~SlideManager()47 SlideManager::~SlideManager()
48 {
49 release();
50 }
51
setup(org_kde_kwin_slide_manager * slidemanager)52 void SlideManager::setup(org_kde_kwin_slide_manager* slidemanager)
53 {
54 Q_ASSERT(slidemanager);
55 Q_ASSERT(!d->slidemanager);
56 d->slidemanager.setup(slidemanager);
57 }
58
release()59 void SlideManager::release()
60 {
61 d->slidemanager.release();
62 }
63
setEventQueue(EventQueue * queue)64 void SlideManager::setEventQueue(EventQueue* queue)
65 {
66 d->queue = queue;
67 }
68
eventQueue()69 EventQueue* SlideManager::eventQueue()
70 {
71 return d->queue;
72 }
73
operator org_kde_kwin_slide_manager*()74 SlideManager::operator org_kde_kwin_slide_manager*()
75 {
76 return d->slidemanager;
77 }
78
operator org_kde_kwin_slide_manager*() const79 SlideManager::operator org_kde_kwin_slide_manager*() const
80 {
81 return d->slidemanager;
82 }
83
isValid() const84 bool SlideManager::isValid() const
85 {
86 return d->slidemanager.isValid();
87 }
88
createSlide(Surface * surface,QObject * parent)89 Slide* SlideManager::createSlide(Surface* surface, QObject* parent)
90 {
91 Q_ASSERT(isValid());
92 Slide* s = new Slide(parent);
93 auto w = org_kde_kwin_slide_manager_create(d->slidemanager, *surface);
94 if (d->queue) {
95 d->queue->addProxy(w);
96 }
97 s->setup(w);
98 return s;
99 }
100
removeSlide(Surface * surface)101 void SlideManager::removeSlide(Surface* surface)
102 {
103 org_kde_kwin_slide_manager_unset(d->slidemanager, *surface);
104 }
105
106 class Slide::Private
107 {
108 public:
109 Private() = default;
110
111 WaylandPointer<org_kde_kwin_slide, org_kde_kwin_slide_release> slide;
112 };
113
Slide(QObject * parent)114 Slide::Slide(QObject* parent)
115 : QObject(parent)
116 , d(new Private)
117 {
118 }
119
~Slide()120 Slide::~Slide()
121 {
122 release();
123 }
124
setup(org_kde_kwin_slide * slide)125 void Slide::setup(org_kde_kwin_slide* slide)
126 {
127 Q_ASSERT(slide);
128 Q_ASSERT(!d->slide);
129 d->slide.setup(slide);
130 }
131
release()132 void Slide::release()
133 {
134 d->slide.release();
135 }
136
operator org_kde_kwin_slide*()137 Slide::operator org_kde_kwin_slide*()
138 {
139 return d->slide;
140 }
141
operator org_kde_kwin_slide*() const142 Slide::operator org_kde_kwin_slide*() const
143 {
144 return d->slide;
145 }
146
isValid() const147 bool Slide::isValid() const
148 {
149 return d->slide.isValid();
150 }
151
commit()152 void Slide::commit()
153 {
154 Q_ASSERT(isValid());
155 org_kde_kwin_slide_commit(d->slide);
156 }
157
setLocation(Slide::Location location)158 void Slide::setLocation(Slide::Location location)
159 {
160 org_kde_kwin_slide_set_location(d->slide, location);
161 }
162
setOffset(qint32 offset)163 void Slide::setOffset(qint32 offset)
164 {
165 org_kde_kwin_slide_set_offset(d->slide, offset);
166 }
167
168 }
169 }
170