kwin/idle_inhibition.cpp
Vlad Zagorodniy 437d35eee2 [wayland] Check presence of the inhibitor object when a client is registered in IdleInhibition
Summary:
Some applications are not able to inhibit the idle behavior because
each of them creates an inhibitor object before the corresponding
ShellClient object becomes ready for painting.

BUG: 401499
FIXED-IN: 5.15.0

Test Plan: idle-inhibit client (from wlroots/examples) works.

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: davidedmundson, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D17227
2018-11-29 18:17:34 +02:00

89 lines
2.5 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "idle_inhibition.h"
#include "deleted.h"
#include "shell_client.h"
#include <KWayland/Server/idle_interface.h>
#include <KWayland/Server/surface_interface.h>
#include <functional>
using KWayland::Server::SurfaceInterface;
namespace KWin
{
IdleInhibition::IdleInhibition(IdleInterface *idle)
: QObject(idle)
, m_idle(idle)
{
}
IdleInhibition::~IdleInhibition() = default;
void IdleInhibition::registerShellClient(ShellClient *client)
{
auto inhibitsIdleChanged = [this, client] {
// TODO: only inhibit if the ShellClient is visible
if (client->surface()->inhibitsIdle()) {
inhibit(client);
} else {
uninhibit(client);
}
};
m_connections[client] = connect(client->surface(), &SurfaceInterface::inhibitsIdleChanged, this, inhibitsIdleChanged);
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);
}
}
);
inhibitsIdleChanged();
}
void IdleInhibition::inhibit(ShellClient *client)
{
if (isInhibited(client)) {
// already inhibited
return;
}
m_idleInhibitors << client;
m_idle->inhibit();
// TODO: notify powerdevil?
}
void IdleInhibition::uninhibit(ShellClient *client)
{
auto it = std::find_if(m_idleInhibitors.begin(), m_idleInhibitors.end(), [client] (auto c) { return c == client; });
if (it == m_idleInhibitors.end()) {
// not inhibited
return;
}
m_idleInhibitors.erase(it);
m_idle->uninhibit();
}
}