examples: Add binary plugin example

This commit is contained in:
Vlad Zahorodnii 2024-02-23 22:29:39 +02:00
parent 38fae969a9
commit e84d5bb666
7 changed files with 135 additions and 0 deletions

1
examples/plugin/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build

View file

@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: None
# SPDX-License-Identifier: CC0-1.0
cmake_minimum_required(VERSION 3.20)
project(quick-effect)
set(KF6_MIN_VERSION "6.0.0")
find_package(ECM ${KF6_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(FeatureSummary)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
find_package(Qt6 CONFIG REQUIRED COMPONENTS
Core
Widgets
)
find_package(KWin REQUIRED COMPONENTS
kwin
)
kcoreaddons_add_plugin(eventlistener INSTALL_NAMESPACE "kwin/plugins")
target_sources(eventlistener PRIVATE
main.cpp
eventlistener.cpp
)
target_link_libraries(eventlistener PRIVATE
KWin::kwin
)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)

View file

@ -0,0 +1,34 @@
/*
SPDX-FileCopyrightText: 2024 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "eventlistener.h"
#include "kwin/input.h"
#include "kwin/input_event.h"
#include <QDebug>
namespace KWin
{
EventListener::EventListener()
{
qDebug() << "Loaded demo event listener plugin";
input()->installInputEventSpy(this);
}
void EventListener::keyEvent(KeyEvent *event)
{
qDebug() << event;
}
void EventListener::pointerEvent(MouseEvent *event)
{
qDebug() << event;
}
} // namespace KWin
#include "moc_eventlistener.cpp"

View file

@ -0,0 +1,26 @@
/*
SPDX-FileCopyrightText: 2024 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include "kwin/plugin.h"
#include "kwin/input_event_spy.h"
namespace KWin
{
class EventListener : public Plugin, public InputEventSpy
{
Q_OBJECT
public:
EventListener();
void keyEvent(KeyEvent *event) override;
void pointerEvent(MouseEvent *event) override;
};
} // namespace KWin

31
examples/plugin/main.cpp Normal file
View file

@ -0,0 +1,31 @@
/*
SPDX-FileCopyrightText: 2024 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "eventlistener.h"
#include <KPluginFactory>
namespace KWin
{
class KWIN_EXPORT EventListenerFactory : public PluginFactory
{
Q_OBJECT
Q_PLUGIN_METADATA(IID PluginFactory_iid FILE "metadata.json")
Q_INTERFACES(KWin::PluginFactory)
public:
explicit EventListenerFactory() = default;
std::unique_ptr<Plugin> create() const override
{
return std::make_unique<EventListener>();
}
};
} // namespace KWin
#include "main.moc"

View file

@ -0,0 +1,5 @@
{
"KPlugin": {
"EnabledByDefault": true
}
}

View file

@ -0,0 +1,2 @@
SPDX-FileCopyrightText: None
SPDX-License-Identifier: CC0-1.0