From 26bf4f51d0d8c27d8218b5283954fd5700ebd528 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Tue, 30 Mar 2021 14:09:16 +0200 Subject: [PATCH] Add a DBus interface to the highlightWindows effect The Taskmanager can now activate it this way, instead of using X atoms. This means it will also work on Wayland. --- .../highlightwindow/highlightwindow.cpp | 29 +++++++++++++++++++ src/effects/highlightwindow/highlightwindow.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/effects/highlightwindow/highlightwindow.cpp b/src/effects/highlightwindow/highlightwindow.cpp index 276f9af95f..8cb82f27c8 100644 --- a/src/effects/highlightwindow/highlightwindow.cpp +++ b/src/effects/highlightwindow/highlightwindow.cpp @@ -3,12 +3,15 @@ This file is part of the KDE project. SPDX-FileCopyrightText: 2009 Lucas Murray + SPDX-FileCopyrightText: 2021 David Redondo SPDX-License-Identifier: GPL-2.0-or-later */ #include "highlightwindow.h" +#include + namespace KWin { @@ -17,6 +20,7 @@ HighlightWindowEffect::HighlightWindowEffect() , m_fadeDuration(animationTime(150)) , m_monitorWindow(nullptr) { + // TODO KF6 remove atom support m_atom = effects->announceSupportProperty("_KDE_WINDOW_HIGHLIGHT", this); connect(effects, &EffectsHandler::windowAdded, this, &HighlightWindowEffect::slotWindowAdded); connect(effects, &EffectsHandler::windowClosed, this, &HighlightWindowEffect::slotWindowClosed); @@ -31,6 +35,17 @@ HighlightWindowEffect::HighlightWindowEffect() m_atom = effects->announceSupportProperty("_KDE_WINDOW_HIGHLIGHT", this); } ); + + QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/KWin/HighlightWindow"), + QStringLiteral("org.kde.KWin.HighlightWindow"), + this, + QDBusConnection::ExportScriptableContents); + QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.KWin.HighlightWindow")); +} + +HighlightWindowEffect::~HighlightWindowEffect() +{ + QDBusConnection::sessionBus().unregisterService(QStringLiteral("org.kde.KWin.HighlightWindow")); } static bool isInitiallyHidden(EffectWindow* w) @@ -44,6 +59,20 @@ static bool isHighlightWindow(EffectWindow *window) return window->isNormalWindow() || window->isDialog(); } +void HighlightWindowEffect::highlightWindows(const QStringList &windows) +{ + QVector effectWindows; + effectWindows.reserve(windows.count()); + for (const auto &window : windows) { + if (auto effectWindow = effects->findWindow(QUuid(window)); effectWindow) { + effectWindows.append(effectWindow); + } else if (auto effectWindow = effects->findWindow(window.toLong()); effectWindow) { + effectWindows.append(effectWindow); + } + } + highlightWindows(effectWindows); +} + void HighlightWindowEffect::slotWindowAdded(EffectWindow* w) { if (!m_highlightedWindows.isEmpty()) { diff --git a/src/effects/highlightwindow/highlightwindow.h b/src/effects/highlightwindow/highlightwindow.h index 2fce155fef..b1cfdccf6b 100644 --- a/src/effects/highlightwindow/highlightwindow.h +++ b/src/effects/highlightwindow/highlightwindow.h @@ -21,6 +21,7 @@ class HighlightWindowEffect : public AnimationEffect public: HighlightWindowEffect(); + ~HighlightWindowEffect() override; int requestedEffectChainPosition() const override { return 70; @@ -28,6 +29,7 @@ public: bool provides(Feature feature) override; bool perform(Feature feature, const QVariantList &arguments) override; + Q_SCRIPTABLE void highlightWindows(const QStringList &windows); public Q_SLOTS: void slotWindowAdded(KWin::EffectWindow* w);