From b90c2c0e6a4b7550f12910dd9111efa2d0945767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 5 Aug 2013 09:42:10 +0200 Subject: [PATCH] Modern variant of forEachClient/forEachUnmanaged Takes a std::function as argument which allows to pass a lambda function which gets executed for each client/unmanged: ws->forEachClient([](Client *client) { client->releaseWindow(); }); --- workspace.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/workspace.h b/workspace.h index a938d9bd2a..4d1e7e39b9 100644 --- a/workspace.h +++ b/workspace.h @@ -32,6 +32,8 @@ along with this program. If not, see . #include // X #include +// std +#include // TODO: Cleanup the order of things in this .h file @@ -76,9 +78,11 @@ public: template Client* findClient(T predicate) const; template void forEachClient(T1 procedure, T2 predicate); template void forEachClient(T procedure); + void forEachClient(std::function func); template Unmanaged* findUnmanaged(T predicate) const; template void forEachUnmanaged(T1 procedure, T2 predicate); template void forEachUnmanaged(T procedure); + void forEachUnmanaged(std::function func); QRect clientArea(clientAreaOption, const QPoint& p, int desktop) const; QRect clientArea(clientAreaOption, const Client* c) const; @@ -686,6 +690,13 @@ inline void Workspace::forEachClient(T1 procedure, T2 predicate) procedure(*it); } +inline +void Workspace::forEachClient(std::function< void (Client*) > func) +{ + std::for_each(clients.constBegin(), clients.constEnd(), func); + std::for_each(desktops.constBegin(), desktops.constEnd(), func); +} + template< typename T > inline void Workspace::forEachClient(T procedure) { @@ -712,6 +723,12 @@ inline void Workspace::forEachUnmanaged(T procedure) return forEachUnmanaged(procedure, TruePredicate()); } +inline +void Workspace::forEachUnmanaged(std::function< void (Unmanaged*) > func) +{ + std::for_each(unmanaged.constBegin(), unmanaged.constEnd(), func); +} + KWIN_COMPARE_PREDICATE(ClientMatchPredicate, Client, const Client*, cl == value); inline bool Workspace::hasClient(const Client* c)