From 7baf5896be0897b7043aaae74170a954be5d9a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 26 Nov 2014 15:34:46 +0100 Subject: [PATCH] Merge SeatInterface::Private::pointerForSurface and ::keyboardForSurface templated helper method. --- src/wayland/seat_interface.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index b95f5dcd10..2a5ff48035 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -255,32 +255,30 @@ SeatInterface::Private *SeatInterface::Private::cast(wl_resource *r) return r ? reinterpret_cast(wl_resource_get_user_data(r)) : nullptr; } -PointerInterface *SeatInterface::Private::pointerForSurface(SurfaceInterface *surface) const +template +static +T *interfaceForSurface(SurfaceInterface *surface, const QVector &interfaces) { if (!surface) { return nullptr; } - for (auto it = pointers.begin(); it != pointers.end(); ++it) { - if (wl_resource_get_client((*it)->resource()) == *surface->client()) { + for (auto it = interfaces.begin(); it != interfaces.end(); ++it) { + if ((*it)->client() == surface->client()) { return (*it); } } return nullptr; } +PointerInterface *SeatInterface::Private::pointerForSurface(SurfaceInterface *surface) const +{ + return interfaceForSurface(surface, pointers); +} + KeyboardInterface *SeatInterface::Private::keyboardForSurface(SurfaceInterface *surface) const { - if (!surface) { - return nullptr; - } - - for (auto it = keyboards.begin(); it != keyboards.end(); ++it) { - if ((*it)->client() == surface->client()) { - return (*it); - } - } - return nullptr; + return interfaceForSurface(surface, keyboards); } void SeatInterface::setHasKeyboard(bool has)