Commit 0332fc68 authored by David Redondo's avatar David Redondo 🏎
Browse files

Use DBus interface for presentWindows

Similiar to highlightWindow the effect has gained a DBus interface
in order to also support wayland.
BUG:397153
parent ee49020b
......@@ -79,21 +79,21 @@ Item {
// "You asked for Tooltips but Tooltips are disabled" message
Kirigami.InlineMessage {
Layout.fillWidth: true
visible: groupedTaskVisualization.currentIndex === 1 && !plasmoid.configuration.showToolTips && backend.canPresentWindows()
visible: groupedTaskVisualization.currentIndex === 1 && !plasmoid.configuration.showToolTips && backend.canPresentWindows
type: Kirigami.MessageType.Warning
text: i18n("Tooltips are disabled, so the 'Present Windows' effect will be displayed instead.")
}
// "You asked for Tooltips but Tooltips are disabled and Present Windows is not available" message
Kirigami.InlineMessage {
Layout.fillWidth: true
visible: groupedTaskVisualization.currentIndex === 1 && !plasmoid.configuration.showToolTips && !backend.canPresentWindows()
visible: groupedTaskVisualization.currentIndex === 1 && !plasmoid.configuration.showToolTips && !backend.canPresentWindows
type: Kirigami.MessageType.Warning
text: i18n("Tooltips are disabled, and the 'Present Windows' effect is not enabled or otherwise available right now, so a textual list will be displayed instead")
}
// "You asked for Present Windows but Present Windows is not available" message
Kirigami.InlineMessage {
Layout.fillWidth: true
visible: groupedTaskVisualization.currentIndex === 2 && !backend.canPresentWindows()
visible: groupedTaskVisualization.currentIndex === 2 && !backend.canPresentWindows
type: Kirigami.MessageType.Warning
text: i18n("The 'Present Windows' effect is not enabled or otherwise available right now, so a textual list will be displayed instead.")
}
......
......@@ -163,7 +163,7 @@ function activateTask(index, model, modifiers, task) {
// ==================================================
// Make sure the Present Windows effect is are actually enabled though;
// if not, fall through to the next option.
else if (backend.canPresentWindows()
else if (backend.canPresentWindows
&& (plasmoid.configuration.groupedTaskVisualization === 2
|| plasmoid.configuration.groupedTaskVisualization === 1)
) {
......
......@@ -36,9 +36,12 @@
#include <QActionGroup>
#include <QApplication>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDBusMetaType>
#include <QDBusPendingCall>
#include <QDBusReply>
#include <QDBusServiceWatcher>
#include <QJsonArray>
#include <QMenu>
#include <QQuickItem>
......@@ -64,11 +67,28 @@ static const QString highlightWindowName = QStringLiteral("org.kde.KWin.Highligh
static const QString highlightWindowPath = QStringLiteral("/org/kde/KWin/HighlightWindow");
static const QString &highlightWindowInterface = highlightWindowName;
static const QString presentWindowsName = QStringLiteral("org.kde.KWin.PresentWindows");
static const QString presentWindowsPath = QStringLiteral("org/kde/KWin/PresentWindows");
static const QString &presentWindowsInterface = presentWindowsName;
Backend::Backend(QObject *parent)
: QObject(parent)
, m_highlightWindows(false)
, m_actionGroup(new QActionGroup(this))
{
m_canPresentWindows = QDBusConnection::sessionBus().interface()->isServiceRegistered(presentWindowsName);
auto watcher = new QDBusServiceWatcher(presentWindowsName,
QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration,
this);
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, [this] {
m_canPresentWindows = true;
Q_EMIT canPresentWindowsChanged();
});
connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, [this] {
m_canPresentWindows = false;
Q_EMIT canPresentWindowsChanged();
});
}
Backend::~Backend()
......@@ -506,38 +526,20 @@ void Backend::ungrabMouse(QQuickItem *item) const
bool Backend::canPresentWindows() const
{
return (KWindowSystem::compositingActive() && KWindowEffects::isEffectAvailable(KWindowEffects::PresentWindowsGroup));
return m_canPresentWindows;
}
void Backend::presentWindows(const QVariant &_winIds)
{
if (!m_taskManagerItem || !m_taskManagerItem->window()) {
return;
}
QList<WId> winIds;
const QVariantList &_winIdsList = _winIds.toList();
foreach (const QVariant &_winId, _winIdsList) {
bool ok = false;
qlonglong winId = _winId.toLongLong(&ok);
if (ok) {
winIds.append(winId);
}
}
if (winIds.isEmpty()) {
return;
}
if (m_windowsToHighlight.count()) {
m_windowsToHighlight.clear();
updateWindowHighlight();
}
KWindowEffects::presentWindows(m_taskManagerItem->window()->winId(), winIds);
auto message = QDBusMessage::createMethodCall(presentWindowsName, presentWindowsPath, presentWindowsInterface, QStringLiteral("presentWindows"));
message << _winIds.toStringList();
QDBusConnection::sessionBus().asyncCall(message);
}
bool Backend::isApplication(const QUrl &url) const
......@@ -592,7 +594,7 @@ void Backend::windowsHovered(const QVariant &_winIds, bool hovered)
m_windowsToHighlight.clear();
if (hovered) {
m_windowsToHighlight = _winIds.value<QStringList>();
m_windowsToHighlight = _winIds.toStringList();
}
updateWindowHighlight();
......
......@@ -45,6 +45,7 @@ class Backend : public QObject
Q_PROPERTY(QQuickItem *toolTipItem READ toolTipItem WRITE setToolTipItem NOTIFY toolTipItemChanged)
Q_PROPERTY(QQuickWindow *groupDialog READ groupDialog WRITE setGroupDialog NOTIFY groupDialogChanged)
Q_PROPERTY(bool highlightWindows READ highlightWindows WRITE setHighlightWindows NOTIFY highlightWindowsChanged)
Q_PROPERTY(bool canPresentWindows READ canPresentWindows NOTIFY canPresentWindowsChanged)
public:
enum MiddleClickAction {
......@@ -82,7 +83,7 @@ public:
Q_INVOKABLE void ungrabMouse(QQuickItem *item) const;
Q_INVOKABLE bool canPresentWindows() const;
bool canPresentWindows() const;
Q_INVOKABLE bool isApplication(const QUrl &url) const;
......@@ -104,6 +105,7 @@ Q_SIGNALS:
void groupDialogChanged() const;
void highlightWindowsChanged() const;
void addLauncher(const QUrl &url) const;
void canPresentWindowsChanged();
void showAllPlaces();
......@@ -123,6 +125,7 @@ private:
QStringList m_windowsToHighlight;
QActionGroup *m_actionGroup = nullptr;
KActivities::Consumer *m_activitiesConsumer = nullptr;
bool m_canPresentWindows = false;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment