~ubuntu-branches/ubuntu/wily/kwin/wily-proposed

« back to all changes in this revision

Viewing changes to wayland_backend.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-08-10 23:16:37 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150810231637-5zb2tstjkez93hml
Tags: 4:5.3.95-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/********************************************************************
2
 
 KWin - the KDE window manager
3
 
 This file is part of the KDE project.
4
 
 
5
 
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
6
 
 
7
 
This program is free software; you can redistribute it and/or modify
8
 
it under the terms of the GNU General Public License as published by
9
 
the Free Software Foundation; either version 2 of the License, or
10
 
(at your option) any later version.
11
 
 
12
 
This program 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
15
 
GNU General Public License for more details.
16
 
 
17
 
You should have received a copy of the GNU General Public License
18
 
along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
*********************************************************************/
20
 
// own
21
 
#include "wayland_backend.h"
22
 
// KWin
23
 
#include "cursor.h"
24
 
#include "input.h"
25
 
#include "main.h"
26
 
#include "scene_qpainter.h"
27
 
#include "screens_wayland.h"
28
 
#include "utils.h"
29
 
#include "wayland_server.h"
30
 
#if HAVE_WAYLAND_EGL
31
 
#include "egl_wayland_backend.h"
32
 
#endif
33
 
#include <KWayland/Client/buffer.h>
34
 
#include <KWayland/Client/compositor.h>
35
 
#include <KWayland/Client/connection_thread.h>
36
 
#include <KWayland/Client/event_queue.h>
37
 
#include <KWayland/Client/fullscreen_shell.h>
38
 
#include <KWayland/Client/keyboard.h>
39
 
#include <KWayland/Client/output.h>
40
 
#include <KWayland/Client/pointer.h>
41
 
#include <KWayland/Client/region.h>
42
 
#include <KWayland/Client/registry.h>
43
 
#include <KWayland/Client/seat.h>
44
 
#include <KWayland/Client/shell.h>
45
 
#include <KWayland/Client/shm_pool.h>
46
 
#include <KWayland/Client/subcompositor.h>
47
 
#include <KWayland/Client/subsurface.h>
48
 
#include <KWayland/Client/surface.h>
49
 
#include <KWayland/Client/touch.h>
50
 
#include <KWayland/Server/buffer_interface.h>
51
 
#include <KWayland/Server/seat_interface.h>
52
 
#include <KWayland/Server/surface_interface.h>
53
 
// Qt
54
 
#include <QDebug>
55
 
#include <QMetaMethod>
56
 
#include <QThread>
57
 
// Wayland
58
 
#if HAVE_WAYLAND_CURSOR
59
 
#include <wayland-cursor.h>
60
 
#endif
61
 
 
62
 
namespace KWin
63
 
