File indexing completed on 2024-11-10 04:57:36
0001 /* 0002 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2020 Adrien Faveraux <ad1rie3@hotmail.fr> 0004 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 #include "touch.h" 0009 #include "clientconnection.h" 0010 #include "display.h" 0011 #include "seat.h" 0012 #include "surface.h" 0013 #include "touch_p.h" 0014 0015 namespace KWin 0016 { 0017 TouchInterfacePrivate *TouchInterfacePrivate::get(TouchInterface *touch) 0018 { 0019 return touch->d.get(); 0020 } 0021 0022 TouchInterfacePrivate::TouchInterfacePrivate(TouchInterface *q, SeatInterface *seat) 0023 : q(q) 0024 , seat(seat) 0025 { 0026 } 0027 0028 void TouchInterfacePrivate::touch_release(Resource *resource) 0029 { 0030 wl_resource_destroy(resource->handle); 0031 } 0032 0033 QList<TouchInterfacePrivate::Resource *> TouchInterfacePrivate::touchesForClient(ClientConnection *client) const 0034 { 0035 return resourceMap().values(client->client()); 0036 } 0037 0038 bool TouchInterfacePrivate::hasTouchesForClient(ClientConnection *client) const 0039 { 0040 return resourceMap().contains(client->client()); 0041 } 0042 0043 TouchInterface::TouchInterface(SeatInterface *seat) 0044 : d(new TouchInterfacePrivate(this, seat)) 0045 { 0046 } 0047 0048 TouchInterface::~TouchInterface() 0049 { 0050 } 0051 0052 SurfaceInterface *TouchInterface::focusedSurface() const 0053 { 0054 return d->focusedSurface; 0055 } 0056 0057 void TouchInterface::sendCancel() 0058 { 0059 if (!d->focusedSurface) { 0060 return; 0061 } 0062 0063 const auto touchResources = d->touchesForClient(d->focusedSurface->client()); 0064 for (TouchInterfacePrivate::Resource *resource : touchResources) { 0065 d->send_cancel(resource->handle); 0066 } 0067 } 0068 0069 void TouchInterface::sendFrame() 0070 { 0071 if (!d->focusedSurface) { 0072 return; 0073 } 0074 0075 const auto touchResources = d->touchesForClient(d->focusedSurface->client()); 0076 for (TouchInterfacePrivate::Resource *resource : touchResources) { 0077 d->send_frame(resource->handle); 0078 } 0079 } 0080 0081 void TouchInterface::sendMotion(qint32 id, const QPointF &localPos) 0082 { 0083 if (!d->focusedSurface) { 0084 return; 0085 } 0086 0087 QPointF pos = d->focusedSurface->toSurfaceLocal(localPos); 0088 0089 const auto touchResources = d->touchesForClient(d->focusedSurface->client()); 0090 for (TouchInterfacePrivate::Resource *resource : touchResources) { 0091 d->send_motion(resource->handle, d->seat->timestamp().count(), id, wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y())); 0092 } 0093 } 0094 0095 void TouchInterface::sendUp(qint32 id, quint32 serial) 0096 { 0097 if (!d->focusedSurface) { 0098 return; 0099 } 0100 0101 const auto touchResources = d->touchesForClient(d->focusedSurface->client()); 0102 for (TouchInterfacePrivate::Resource *resource : touchResources) { 0103 d->send_up(resource->handle, serial, d->seat->timestamp().count(), id); 0104 } 0105 } 0106 0107 void TouchInterface::sendDown(qint32 id, quint32 serial, const QPointF &localPos, SurfaceInterface *surface) 0108 { 0109 if (!surface) { 0110 return; 0111 } 0112 0113 d->focusedSurface = surface; 0114 0115 QPointF pos = d->focusedSurface->toSurfaceLocal(localPos); 0116 0117 const auto touchResources = d->touchesForClient(d->focusedSurface->client()); 0118 for (TouchInterfacePrivate::Resource *resource : touchResources) { 0119 d->send_down(resource->handle, 0120 serial, 0121 d->seat->timestamp().count(), 0122 d->focusedSurface->resource(), 0123 id, 0124 wl_fixed_from_double(pos.x()), 0125 wl_fixed_from_double(pos.y())); 0126 } 0127 } 0128 0129 } // namespace KWin 0130 0131 #include "moc_touch.cpp"