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
56 changes: 56 additions & 0 deletions src/libinputactions/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,51 @@ enum class ComparisonOperator
Regex
};

// https://wayland.app/protocols/cursor-shape-v1#wp_cursor_shape_device_v1:enum:shape
enum class CursorShape
{
Default,
ContextMenu,
Help,
Pointer,
Progress,
Wait,
Cell,
Crosshair,
Text,
VerticalText,
Alias,
Copy,
Move,
NoDrop,
NotAllowed,
Grab,
Grabbing,
EResize,
NResize,
NEResize,
NWResize,
SResize,
SEResize,
SWResize,
WResize,
EWResize,
NSResize,
NESWResize,
NWSEResize,
ColResize,
RowResize,
AllScroll,
ZoomIn,
ZoomOut,
DndAsk,
AllResize,

// KWin https://invent.kde.org/plasma/kwin/-/blob/d36646652272d5793eb07498db2d4e45109536fb/src/cursor.cpp#L585
UpArrow,
};
Q_ENUM_NS(CursorShape)

enum class InputDeviceType
{
Unknown = 0,
Expand All @@ -42,6 +87,17 @@ enum class InputDeviceType
Q_DECLARE_FLAGS(InputDeviceTypes, InputDeviceType)
Q_DECLARE_OPERATORS_FOR_FLAGS(InputDeviceTypes)

// Currently for scripting only
enum class KeyboardModifier
{
None = Qt::KeyboardModifier::NoModifier,
Shift = Qt::KeyboardModifier::ShiftModifier,
Control = Qt::KeyboardModifier::ControlModifier,
Alt = Qt::KeyboardModifier::AltModifier,
Meta = Qt::KeyboardModifier::MetaModifier,
};
Q_ENUM_NS(KeyboardModifier)

enum class TriggerSpeed
{
Any,
Expand Down
45 changes: 1 addition & 44 deletions src/libinputactions/interfaces/CursorShapeProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,12 @@
#pragma once

#include <QString>
#include <libinputactions/globals.h>
#include <map>

namespace InputActions
{

// https://wayland.app/protocols/cursor-shape-v1#wp_cursor_shape_device_v1:enum:shape
enum class CursorShape
{
Default,
ContextMenu,
Help,
Pointer,
Progress,
Wait,
Cell,
Crosshair,
Text,
VerticalText,
Alias,
Copy,
Move,
NoDrop,
NotAllowed,
Grab,
Grabbing,
EResize,
NResize,
NEResize,
NWResize,
SResize,
SEResize,
SWResize,
WResize,
EWResize,
NSResize,
NESWResize,
NWSEResize,
ColResize,
RowResize,
AllScroll,
ZoomIn,
ZoomOut,
DndAsk,
AllResize,

// KWin https://invent.kde.org/plasma/kwin/-/blob/d36646652272d5793eb07498db2d4e45109536fb/src/cursor.cpp#L585
UpArrow,
};

static const std::map<QString, CursorShape> CURSOR_SHAPES = {
{"default", CursorShape::Default},
{"context_menu", CursorShape::ContextMenu},
Expand Down
15 changes: 15 additions & 0 deletions src/libinputactions/scripting/ScriptingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libinputactions/InputActionsMain.h>
#include <libinputactions/PointF.h>
#include <libinputactions/config/ConfigIssue.h>
#include <libinputactions/globals.h>
#include <libinputactions/helpers/QString.h>
#include <libinputactions/helpers/QThread.h>
#include <libinputactions/interfaces/NotificationManager.h>
Expand Down Expand Up @@ -71,8 +72,13 @@ void ScriptingEngine::initialize()
m_coreModule = std::make_unique<CoreModule>();
QJSEngine::setObjectOwnership(m_coreModule.get(), QJSEngine::CppOwnership);
auto coreModule = m_engine->newQObject(m_coreModule.get());
coreModule.setProperty("KeyboardModifier", newEnum<KeyboardModifier>());
registerBuiltinModule("inputactions/core", coreModule);

auto desktopModule = m_engine->newObject();
desktopModule.setProperty("CursorShape", newEnum<CursorShape>());
registerBuiltinModule("inputactions/desktop", desktopModule);

auto fsModule = m_engine->newObject();
fsModule.setProperty("File", m_engine->newQMetaObject(&File::staticMetaObject));
auto file = fsModule.property("File");
Expand Down Expand Up @@ -166,6 +172,15 @@ void ScriptingEngine::registerBuiltinModule(const QString &name, QJSValue value)
m_builtinModules[name] = std::move(value);
}

QJSValue ScriptingEngine::newEnum(const QMetaEnum &metaEnum)
{
auto object = ensureEngine().newObject();
for (int i = 0; i < metaEnum.keyCount(); i++) {
object.setProperty(metaEnum.key(i), metaEnum.value(i));
}
return object;
}

QJSValue ScriptingEngine::evaluate(const QString &script)
{
const auto result = ensureEngine().evaluate(script);
Expand Down
8 changes: 8 additions & 0 deletions src/libinputactions/scripting/ScriptingEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "FunctionWrapper.h"
#include <QJSEngine>
#include <QMetaEnum>
#include <QObject>
#include <memory>

Expand Down Expand Up @@ -90,6 +91,13 @@ private slots:

void registerBuiltinModule(const QString &name, QJSValue value);

template<typename T>
QJSValue newEnum()
{
return newEnum(QMetaEnum::fromType<T>());
}
QJSValue newEnum(const QMetaEnum &metaEnum);

std::optional<QJSEngine> m_engine;

std::unique_ptr<CoreModule> m_coreModule;
Expand Down
1 change: 1 addition & 0 deletions src/libinputactions/variables/VariableOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QLoggingCategory>
#include <QRegularExpression>
#include <libinputactions/PointF.h>
#include <libinputactions/globals.h>
#include <libinputactions/interfaces/CursorShapeProvider.h>

Q_LOGGING_CATEGORY(INPUTACTIONS_VARIABLE_OPERATIONS, "inputactions.variable.operations")
Expand Down