{
64
 
namespace Wayland
65
 
{
66
 
 
67
 
using namespace KWayland::Client;
68
 
 
69
 
WaylandSeat::WaylandSeat(wl_seat *seat, WaylandBackend *backend)
70
 
    : QObject(NULL)
71
 
    , m_seat(new Seat(this))
72
 
    , m_pointer(NULL)
73
 
    , m_keyboard(NULL)
74
 
    , m_touch(nullptr)
75
 
    , m_cursor(NULL)
76
 
#if HAVE_WAYLAND_CURSOR
77
 
    , m_theme(new WaylandCursorTheme(backend->shmPool(), this))
78
 
#endif
79
 
    , m_enteredSerial(0)
80
 
    , m_backend(backend)
81
 
    , m_installCursor(false)
82
 
{
83
 
    m_seat->setup(seat);
84
 
    connect(m_seat, &Seat::hasKeyboardChanged, this,
85
 
        [this](bool hasKeyboard) {
86
 
            if (hasKeyboard) {
87
 
                m_keyboard = m_seat->createKeyboard(this);
88
 
                connect(m_keyboard, &Keyboard::keyChanged, this,
89
 
                    [this](quint32 key, Keyboard::KeyState state, quint32 time) {
90
 
                        auto toState = [state] {
91
 
                            switch (state) {
92
 
                            case Keyboard::KeyState::Pressed:
93
 
                                return InputRedirection::KeyboardKeyPressed;
94
 
                            case Keyboard::KeyState::Released:
95
 
                                return InputRedirection::KeyboardKeyReleased;
96
 
                            }
97
 
                            abort();
98
 
                        };
99
 
                        input()->processKeyboardKey(key, toState(), time);
100
 
                    }
101
 
                );
102
 
                connect(m_keyboard, &Keyboard::modifiersChanged, this,
103
 
                    [this](quint32 depressed, quint32 latched, quint32 locked, quint32 group) {
104
 
                        input()->processKeyboardModifiers(depressed, latched, locked, group);
105
 
                    }
106
 
                );
107
 
                connect(m_keyboard, &Keyboard::keymapChanged, this,
108
 
                    [this](int fd, quint32 size) {
109
 
                        input()->processKeymapChange(fd, size);
110
 
                    }
111
 
                );
112
 
            } else {
113
 
                destroyKeyboard();
114
 
            }
115
 
        }
116
 
    );
117
 
    connect(m_seat, &Seat::hasPointerChanged, this,
118
 
        [this](bool hasPointer) {
119
 
            if (hasPointer && !m_pointer) {
120
 
                m_pointer = m_seat->createPointer(this);
121
 
                connect(m_pointer, &Pointer::entered, this,
122
 
                    [this](quint32 serial) {
123
 
                        m_enteredSerial = serial;
124
 
                        if (!m_installCursor) {
125
 
                            // explicitly hide cursor
126
 
                            m_pointer->hideCursor();
127
 
                        }
128
 
                    }
129
 
                );
130
 
                connect(m_pointer, &Pointer::motion, this,
131
 
                    [this](const QPointF &relativeToSurface, quint32 time) {
132
 
                        input()->processPointerMotion(relativeToSurface.toPoint(), time);
133
 
                    }
134
 
                );
135
 
                connect(m_pointer, &Pointer::buttonStateChanged, this,
136
 
                    [this](quint32 serial, quint32 time, quint32 button, Pointer::ButtonState state) {
137
 
                        Q_UNUSED(serial)
138
 
                        auto toState = [state] {
139
 
                            switch (state) {
140
 
                            case Pointer::ButtonState::Pressed:
141
 
                                return InputRedirection::PointerButtonPressed;
142
 
                            case Pointer::ButtonState::Released:
143
 
                                return InputRedirection::PointerButtonReleased;
144
 
                            }
145
 
                            abort();
146
 
                        };
147
 
                        input()->processPointerButton(button, toState(), time);
148
 
                    }
149
 
                );
150
 
                connect(m_pointer, &Pointer::axisChanged, this,
151
 
                    [this](quint32 time, Pointer::Axis axis, qreal delta) {
152
 
                        auto toAxis = [axis] {
153
 
                            switch (axis) {
154
 
                            case Pointer::Axis::Horizontal:
155
 
                                return InputRedirection::PointerAxisHorizontal;
156
 
                            case Pointer::Axis::Vertical:
157
 
                                return InputRedirection::PointerAxisVertical;
158
 
                            }
159
 
                            abort();
160
 
                        };
161
 
                        input()->processPointerAxis(toAxis(), delta, time);
162
 
                    }
163
 
                );
164
 
            } else {
165
 
                destroyPointer();
166
 
            }
167
 
        }
168
 
    );
169
 
    connect(m_seat, &Seat::hasTouchChanged,
170
 
        [this] (bool hasTouch) {
171
 
            if (hasTouch && !m_touch) {
172
 
                m_touch = m_seat->createTouch(this);
173
 
                connect(m_touch, &Touch::sequenceCanceled, input(), &InputRedirection::cancelTouch);
174
 
                connect(m_touch, &Touch::frameEnded, input(), &InputRedirection::touchFrame);
175
 
                connect(m_touch, &Touch::sequenceStarted, this,
176
 
                    [] (TouchPoint *tp) {
177
 
                        input()->processTouchDown(tp->id(), tp->position(), tp->time());
178
 
                    }
179
 
                );
180
 
                connect(m_touch, &Touch::pointAdded, this,
181
 
                    [] (TouchPoint *tp) {
182
 
                        input()->processTouchDown(tp->id(), tp->position(), tp->time());
183
 
                    }
184
 
                );
185
 
                connect(m_touch, &Touch::pointRemoved, this,
186
 
                    [] (TouchPoint *tp) {
187
 
                        input()->processTouchUp(tp->id(), tp->time());
188
 
                    }
189
 
                );
190
 
                connect(m_touch, &Touch::pointMoved, this,
191
 
                    [] (TouchPoint *tp) {
192
 
                        input()->processTouchMotion(tp->id(), tp->position(), tp->time());
193
 
                    }
194
 
                );
195
 
            } else {
196
 
                destroyTouch();
197
 
            }
198
 
        }
199
 
    );
200
 
    WaylandServer *server = waylandServer();
201
 
    if (server) {
202
 
        using namespace KWayland::Server;
203
 
        SeatInterface *si = server->seat();
204
 
        connect(m_seat, &Seat::hasKeyboardChanged, si, &SeatInterface::setHasKeyboard);
205
 
        connect(m_seat, &Seat::hasPointerChanged, si, &SeatInterface::setHasPointer);
206
 
        connect(m_seat, &Seat::hasTouchChanged, si, &SeatInterface::setHasTouch);
207
 
        connect(m_seat, &Seat::nameChanged, si, &SeatInterface::setName);
208
 
    }
209
 
}
210
 
 
211
 
WaylandSeat::~WaylandSeat()
212
 
{
213
 
    destroyPointer();
214
 
    destroyKeyboard();
215
 
    destroyTouch();
216
 
}
217
 
 
218
 
void WaylandSeat::destroyPointer()
219
 
{
220
 
    delete m_pointer;
221
 
    m_pointer = nullptr;
222
 
}
223
 
 
224
 
void WaylandSeat::destroyKeyboard()
225
 
{
226
 
    delete m_keyboard;
227
 
    m_keyboard = nullptr;
228
 
}
229
 
 
230
 
void WaylandSeat::destroyTouch()
231
 
{
232
 
    delete m_touch;
233
 
    m_touch = nullptr;
234
 
}
235
 
 
236
 
void WaylandSeat::installCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotSpot)
237
 
{
238
 
    if (!m_installCursor) {
239
 
        return;
240
 
    }
241
 
    if (!m_pointer || !m_pointer->isValid()) {
242
 
        return;
243
 
    }
244
 
    if (!m_cursor) {
245
 
        m_cursor = m_backend->compositor()->createSurface(this);
246
 
    }
247
 
    if (!m_cursor || !m_cursor->isValid()) {
248
 
        return;
249
 
    }
250
 
    m_pointer->setCursor(m_cursor, hotSpot);
251
 
    m_cursor->attachBuffer(image);
252
 
    m_cursor->damage(QRect(QPoint(0,0), size));
253
 
    m_cursor->commit(Surface::CommitFlag::None);
254
 
}
255
 
 
256
 
void WaylandSeat::installCursorImage(Qt::CursorShape shape)
257
 
{
258
 
#if HAVE_WAYLAND_CURSOR
259
 
    wl_cursor_image *image = m_theme->get(shape);
260
 
    if (!image) {
261
 
        return;
262
 
    }
263
 
    installCursorImage(wl_cursor_image_get_buffer(image),
264
 
                       QSize(image->width, image->height),
265
 
                       QPoint(image->hotspot_x, image->hotspot_y));
266
 
#endif
267
 
}
268
 
 
269
 
void WaylandSeat::installCursorImage(const QImage &image, const QPoint &hotSpot)
270
 
{
271
 
    installCursorImage(*(m_backend->shmPool()->createBuffer(image).data()), image.size(), hotSpot);
272
 
}
273
 
 
274
 
void WaylandSeat::setInstallCursor(bool install)
275
 
{
276
 
    // TODO: remove, add?
277
 
    m_installCursor = install;
278
 
}
279
 
 
280
 
#if HAVE_WAYLAND_CURSOR
281
 
WaylandCursorTheme::WaylandCursorTheme(KWayland::Client::ShmPool *shm, QObject *parent)
282
 
    : QObject(parent)
283
 
    , m_theme(nullptr)
284
 
    , m_shm(shm)
285
 
{
286
 
}
287
 
 
288
 
WaylandCursorTheme::~WaylandCursorTheme()
289
 
{
290
 
    destroyTheme();
291
 
}
292
 
 
293
 
void WaylandCursorTheme::loadTheme()
294
 
{
295
 
    if (!m_shm->isValid()) {
296
 
        return;
297
 
    }
298
 
    Cursor *c = Cursor::self();
299
 
    if (!m_theme) {
300
 
        // so far the theme had not been created, this means we need to start tracking theme changes
301
 
        connect(c, &Cursor::themeChanged, this, &WaylandCursorTheme::loadTheme);
302
 
    } else {
303
 
        destroyTheme();
304
 
    }
305
 
    m_theme = wl_cursor_theme_load(c->themeName().toUtf8().constData(),
306
 
                                   c->themeSize() ? c->themeSize() : -1, m_shm->shm());
307
 
}
308
 
 
309
 
void WaylandCursorTheme::destroyTheme()
310
 
{
311
 
    if (!m_theme) {
312
 
        return;
313
 
    }
314
 
    wl_cursor_theme_destroy(m_theme);
315
 
    m_theme = nullptr;
316
 
}
317
 
 
318
 
wl_cursor_image *WaylandCursorTheme::get(Qt::CursorShape shape)
319
 
{
320
 
    if (!m_theme) {
321
 
        loadTheme();
322
 
    }
323
 
    if (!m_theme) {
324
 
        // loading cursor failed
325
 
        return nullptr;
326
 
    }
327
 
    wl_cursor *c = wl_cursor_theme_get_cursor(m_theme, Cursor::self()->cursorName(shape).constData());
328
 
    if (!c || c->image_count <= 0) {
329
 
        return nullptr;
330
 
    }
331
 
    return c->images[0];
332
 
}
333
 
#endif
334
 
 
335
 
WaylandCursor::WaylandCursor(Surface *parentSurface, WaylandBackend *backend)
336
 
    : QObject(backend)
337
 
    , m_backend(backend)
338
 
#if HAVE_WAYLAND_CURSOR
339
 
    , m_theme(new WaylandCursorTheme(backend->shmPool(), this))
340
 
#endif
341
 
{
342
 
    auto surface = backend->compositor()->createSurface(this);
343
 
    m_subSurface = backend->subCompositor()->createSubSurface(QPointer<Surface>(surface), QPointer<Surface>(parentSurface), this);
344
 
 
345
 
    connect(Cursor::self(), &Cursor::posChanged, this,
346
 
        [this](const QPoint &pos) {
347
 
            m_subSurface->setPosition(pos - m_hotSpot);
348
 
            QPointer<Surface> parent = m_subSurface->parentSurface();
349
 
            if (parent.isNull()) {
350
 
                return;
351
 
            }
352
 
            parent->commit(Surface::CommitFlag::None);
353
 
        }
354
 
    );
355
 
 
356
 
    // install a default cursor image:
357
 
    setCursorImage(Qt::ArrowCursor);
358
 
}
359
 
 
360
 
void WaylandCursor::setHotSpot(const QPoint &pos)
361
 
{
362
 
    if (m_hotSpot == pos) {
363
 
        return;
364
 
    }
365
 
    m_hotSpot = pos;
366
 
    emit hotSpotChanged(m_hotSpot);
367
 
}
368
 
 
369
 
void WaylandCursor::setCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotspot)
370
 
