kwin/src/cursordelegate_qpainter.cpp
Vlad Zahorodnii d2fb4147fc Move multi-purpose code in its own directory
Things such as Output, InputDevice and so on are made to be
multi-purpose. In order to make this separation more clear, this change
moves that code in the core directory. Some things still link to the
abstraction level above (kwin), they can be tackled in future refactors.
Ideally code in core/ should depend either on other code in core/ or
system libs.
2022-09-06 11:21:40 +03:00

39 lines
923 B
C++

/*
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "cursordelegate_qpainter.h"
#include "core/renderlayer.h"
#include "core/rendertarget.h"
#include "cursor.h"
#include <QPainter>
namespace KWin
{
CursorDelegateQPainter::CursorDelegateQPainter(QObject *parent)
: RenderLayerDelegate(parent)
{
}
void CursorDelegateQPainter::paint(RenderTarget *renderTarget, const QRegion &region)
{
if (!region.intersects(layer()->mapToGlobal(layer()->rect()))) {
return;
}
QImage *buffer = std::get<QImage *>(renderTarget->nativeHandle());
if (Q_UNLIKELY(!buffer)) {
return;
}
const Cursor *cursor = Cursors::self()->currentCursor();
QPainter painter(buffer);
painter.setClipRegion(region);
painter.drawImage(layer()->mapToGlobal(layer()->rect()), cursor->image());
}
} // namespace KWin