diff --git a/idle_inhibition.cpp b/idle_inhibition.cpp index fa04af713..30c433fb9 100644 --- a/idle_inhibition.cpp +++ b/idle_inhibition.cpp @@ -1,116 +1,117 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2017 Martin Flöser Copyright (C) 2018 Vlad Zagorodniy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "idle_inhibition.h" #include "deleted.h" #include "shell_client.h" #include "workspace.h" #include #include +#include #include using KWayland::Server::SurfaceInterface; namespace KWin { IdleInhibition::IdleInhibition(IdleInterface *idle) : QObject(idle) , m_idle(idle) { // Workspace is created after the wayland server is initialized. connect(kwinApp(), &Application::workspaceCreated, this, &IdleInhibition::slotWorkspaceCreated); } IdleInhibition::~IdleInhibition() = default; void IdleInhibition::registerShellClient(ShellClient *client) { auto updateInhibit = [this, client] { update(client); }; m_connections[client] = connect(client->surface(), &SurfaceInterface::inhibitsIdleChanged, this, updateInhibit); connect(client, &ShellClient::desktopChanged, this, updateInhibit); connect(client, &ShellClient::clientMinimized, this, updateInhibit); connect(client, &ShellClient::clientUnminimized, this, updateInhibit); connect(client, &ShellClient::windowHidden, this, updateInhibit); connect(client, &ShellClient::windowShown, this, updateInhibit); connect(client, &ShellClient::windowClosed, this, [this, client] { uninhibit(client); auto it = m_connections.find(client); if (it != m_connections.end()) { disconnect(it.value()); m_connections.erase(it); } } ); updateInhibit(); } void IdleInhibition::inhibit(AbstractClient *client) { if (isInhibited(client)) { // already inhibited return; } m_idleInhibitors << client; m_idle->inhibit(); // TODO: notify powerdevil? } void IdleInhibition::uninhibit(AbstractClient *client) { - auto it = std::find_if(m_idleInhibitors.begin(), m_idleInhibitors.end(), [client] (auto c) { return c == client; }); + auto it = std::find(m_idleInhibitors.begin(), m_idleInhibitors.end(), client); if (it == m_idleInhibitors.end()) { // not inhibited return; } m_idleInhibitors.erase(it); m_idle->uninhibit(); } void IdleInhibition::update(AbstractClient *client) { // TODO: Don't honor the idle inhibitor object if the shell client is not // on the current activity (currently, activities are not supported). const bool visible = client->isShown(true) && client->isOnCurrentDesktop(); if (visible && client->surface()->inhibitsIdle()) { inhibit(client); } else { uninhibit(client); } } void IdleInhibition::slotWorkspaceCreated() { connect(workspace(), &Workspace::currentDesktopChanged, this, &IdleInhibition::slotDesktopChanged); } void IdleInhibition::slotDesktopChanged() { workspace()->forEachAbstractClient([this] (AbstractClient *c) { update(c); }); } } diff --git a/idle_inhibition.h b/idle_inhibition.h index 79e5106df..a5f310e2b 100644 --- a/idle_inhibition.h +++ b/idle_inhibition.h @@ -1,73 +1,71 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2017 Martin Flöser Copyright (C) 2018 Vlad Zagorodniy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #pragma once #include #include #include -#include - namespace KWayland { namespace Server { class IdleInterface; } } using KWayland::Server::IdleInterface; namespace KWin { class AbstractClient; class ShellClient; class IdleInhibition : public QObject { Q_OBJECT public: explicit IdleInhibition(IdleInterface *idle); ~IdleInhibition(); void registerShellClient(ShellClient *client); bool isInhibited() const { return !m_idleInhibitors.isEmpty(); } bool isInhibited(AbstractClient *client) const { - return std::any_of(m_idleInhibitors.begin(), m_idleInhibitors.end(), [client] (auto c) { return c == client; }); + return m_idleInhibitors.contains(client); } private Q_SLOTS: void slotWorkspaceCreated(); void slotDesktopChanged(); private: void inhibit(AbstractClient *client); void uninhibit(AbstractClient *client); void update(AbstractClient *client); IdleInterface *m_idle; QVector m_idleInhibitors; QMap m_connections; }; }