{
371
 
    QPointer<Surface> cursor = m_subSurface->surface();
372
 
    if (cursor.isNull()) {
373
 
        return;
374
 
    }
375
 
    cursor->attachBuffer(image);
376
 
    cursor->damage(QRect(QPoint(0,0), size));
377
 
    cursor->setInputRegion(m_backend->compositor()->createRegion(QRegion()).get());
378
 
    cursor->commit(Surface::CommitFlag::None);
379
 
    setHotSpot(hotspot);
380
 
    m_subSurface->setPosition(Cursor::pos() - m_hotSpot);
381
 
    QPointer<Surface> parent = m_subSurface->parentSurface();
382
 
    if (parent.isNull()) {
383
 
        return;
384
 
    }
385
 
    parent->commit(Surface::CommitFlag::None);
386
 
}
387
 
 
388
 
void WaylandCursor::setCursorImage(const QImage &image, const QPoint &hotspot)
389
 
{
390
 
    setCursorImage(*(m_backend->shmPool()->createBuffer(image).data()), image.size(), hotspot);
391
 
}
392
 
 
393
 
void WaylandCursor::setCursorImage(Qt::CursorShape shape)
394
 
{
395
 
#if HAVE_WAYLAND_CURSOR
396
 
    wl_cursor_image *image = m_theme->get(shape);
397
 
    if (!image) {
398
 
        return;
399
 
    }
400
 
    setCursorImage(wl_cursor_image_get_buffer(image),
401
 
                   QSize(image->width, image->height),
402
 
                   QPoint(image->hotspot_x, image->hotspot_y));
403
 
#endif
404
 
}
405
 
 
406
 
