be759b7d33
Summary: Currently, we have only one shell client type - XdgShellClient. We use it when we are dealing with Wayland clients. But it isn't really a good idea because we may need to support shell surfaces other than xdg-shell ones, for example input panel surfaces. In order to make kwin more extensible, this change replaces all usages of the XdgShellClient class with the AbstractClient class. Test Plan: Existing tests pass. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D27778
121 lines
3.7 KiB
C++
121 lines
3.7 KiB
C++
/********************************************************************
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
|
|
Copyright (C) 2018 Vlad Zahorodnii <vlad.zahorodnii@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 "abstract_client.h"
|
|
#include "deleted.h"
|
|
#include "workspace.h"
|
|
|
|
#include <KWayland/Server/idle_interface.h>
|
|
#include <KWayland/Server/surface_interface.h>
|
|
|
|
#include <algorithm>
|
|
#include <functional>
|
|
|
|
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::registerClient(AbstractClient *client)
|
|
{
|
|
auto updateInhibit = [this, client] {
|
|
update(client);
|
|
};
|
|
|
|
m_connections[client] = connect(client->surface(), &SurfaceInterface::inhibitsIdleChanged, this, updateInhibit);
|
|
connect(client, &AbstractClient::desktopChanged, this, updateInhibit);
|
|
connect(client, &AbstractClient::clientMinimized, this, updateInhibit);
|
|
connect(client, &AbstractClient::clientUnminimized, this, updateInhibit);
|
|
connect(client, &AbstractClient::windowHidden, this, updateInhibit);
|
|
connect(client, &AbstractClient::windowShown, this, updateInhibit);
|
|
connect(client, &AbstractClient::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(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)
|
|
{
|
|
if (client->isInternal()) {
|
|
return;
|
|
}
|
|
|
|
// 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); });
|
|
}
|
|
|
|
}
|