KWin
Loading...
Searching...
No Matches
Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KWin::Cursor Class Reference

Replacement for QCursor. More...

#include <cursor.h>

Inheritance diagram for KWin::Cursor:
KWin::InputRedirectionCursor KWin::SurfaceCursor KWin::X11Cursor

Signals

void posChanged (const QPointF &pos)
 
void mouseChanged (const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers)
 
void cursorChanged ()
 Signal emitted when the cursor image changes.
 
void themeChanged ()
 
void rendered (std::chrono::milliseconds timestamp)
 

Public Member Functions

 Cursor ()
 
 ~Cursor () override
 
void startMousePolling ()
 
void stopMousePolling ()
 
void startCursorTracking ()
 Enables tracking changes of cursor images.
 
void stopCursorTracking ()
 Disables tracking changes of cursor images.
 
const QString & themeName () const
 The name of the currently used Cursor theme.
 
int themeSize () const
 The size of the currently used Cursor theme.
 
QPointF pos ()
 
void setPos (const QPointF &pos)
 
xcb_cursor_t x11Cursor (CursorShape shape)
 
xcb_cursor_t x11Cursor (const QByteArray &name)
 
QPointF hotspot () const
 
QRectF geometry () const
 
QRectF rect () const
 
CursorSourcesource () const
 
void setSource (CursorSource *source)
 
bool isOnOutput (Output *output) const
 
void markAsRendered (std::chrono::milliseconds timestamp)
 

Static Public Member Functions

static QString defaultThemeName ()
 
static int defaultThemeSize ()
 

Protected Member Functions

virtual void doSetPos ()
 
virtual void doGetPos ()
 
virtual void doStartMousePolling ()
 
virtual void doStopMousePolling ()
 
virtual void doStartCursorTracking ()
 
virtual void doStopCursorTracking ()
 
bool isCursorTracking () const
 
const QPointF & currentPos () const
 
void updatePos (const QPointF &pos)
 

Detailed Description

Replacement for QCursor.

This class provides a similar API to QCursor and should be preferred inside KWin. It allows to get the position and warp the mouse cursor with static methods just like QCursor. It also provides the possibility to get an X11 cursor for a Qt::CursorShape - a functionality lost in Qt 5's QCursor implementation.

In addition the class provides a mouse polling facility as required by e.g. Effects and ScreenEdges and emits signals when the mouse position changes. In opposite to QCursor this class is a QObject and cannot be constructed. Instead it provides a singleton getter, though the most important methods are wrapped in a static method, just like QCursor.

The actual implementation is split into two parts: a system independent interface and a windowing system specific subclass. So far only an X11 backend is implemented which uses query pointer to fetch the position and warp pointer to set the position. It uses a timer based mouse polling and can provide X11 cursors through the XCursor library.

Definition at line 101 of file cursor.h.

Constructor & Destructor Documentation

◆ Cursor()

KWin::Cursor::Cursor ( )

Definition at line 112 of file cursor.cpp.

◆ ~Cursor()

KWin::Cursor::~Cursor ( )
override

Definition at line 129 of file cursor.cpp.

Member Function Documentation

◆ currentPos()

const QPointF & KWin::Cursor::currentPos ( ) const
inlineprotected

Provides the actual internal cursor position to inheriting classes. If an inheriting class needs access to the cursor position this method should be used instead of the static pos, as the static method syncs with the underlying system's cursor.

Definition at line 312 of file cursor.h.

◆ cursorChanged

void KWin::Cursor::cursorChanged ( )
signal

Signal emitted when the cursor image changes.

To enable these signals use startCursorTracking.

See also
startCursorTracking
stopCursorTracking

◆ defaultThemeName()

QString KWin::Cursor::defaultThemeName ( )
static

Returns the default Xcursor theme name.

Definition at line 333 of file cursor.cpp.

◆ defaultThemeSize()

int KWin::Cursor::defaultThemeSize ( )
static

Returns the default Xcursor theme size.

Definition at line 338 of file cursor.cpp.

◆ doGetPos()

void KWin::Cursor::doGetPos ( )
protectedvirtual

Called from pos() to allow syncing the internal position with the underlying system's cursor position.

Reimplemented in KWin::X11Cursor.

Definition at line 270 of file cursor.cpp.

◆ doSetPos()

void KWin::Cursor::doSetPos ( )
protectedvirtual

Performs the actual warping of the cursor.

Reimplemented in KWin::X11Cursor, and KWin::InputRedirectionCursor.

Definition at line 265 of file cursor.cpp.

◆ doStartCursorTracking()

void KWin::Cursor::doStartCursorTracking ( )
protectedvirtual

Called from startCursorTracking when cursor image tracking gets activated. Inheriting class needs to overwrite to enable platform specific code for the tracking.

Reimplemented in KWin::X11Cursor.

Definition at line 325 of file cursor.cpp.

◆ doStartMousePolling()

void KWin::Cursor::doStartMousePolling ( )
protectedvirtual

Called from startMousePolling when the mouse polling gets activated. Base implementation does nothing, inheriting classes can overwrite to e.g. start a timer.