WaylandBackend::WaylandBackend(const QByteArray &display, QObject *parent)
407
 
    : AbstractBackend(parent)
408
 
    , m_display(nullptr)
409
 
    , m_eventQueue(new EventQueue(this))
410
 
    , m_registry(new Registry(this))
411
 
    , m_compositor(new Compositor(this))
412
 
    , m_shell(new Shell(this))
413
 
    , m_surface(nullptr)
414
 
    , m_shellSurface(NULL)
415
 
    , m_seat()
416
 
    , m_shm(new ShmPool(this))
417
 
    , m_connectionThreadObject(new ConnectionThread(nullptr))
418
 
    , m_connectionThread(nullptr)
419
 
    , m_fullscreenShell(new FullscreenShell(this))
420
 
    , m_subCompositor(new SubCompositor(this))
421
 
    , m_cursor(nullptr)
422
 
{
423
 
    connect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::checkBackendReady);
424
 
    connect(m_registry, &Registry::compositorAnnounced, this,
425
 
        [this](quint32 name) {
426
 
            m_compositor->setup(m_registry->bindCompositor(name, 1));
427
 
        }
428
 
    );
429
 
    connect(m_registry, &Registry::shellAnnounced, this,
430
 
        [this](quint32 name) {
431
 
            m_shell->setup(m_registry->bindShell(name, 1));
432
 
        }
433
 
    );
