2022-12-19 08:45:29 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scene/cursoritem.h"
|
|
|
|
#include "cursor.h"
|
|
|
|
#include "cursorsource.h"
|
2023-11-20 10:43:05 +00:00
|
|
|
#include "effect/effect.h"
|
2022-12-19 08:45:29 +00:00
|
|
|
#include "scene/imageitem.h"
|
|
|
|
#include "scene/itemrenderer.h"
|
|
|
|
#include "scene/scene.h"
|
|
|
|
#include "scene/surfaceitem_wayland.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
CursorItem::CursorItem(Scene *scene, Item *parent)
|
|
|
|
: Item(scene, parent)
|
|
|
|
{
|
|
|
|
refresh();
|
|
|
|
connect(Cursors::self(), &Cursors::currentCursorChanged, this, &CursorItem::refresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
CursorItem::~CursorItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CursorItem::refresh()
|
|
|
|
{
|
|
|
|
const CursorSource *source = Cursors::self()->currentCursor()->source();
|
|
|
|
if (auto surfaceSource = qobject_cast<const SurfaceCursorSource *>(source)) {
|
2023-04-06 12:06:48 +00:00
|
|
|
setSurface(surfaceSource->surface());
|
2022-12-19 08:45:29 +00:00
|
|
|
} else if (auto shapeSource = qobject_cast<const ShapeCursorSource *>(source)) {
|
|
|
|
setImage(shapeSource->image());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
void CursorItem::setSurface(SurfaceInterface *surface)
|
2022-12-19 08:45:29 +00:00
|
|
|
{
|
|
|
|
m_imageItem.reset();
|
|
|
|
|
|
|
|
if (!m_surfaceItem || m_surfaceItem->surface() != surface) {
|
|
|
|
if (surface) {
|
|
|
|
m_surfaceItem = std::make_unique<SurfaceItemWayland>(surface, scene(), this);
|
|
|
|
} else {
|
|
|
|
m_surfaceItem.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CursorItem::setImage(const QImage &image)
|
|
|
|
{
|
|
|
|
m_surfaceItem.reset();
|
|
|
|
|
|
|
|
if (!m_imageItem) {
|
2023-08-10 16:31:43 +00:00
|
|
|
m_imageItem = scene()->renderer()->createImageItem(scene(), this);
|
2022-12-19 08:45:29 +00:00
|
|
|
}
|
|
|
|
m_imageItem->setImage(image);
|
|
|
|
m_imageItem->setSize(image.size() / image.devicePixelRatio());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|
2023-07-05 06:30:14 +00:00
|
|
|
|
|
|
|
#include "moc_cursoritem.cpp"
|