diff --git a/src/scripting/workspace_wrapper.cpp b/src/scripting/workspace_wrapper.cpp index 6d94893047..d534f2e9a3 100644 --- a/src/scripting/workspace_wrapper.cpp +++ b/src/scripting/workspace_wrapper.cpp @@ -280,6 +280,16 @@ void WorkspaceWrapper::hideOutline() workspace()->outline()->hide(); } +QList WorkspaceWrapper::stackingOrder() const +{ + return workspace()->stackingOrder(); +} + +void WorkspaceWrapper::raiseWindow(KWin::Window *window) +{ + KWin::Workspace::self()->raiseWindow(window); +} + Window *WorkspaceWrapper::getClient(qulonglong windowId) { auto window = Workspace::self()->findClient(Predicate::WindowMatch, windowId); @@ -287,6 +297,35 @@ Window *WorkspaceWrapper::getClient(qulonglong windowId) return window; } +QList WorkspaceWrapper::windowAt(const QPointF &pos, int count) const +{ + QList result; + int found = 0; + const QList &stacking = workspace()->stackingOrder(); + if (stacking.isEmpty()) { + return result; + } + auto it = stacking.end(); + do { + if (found == count) { + return result; + } + --it; + Window *window = (*it); + if (window->isDeleted()) { + continue; + } + if (!window->isOnCurrentActivity() || !window->isOnCurrentDesktop() || window->isMinimized() || window->isHiddenInternal()) { + continue; + } + if (window->hitTest(pos)) { + result.append(window); + found++; + } + } while (it != stacking.begin()); + return result; +} + QSize WorkspaceWrapper::desktopGridSize() const { return VirtualDesktopManager::self()->grid().size(); diff --git a/src/scripting/workspace_wrapper.h b/src/scripting/workspace_wrapper.h index b6918df835..29ddf470ba 100644 --- a/src/scripting/workspace_wrapper.h +++ b/src/scripting/workspace_wrapper.h @@ -54,6 +54,11 @@ class WorkspaceWrapper : public QObject * @see virtualScreenSize */ Q_PROPERTY(QRect virtualScreenGeometry READ virtualScreenGeometry NOTIFY virtualScreenGeometryChanged) + /** + * List of Clients currently managed by KWin, orderd by + * their visibility (later ones cover earlier ones). + */ + Q_PROPERTY(QList stackingOrder READ stackingOrder) /** * The current position of the cursor. */ @@ -230,12 +235,32 @@ public: * Provides support information about the currently running KWin instance. */ Q_SCRIPTABLE QString supportInformation() const; + + /** + * List of Clients currently managed by KWin, orderd by + * their visibility (later ones cover earlier ones). + */ + QList stackingOrder() const; + /** + * Raises a Window above all others on the screen. + * @param window The Window to raise + */ + Q_INVOKABLE void raiseWindow(KWin::Window *window); /** * Finds the Client with the given @p windowId. * @param windowId The window Id of the Client * @return The found Client or @c null */ Q_SCRIPTABLE KWin::Window *getClient(qulonglong windowId); + /** + * Finds up to count windows at a particular location, + * prioritizing the topmost one first. A negative count + * returns all matching clients. + * @param pos The location to look for + * @param count The number of clients to return + * @return A list of Client objects + */ + Q_INVOKABLE QList windowAt(const QPointF &pos, int count = 1) const; public Q_SLOTS: // all the available key bindings