2011-11-10 13:28:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2011 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 "thumbnailitem.h"
|
|
|
|
// KWin
|
|
|
|
#include "client.h"
|
2012-03-29 18:17:57 +00:00
|
|
|
#include "composite.h"
|
2011-11-10 13:28:06 +00:00
|
|
|
#include "effects.h"
|
|
|
|
#include "workspace.h"
|
2015-05-21 08:52:00 +00:00
|
|
|
#include "shell_client.h"
|
|
|
|
#include "wayland_server.h"
|
2011-11-10 13:28:06 +00:00
|
|
|
// Qt
|
2013-09-02 11:14:39 +00:00
|
|
|
#include <QDebug>
|
2013-08-08 09:39:39 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QQuickWindow>
|
2011-11-10 13:28:06 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
2012-03-29 13:32:41 +00:00
|
|
|
|
2013-08-08 09:39:39 +00:00
|
|
|
AbstractThumbnailItem::AbstractThumbnailItem(QQuickItem *parent)
|
|
|
|
: QQuickPaintedItem(parent)
|
2013-03-19 08:08:32 +00:00
|
|
|
, m_brightness(1.0)
|
|
|
|
, m_saturation(1.0)
|
2013-08-08 09:39:39 +00:00
|
|
|
, m_clipToItem()
|
2011-11-10 13:28:06 +00:00
|
|
|
{
|
2013-03-06 08:46:25 +00:00
|
|
|
connect(Compositor::self(), SIGNAL(compositingToggled(bool)), SLOT(compositingToggled()));
|
|
|
|
compositingToggled();
|
2011-11-10 13:28:06 +00:00
|
|
|
QTimer::singleShot(0, this, SLOT(init()));
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:32:41 +00:00
|
|
|
AbstractThumbnailItem::~AbstractThumbnailItem()
|
2011-11-10 13:28:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:32:41 +00:00
|
|
|
void AbstractThumbnailItem::compositingToggled()
|
2013-03-06 08:46:25 +00:00
|
|
|
{
|
|
|
|
m_parent.clear();
|
|
|
|
if (effects) {
|
|
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), SLOT(effectWindowAdded()));
|
|
|
|
connect(effects, SIGNAL(windowDamaged(KWin::EffectWindow*,QRect)), SLOT(repaint(KWin::EffectWindow*)));
|
|
|
|
effectWindowAdded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:32:41 +00:00
|
|
|
void AbstractThumbnailItem::init()
|
2011-11-10 13:28:06 +00:00
|
|
|
{
|
|
|
|
findParentEffectWindow();
|
2019-08-10 14:25:02 +00:00
|
|
|
if (m_parent) {
|
|
|
|
m_parent->registerThumbnail(this);
|
2011-11-10 13:28:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:32:41 +00:00
|
|
|
void AbstractThumbnailItem::findParentEffectWindow()
|
2011-11-10 13:28:06 +00:00
|
|
|
{
|
|
|
|
if (effects) {
|
2013-08-08 09:39:39 +00:00
|
|
|
QQuickWindow *qw = window();
|
|
|
|
if (!qw) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCDebug(KWIN_CORE) << "No QQuickWindow assigned yet";
|
2011-11-10 13:28:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-01-20 13:04:13 +00:00
|
|
|
if (auto *w = static_cast<EffectWindowImpl*>(effects->findWindow(qw))) {
|
2019-08-10 14:25:02 +00:00
|
|
|
m_parent = QPointer<EffectWindowImpl>(w);
|
2011-11-10 13:28:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:32:41 +00:00
|
|
|
void AbstractThumbnailItem::effectWindowAdded()
|
|
|
|
{
|
|
|
|
// the window might be added before the EffectWindow is created
|
|
|
|
// by using this slot we can register the thumbnail when it is finally created
|
|
|
|
if (m_parent.isNull()) {
|
|
|
|
findParentEffectWindow();
|
2019-08-10 14:25:02 +00:00
|
|
|
if (m_parent) {
|
|
|
|
m_parent->registerThumbnail(this);
|
2012-03-29 13:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractThumbnailItem::setBrightness(qreal brightness)
|
|
|
|
{
|
|
|
|
if (qFuzzyCompare(brightness, m_brightness)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_brightness = brightness;
|
|
|
|
update();
|
|
|
|
emit brightnessChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractThumbnailItem::setSaturation(qreal saturation)
|
|
|
|
{
|
|
|
|
if (qFuzzyCompare(saturation, m_saturation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_saturation = saturation;
|
|
|
|
update();
|
|
|
|
emit saturationChanged();
|
|
|
|
}
|
|
|
|
|
2013-08-08 09:39:39 +00:00
|
|
|
void AbstractThumbnailItem::setClipTo(QQuickItem *clip)
|
|
|
|
{
|
|
|
|
m_clipToItem = QPointer<QQuickItem>(clip);
|
|
|
|
emit clipToChanged();
|
|
|
|
}
|
2012-03-29 13:32:41 +00:00
|
|
|
|
2013-08-08 09:39:39 +00:00
|
|
|
WindowThumbnailItem::WindowThumbnailItem(QQuickItem* parent)
|
2012-03-29 13:32:41 +00:00
|
|
|
: AbstractThumbnailItem(parent)
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
, m_wId(nullptr)
|
|
|
|
, m_client(nullptr)
|
2012-03-29 13:32:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:46:53 +00:00
|
|
|
WindowThumbnailItem::~WindowThumbnailItem()
|
2012-03-29 13:32:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-20 13:04:13 +00:00
|
|
|
void WindowThumbnailItem::setWId(const QUuid &wId)
|
2011-11-10 13:28:06 +00:00
|
|
|
{
|
2013-03-26 13:43:36 +00:00
|
|
|
if (m_wId == wId) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-10 13:28:06 +00:00
|
|
|
m_wId = wId;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
if (m_wId != nullptr) {
|
2019-01-20 13:04:13 +00:00
|
|
|
setClient(workspace()->findAbstractClient([this] (const AbstractClient *c) { return c->internalId() == m_wId; }));
|
2013-03-26 13:43:36 +00:00
|
|
|
} else if (m_client) {
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
m_client = nullptr;
|
2013-03-26 13:43:36 +00:00
|
|
|
emit clientChanged();
|
|
|
|
}
|
2011-11-10 13:28:06 +00:00
|
|
|
emit wIdChanged(wId);
|
|
|
|
}
|
|
|
|
|
2015-05-20 14:23:42 +00:00
|
|
|
void WindowThumbnailItem::setClient(AbstractClient *client)
|
2013-03-26 13:43:36 +00:00
|
|
|
{
|
|
|
|
if (m_client == client) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_client = client;
|
|
|
|
if (m_client) {
|
2019-01-20 13:04:13 +00:00
|
|
|
setWId(m_client->internalId());
|
2013-03-26 13:43:36 +00:00
|
|
|
} else {
|
2019-01-20 13:04:13 +00:00
|
|
|
setWId({});
|
2013-03-26 13:43:36 +00:00
|
|
|
}
|
|
|
|
emit clientChanged();
|
|
|
|
}
|
|
|
|
|
2013-08-08 09:39:39 +00:00
|
|
|
void WindowThumbnailItem::paint(QPainter *painter)
|
2011-11-10 13:28:06 +00:00
|
|
|
{
|
|
|
|
if (effects) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-20 13:04:13 +00:00
|
|
|
auto client = workspace()->findAbstractClient([this] (const AbstractClient *c) { return c->internalId() == m_wId; });
|
2011-11-10 13:28:06 +00:00
|
|
|
if (!client) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-06 13:41:23 +00:00
|
|
|
QPixmap pixmap = client->icon().pixmap(boundingRect().size().toSize());
|
2011-11-10 13:28:06 +00:00
|
|
|
const QSize size(boundingRect().size().toSize() - pixmap.size());
|
|
|
|
painter->drawPixmap(boundingRect().adjusted(size.width()/2.0, size.height()/2.0, -size.width()/2.0, -size.height()/2.0).toRect(),
|
|
|
|
pixmap);
|
|
|
|
}
|
|
|
|
|
2012-03-29 13:46:53 +00:00
|
|
|
void WindowThumbnailItem::repaint(KWin::EffectWindow *w)
|
2012-03-16 11:33:48 +00:00
|
|
|
{
|
2019-01-20 13:04:13 +00:00
|
|
|
if (static_cast<KWin::EffectWindowImpl*>(w)->window()->internalId() == m_wId) {
|
2012-03-16 11:33:48 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 09:39:39 +00:00
|
|
|
DesktopThumbnailItem::DesktopThumbnailItem(QQuickItem *parent)
|
2012-03-29 18:17:57 +00:00
|
|
|
: AbstractThumbnailItem(parent)
|
|
|
|
, m_desktop(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DesktopThumbnailItem::~DesktopThumbnailItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopThumbnailItem::setDesktop(int desktop)
|
|
|
|
{
|
|
|
|
desktop = qBound<int>(1, desktop, VirtualDesktopManager::self()->count());
|
|
|
|
if (desktop == m_desktop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_desktop = desktop;
|
|
|
|
update();
|
|
|
|
emit desktopChanged(m_desktop);
|
|
|
|
}
|
|
|
|
|
2013-08-08 09:39:39 +00:00
|
|
|
void DesktopThumbnailItem::paint(QPainter *painter)
|
2012-03-29 18:17:57 +00:00
|
|
|
{
|
2013-08-08 09:39:39 +00:00
|
|
|
Q_UNUSED(painter)
|
2012-03-29 18:17:57 +00:00
|
|
|
if (effects) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO: render icon
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopThumbnailItem::repaint(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (w->isOnDesktop(m_desktop)) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:28:06 +00:00
|
|
|
} // namespace KWin
|