Skip to content

Commit 62a393e

Browse files
authored
Merge pull request #44 from InputActions/scripting-missing-enums
scripting: add KeyboardModifier and CursorShape enums
2 parents 096c723 + 7b8ba7f commit 62a393e

5 files changed

Lines changed: 81 additions & 44 deletions

File tree

src/libinputactions/globals.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,51 @@ enum class ComparisonOperator
3131
Regex
3232
};
3333

34+
// https://wayland.app/protocols/cursor-shape-v1#wp_cursor_shape_device_v1:enum:shape
35+
enum class CursorShape
36+
{
37+
Default,
38+
ContextMenu,
39+
Help,
40+
Pointer,
41+
Progress,
42+
Wait,
43+
Cell,
44+
Crosshair,
45+
Text,
46+
VerticalText,
47+
Alias,
48+
Copy,
49+
Move,
50+
NoDrop,
51+
NotAllowed,
52+
Grab,
53+
Grabbing,
54+
EResize,
55+
NResize,
56+
NEResize,
57+
NWResize,
58+
SResize,
59+
SEResize,
60+
SWResize,
61+
WResize,
62+
EWResize,
63+
NSResize,
64+
NESWResize,
65+
NWSEResize,
66+
ColResize,
67+
RowResize,
68+
AllScroll,
69+
ZoomIn,
70+
ZoomOut,
71+
DndAsk,
72+
AllResize,
73+
74+
// KWin https://invent.kde.org/plasma/kwin/-/blob/d36646652272d5793eb07498db2d4e45109536fb/src/cursor.cpp#L585
75+
UpArrow,
76+
};
77+
Q_ENUM_NS(CursorShape)
78+
3479
enum class InputDeviceType
3580
{
3681
Unknown = 0,
@@ -42,6 +87,17 @@ enum class InputDeviceType
4287
Q_DECLARE_FLAGS(InputDeviceTypes, InputDeviceType)
4388
Q_DECLARE_OPERATORS_FOR_FLAGS(InputDeviceTypes)
4489

90+
// Currently for scripting only
91+
enum class KeyboardModifier
92+
{
93+
None = Qt::KeyboardModifier::NoModifier,
94+
Shift = Qt::KeyboardModifier::ShiftModifier,
95+
Control = Qt::KeyboardModifier::ControlModifier,
96+
Alt = Qt::KeyboardModifier::AltModifier,
97+
Meta = Qt::KeyboardModifier::MetaModifier,
98+
};
99+
Q_ENUM_NS(KeyboardModifier)
100+
45101
enum class TriggerSpeed
46102
{
47103
Any,

src/libinputactions/interfaces/CursorShapeProvider.h

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,12 @@
1919
#pragma once
2020

2121
#include <QString>
22+
#include <libinputactions/globals.h>
2223
#include <map>
2324

2425
namespace InputActions
2526
{
2627

27-
// https://wayland.app/protocols/cursor-shape-v1#wp_cursor_shape_device_v1:enum:shape
28-
enum class CursorShape
29-
{
30-
Default,
31-
ContextMenu,
32-
Help,
33-
Pointer,
34-
Progress,
35-
Wait,
36-
Cell,
37-
Crosshair,
38-
Text,
39-
VerticalText,
40-
Alias,
41-
Copy,
42-
Move,
43-
NoDrop,
44-
NotAllowed,
45-
Grab,
46-
Grabbing,
47-
EResize,
48-
NResize,
49-
NEResize,
50-
NWResize,
51-
SResize,
52-
SEResize,
53-
SWResize,
54-
WResize,
55-
EWResize,
56-
NSResize,
57-
NESWResize,
58-
NWSEResize,
59-
ColResize,
60-
RowResize,
61-
AllScroll,
62-
ZoomIn,
63-
ZoomOut,
64-
DndAsk,
65-
AllResize,
66-
67-
// KWin https://invent.kde.org/plasma/kwin/-/blob/d36646652272d5793eb07498db2d4e45109536fb/src/cursor.cpp#L585
68-
UpArrow,
69-
};
70-
7128
static const std::map<QString, CursorShape> CURSOR_SHAPES = {
7229
{"default", CursorShape::Default},
7330
{"context_menu", CursorShape::ContextMenu},

src/libinputactions/scripting/ScriptingEngine.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <libinputactions/InputActionsMain.h>
2525
#include <libinputactions/PointF.h>
2626
#include <libinputactions/config/ConfigIssue.h>
27+
#include <libinputactions/globals.h>
2728
#include <libinputactions/helpers/QString.h>
2829
#include <libinputactions/helpers/QThread.h>
2930
#include <libinputactions/interfaces/NotificationManager.h>
@@ -71,8 +72,13 @@ void ScriptingEngine::initialize()
7172
m_coreModule = std::make_unique<CoreModule>();
7273
QJSEngine::setObjectOwnership(m_coreModule.get(), QJSEngine::CppOwnership);
7374
auto coreModule = m_engine->newQObject(m_coreModule.get());
75+
coreModule.setProperty("KeyboardModifier", newEnum<KeyboardModifier>());
7476
registerBuiltinModule("inputactions/core", coreModule);
7577

78+
auto desktopModule = m_engine->newObject();
79+
desktopModule.setProperty("CursorShape", newEnum<CursorShape>());
80+
registerBuiltinModule("inputactions/desktop", desktopModule);
81+
7682
auto fsModule = m_engine->newObject();
7783
fsModule.setProperty("File", m_engine->newQMetaObject(&File::staticMetaObject));
7884
auto file = fsModule.property("File");
@@ -166,6 +172,15 @@ void ScriptingEngine::registerBuiltinModule(const QString &name, QJSValue value)
166172
m_builtinModules[name] = std::move(value);
167173
}
168174

175+
QJSValue ScriptingEngine::newEnum(const QMetaEnum &metaEnum)
176+
{
177+
auto object = ensureEngine().newObject();
178+
for (int i = 0; i < metaEnum.keyCount(); i++) {
179+
object.setProperty(metaEnum.key(i), metaEnum.value(i));
180+
}
181+
return object;
182+
}
183+
169184
QJSValue ScriptingEngine::evaluate(const QString &script)
170185
{
171186
const auto result = ensureEngine().evaluate(script);

src/libinputactions/scripting/ScriptingEngine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "FunctionWrapper.h"
2222
#include <QJSEngine>
23+
#include <QMetaEnum>
2324
#include <QObject>
2425
#include <memory>
2526

@@ -90,6 +91,13 @@ private slots:
9091

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

94+
template<typename T>
95+
QJSValue newEnum()
96+
{
97+
return newEnum(QMetaEnum::fromType<T>());
98+
}
99+
QJSValue newEnum(const QMetaEnum &metaEnum);
100+
93101
std::optional<QJSEngine> m_engine;
94102

95103
std::unique_ptr<CoreModule> m_coreModule;

src/libinputactions/variables/VariableOperations.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <QLoggingCategory>
2323
#include <QRegularExpression>
2424
#include <libinputactions/PointF.h>
25+
#include <libinputactions/globals.h>
2526
#include <libinputactions/interfaces/CursorShapeProvider.h>
2627

2728
Q_LOGGING_CATEGORY(INPUTACTIONS_VARIABLE_OPERATIONS, "inputactions.variable.operations")

0 commit comments

Comments
 (0)