Add Workspace::findToplevel

Like findClient and findUnmanaged, just a little bit more generic.
Toplevel::findInList got adjusted to support it.
icc-effect-5.14.5
Martin Gräßlin 2015-02-09 16:07:30 +01:00
parent 7843bbdbfb
commit e463905f04
4 changed files with 22 additions and 5 deletions

View File

@ -731,7 +731,7 @@ xcb_timestamp_t Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id, c
; // is transient for currently active window, even though it's not
// the same app (e.g. kcookiejar dialog) -> allow activation
else if (groupTransient() &&
findInList<Client>(mainClients(), sameApplicationActiveHackPredicate) == NULL)
findInList<Client, Client>(mainClients(), sameApplicationActiveHackPredicate) == NULL)
; // standalone transient
else
first_window = false;

View File

@ -361,8 +361,8 @@ public:
* @param func The condition function (compare std::find_if)
* @return T* The found Toplevel or @c null if there is no matching Toplevel
*/
template <class T>
static T *findInList(const QList<T*> &list, std::function<bool (const T*)> func);
template <class T, class U>
static T *findInList(const QList<T*> &list, std::function<bool (const U*)> func);
Q_SIGNALS:
void opacityChanged(KWin::Toplevel* toplevel, qreal oldOpacity);
@ -718,9 +718,11 @@ inline quint32 Toplevel::surfaceId() const
return m_surfaceId;
}
template <class T>
inline T *Toplevel::findInList(const QList<T*> &list, std::function<bool (const T*)> func)
template <class T, class U>
inline T *Toplevel::findInList(const QList<T*> &list, std::function<bool (const U*)> func)
{
static_assert(std::is_base_of<U, T>::value,
"U must be derived from T");
const auto it = std::find_if(list.begin(), list.end(), func);
if (it == list.end()) {
return nullptr;

View File

@ -1576,6 +1576,20 @@ Client *Workspace::findClient(Predicate predicate, xcb_window_t w) const
return nullptr;
}
Toplevel *Workspace::findToplevel(std::function<bool (const Toplevel*)> func) const
{
if (Client *ret = Toplevel::findInList(clients, func)) {
return ret;
}
if (Client *ret = Toplevel::findInList(desktops, func)) {
return ret;
}
if (Unmanaged *ret = Toplevel::findInList(unmanaged, func)) {
return ret;
}
return nullptr;
}
} // namespace
#include "workspace.moc"

View File

@ -122,6 +122,7 @@ public:
*/
Unmanaged *findUnmanaged(xcb_window_t w) const;
void forEachUnmanaged(std::function<void (Unmanaged*)> func);
Toplevel *findToplevel(std::function<bool (const Toplevel*)> func) const;
QRect clientArea(clientAreaOption, const QPoint& p, int desktop) const;
QRect clientArea(clientAreaOption, const Client* c) const;