51 , m_keyboard(keyboard)
53 connect(keyboard, &Keyboard::left,
this, [
this](quint32 time) {
54 for (quint32 key : std::as_const(m_pressedKeys)) {
57 m_pressedKeys.clear();
59 connect(keyboard, &Keyboard::keyChanged,
this, [
this](quint32 key, Keyboard::KeyState nativeState, quint32 time) {
61 switch (nativeState) {
62 case Keyboard::KeyState::Pressed:
63 if (key == KEY_RIGHTCTRL) {
64 m_seat->
backend()->togglePointerLock();
67 m_pressedKeys.insert(key);
69 case Keyboard::KeyState::Released:
70 m_pressedKeys.remove(key);
76 Q_EMIT
keyChanged(key, state, std::chrono::milliseconds(time),
this);
84 connect(pointer, &Pointer::entered,
this, [
this](quint32 serial,
const QPointF &relativeToSurface) {
89 connect(pointer, &Pointer::left,
this, [
this]() {
91 const auto outputs = m_seat->
backend()->outputs();
92 for (
Output *output : outputs) {
94 if (waylandOutput->cursor()->pointer()) {
95 waylandOutput->cursor()->setPointer(
nullptr);
99 connect(pointer, &Pointer::motion,
this, [
this](
const QPointF &relativeToSurface, quint32 time) {
102 const QPointF absolutePos = output->
geometry().topLeft() + relativeToSurface;
105 connect(pointer, &Pointer::buttonStateChanged,
this, [
this](quint32 serial, quint32 time, quint32 button, Pointer::ButtonState nativeState) {
107 switch (nativeState) {
108 case Pointer::ButtonState::Pressed:
111 case Pointer::ButtonState::Released:
120 connect(pointer, &Pointer::axisChanged,
this, [
this](quint32 time, Pointer::Axis nativeAxis, qreal delta) {
122 switch (nativeAxis) {
123 case Pointer::Axis::Horizontal:
126 case Pointer::Axis::Vertical:
135 connect(pointer, &Pointer::frame,
this, [
this]() {
140 if (pointerGestures) {
141 m_pinchGesture.reset(pointerGestures->createPinchGesture(m_pointer.get(),
this));
142 connect(m_pinchGesture.get(), &PointerPinchGesture::started,
this, [
this](quint32 serial, quint32 time) {
143 Q_EMIT pinchGestureBegin(m_pinchGesture->fingerCount(), std::chrono::milliseconds(time), this);
145 connect(m_pinchGesture.get(), &PointerPinchGesture::updated,
this, [
this](
const QSizeF &delta, qreal scale, qreal rotation, quint32 time) {
146 Q_EMIT pinchGestureUpdate(scale, rotation, sizeToPoint(delta), std::chrono::milliseconds(time), this);
148 connect(m_pinchGesture.get(), &PointerPinchGesture::ended,
this, [
this](quint32 serial, quint32 time) {
149 Q_EMIT pinchGestureEnd(std::chrono::milliseconds(time), this);
151 connect(m_pinchGesture.get(), &PointerPinchGesture::cancelled,
this, [
this](quint32 serial, quint32 time) {
152 Q_EMIT pinchGestureCancelled(std::chrono::milliseconds(time), this);
155 m_swipeGesture.reset(pointerGestures->createSwipeGesture(m_pointer.get(),
this));
156 connect(m_swipeGesture.get(), &PointerSwipeGesture::started,
this, [
this](quint32 serial, quint32 time) {
157 Q_EMIT swipeGestureBegin(m_swipeGesture->fingerCount(), std::chrono::milliseconds(time), this);
159 connect(m_swipeGesture.get(), &PointerSwipeGesture::updated,
this, [
this](
const QSizeF &delta, quint32 time) {
160 Q_EMIT swipeGestureUpdate(sizeToPoint(delta), std::chrono::milliseconds(time), this);
162 connect(m_swipeGesture.get(), &PointerSwipeGesture::ended,
this, [
this](quint32 serial, quint32 time) {
163 Q_EMIT swipeGestureEnd(std::chrono::milliseconds(time), this);
165 connect(m_swipeGesture.get(), &PointerSwipeGesture::cancelled,
this, [
this](quint32 serial, quint32 time) {
166 Q_EMIT swipeGestureCancelled(std::chrono::milliseconds(time), this);
184 connect(touch, &Touch::sequenceCanceled,
this, [
this]() {
187 connect(touch, &Touch::frameEnded,
this, [
this]() {
190 connect(touch, &Touch::sequenceStarted,
this, [
this](TouchPoint *tp) {
191 Q_EMIT
touchDown(tp->id(), tp->position(), std::chrono::milliseconds(tp->time()),
this);
193 connect(touch, &Touch::pointAdded,
this, [
this](TouchPoint *tp) {
194 Q_EMIT
touchDown(tp->id(), tp->position(), std::chrono::milliseconds(tp->time()),
this);
196 connect(touch, &Touch::pointRemoved,
this, [
this](TouchPoint *tp) {
197 Q_EMIT
touchUp(tp->id(), std::chrono::milliseconds(tp->time()),
this);
199 connect(touch, &Touch::pointMoved,
this, [
this](TouchPoint *tp) {
200 Q_EMIT
touchMotion(tp->id(), tp->position(), std::chrono::milliseconds(tp->time()),
this);
437 m_display = std::make_unique<WaylandDisplay>();
438 if (!m_display->initialize(m_options.
socketName)) {
443 m_drmFileDescriptor =
FileDescriptor(open(dmabuf->mainDevice(), O_RDWR | O_CLOEXEC));
444 if (m_drmFileDescriptor.
isValid()) {
445 m_gbmDevice = gbm_create_device(m_drmFileDescriptor.
get());
447 qCWarning(KWIN_WAYLAND_BACKEND) <<
"Failed to open drm render node" << dmabuf->mainDevice();
453 m_seat = std::make_unique<WaylandSeat>(m_display->seat(),
this);
455 QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance();
456 QObject::connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, m_display.get(), &
WaylandDisplay::flush);
457 QObject::connect(dispatcher, &QAbstractEventDispatcher::awake, m_display.get(), &
WaylandDisplay::flush);
461 m_seat->createRelativePointer();
463 m_seat->destroyRelativePointer();
638 auto &buffer = m_buffers[graphicsBuffer];
640 wl_buffer *handle =
nullptr;
642 handle = importDmaBufBuffer(m_display.get(), attributes);
644 handle = importShmBuffer(m_display.get(), attributes);
646 qCWarning(KWIN_WAYLAND_BACKEND) << graphicsBuffer <<
"has unknown type";
650 buffer = std::make_unique<WaylandBuffer>(handle, graphicsBuffer);
652 m_buffers.erase(graphicsBuffer);
655 static const wl_buffer_listener listener = {
656 .release = [](
void *userData, wl_buffer *buffer) {
661 wl_buffer_add_listener(handle, &listener, buffer.get());
665 return buffer->handle();