|
11 | 11 | #include "KandoKWinIntegrationPlugin.h" |
12 | 12 |
|
13 | 13 | #include <effect/effecthandler.h> |
| 14 | +#include <effect/effectwindow.h> |
14 | 15 |
|
15 | 16 | #include <QDBusConnection> |
16 | 17 | #include <QDBusError> |
@@ -69,3 +70,46 @@ QVariantMap KandoKWinIntegrationPlugin::getWMInfo() const { |
69 | 70 | {QStringLiteral("workAreaHeight"), qRound(workArea.height())}, |
70 | 71 | }; |
71 | 72 | } |
| 73 | + |
| 74 | +QVariantList KandoKWinIntegrationPlugin::getOpenWindows() const { |
| 75 | + QVariantList windows; |
| 76 | + |
| 77 | + for (const auto* window : KWin::effects->stackingOrder()) { |
| 78 | + if (!window || window->isDeleted() || !window->isManaged() || |
| 79 | + window->isSpecialWindow() || window->isSkipSwitcher()) { |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | + const auto windowName = window->caption(); |
| 84 | + const auto appName = window->windowClass(); |
| 85 | + |
| 86 | + if (windowName.isEmpty() && appName.isEmpty()) { |
| 87 | + continue; |
| 88 | + } |
| 89 | + |
| 90 | + windows.push_back(QVariantList{windowName, appName}); |
| 91 | + } |
| 92 | + |
| 93 | + return windows; |
| 94 | +} |
| 95 | + |
| 96 | +bool KandoKWinIntegrationPlugin::focusWindow(const QString& windowName, |
| 97 | + const QString& appName) const { |
| 98 | + const auto windows = KWin::effects->stackingOrder(); |
| 99 | + |
| 100 | + // Iterate top-most first so we focus the window the user most likely expects. |
| 101 | + for (auto it = windows.rbegin(); it != windows.rend(); ++it) { |
| 102 | + auto* window = *it; |
| 103 | + |
| 104 | + if (!window || window->isDeleted() || !window->isManaged()) { |
| 105 | + continue; |
| 106 | + } |
| 107 | + |
| 108 | + if (window->caption() == windowName && window->windowClass() == appName) { |
| 109 | + KWin::effects->activateWindow(window); |
| 110 | + return true; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + return false; |
| 115 | +} |
0 commit comments