Add CursorSource::frame

This fixes not sending frame callbacks for tablet cursors. And in general
this simplifies the code by removing a level of indirection responsible for
communicating the frame timestamps, the Compositor can tell the CursorSource
the frame time directly.
This commit is contained in:
Vlad Zahorodnii 2024-07-30 14:44:52 +03:00
parent ecf7211d2d
commit 398cf8df1b
7 changed files with 21 additions and 22 deletions

View file

@ -12,6 +12,7 @@
#include "core/outputbackend.h"
#include "core/renderbackend.h"
#include "core/renderlayer.h"
#include "cursorsource.h"
#include "effect/effecthandler.h"
#include "ftrace.h"
#include "main.h"
@ -354,7 +355,9 @@ void WaylandCompositor::composite(RenderLoop *renderLoop)
if (!Cursors::self()->isCursorHidden()) {
Cursor *cursor = Cursors::self()->currentCursor();
if (cursor->geometry().intersects(output->geometry())) {
cursor->markAsRendered(frameTime);
if (CursorSource *source = cursor->source()) {
source->frame(frameTime);
}
}
}
}

View file

@ -218,11 +218,6 @@ void Cursor::setPos(const QPointF &pos)
doSetPos();
}
void Cursor::markAsRendered(std::chrono::milliseconds timestamp)
{
Q_EMIT rendered(timestamp);
}
#if KWIN_BUILD_X11
xcb_cursor_t Cursor::x11Cursor(CursorShape shape)
{

View file

@ -161,8 +161,6 @@ public:
*/
bool isOnOutput(Output *output) const;
void markAsRendered(std::chrono::milliseconds timestamp);
Q_SIGNALS:
void posChanged(const QPointF &pos);
void mouseChanged(const QPointF &pos, const QPointF &oldpos,
@ -178,7 +176,6 @@ Q_SIGNALS:
*/
void cursorChanged();
void themeChanged();
void rendered(std::chrono::milliseconds timestamp);
protected:
/**

View file

@ -31,6 +31,10 @@ QPointF CursorSource::hotspot() const
return m_hotspot;
}
void CursorSource::frame(std::chrono::milliseconds timestamp)
{
}
ShapeCursorSource::ShapeCursorSource(QObject *parent)
: CursorSource(parent)
{
@ -126,6 +130,15 @@ SurfaceInterface *SurfaceCursorSource::surface() const
return m_surface;
}
void SurfaceCursorSource::frame(std::chrono::milliseconds timestamp)
{
if (m_surface) {
m_surface->traverseTree([&timestamp](SurfaceInterface *surface) {
surface->frameRendered(timestamp.count());
});
}
}
void SurfaceCursorSource::refresh()
{
m_size = m_surface->size();

View file

@ -32,6 +32,8 @@ public:
QSizeF size() const;
QPointF hotspot() const;
virtual void frame(std::chrono::milliseconds timestamp);
Q_SIGNALS:
void changed();
@ -84,6 +86,8 @@ public:
SurfaceInterface *surface() const;
void frame(std::chrono::milliseconds timestamp) override;
public Q_SLOTS:
void update(SurfaceInterface *surface, const QPointF &hotspot);

View file

@ -106,7 +106,6 @@ void PointerInputRedirection::init()
}
});
connect(Cursors::self()->mouse(), &Cursor::rendered, m_cursor, &CursorImage::markAsRendered);
connect(m_cursor, &CursorImage::changed, Cursors::self()->mouse(), [this] {
Cursors::self()->mouse()->setSource(m_cursor->source());
m_cursor->updateCursorOutputs(m_pos);
@ -1021,17 +1020,6 @@ void CursorImage::updateCursorOutputs(const QPointF &pos)
}
}
void CursorImage::markAsRendered(std::chrono::milliseconds timestamp)
{
if (m_currentSource == m_serverCursor.surface.get()) {
if (auto cursorSurface = m_serverCursor.surface->surface()) {
cursorSurface->traverseTree([&timestamp](SurfaceInterface *surface) {
surface->frameRendered(timestamp.count());
});
}
}
}
void CursorImage::handleFocusedSurfaceChanged()
{
PointerInterface *pointer = waylandServer()->seat()->pointer();

View file

@ -234,7 +234,6 @@ public:
void setSource(CursorSource *source);
void updateCursorOutputs(const QPointF &pos);
void markAsRendered(std::chrono::milliseconds timestamp);
Q_SIGNALS:
void changed();