2014-07-22 11:11:19 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2014 Martin Gräßlin <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 "decoratedclient.h"
|
2015-04-29 10:02:54 +00:00
|
|
|
#include "decorationpalette.h"
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "decorationrenderer.h"
|
2015-12-03 16:29:06 +00:00
|
|
|
#include "abstract_client.h"
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "composite.h"
|
|
|
|
#include "cursor.h"
|
|
|
|
#include "options.h"
|
2017-08-20 20:15:21 +00:00
|
|
|
#include "platform.h"
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KDecoration2/DecoratedClient>
|
|
|
|
#include <KDecoration2/Decoration>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace Decoration
|
|
|
|
{
|
|
|
|
|
2015-12-03 16:29:06 +00:00
|
|
|
DecoratedClientImpl::DecoratedClientImpl(AbstractClient *client, KDecoration2::DecoratedClient *decoratedClient, KDecoration2::Decoration *decoration)
|
2014-07-22 11:11:19 +00:00
|
|
|
: QObject()
|
2017-01-11 09:21:03 +00:00
|
|
|
, ApplicationMenuEnabledDecoratedClientPrivate(decoratedClient, decoration)
|
2014-07-22 11:11:19 +00:00
|
|
|
, m_client(client)
|
2016-08-10 08:48:55 +00:00
|
|
|
, m_clientSize(client->clientSize())
|
2014-07-22 11:11:19 +00:00
|
|
|
, m_renderer(nullptr)
|
|
|
|
{
|
|
|
|
createRenderer();
|
2014-10-21 05:46:44 +00:00
|
|
|
client->setDecoratedClient(QPointer<DecoratedClientImpl>(this));
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::activeChanged, this,
|
2014-07-22 11:11:19 +00:00
|
|
|
[decoratedClient, client]() {
|
|
|
|
emit decoratedClient->activeChanged(client->isActive());
|
|
|
|
}
|
|
|
|
);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::geometryChanged, this,
|
2016-08-10 08:48:55 +00:00
|
|
|
[decoratedClient, this]() {
|
|
|
|
if (m_client->clientSize() == m_clientSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto oldSize = m_clientSize;
|
|
|
|
m_clientSize = m_client->clientSize();
|
|
|
|
if (oldSize.width() != m_clientSize.width()) {
|
|
|
|
emit decoratedClient->widthChanged(m_clientSize.width());
|
|
|
|
}
|
|
|
|
if (oldSize.height() != m_clientSize.height()) {
|
|
|
|
emit decoratedClient->heightChanged(m_clientSize.height());
|
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::desktopChanged, this,
|
2014-07-22 11:11:19 +00:00
|
|
|
[decoratedClient, client]() {
|
|
|
|
emit decoratedClient->onAllDesktopsChanged(client->isOnAllDesktops());
|
|
|
|
}
|
|
|
|
);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::captionChanged, this,
|
2014-07-22 11:11:19 +00:00
|
|
|
[decoratedClient, client]() {
|
|
|
|
emit decoratedClient->captionChanged(client->caption());
|
|
|
|
}
|
|
|
|
);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::iconChanged, this,
|
2014-07-22 11:11:19 +00:00
|
|
|
[decoratedClient, client]() {
|
|
|
|
emit decoratedClient->iconChanged(client->icon());
|
|
|
|
}
|
|
|
|
);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::shadeChanged, this,
|
2016-01-07 22:12:40 +00:00
|
|
|
&Decoration::DecoratedClientImpl::signalShadeChange);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::keepAboveChanged, decoratedClient, &KDecoration2::DecoratedClient::keepAboveChanged);
|
|
|
|
connect(client, &AbstractClient::keepBelowChanged, decoratedClient, &KDecoration2::DecoratedClient::keepBelowChanged);
|
2016-05-23 07:28:27 +00:00
|
|
|
m_compositorToggledConnection = connect(Compositor::self(), &Compositor::compositingToggled, this,
|
2014-07-22 11:11:19 +00:00
|
|
|
[this, decoration]() {
|
|
|
|
delete m_renderer;
|
|
|
|
m_renderer = nullptr;
|
|
|
|
createRenderer();
|
|
|
|
decoration->update();
|
|
|
|
}
|
|
|
|
);
|
2016-05-23 07:28:27 +00:00
|
|
|
connect(Compositor::self(), &Compositor::aboutToDestroy, this,
|
|
|
|
[this] {
|
|
|
|
disconnect(m_compositorToggledConnection);
|
|
|
|
m_compositorToggledConnection = QMetaObject::Connection();
|
|
|
|
}
|
|
|
|
);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::quickTileModeChanged, decoratedClient,
|
2014-07-25 09:20:34 +00:00
|
|
|
[this, decoratedClient]() {
|
2014-11-11 13:33:31 +00:00
|
|
|
emit decoratedClient->adjacentScreenEdgesChanged(adjacentScreenEdges());
|
2014-07-25 09:20:34 +00:00
|
|
|
}
|
|
|
|
);
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::closeableChanged, decoratedClient, &KDecoration2::DecoratedClient::closeableChanged);
|
|
|
|
connect(client, &AbstractClient::shadeableChanged, decoratedClient, &KDecoration2::DecoratedClient::shadeableChanged);
|
|
|
|
connect(client, &AbstractClient::minimizeableChanged, decoratedClient, &KDecoration2::DecoratedClient::minimizeableChanged);
|
|
|
|
connect(client, &AbstractClient::maximizeableChanged, decoratedClient, &KDecoration2::DecoratedClient::maximizeableChanged);
|
2015-01-08 11:45:40 +00:00
|
|
|
|
2015-12-03 16:29:06 +00:00
|
|
|
connect(client, &AbstractClient::paletteChanged, decoratedClient, &KDecoration2::DecoratedClient::paletteChanged);
|
2017-01-11 09:21:03 +00:00
|
|
|
|
|
|
|
connect(client, &AbstractClient::hasApplicationMenuChanged, decoratedClient, &KDecoration2::DecoratedClient::hasApplicationMenuChanged);
|
|
|
|
connect(client, &AbstractClient::applicationMenuActiveChanged, decoratedClient, &KDecoration2::DecoratedClient::applicationMenuActiveChanged);
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DecoratedClientImpl::~DecoratedClientImpl() = default;
|
|
|
|
|
2016-01-07 22:12:40 +00:00
|
|
|
void DecoratedClientImpl::signalShadeChange() {
|
|
|
|
emit decoratedClient()->shadedChanged(m_client->isShade());
|
|
|
|
}
|
|
|
|
|
2014-10-23 08:56:43 +00:00
|
|
|
#define DELEGATE(type, name, clientName) \
|
2014-07-22 11:11:19 +00:00
|
|
|
type DecoratedClientImpl::name() const \
|
|
|
|
{ \
|
2014-10-23 08:56:43 +00:00
|
|
|
return m_client->clientName(); \
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-23 08:56:43 +00:00
|
|
|
#define DELEGATE2(type, name) DELEGATE(type, name, name)
|
|
|
|
|
|
|
|
DELEGATE2(QString, caption)
|
|
|
|
DELEGATE2(bool, isActive)
|
|
|
|
DELEGATE2(bool, isCloseable)
|
|
|
|
DELEGATE(bool, isMaximizeable, isMaximizable)
|
|
|
|
DELEGATE(bool, isMinimizeable, isMinimizable)
|
|
|
|
DELEGATE2(bool, isModal)
|
|
|
|
DELEGATE(bool, isMoveable, isMovable)
|
|
|
|
DELEGATE(bool, isResizeable, isResizable)
|
|
|
|
DELEGATE2(bool, isShadeable)
|
|
|
|
DELEGATE2(bool, providesContextHelp)
|
|
|
|
DELEGATE2(int, desktop)
|
|
|
|
DELEGATE2(bool, isOnAllDesktops)
|
|
|
|
DELEGATE2(QPalette, palette)
|
|
|
|
DELEGATE2(QIcon, icon)
|
2014-07-22 11:11:19 +00:00
|
|
|
|
2014-10-23 08:56:43 +00:00
|
|
|
#undef DELEGATE2
|
2014-07-22 11:11:19 +00:00
|
|
|
#undef DELEGATE
|
|
|
|
|
|
|
|
#define DELEGATE(type, name, clientName) \
|
|
|
|
type DecoratedClientImpl::name() const \
|
|
|
|
{ \
|
|
|
|
return m_client->clientName(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
DELEGATE(bool, isKeepAbove, keepAbove)
|
|
|
|
DELEGATE(bool, isKeepBelow, keepBelow)
|
|
|
|
DELEGATE(bool, isShaded, isShade)
|
2016-05-02 15:47:39 +00:00
|
|
|
DELEGATE(WId, windowId, windowId)
|
2014-07-22 11:11:19 +00:00
|
|
|
DELEGATE(WId, decorationId, frameId)
|
|
|
|
|
|
|
|
#undef DELEGATE
|
|
|
|
|
|
|
|
#define DELEGATE(name, op) \
|
|
|
|
void DecoratedClientImpl::name() \
|
|
|
|
{ \
|
2014-12-02 09:39:38 +00:00
|
|
|
Workspace::self()->performWindowOperation(m_client, Options::op); \
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DELEGATE(requestToggleShade, ShadeOp)
|
|
|
|
DELEGATE(requestToggleOnAllDesktops, OnAllDesktopsOp)
|
|
|
|
DELEGATE(requestToggleKeepAbove, KeepAboveOp)
|
|
|
|
DELEGATE(requestToggleKeepBelow, KeepBelowOp)
|
|
|
|
|
|
|
|
#undef DELEGATE
|
|
|
|
|
|
|
|
#define DELEGATE(name, clientName) \
|
|
|
|
void DecoratedClientImpl::name() \
|
|
|
|
{ \
|
|
|
|
m_client->clientName(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
DELEGATE(requestContextHelp, showContextHelp)
|
|
|
|
DELEGATE(requestMinimize, minimize)
|
|
|
|
|
|
|
|
#undef DELEGATE
|
|
|
|
|
2015-10-19 15:26:17 +00:00
|
|
|
void DecoratedClientImpl::requestClose()
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(m_client, "closeWindow", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
2015-03-31 13:26:42 +00:00
|
|
|
QColor DecoratedClientImpl::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const
|
|
|
|
{
|
|
|
|
auto dp = m_client->decorationPalette();
|
|
|
|
if (dp) {
|
|
|
|
return dp->color(group, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QColor();
|
|
|
|
}
|
|
|
|
|
2018-02-04 14:34:10 +00:00
|
|
|
void DecoratedClientImpl::requestShowToolTip(const QString &text)
|
|
|
|
{
|
|
|
|
Q_UNUSED(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecoratedClientImpl::requestHideToolTip()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
void DecoratedClientImpl::requestShowWindowMenu()
|
|
|
|
{
|
|
|
|
// TODO: add rect to requestShowWindowMenu
|
|
|
|
Workspace::self()->showWindowMenu(QRect(Cursor::pos(), Cursor::pos()), m_client);
|
|
|
|
}
|
|
|
|
|
2017-01-11 09:21:03 +00:00
|
|
|
void DecoratedClientImpl::requestShowApplicationMenu(const QRect &rect, int actionId)
|
|
|
|
{
|
|
|
|
Workspace::self()->showApplicationMenu(rect, m_client, actionId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecoratedClientImpl::showApplicationMenu(int actionId)
|
|
|
|
{
|
|
|
|
decoration()->showApplicationMenu(actionId);
|
|
|
|
}
|
|
|
|
|
2014-11-11 08:53:54 +00:00
|
|
|
void DecoratedClientImpl::requestToggleMaximization(Qt::MouseButtons buttons)
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
2016-05-11 11:33:03 +00:00
|
|
|
QMetaObject::invokeMethod(this, "delayedRequestToggleMaximization", Qt::QueuedConnection, Q_ARG(Options::WindowOperation, options->operationMaxButtonClick(buttons)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecoratedClientImpl::delayedRequestToggleMaximization(Options::WindowOperation operation)
|
|
|
|
{
|
|
|
|
Workspace::self()->performWindowOperation(m_client, operation);
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DecoratedClientImpl::width() const
|
|
|
|
{
|
2016-08-10 08:48:55 +00:00
|
|
|
return m_clientSize.width();
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DecoratedClientImpl::height() const
|
|
|
|
{
|
2016-08-10 08:48:55 +00:00
|
|
|
return m_clientSize.height();
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DecoratedClientImpl::isMaximizedVertically() const
|
|
|
|
{
|
2014-12-02 12:49:08 +00:00
|
|
|
return m_client->maximizeMode() & MaximizeVertical;
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DecoratedClientImpl::isMaximized() const
|
|
|
|
{
|
|
|
|
return isMaximizedHorizontally() && isMaximizedVertically();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DecoratedClientImpl::isMaximizedHorizontally() const
|
|
|
|
{
|
2014-12-02 12:49:08 +00:00
|
|
|
return m_client->maximizeMode() & MaximizeHorizontal;
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 13:33:31 +00:00
|
|
|
Qt::Edges DecoratedClientImpl::adjacentScreenEdges() const
|
2014-07-25 09:20:34 +00:00
|
|
|
{
|
|
|
|
Qt::Edges edges;
|
2017-07-18 19:12:37 +00:00
|
|
|
const QuickTileMode mode = m_client->quickTileMode();
|
|
|
|
if (mode.testFlag(QuickTileFlag::Left)) {
|
2014-07-25 09:20:34 +00:00
|
|
|
edges |= Qt::LeftEdge;
|
2017-07-18 19:12:37 +00:00
|
|
|
if (!mode.testFlag(QuickTileFlag::Top) && !mode.testFlag(QuickTileFlag::Bottom)) {
|
2014-07-25 09:20:34 +00:00
|
|
|
// using complete side
|
|
|
|
edges |= Qt::TopEdge | Qt::BottomEdge;
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 19:12:37 +00:00
|
|
|
if (mode.testFlag(QuickTileFlag::Top)) {
|
2014-07-25 09:20:34 +00:00
|
|
|
edges |= Qt::TopEdge;
|
|
|
|
}
|
2017-07-18 19:12:37 +00:00
|
|
|
if (mode.testFlag(QuickTileFlag::Right)) {
|
2014-07-25 09:20:34 +00:00
|
|
|
edges |= Qt::RightEdge;
|
2017-07-18 19:12:37 +00:00
|
|
|
if (!mode.testFlag(QuickTileFlag::Top) && !mode.testFlag(QuickTileFlag::Bottom)) {
|
2014-07-25 09:20:34 +00:00
|
|
|
// using complete side
|
|
|
|
edges |= Qt::TopEdge | Qt::BottomEdge;
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 19:12:37 +00:00
|
|
|
if (mode.testFlag(QuickTileFlag::Bottom)) {
|
2014-07-25 09:20:34 +00:00
|
|
|
edges |= Qt::BottomEdge;
|
|
|
|
}
|
|
|
|
return edges;
|
|
|
|
}
|
|
|
|
|
2017-01-11 09:21:03 +00:00
|
|
|
bool DecoratedClientImpl::hasApplicationMenu() const
|
|
|
|
{
|
|
|
|
return m_client->hasApplicationMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DecoratedClientImpl::isApplicationMenuActive() const
|
|
|
|
{
|
|
|
|
return m_client->applicationMenuActive();
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
void DecoratedClientImpl::createRenderer()
|
|
|
|
{
|
2017-08-20 20:15:21 +00:00
|
|
|
m_renderer = kwinApp()->platform()->createDecorationRenderer(this);
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 05:14:21 +00:00
|
|
|
void DecoratedClientImpl::destroyRenderer()
|
|
|
|
{
|
|
|
|
delete m_renderer;
|
|
|
|
m_renderer = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
}
|