Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ set(libinputactions_SRCS
libinputactions/conditions/ConditionGroup.cpp
libinputactions/conditions/CustomCondition.cpp
libinputactions/conditions/VariableCondition.cpp
libinputactions/dbus/DBusInterfaceBase.cpp
libinputactions/dbus/IntegratedDBusInterface.cpp
libinputactions/dbus/MainDBusInterface.cpp
libinputactions/handlers/InputTriggerHandler.cpp
libinputactions/handlers/KeyboardTriggerHandler.cpp
libinputactions/handlers/MotionTriggerHandler.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/libinputactions/InputActionsMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "config/ConfigIssueManager.h"
#include "config/ConfigLoader.h"
#include "config/GlobalConfig.h"
#include "dbus/MainDBusInterface.h"
#include "input/StrokeRecorder.h"
#include "input/backends/InputBackend.h"
#include "interfaces/ConfigProvider.h"
Expand Down Expand Up @@ -52,6 +53,7 @@ InputActionsMain::~InputActionsMain()
g_globalConfig.reset();
g_configProvider.reset();
g_inputBackend.reset();
g_mainDbusInterface.reset();
g_scriptingEngine.reset();
g_strokeRecorder.reset();
g_variableRegistry.reset();
Expand Down Expand Up @@ -98,6 +100,7 @@ void InputActionsMain::setMissingImplementations()
setMissingImplementation(g_configLoader);
setMissingImplementation(g_globalConfig);
setMissingImplementation(g_inputBackend);
setMissingImplementation(g_mainDbusInterface);
setMissingImplementation(g_strokeRecorder);
setMissingImplementation(g_variableRegistry);

Expand Down
3 changes: 0 additions & 3 deletions src/libinputactions/InputActionsMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#pragma once

#include "dbus/IntegratedDBusInterface.h"
#include <QObject>

namespace InputActions
Expand Down Expand Up @@ -78,8 +77,6 @@ private slots:
member = std::make_unique<T>();
}
}

IntegratedDBusInterface m_dbusInterface;
};

inline InputActionsMain *g_inputActions;
Expand Down
78 changes: 0 additions & 78 deletions src/libinputactions/dbus/DBusInterfaceBase.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions src/libinputactions/dbus/DBusInterfaceBase.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,52 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "IntegratedDBusInterface.h"
#include "MainDBusInterface.h"
#include <QRegularExpression>
#include <libinputactions/InputActionsMain.h>
#include <libinputactions/config/ConfigIssueManager.h>
#include <libinputactions/config/ConfigLoader.h>
#include <libinputactions/config/GlobalConfig.h>
#include <libinputactions/helpers/QDBusConnection.h>
#include <libinputactions/input/StrokeRecorder.h>
#include <libinputactions/input/backends/InputBackend.h>
#include <libinputactions/input/devices/InputDevice.h>
#include <libinputactions/interfaces/OnScreenMessageManager.h>
#include <libinputactions/triggers/core/StrokeTriggerCore.h>
#include <libinputactions/variables/VariableRegistry.h>

namespace InputActions
{

IntegratedDBusInterface::IntegratedDBusInterface()
MainDBusInterface::MainDBusInterface()
: m_bus(QDBusConnectionHelpers::sessionBus())
{
m_bus.registerService(INPUTACTIONS_DBUS_SERVICE);
m_bus.registerObject(INPUTACTIONS_DBUS_PATH, this, QDBusConnection::ExportAllSlots);
}

IntegratedDBusInterface::~IntegratedDBusInterface()
MainDBusInterface::~MainDBusInterface()
{
m_bus.unregisterService(INPUTACTIONS_DBUS_SERVICE);
m_bus.unregisterObject(INPUTACTIONS_DBUS_PATH);
}

QString IntegratedDBusInterface::deviceList()
QString MainDBusInterface::deviceList()
{
return DBusInterfaceBase::deviceList();
QStringList result;
for (const auto *device : g_inputBackend->devices()) {
result.push_back(device->toString());
}
result.sort();
return result.join("\n\n");
}

QString IntegratedDBusInterface::issues()
QString MainDBusInterface::issues()
{
return DBusInterfaceBase::issues();
return g_configIssueManager->issuesToString();
}

void IntegratedDBusInterface::recordStroke(const QDBusMessage &message)
void MainDBusInterface::recordStroke(const QDBusMessage &message)
{
if (!g_inputBackend->initialized()) {
sendErrorReply(QDBusError::Failed, "Stroke recording requires a valid configuration to be active.");
Expand All @@ -74,23 +81,60 @@ void IntegratedDBusInterface::recordStroke(const QDBusMessage &message)
});
}