434
 
    connect(m_registry, &Registry::outputAnnounced, this,
435
 
        [this](quint32 name) {
436
 
            Output *output = new Output(this);
437
 
            output->setup(m_registry->bindOutput(name, 2));
438
 
            m_outputs.append(output);
439
 
            connect(output, &Output::changed, this, &WaylandBackend::outputsChanged);
440
 
        }
441
 
    );
442
 
    connect(m_registry, &Registry::seatAnnounced, this,
443
 
        [this](quint32 name) {
444
 
            if (Application::usesLibinput()) {
445
 
                return;
446
 
            }
447
 
            m_seat.reset(new WaylandSeat(m_registry->bindSeat(name, 2), this));
448
 
        }
449
 
    );
450
 
    connect(m_registry, &Registry::shmAnnounced, this,
451
 
        [this](quint32 name) {
452
 
            m_shm->setup(m_registry->bindShm(name, 1));
453
 
        }
454
 
    );
455
 
    connect(m_registry, &Registry::fullscreenShellAnnounced, this,
456
 
        [this](quint32 name, quint32 version) {
457
 
            m_fullscreenShell->setup(m_registry->bindFullscreenShell(name, version));
458
 
        }
459
 
    );
460
 
    connect(m_registry, &Registry::subCompositorAnnounced, this,
461
 
        [this](quint32 name, quint32 version) {
462
 
            m_subCompositor->setup(m_registry->bindSubCompositor(name, version));
463
 
        }
464
 
    );
465
 
    connect(m_registry, &Registry::interfacesAnnounced, this, &WaylandBackend::createSurface);
