Changeset View
Changeset View
Standalone View
Standalone View
runners/windows/windowsrunner.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
70 | // Called in the main thread | 70 | // Called in the main thread | ||
71 | void WindowsRunner::gatherInfo() | 71 | void WindowsRunner::gatherInfo() | ||
72 | { | 72 | { | ||
73 | QMutexLocker locker(&m_mutex); | 73 | QMutexLocker locker(&m_mutex); | ||
74 | if (!m_inSession) { | 74 | if (!m_inSession) { | ||
75 | return; | 75 | return; | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | foreach (const WId w, KWindowSystem::windows()) { | 78 | const auto windows = KWindowSystem::windows(); | ||
79 | for (const WId &w : windows) { | ||||
davidedmundson: Does this detach? | |||||
79 | KWindowInfo info(w, NET::WMWindowType | NET::WMDesktop | | 80 | KWindowInfo info(w, NET::WMWindowType | NET::WMDesktop | | ||
80 | NET::WMState | NET::XAWMState | | 81 | NET::WMState | NET::XAWMState | | ||
81 | NET::WMName, | 82 | NET::WMName, | ||
82 | NET::WM2WindowClass | NET::WM2WindowRole | NET::WM2AllowedActions); | 83 | NET::WM2WindowClass | NET::WM2WindowRole | NET::WM2AllowedActions); | ||
83 | if (info.valid()) { | 84 | if (info.valid()) { | ||
84 | // ignore NET::Tool and other special window types | 85 | // ignore NET::Tool and other special window types | ||
85 | NET::WindowType wType = info.windowType(NET::NormalMask | NET::DesktopMask | NET::DockMask | | 86 | NET::WindowType wType = info.windowType(NET::NormalMask | NET::DesktopMask | NET::DockMask | | ||
86 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | | 87 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 129 | { | |||
175 | // keyword match: when term starts with "window" we list all windows | 176 | // keyword match: when term starts with "window" we list all windows | ||
176 | // the list can be restricted to windows matching a given name, class, role or desktop | 177 | // the list can be restricted to windows matching a given name, class, role or desktop | ||
177 | if (term.startsWith(i18nc("Note this is a KRunner keyword", "window") , Qt::CaseInsensitive)) { | 178 | if (term.startsWith(i18nc("Note this is a KRunner keyword", "window") , Qt::CaseInsensitive)) { | ||
178 | const QStringList keywords = term.split(QLatin1Char(' ')); | 179 | const QStringList keywords = term.split(QLatin1Char(' ')); | ||
179 | QString windowName; | 180 | QString windowName; | ||
180 | QString windowClass; | 181 | QString windowClass; | ||
181 | QString windowRole; | 182 | QString windowRole; | ||
182 | int desktop = -1; | 183 | int desktop = -1; | ||
183 | foreach (const QString& keyword, keywords) { | 184 | for (const QString& keyword : keywords) { | ||
184 | if (keyword.endsWith(QLatin1Char('='))) { | 185 | if (keyword.endsWith(QLatin1Char('='))) { | ||
185 | continue; | 186 | continue; | ||
186 | } | 187 | } | ||
187 | if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + QStringLiteral("=") , Qt::CaseInsensitive)) { | 188 | if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + QStringLiteral("=") , Qt::CaseInsensitive)) { | ||
188 | windowName = keyword.split(QStringLiteral("="))[1]; | 189 | windowName = keyword.split(QStringLiteral("="))[1]; | ||
189 | } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "class") + QStringLiteral("=") , Qt::CaseInsensitive)) { | 190 | } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "class") + QStringLiteral("=") , Qt::CaseInsensitive)) { | ||
190 | windowClass = keyword.split(QStringLiteral("="))[1]; | 191 | windowClass = keyword.split(QStringLiteral("="))[1]; | ||
191 | } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "role") + QStringLiteral("=") , Qt::CaseInsensitive)) { | 192 | } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "role") + QStringLiteral("=") , Qt::CaseInsensitive)) { | ||
Show All 18 Lines | 209 | while(it.hasNext()) { | |||
210 | WId w = it.key(); | 211 | WId w = it.key(); | ||
211 | KWindowInfo info = it.value(); | 212 | KWindowInfo info = it.value(); | ||
212 | QString windowClassCompare = QString::fromUtf8(info.windowClassName()) + QLatin1Char(' ') + | 213 | QString windowClassCompare = QString::fromUtf8(info.windowClassName()) + QLatin1Char(' ') + | ||
213 | QString::fromUtf8(info.windowClassClass()); | 214 | QString::fromUtf8(info.windowClassClass()); | ||
214 | // exclude not matching windows | 215 | // exclude not matching windows | ||
215 | if (!KWindowSystem::hasWId(w)) { | 216 | if (!KWindowSystem::hasWId(w)) { | ||
216 | continue; | 217 | continue; | ||
217 | } | 218 | } | ||
218 | if (!windowName.isEmpty() && !info.name().contains(windowName, Qt::CaseInsensitive)) { | 219 | if (!windowName.isEmpty() && !info.name().startsWith(windowName, Qt::CaseInsensitive)) { | ||
219 | continue; | 220 | continue; | ||
220 | } | 221 | } | ||
221 | if (!windowClass.isEmpty() && !windowClassCompare.contains(windowClass, Qt::CaseInsensitive)) { | 222 | if (!windowClass.isEmpty() && !windowClassCompare.contains(windowClass, Qt::CaseInsensitive)) { | ||
222 | continue; | 223 | continue; | ||
223 | } | 224 | } | ||
224 | if (!windowRole.isEmpty() && !QString::fromUtf8(info.windowRole()).contains(windowRole, Qt::CaseInsensitive)) { | 225 | if (!windowRole.isEmpty() && !QString::fromUtf8(info.windowRole()).contains(windowRole, Qt::CaseInsensitive)) { | ||
225 | continue; | 226 | continue; | ||
226 | } | 227 | } | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 280 | while (it.hasNext()) { | |||
291 | } else if ((info.name().contains(term, Qt::CaseInsensitive) || | 292 | } else if ((info.name().contains(term, Qt::CaseInsensitive) || | ||
292 | className.contains(term, Qt::CaseInsensitive)) && | 293 | className.contains(term, Qt::CaseInsensitive)) && | ||
293 | actionSupported(info, action)) { | 294 | actionSupported(info, action)) { | ||
294 | matches << windowMatch(info, action, 0.7, Plasma::QueryMatch::PossibleMatch); | 295 | matches << windowMatch(info, action, 0.7, Plasma::QueryMatch::PossibleMatch); | ||
295 | } | 296 | } | ||
296 | } | 297 | } | ||
297 | 298 | | |||
298 | // check for matching desktops by name | 299 | // check for matching desktops by name | ||
299 | foreach (const QString& desktopName, m_desktopNames) { | 300 | for (const QString& desktopName : qAsConst(m_desktopNames)) { | ||
300 | int desktop = m_desktopNames.indexOf(desktopName) +1; | 301 | int desktop = m_desktopNames.indexOf(desktopName) +1; | ||
301 | if (desktopName.contains(term, Qt::CaseInsensitive)) { | 302 | if (desktopName.contains(term, Qt::CaseInsensitive)) { | ||
302 | // desktop name matches - offer switch to | 303 | // desktop name matches - offer switch to | ||
303 | // only add desktops if it hasn't been added by the keyword which is quite likely | 304 | // only add desktops if it hasn't been added by the keyword which is quite likely | ||
304 | if (!desktopAdded && desktop != KWindowSystem::currentDesktop()) { | 305 | if (!desktopAdded && desktop != KWindowSystem::currentDesktop()) { | ||
305 | matches << desktopMatch(desktop, 0.8); | 306 | matches << desktopMatch(desktop, 0.8); | ||
306 | } | 307 | } | ||
307 | 308 | | |||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |
Does this detach?