7 #include "event_queue.h" 11 #include "wayland_pointer_p.h" 13 #include <QGuiApplication> 15 #include <qpa/qplatformnativeinterface.h> 17 #include <wayland-client-protocol.h> 24 class Q_DECL_HIDDEN Shell::Private
27 WaylandPointer<wl_shell, wl_shell_destroy> shell;
28 EventQueue *queue =
nullptr;
47 Q_EMIT interfaceAboutToBeDestroyed();
56 Q_EMIT interfaceAboutToBeReleased();
60 void Shell::setup(wl_shell *shell)
64 d->shell.setup(shell);
81 connect(
this, &Shell::interfaceAboutToBeReleased, s, &ShellSurface::release);
82 connect(
this, &Shell::interfaceAboutToBeDestroyed, s, &ShellSurface::destroy);
83 auto w = wl_shell_get_shell_surface(d->shell, surface);
85 d->queue->addProxy(w);
94 return createSurface(*surface, parent);
97 bool Shell::isValid()
const 99 return d->shell.isValid();
102 Shell::operator wl_shell*()
107 Shell::operator wl_shell*()
const 112 class Q_DECL_HIDDEN ShellSurface::Private
115 Private(ShellSurface *q);
116 void setup(wl_shell_surface *surface);
118 WaylandPointer<wl_shell_surface, wl_shell_surface_destroy> surface;
123 void ping(uint32_t serial);
124 static void pingCallback(
void *data,
struct wl_shell_surface *shellSurface, uint32_t serial);
125 static void configureCallback(
void *data,
struct wl_shell_surface *shellSurface, uint32_t edges, int32_t width, int32_t height);
126 static void popupDoneCallback(
void *data,
struct wl_shell_surface *shellSurface);
129 static const struct wl_shell_surface_listener s_listener;
134 ShellSurface::Private::Private(ShellSurface *q)
139 void ShellSurface::Private::setup(wl_shell_surface *s)
144 wl_shell_surface_add_listener(surface, &s_listener,
this);
147 ShellSurface *ShellSurface::fromWindow(
QWindow *window)
152 QPlatformNativeInterface *native = qApp->platformNativeInterface();
157 wl_shell_surface *s =
reinterpret_cast<wl_shell_surface*
>(native->nativeResourceForWindow(QByteArrayLiteral(
"wl_shell_surface"), window));
161 if (
auto surface =
get(s)) {
164 ShellSurface *surface =
new ShellSurface(window);
165 surface->d->surface.setup(s,
true);
169 ShellSurface *ShellSurface::fromQtWinId(WId wid)
173 for (
auto win : qApp->allWindows()) {
174 if (win->winId() == wid) {
183 return fromWindow(window);
186 ShellSurface *ShellSurface::get(wl_shell_surface *native)
188 auto it = std::find_if(Private::s_surfaces.constBegin(), Private::s_surfaces.constEnd(),
189 [native](ShellSurface *s) {
190 return s->d->surface == native;
193 if (it != Private::s_surfaces.constEnd()) {
201 , d(
new Private(
this))
203 Private::s_surfaces <<
this;
206 ShellSurface::~ShellSurface()
208 Private::s_surfaces.removeOne(
this);
212 void ShellSurface::release()
214 d->surface.release();
217 void ShellSurface::destroy()
219 d->surface.destroy();
223 const struct wl_shell_surface_listener ShellSurface::Private::s_listener = {
230 void ShellSurface::Private::configureCallback(
void *data, wl_shell_surface *shellSurface, uint32_t edges, int32_t width, int32_t height)
233 auto s =
reinterpret_cast<ShellSurface::Private*
>(data);
234 Q_ASSERT(s->surface == shellSurface);
235 s->q->setSize(
QSize(width, height));
238 void ShellSurface::Private::pingCallback(
void *data, wl_shell_surface *shellSurface, uint32_t serial)
240 auto s =
reinterpret_cast<ShellSurface::Private*
>(data);
241 Q_ASSERT(s->surface == shellSurface);
245 void ShellSurface::Private::popupDoneCallback(
void *data, wl_shell_surface *shellSurface)
247 auto s =
reinterpret_cast<ShellSurface::Private*
>(data);
248 Q_ASSERT(s->surface == shellSurface);
252 void ShellSurface::setup(wl_shell_surface *surface)
257 void ShellSurface::Private::ping(uint32_t serial)
259 wl_shell_surface_pong(surface, serial);
263 void ShellSurface::setSize(
const QSize &size)
265 if (d->size == size) {
272 void ShellSurface::setFullscreen(
Output *output)
275 wl_shell_surface_set_fullscreen(d->surface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, output ? output->output() :
nullptr);
278 void ShellSurface::setMaximized(
Output *output)
281 wl_shell_surface_set_maximized(d->surface, output ? output->output() :
nullptr);
284 void ShellSurface::setToplevel()
287 wl_shell_surface_set_toplevel(d->surface);
293 uint32_t wlFlags = 0;
294 if (flags.
testFlag(TransientFlag::NoFocus)) {
295 wlFlags |= WL_SHELL_SURFACE_TRANSIENT_INACTIVE;
297 wl_shell_surface_set_transient(d->surface, *parent, offset.
x(), offset.
y(), wlFlags);
304 Q_ASSERT(grabbedSeat);
305 uint32_t wlFlags = 0;
306 if (flags.
testFlag(TransientFlag::NoFocus)) {
307 wlFlags |= WL_SHELL_SURFACE_TRANSIENT_INACTIVE;
309 wl_shell_surface_set_popup(d->surface, *grabbedSeat, grabSerial, *parent, offset.
x(), offset.
y(), wlFlags);
312 void ShellSurface::requestMove(
Seat *seat, quint32 serial)
317 wl_shell_surface_move(d->surface, *seat, serial);
320 void ShellSurface::requestResize(
Seat *seat, quint32 serial,
Qt::Edges edges)
325 uint wlEdge = WL_SHELL_SURFACE_RESIZE_NONE;
328 wlEdge = WL_SHELL_SURFACE_RESIZE_TOP_LEFT;
330 wlEdge = WL_SHELL_SURFACE_RESIZE_TOP_RIGHT;
332 wlEdge = WL_SHELL_SURFACE_RESIZE_TOP;
336 wlEdge = WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT;
338 wlEdge = WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT;
340 wlEdge = WL_SHELL_SURFACE_RESIZE_BOTTOM;
343 wlEdge = WL_SHELL_SURFACE_RESIZE_RIGHT;
345 wlEdge = WL_SHELL_SURFACE_RESIZE_LEFT;
348 wl_shell_surface_resize(d->surface, *seat, serial, wlEdge);
351 void ShellSurface::setTitle(
const QString &title)
356 void ShellSurface::setWindowClass(
const QByteArray &windowClass)
358 wl_shell_surface_set_class(d->surface, windowClass.
constData());
361 QSize ShellSurface::size()
const 366 bool ShellSurface::isValid()
const 371 ShellSurface::operator wl_shell_surface*()
376 ShellSurface::operator wl_shell_surface*()
const bool isValid() const const
void setup(wl_shell_surface *surface)
Setup this ShellSurface to manage the surface.
Wrapper class for wl_event_queue interface.
Wrapper for the wl_seat interface.
Wrapper for the wl_output interface.
Wrapper for the wl_surface interface.
const char * constData() const const
Wrapper for the wl_shell_surface interface.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
bool testFlag(Enum flag) const const
void pinged()
Signal is emitted when the ShellSurface received a ping request.
QByteArray toUtf8() const const