2022-02-05 09:47:00 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
2022-04-12 13:14:23 +00:00
|
|
|
#include "cursordelegate_qpainter.h"
|
2022-02-05 09:47:00 +00:00
|
|
|
#include "cursor.h"
|
2022-04-12 08:16:27 +00:00
|
|
|
#include "renderlayer.h"
|
|
|
|
#include "rendertarget.h"
|
2022-02-05 09:47:00 +00:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2022-04-12 13:14:23 +00:00
|
|
|
CursorDelegateQPainter::CursorDelegateQPainter(QObject *parent)
|
|
|
|
: RenderLayerDelegate(parent)
|
2022-02-05 09:47:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:14:23 +00:00
|
|
|
void CursorDelegateQPainter::paint(RenderTarget *renderTarget, const QRegion ®ion)
|
2022-02-05 09:47:00 +00:00
|
|
|
{
|
2022-04-12 13:14:23 +00:00
|
|
|
if (!region.intersects(layer()->mapToGlobal(layer()->rect()))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:16:27 +00:00
|
|
|
QImage *buffer = std::get<QImage *>(renderTarget->nativeHandle());
|
|
|
|
if (Q_UNLIKELY(!buffer)) {
|
2022-02-05 09:47:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Cursor *cursor = Cursors::self()->currentCursor();
|
2022-04-12 08:16:27 +00:00
|
|
|
QPainter painter(buffer);
|
2022-02-05 09:47:00 +00:00
|
|
|
painter.setClipRegion(region);
|
2022-04-12 13:14:23 +00:00
|
|
|
painter.drawImage(layer()->mapToGlobal(layer()->rect()), cursor->image());
|
2022-02-05 09:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|