diff --git a/src/core/plasma-api/utils.hpp b/src/core/plasma-api/utils.hpp new file mode 100644 index 00000000..70d82871 --- /dev/null +++ b/src/core/plasma-api/utils.hpp @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin +// SPDX-License-Identifier: MIT + +#pragma once + +#define BI_READ_ONLY_PROPERTY(TYPE, NAME) \ + TYPE NAME() const \ + { \ + return m_kwinImpl->property(#NAME).value(); \ + } + +#define BI_PROPERTY(TYPE, NAME, SETTER_NAME) \ + BI_READ_ONLY_PROPERTY(TYPE, NAME) \ + \ + void SETTER_NAME(const TYPE &value) \ + { \ + m_kwinImpl->setProperty(#NAME, QVariant::fromValue(value)); \ + } diff --git a/src/core/plasma-api/workspace.cpp b/src/core/plasma-api/workspace.cpp index 05803e07..a6c78aa6 100644 --- a/src/core/plasma-api/workspace.cpp +++ b/src/core/plasma-api/workspace.cpp @@ -44,16 +44,6 @@ void Workspace::wrapSignals() wrapComplexSignal(SIGNAL(currentDesktopChanged(int, KWin::AbstractClient *)), SLOT(currentDesktopChangedTransformer(int, KWin::AbstractClient *))); }; -int Workspace::currentDesktop() -{ - return m_kwinImpl->property("currentDesktop").value(); -} - -void Workspace::setCurrentDesktop(int desktop) -{ - m_kwinImpl->setProperty("currentDesktop", QVariant::fromValue(desktop)); -} - void Workspace::currentDesktopChangedTransformer(int desktop, KWin::AbstractClient *kwinClient) { // Since we don't know the KWin internal implementation we have to use reinterpret_cast diff --git a/src/core/plasma-api/workspace.hpp b/src/core/plasma-api/workspace.hpp index bdaebc68..bf2de70b 100644 --- a/src/core/plasma-api/workspace.hpp +++ b/src/core/plasma-api/workspace.hpp @@ -8,6 +8,8 @@ #include "plasma-api/client.hpp" +#include "utils.hpp" + // Forward declare KWin Classes namespace KWin { @@ -23,8 +25,7 @@ public: Workspace(QQmlEngine *engine); Workspace(const Workspace &); - int currentDesktop(); - void setCurrentDesktop(int desktop); + BI_PROPERTY(int, currentDesktop, setCurrentDesktop); public Q_SLOTS: void currentDesktopChangedTransformer(int desktop, KWin::AbstractClient *kwinClient);