Reimplemented in KWin::X11Cursor.

Definition at line 300 of file cursor.cpp.

◆ doStopCursorTracking()

void KWin::Cursor::doStopCursorTracking ( )
protectedvirtual

Called from stopCursorTracking when cursor image tracking gets deactivated. Inheriting class needs to overwrite to disable platform specific code for the tracking.

Reimplemented in KWin::X11Cursor.

Definition at line 329 of file cursor.cpp.

◆ doStopMousePolling()

void KWin::Cursor::doStopMousePolling ( )
protectedvirtual

Called from stopMousePolling when the mouse polling gets deactivated. Base implementation does nothing, inheriting classes can overwrite to e.g. stop a timer.

Reimplemented in KWin::X11Cursor.

Definition at line 304 of file cursor.cpp.

◆ geometry()

QRectF KWin::Cursor::geometry ( ) const

Definition at line 190 of file cursor.cpp.

◆ hotspot()

QPointF KWin::Cursor::hotspot ( ) const

Definition at line 182 of file cursor.cpp.

◆ isCursorTracking()

bool KWin::Cursor::isCursorTracking ( ) const
inlineprotected

Definition at line 327 of file cursor.h.

◆ isOnOutput()

bool KWin::Cursor::isOnOutput ( Output * output) const

Returns true if the cursor is visible on the given output; otherwise returns false.

Definition at line 174 of file cursor.cpp.

◆ markAsRendered()

void KWin::Cursor::markAsRendered ( std::chrono::milliseconds timestamp)

Definition at line 220 of file cursor.cpp.

◆ mouseChanged

void KWin::Cursor::mouseChanged ( const QPointF & pos,
const QPointF & oldpos,
Qt::MouseButtons buttons,
Qt::MouseButtons oldbuttons,
Qt::KeyboardModifiers modifiers,
Qt::KeyboardModifiers oldmodifiers )
signal

◆ pos()

QPointF KWin::Cursor::pos ( )

Returns the current cursor position. This method does an update of the mouse position if needed. It's save to call it multiple times.

Implementing subclasses should prefer to use currentPos which is not performing a check for update.

Definition at line 204 of file cursor.cpp.

◆ posChanged

void KWin::Cursor::posChanged ( const QPointF & pos)
signal

◆ rect()

QRectF KWin::Cursor::rect ( ) const

Definition at line 195 of file cursor.cpp.

◆ rendered

void KWin::Cursor::rendered ( std::chrono::milliseconds timestamp)
signal

◆ setPos()

void KWin::Cursor::setPos ( const QPointF & pos)

Warps the mouse cursor to new pos.

Definition at line 210 of file cursor.cpp.

◆ setSource()

void KWin::Cursor::setSource ( CursorSource * source)

Definition at line 703 of file cursor.cpp.

◆ source()

CursorSource * KWin::Cursor::source ( ) const

Definition at line 698 of file cursor.cpp.

◆ startCursorTracking()

void KWin::Cursor::startCursorTracking ( )

Enables tracking changes of cursor images.

After enabling cursor change tracking the signal cursorChanged will be emitted whenever a change to the cursor image is recognized.

Use stopCursorTracking to no longer emit this signal. Note: the signal will be emitted until each call of this method has been matched with a call to stopCursorTracking.

This tracking is not about pointer position tracking.

See also
stopCursorTracking
cursorChanged

Definition at line 308 of file cursor.cpp.

◆ startMousePolling()

void KWin::Cursor::startMousePolling ( )

Definition at line 283 of file cursor.cpp.

◆ stopCursorTracking()

void KWin::Cursor::stopCursorTracking ( )

Disables tracking changes of cursor images.

Only call after using startCursorTracking.

See also
startCursorTracking

Definition at line 316 of file cursor.cpp.

◆ stopMousePolling()

void KWin::Cursor::stopMousePolling ( )

Definition at line 291 of file cursor.cpp.

◆ themeChanged

void KWin::Cursor::themeChanged ( )
signal

◆ themeName()

const QString & KWin::Cursor::themeName ( ) const
inline

The name of the currently used Cursor theme.

Returns
const QString&

Definition at line 317 of file cursor.h.

◆ themeSize()

int KWin::Cursor::themeSize ( ) const
inline

The size of the currently used Cursor theme.

Returns
int

Definition at line 322 of file cursor.h.

◆ updatePos()

void KWin::Cursor::updatePos ( const QPointF & pos)
protected

Updates the internal position to pos without warping the pointer as setPos does.

Definition at line 274 of file cursor.cpp.

◆ x11Cursor() [1/2]

xcb_cursor_t KWin::Cursor::x11Cursor ( const QByteArray & name)

Notice: if available always use the CursorShape variant to avoid cache duplicates for ambiguous cursor names in the non existing cursor name specification

Definition at line 230 of file cursor.cpp.

◆ x11Cursor() [2/2]

xcb_cursor_t KWin::Cursor::x11Cursor ( CursorShape shape)

Definition at line 225 of file cursor.cpp.


The documentation for this class was generated from the following files: