Skip to content

Commit

Permalink
scripting: Expose cursor position to the API
Browse files Browse the repository at this point in the history
Added cursorPos property and cursorPosChanged signal to WorkspaceWrapper
  • Loading branch information
Yunus Erdem Ergül authored and zzag committed Oct 30, 2022
1 parent 88991f9 commit 96cfc41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/scripting/workspace_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "workspace_wrapper.h"
#include "core/output.h"
#include "cursor.h"
#include "outline.h"
#include "virtualdesktops.h"
#include "workspace.h"
Expand Down Expand Up @@ -61,6 +62,7 @@ WorkspaceWrapper::WorkspaceWrapper(QObject *parent)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(QApplication::desktop(), &QDesktopWidget::resized, this, &WorkspaceWrapper::screenResized);
#endif
connect(Cursors::self()->mouse(), &Cursor::posChanged, this, &WorkspaceWrapper::cursorPosChanged);

const QList<Window *> clients = ws->allClientList();
for (Window *client : clients) {
Expand Down Expand Up @@ -138,6 +140,11 @@ QStringList WorkspaceWrapper::activityList() const
#endif
}

QPoint WorkspaceWrapper::cursorPos() const
{
return Cursors::self()->mouse()->pos();
}

#define SLOTWRAPPER(name) \
void WorkspaceWrapper::name() \
{ \
Expand Down
11 changes: 10 additions & 1 deletion src/scripting/workspace_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class WorkspaceWrapper : public QObject
* @see virtualScreenSize
*/
Q_PROPERTY(QRect virtualScreenGeometry READ virtualScreenGeometry NOTIFY virtualScreenGeometryChanged)
/**
* The current position of the cursor.
*/
Q_PROPERTY(QPoint cursorPos READ cursorPos NOTIFY cursorPosChanged)

private:
Q_DISABLE_COPY(WorkspaceWrapper)
Expand Down Expand Up @@ -160,13 +164,17 @@ class WorkspaceWrapper : public QObject
* @since 5.0
*/
void virtualScreenGeometryChanged();

/**
* This signal is emitted when the current virtual desktop changes.
*
* @since 5.23
*/
void currentVirtualDesktopChanged();
/**
* This signal is emitted when the cursor position changes.
* @see cursorPos()
*/
void cursorPosChanged();

public:
//------------------------------------------------------------------
Expand Down Expand Up @@ -231,6 +239,7 @@ class WorkspaceWrapper : public QObject
QStringList activityList() const;
QSize virtualScreenSize() const;
QRect virtualScreenGeometry() const;
QPoint cursorPos() const;

VirtualDesktop *currentVirtualDesktop() const;
void setCurrentVirtualDesktop(VirtualDesktop *desktop);
Expand Down

0 comments on commit 96cfc41

Please sign in to comment.