1 /********************************************************************
2 Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
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 "fullscreen_shell.h"
21 #include "output.h"
22 #include "surface.h"
23 #include "wayland_pointer_p.h"
24
25 #include <QDebug>
26 // wayland
27 #include <wayland-client-protocol.h>
28 #include <wayland-fullscreen-shell-client-protocol.h>
29
30 namespace Wrapland
31 {
32 namespace Client
33 {
34
35 class Q_DECL_HIDDEN FullscreenShell::Private
36 {
37 public:
38 Private(FullscreenShell* q);
39 void setup(_wl_fullscreen_shell* shell);
40
41 WaylandPointer<_wl_fullscreen_shell, _wl_fullscreen_shell_release> shell;
42 EventQueue* queue = nullptr;
43 bool capabilityArbitraryModes = false;
44 bool capabilityCursorPlane = false;
45
46 private:
47 void handleCapabilities(uint32_t capability);
48 static void
49 capabilitiesAnnounce(void* data, struct _wl_fullscreen_shell* shell, uint32_t capability);
50 static _wl_fullscreen_shell_listener s_fullscreenShellListener;
51 FullscreenShell* q;
52 };
53
54 _wl_fullscreen_shell_listener FullscreenShell::Private::s_fullscreenShellListener
55 = {FullscreenShell::Private::capabilitiesAnnounce};
56
Private(FullscreenShell * q)57 FullscreenShell::Private::Private(FullscreenShell* q)
58 : q(q)
59 {
60 }
61
setup(_wl_fullscreen_shell * s)62 void FullscreenShell::Private::setup(_wl_fullscreen_shell* s)
63 {
64 Q_ASSERT(!shell);
65 Q_ASSERT(s);
66 shell.setup(s);
67 _wl_fullscreen_shell_add_listener(shell, &s_fullscreenShellListener, this);
68 }
69
capabilitiesAnnounce(void * data,_wl_fullscreen_shell * shell,uint32_t capability)70 void FullscreenShell::Private::capabilitiesAnnounce(void* data,
71 _wl_fullscreen_shell* shell,
72 uint32_t capability)
73 {
74 auto s = reinterpret_cast<FullscreenShell::Private*>(data);
75 Q_ASSERT(shell == s->shell);
76 s->handleCapabilities(capability);
77 }
78
handleCapabilities(uint32_t capability)79 void FullscreenShell::Private::handleCapabilities(uint32_t capability)
80 {
81 if (capability & _WL_FULLSCREEN_SHELL_CAPABILITY_ARBITRARY_MODES) {
82 capabilityArbitraryModes = true;
83 emit q->capabilityArbitraryModesChanged(capabilityArbitraryModes);
84 }
85 if (capability & _WL_FULLSCREEN_SHELL_CAPABILITY_CURSOR_PLANE) {
86 capabilityCursorPlane = true;
87 emit q->capabilityCursorPlaneChanged(capabilityCursorPlane);
88 }
89 }
90
FullscreenShell(QObject * parent)91 FullscreenShell::FullscreenShell(QObject* parent)
92 : QObject(parent)
93 , d(new Private(this))
94 {
95 }
96
~FullscreenShell()97 FullscreenShell::~FullscreenShell()
98 {
99 release();
100 }
101
release()102 void FullscreenShell::release()
103 {
104 d->shell.release();
105 }
106
setup(_wl_fullscreen_shell * shell)107 void FullscreenShell::setup(_wl_fullscreen_shell* shell)
108 {
109 d->setup(shell);
110 }
111
eventQueue() const112 EventQueue* FullscreenShell::eventQueue() const
113 {
114 return d->queue;
115 }
116
setEventQueue(EventQueue * queue)117 void FullscreenShell::setEventQueue(EventQueue* queue)
118 {
119 d->queue = queue;
120 }
121
present(wl_surface * surface,wl_output * output)122 void FullscreenShell::present(wl_surface* surface, wl_output* output)
123 {
124 Q_ASSERT(d->shell);
125 _wl_fullscreen_shell_present_surface(
126 d->shell, surface, _WL_FULLSCREEN_SHELL_PRESENT_METHOD_DEFAULT, output);
127 }
128
present(Surface * surface,Output * output)129 void FullscreenShell::present(Surface* surface, Output* output)
130 {
131 Q_ASSERT(surface);
132 Q_ASSERT(output);
133 present(*surface, *output);
134 }
135
isValid() const136 bool FullscreenShell::isValid() const
137 {
138 return d->shell.isValid();
139 }
140
hasCapabilityArbitraryModes() const141 bool FullscreenShell::hasCapabilityArbitraryModes() const
142 {
143 return d->capabilityArbitraryModes;
144 }
145
hasCapabilityCursorPlane() const146 bool FullscreenShell::hasCapabilityCursorPlane() const
147 {
148 return d->capabilityCursorPlane;
149 }
150
151 }
152 }
153