wayland: Do not allocate a full list just to check if there's values

This commit is contained in:
Aleix Pol 2022-07-21 23:51:42 +02:00 committed by Aleix Pol Gonzalez
parent 40044f21e1
commit c73444dd12
3 changed files with 9 additions and 3 deletions

View file

@ -1081,7 +1081,7 @@ void SeatInterface::notifyTouchDown(qint32 id, const QPointF &globalPosition)
if (id == 0 && hasPointer() && focusedTouchSurface()) {
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(d->touch.data());
if (touchPrivate->touchesForClient(focusedTouchSurface()->client()).isEmpty()) {
if (!touchPrivate->hasTouchesForClient(focusedTouchSurface()->client())) {
// If the client did not bind the touch interface fall back
// to at least emulating touch through pointer events.
d->pointer->sendEnter(focusedTouchSurface(), pos, serial);
@ -1117,7 +1117,7 @@ void SeatInterface::notifyTouchMotion(qint32 id, const QPointF &globalPosition)
if (hasPointer() && focusedTouchSurface()) {
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(d->touch.data());
if (touchPrivate->touchesForClient(focusedTouchSurface()->client()).isEmpty()) {
if (!touchPrivate->hasTouchesForClient(focusedTouchSurface()->client())) {
// Client did not bind touch, fall back to emulating with pointer events.
d->pointer->sendMotion(pos);
d->pointer->sendFrame();
@ -1148,7 +1148,7 @@ void SeatInterface::notifyTouchUp(qint32 id)
if (id == 0 && hasPointer() && focusedTouchSurface()) {
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(d->touch.data());
if (touchPrivate->touchesForClient(focusedTouchSurface()->client()).isEmpty()) {
if (!touchPrivate->hasTouchesForClient(focusedTouchSurface()->client())) {
// Client did not bind touch, fall back to emulating with pointer events.
const quint32 serial = display()->nextSerial();
d->pointer->sendButton(BTN_LEFT, PointerButtonState::Released, serial);

View file

@ -35,6 +35,11 @@ QList<TouchInterfacePrivate::Resource *> TouchInterfacePrivate::touchesForClient
return resourceMap().values(client->client());
}
bool TouchInterfacePrivate::hasTouchesForClient(ClientConnection *client) const
{
return resourceMap().contains(client->client());
}
TouchInterface::TouchInterface(SeatInterface *seat)
: d(new TouchInterfacePrivate(this, seat))
{

View file

@ -21,6 +21,7 @@ public:
TouchInterfacePrivate(TouchInterface *q, SeatInterface *seat);
QList<Resource *> touchesForClient(ClientConnection *client) const;
bool hasTouchesForClient(ClientConnection *client) const;
TouchInterface *q;
QPointer<SurfaceInterface> focusedSurface;