mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-09-11 00:15:37 +03:00
refactor: proof of concept: signal handler port
This commit is contained in:
parent
4b02c4b699
commit
288d9cf944
@ -13,8 +13,25 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "logger.hpp"
|
||||
#include "plasma-api/client.hpp"
|
||||
#include "plasma-api/workspace.hpp"
|
||||
#include "ts-proxy.hpp"
|
||||
|
||||
namespace Bismuth
|
||||
{
|
||||
Controller::Controller(PlasmaApi::Api &api)
|
||||
: m_plasmaApi(api)
|
||||
, m_proxy()
|
||||
{
|
||||
bindEvents();
|
||||
}
|
||||
|
||||
void Controller::bindEvents()
|
||||
{
|
||||
auto &workspace = m_plasmaApi.workspace();
|
||||
connect(&workspace, &PlasmaApi::Workspace::currentDesktopChanged, this, &Controller::onCurrentSurfaceChanged);
|
||||
}
|
||||
|
||||
void Controller::registerAction(const Action &data)
|
||||
{
|
||||
@ -39,6 +56,20 @@ void Controller::registerAction(const Action &data)
|
||||
m_registeredShortcuts.push_back(action);
|
||||
};
|
||||
|
||||
void Controller::onCurrentSurfaceChanged()
|
||||
{
|
||||
if (m_proxy) {
|
||||
auto ctl = m_proxy->jsController();
|
||||
auto func = ctl.property("onCurrentSurfaceChanged");
|
||||
func.callWithInstance(ctl);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::setProxy(TSProxy *proxy)
|
||||
{
|
||||
m_proxy = proxy;
|
||||
}
|
||||
|
||||
Action::Action(const QString &id, const QString &description, const QString &defaultKeybinding, std::function<void()> callback)
|
||||
{
|
||||
this->id = id;
|
||||
|
@ -11,6 +11,10 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "plasma-api/api.hpp"
|
||||
|
||||
class TSProxy;
|
||||
|
||||
namespace Bismuth
|
||||
{
|
||||
|
||||
@ -27,10 +31,21 @@ class Controller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Controller(PlasmaApi::Api &);
|
||||
|
||||
void bindEvents();
|
||||
void registerAction(const Action &);
|
||||
|
||||
void setProxy(TSProxy *);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onCurrentSurfaceChanged();
|
||||
|
||||
private:
|
||||
std::vector<QAction *> m_registeredShortcuts{};
|
||||
|
||||
PlasmaApi::Api &m_plasmaApi;
|
||||
TSProxy *m_proxy;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ void Core::init()
|
||||
m_plasmaApi = std::make_unique<PlasmaApi::Api>(m_engine);
|
||||
m_controller = std::make_unique<Bismuth::Controller>(*m_plasmaApi);
|
||||
m_tsProxy = std::make_unique<TSProxy>(m_engine, *m_controller, *m_plasmaApi, *m_config);
|
||||
m_controller->setProxy(m_tsProxy.get());
|
||||
}
|
||||
|
||||
TSProxy *Core::tsProxy() const
|
||||
|
@ -131,8 +131,18 @@ void TSProxy::registerShortcut(const QJSValue &tsAction)
|
||||
}});
|
||||
}
|
||||
|
||||
Q_INVOKABLE void TSProxy::log(const QJSValue &value)
|
||||
void TSProxy::log(const QJSValue &value)
|
||||
{
|
||||
auto valAsString = value.toString();
|
||||
qDebug(Bi).noquote() << valAsString;
|
||||
};
|
||||
|
||||
void TSProxy::setJsController(const QJSValue &value)
|
||||
{
|
||||
m_jsController = value;
|
||||
}
|
||||
|
||||
QJSValue TSProxy::jsController()
|
||||
{
|
||||
return m_jsController;
|
||||
}
|
||||
|
@ -41,9 +41,13 @@ public:
|
||||
*/
|
||||
Q_INVOKABLE void log(const QJSValue &);
|
||||
|
||||
Q_INVOKABLE void setJsController(const QJSValue &);
|
||||
QJSValue jsController();
|
||||
|
||||
private:
|
||||
QQmlEngine *m_engine;
|
||||
Bismuth::Config &m_config;
|
||||
Bismuth::Controller &m_controller;
|
||||
PlasmaApi::Api &m_plasmaApi;
|
||||
QJSValue m_jsController;
|
||||
};
|
||||
|
@ -187,13 +187,6 @@ export class DriverImpl implements Driver {
|
||||
this.controller.onCurrentSurfaceChanged();
|
||||
};
|
||||
|
||||
const onCurrentDesktopChanged = (
|
||||
_desktop: number,
|
||||
_client: KWin.Client
|
||||
): void => {
|
||||
this.controller.onCurrentSurfaceChanged();
|
||||
};
|
||||
|
||||
const onClientAdded = (client: KWin.Client): void => {
|
||||
this.log.log(`Client added: ${client}`);
|
||||
|
||||
@ -258,10 +251,6 @@ export class DriverImpl implements Driver {
|
||||
this.kwinApi.workspace.currentActivityChanged,
|
||||
onCurrentActivityChanged
|
||||
);
|
||||
this.connect(
|
||||
this.proxy.workspace().currentDesktopChanged,
|
||||
onCurrentDesktopChanged
|
||||
);
|
||||
this.connect(this.kwinApi.workspace.clientAdded, onClientAdded);
|
||||
this.connect(this.kwinApi.workspace.clientRemoved, onClientRemoved);
|
||||
this.connect(this.kwinApi.workspace.clientMaximizeSet, onClientMaximizeSet);
|
||||
|
@ -29,6 +29,7 @@ Item {
|
||||
};
|
||||
// Init legacy JS backend
|
||||
scriptRoot.controller = Bismuth.init(qmlObjects, kwinScriptingAPI, core.proxy);
|
||||
core.proxy.setJsController(scriptRoot.controller);
|
||||
}
|
||||
Component.onDestruction: {
|
||||
core.proxy.log("Calling event hooks destructors... Goodbye.");
|
||||
|
Loading…
Reference in New Issue
Block a user