466
 
    m_connectionThreadObject->setSocketName(display);
467
 
    initConnection();
468
 
}
469
 
 
470
 
WaylandBackend::~WaylandBackend()
471
 
{
472
 
    destroyOutputs();
473
 
    if (m_shellSurface) {
474
 
        m_shellSurface->release();
475
 
    }
476
 
    m_fullscreenShell->release();
477
 
    if (m_surface) {
478
 
        m_surface->release();
479
 
    }
480
 
    m_shell->release();
481
 
    m_compositor->release();
482
 
    m_registry->release();
483
 
    m_seat.reset();
484
 
    m_shm->release();
485
 
    m_eventQueue->release();
486
 
 
487
 
    m_connectionThreadObject->deleteLater();
488
 
    m_connectionThread->quit();
489
 
    m_connectionThread->wait();
490
 
 
491
 
    qCDebug(KWIN_CORE) << "Destroyed Wayland display";
492
 
}
493
 
 
494
 
void WaylandBackend::destroyOutputs()
495
 
{
496
 
    qDeleteAll(m_outputs);
497
 
    m_outputs.clear();
498
 
}
499
 
 
500
 
void WaylandBackend::initConnection()
501
 
{
502
 
    connect(m_connectionThreadObject, &ConnectionThread::connected, this,
503
 
        [this]() {
504
 
            // create the event queue for the main gui thread
505
 
            m_display = m_connectionThreadObject->display();
506
 
            m_eventQueue->setup(m_connectionThreadObject);
507
 
            m_registry->setEventQueue(m_eventQueue);
508
 
            // setup registry
509
 
            m_registry->create(m_display);
510
 
            m_registry->setup();
511
 
        },
512
 
        Qt::QueuedConnection);
513
 
    connect(m_connectionThreadObject, &ConnectionThread::connectionDied, this,
514
 
        [this]() {
515
 
            m_ready = false;
516
 
            emit systemCompositorDied();
517
 
            m_seat.reset();
518
 
            m_shm->destroy();
519
 
            destroyOutputs();
520
 
            if (m_shellSurface) {
521
 
                m_shellSurface->destroy();
522
 
                delete m_shellSurface;
523
 
                m_shellSurface = nullptr;
524
 
            }
525
 
            m_fullscreenShell->destroy();
526
 
            if (m_surface) {
527
 
                m_surface->destroy();
528
 
                delete m_surface;
529
 
                m_surface = nullptr;
530
 
            }
531
 
            if (m_shell) {
532
 
                m_shell->destroy();
533
 
            }
534
 
            m_compositor->destroy();
535
 
            m_registry->destroy();
536
 
            m_eventQueue->destroy();
537
 
            if (m_display) {
538
 
                m_display = nullptr;
539
 
            }
540
 
        },
541
 
        Qt::QueuedConnection);
542
 
    connect(m_connectionThreadObject, &ConnectionThread::failed, this, &WaylandBackend::connectionFailed, Qt::QueuedConnection);
543
 
 
544
 
    m_connectionThread = new QThread(this);
545
 
    m_connectionThreadObject->moveToThread(m_connectionThread);
546
 
    m_connectionThread->start();
547
 
 
548
 
    m_connectionThreadObject->initConnection();
549
 
}
550
 
 
551
 
void WaylandBackend::installCursorImage(Qt::CursorShape shape)
552
 
{
553
 
    if (!m_seat.isNull() && m_seat->isInstallCursor()) {
554
 
        m_seat->installCursorImage(shape);
555
 
    } else if (m_cursor) {
556
 
        m_cursor->setCursorImage(shape);
557
 
    }
558
 
}
559
 
 
560
 
void WaylandBackend::installCursorFromServer()
561
 
