chore: basic core plugin

This plugin will encapsulate all the logic of the window tiling
extension. It is intended to replace the legacy TypeScript logic,
to be more robust, testable and more feature rich.

The explanations on why TypeScript is not a way to go can be found in
the following section of the blog post:

https://genda.life/posts/bismuth-future/#motivation
This commit is contained in:
Mikhail Zolotukhin 2022-01-27 20:30:50 +03:00
parent 0d1796b1d8
commit ce251e115a
9 changed files with 150 additions and 4 deletions

View File

@ -1,3 +1,3 @@
{
"conventionalCommits.scopes": ["kcm", "kwinscript"]
"conventionalCommits.scopes": ["kcm", "kwinscript", "core"]
}

View File

@ -1,3 +0,0 @@
SPDX-FileCopyrightText: none
SPDX-License-Identifier: MIT

View File

@ -1,5 +1,6 @@
# SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
# SPDX-License-Identifier: MIT
add_subdirectory(core)
add_subdirectory(kcm)
add_subdirectory(kwinscript)

32
src/core/CMakeLists.txt Normal file
View File

@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin <mail@genda.life>
# SPDX-License-Identifier: MIT
project(bismuth-core)
add_library(bismuth_core SHARED)
target_sources(
bismuth_core
PRIVATE
qml-plugin.cpp
qmldir
)
target_link_libraries(
bismuth_core
PRIVATE
Qt5::Core
Qt5::Quick
Qt5::Qml
)
install(
FILES "qmldir"
DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/core"
)
install(
TARGETS bismuth_core
DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/core"
)

8
src/core/config.hpp Normal file
View File

@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin <mail@genda.life>
// SPDX-License-Identifier: MIT
namespace Bismuth
{
struct Config {
};
}

44
src/core/qml-plugin.cpp Normal file
View File

@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin <mail@genda.life>
// SPDX-License-Identifier: MIT
#include "qml-plugin.hpp"
void CorePlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.bismuth.core"));
qmlRegisterModule(uri, 1, 0);
qmlRegisterType<Core>(uri, 1, 0, "Core");
}
Core::Core(QQuickItem *parent)
: QQuickItem(parent)
, m_kwinApi()
, m_qmlElements()
, m_config()
{
}
void Core::start()
{
}
QJSValue Core::kwinApi()
{
return m_kwinApi;
};
void Core::setKwinApi(const QJSValue &kwinApi)
{
m_kwinApi = kwinApi;
};
QJSValue Core::qmlElements()
{
return m_kwinApi;
}
void Core::setQmlElements(const QJSValue &qmlElements)
{
m_qmlElements = qmlElements;
};

47
src/core/qml-plugin.hpp Normal file
View File

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin <mail@genda.life>
// SPDX-License-Identifier: MIT
#include <QJSValue>
#include <QObject>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
#include <QQuickItem>
#include <memory>
#include "config.hpp"
class CorePlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
public:
void registerTypes(const char *uri) override;
};
class Core : public QQuickItem
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QJSValue kwinApi READ kwinApi WRITE setKwinApi)
Q_PROPERTY(QJSValue qmlElements READ qmlElements WRITE setQmlElements)
public:
Core(QQuickItem *parent = nullptr);
Q_INVOKABLE void start();
QJSValue kwinApi();
void setKwinApi(const QJSValue &);
QJSValue qmlElements();
void setQmlElements(const QJSValue &);
private:
QJSValue m_kwinApi;
QJSValue m_qmlElements;
std::unique_ptr<Bismuth::Config> m_config;
};

8
src/core/qmldir Normal file
View File

@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin <mail@genda.life>
# SPDX-License-Identifier: MIT
module org.kde.bismuth.core
# Plugin name is the name of the library in the CMakeLists.txt
plugin bismuth_core
classname CorePlugin

View File

@ -4,6 +4,7 @@
import "../code/index.mjs" as Bismuth
import QtQuick 2.0
import org.kde.bismuth.core 1.0 as BiCore
import org.kde.kwin 2.0
import org.kde.taskmanager 0.1 as TaskManager
@ -26,12 +27,20 @@ Item {
"KWin": KWin
};
scriptRoot.controller = Bismuth.init(qmlObjects, kwinScriptingAPI);
// Init core
core.kwinApi = kwinScriptingAPI;
core.qmlElements = qmlObjects;
core.start();
}
Component.onDestruction: {
console.log("[Bismuth] Everybody is dead");
scriptRoot.controller.drop();
}
BiCore.Core {
id: core
}
TrayItem {
id: trayItem
}