QString IntegratedDBusInterface::reloadConfig()
QString MainDBusInterface::reloadConfig()
{
if (!m_allowConfigLoading) {
sendErrorReply(QDBusError::Failed, "Loading the configuration is not allowed while the client is inactive.");
return {};
}

g_configLoader->load({
.manual = true,
});
return g_configIssueManager->issuesToString();
}

QString IntegratedDBusInterface::suspend()
QString MainDBusInterface::suspend()
{
if (!m_allowConfigLoading) {
sendErrorReply(QDBusError::Failed, "Suspending is not allowed while the client is inactive.");
return {};
}

g_inputActions->suspend();
return "success";
}

QString IntegratedDBusInterface::variables(QString filter)
QString MainDBusInterface::variables(QString filter)
{
if (!g_globalConfig->allowExternalVariableAccess()) {
return "External variable access has been disabled. Set 'external_variable_access' to 'true' to enable.";
}

QStringList result;
const QRegularExpression filterRegex(filter);
for (const auto &[name, variable] : g_variableRegistry->variables()) {
if (variable->hidden() || !filterRegex.match(name).hasMatch()) {
continue;
}
result.push_back(QString("%1: %2").arg(name, variable->operations()->toString()));
}
return result.join('\n');
}

QString MainDBusInterface::strokeToBase64(const Stroke &stroke)
{
return variableList(g_variableRegistry.get(), filter);
QByteArray bytes;
const auto &points = stroke.points();
for (size_t i = 0; i < points.size(); i++) {
// All values range from -1 to 1
bytes.push_back(static_cast<char>(points[i].x * 100));
bytes.push_back(static_cast<char>(points[i].y * 100));
bytes.push_back(static_cast<char>(points[i].t * 100));
bytes.push_back(static_cast<char>(points[i].alpha * 100));
}

return QString("'%1'").arg(bytes.toBase64());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#pragma once

#include "DBusInterfaceBase.h"
#include <QDBusConnection>
#include <QDBusContext>
#include <QDBusMessage>
Expand All @@ -30,8 +29,10 @@ namespace InputActions
static const QString INPUTACTIONS_DBUS_SERVICE = "org.inputactions";
static const QString INPUTACTIONS_DBUS_PATH = "/";

class IntegratedDBusInterface
: public DBusInterfaceBase
class Stroke;

class MainDBusInterface
: public QObject
, protected QDBusContext
{
Q_OBJECT
Expand All @@ -41,12 +42,17 @@ class IntegratedDBusInterface
/**
* Registers the interface.
*/
IntegratedDBusInterface();
MainDBusInterface();

/**
* Unregisters the interface.
*/
~IntegratedDBusInterface() override;
~MainDBusInterface() override;

/**
* Sets whether loading the config and suspending InputActions through the DBus interface is allowed. This is only used in the standalone implementation.
*/
void setAllowConfigLoading(bool value) { m_allowConfigLoading = value; }

public slots:
QString deviceList();
Expand All @@ -57,8 +63,14 @@ public slots:
QString variables(QString filter = "");

private:
static QString strokeToBase64(const Stroke &stroke);

QDBusConnection m_bus;
QDBusMessage m_reply;

bool m_allowConfigLoading = true;
};

inline std::shared_ptr<MainDBusInterface> g_mainDbusInterface;

}
2 changes: 1 addition & 1 deletion src/libinputactions/helpers/QDBusConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace InputActions::QDBusConnectionHelpers
/**
* Same as QDBusConnection::sessionBus, but uses QDBusConnection::connectToBus with the address specified in the DBUS_SESSION_BUS_ADDRESS environment variable
* for setgid binaries.
*
*
* Connection is cached.
*/
const QDBusConnection &sessionBus();
Expand Down
5 changes: 5 additions & 0 deletions tests/libinputactions/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
namespace InputActions
{

Test::~Test()
{
delete g_inputActions;
}

void Test::initMain()
{
int argc = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/libinputactions/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Test : public QObject
Q_OBJECT

public:
~Test() override;

static void initMain();
};

Expand Down