{
562
 
    if (!waylandServer() || !waylandServer()->seat()->focusedPointer()) {
563
 
        return;
564
 
    }
565
 
    auto c = waylandServer()->seat()->focusedPointer()->cursor();
566
 
    if (c) {
567
 
        auto cursorSurface = c->surface();
568
 
        if (!cursorSurface.isNull()) {
569
 
            auto buffer = cursorSurface.data()->buffer();
570
 
            if (buffer) {
571
 
                // set cursor
572
 
                if (!m_seat.isNull() && m_seat->isInstallCursor()) {
573
 
                    m_seat->installCursorImage(buffer->data(), c->hotspot());
574
 
                } else if (m_cursor) {
575
 
                    m_cursor->setCursorImage(buffer->data(), c->hotspot());
576
 
                }
577
 
                return;
578
 
            }
579
 
        }
580
 
    }
581
 
    // TODO: unset cursor
582
 
}
583
 
 
584
 
void WaylandBackend::createSurface()
585
 
{
586
 
    m_surface = m_compositor->createSurface(this);
587
 
    if (!m_surface || !m_surface->isValid()) {
588
 
        qCritical() << "Creating Wayland Surface failed";
589
 
        return;
590
 
    }
591
 
    if (m_subCompositor->isValid()) {
592
 
        // we have a sub compositor - let's use it for mouse cursor
593
 
        m_cursor = new WaylandCursor(m_surface, this);
594
 
    } else {
595
 
        // no sub-compositor - use the seat for setting the cursor image
596
 
        if (m_seat) {
597
 
            m_seat->setInstallCursor(true);
598
 
        }
599
 
    }
600
 
    if (m_fullscreenShell->isValid()) {
601
 
        Output *o = m_outputs.first();
602
 
        m_fullscreenShell->present(m_surface, o);
603
 
        if (o->pixelSize().isValid()) {
604
 
            emit shellSurfaceSizeChanged(o->pixelSize());
605
 
        }
606
 
        connect(o, &Output::changed, this,
607
 
            [this, o]() {
608
 
                if (o->pixelSize().isValid()) {
609
 
                    emit shellSurfaceSizeChanged(o->pixelSize());
610
 
                }
611
 
            }
612
 
        );
613
 
    } else if (m_shell->isValid()) {
614
 
        // map the surface as fullscreen
615
 
        m_shellSurface = m_shell->createSurface(m_surface, this);
616
 
        m_shellSurface->setFullscreen();
617
 
        connect(m_shellSurface, &ShellSurface::sizeChanged, this, &WaylandBackend::shellSurfaceSizeChanged);
618
 
    }
619
 
}
620
 
 
621
 
QSize WaylandBackend::shellSurfaceSize() const
622
 
{
623
 
    if (m_shellSurface) {
624
 
        return m_shellSurface->size();
625
 
    }
626
 
    if (m_fullscreenShell->isValid()) {
627
 
        return m_outputs.first()->pixelSize();
628
 
    }
629
 
    return QSize();
630
 
}
631
 
 
632
 
void WaylandBackend::checkBackendReady()
633
 
{
634
 
    if (!shellSurfaceSize().isValid()) {
635
 
        return;
636
 
    }
637
 
    disconnect(this, &WaylandBackend::shellSurfaceSizeChanged, this, &WaylandBackend::checkBackendReady);
638
 
    m_ready = true;
639
 
    emit backendReady();
640
 
}
641
 
 
642
 
void WaylandBackend::connectNotify(const QMetaMethod &signal)
643
 
{
644
 
    if (m_ready && signal == QMetaMethod::fromSignal(&WaylandBackend::backendReady)) {
645
 
        // backend is already ready, let's emit the signal
646
 
        signal.invoke(this, Qt::QueuedConnection);
647
 
    }
648
 
}
649
 
 
650
 
Screens *WaylandBackend::createScreens(QObject *parent)
651
 
{
652
 
    return new WaylandScreens(this, parent);
653
 
}
654
 
 
655
 
OpenGLBackend *WaylandBackend::createOpenGLBackend()
656
 
{
657
 
#if HAVE_WAYLAND_EGL
658
 
    return new EglWaylandBackend(this);
659
 
#else
660
 
    return nullptr;
661
 
#endif
662
 
}
663
 
 
664
 
QPainterBackend *WaylandBackend::createQPainterBackend()
665
 
{
666
 
    return new WaylandQPainterBackend(this);
667
 
}
668
 
 
669
 
}
670
 
 
671
 
} // KWin