Skip to content
Open
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
8 changes: 6 additions & 2 deletions doc-dev/reference-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ The following grammar is supported:
LABEL = <string identifier>
SHORTCUT = MODMASK- | MODMASK-KEY | KEY | MODMASK
MODMASK = [MODMASK]+ | [L|R]{S|C|A|G} | {p|r|h|t} | {s|i|o}
NAVIGATIONMODE = cursor | scroll | caret | media | zoom | zoomPc | zoomMac | none
NAVIGATIONMODE = cursor | scroll | caret | media | zoom | zoomPc | zoomMac | none | gamepadStickLeft | gamepadStickRight
NAVIGATIONMODECUSTOM = caret | media | zoomPc | zoomMac
MODULEID = trackball | touchpad | trackpoint | keycluster
KEY = CHAR|KEYABBREV
Expand All @@ -184,11 +184,14 @@ The following grammar is supported:
KEYABBREV = f1 | f2 | f3 | f4 | f5 | f6 | f7 | f8 | f9 | f10 | f11 | f12 | f13 | f14 | f15 | f16 | f17 | f18 | f19 | f20 | f21 | f22 | f23 | f24
KEYABBREV = mediaVolumeMute | mediaVolumeUp | mediaVolumeDown | mediaRecord | mediaFastForward | mediaRewind | mediaNext | mediaPrevious | mediaStop | mediaPlayPause | mediaPause
KEYABBREV = systemPowerDown | systemSleep | systemWakeUp
KEYABBREV = mouseBtnLeft | mouseBtnRight | mouseBtnMiddle | mouseBtn4 | mouseBtn5 | mouseBtn6 | mouseBtn7 | mouseBtn8
KEYABBREV = mouse.btn1 | mouse.btn2 | mouse.btn3 | mouse.btn4 | mouse.btn5 | mouse.btn6 | mouse.btn7 | mouse.btn8 | mouse.btnLeft | mouse.btnMiddle | mouse.btnRight
KEYABBREV = gamepad.a | gamepad.b | gamepad.back | gamepad.dPadDown | gamepad.dPadLeft | gamepad.dPadRight | gamepad.dPadUp | gamepad.home
KEYABBREV = gamepad.leftBumper | gamepad.leftStick | gamepad.rightBumper | gamepad.rightStick | gamepad.start | gamepad.x | gamepad.y
MACRONAME = <Case sensitive macro identifier as named in Agent. Identifier shall not contain spaces.>
############
#DEPRECATED#
############
KEYABBREV = mouseBtnLeft | mouseBtnRight | mouseBtnMiddle | mouseBtn4 | mouseBtn5 | mouseBtn6 | mouseBtn7 | mouseBtn8
COMMAND = set macroEngine.scheduler {blocking|preemptive}
COMMAND = set doubletapDelay <time in ms, at most 65535, alias to doubletapTimeout (NUMBER)>
COMMAND = switchLayer LAYERID
Expand Down Expand Up @@ -553,6 +556,7 @@ UHK modules feature four navigation modes, which are mapped by layer and module.
- **Media mode** - in this mode, up/down directions control volume (via media key scancodes), while horizontal play/pause and switch to next track. At the moment, this mode is not enabled by default on any layer. Sensitivity is shared with the caret mode.
- **Zoom mode pc / mac** - in this mode, `Ctrl +`/`Ctrl -` or `Gui +`/`Gui -` shortcuts are produced.
- **Zoom mode** - This mode serves specifically to implement touchpad's gesture. It alternates actions of zoomPc and zoomMac modes. Can be customized via `set module.touchpad.pinchZoomMode NAVIGATIONMODE`.
- **gamepadStickLeft / gamepadStickRight** - in this module, trackpoint acts as a gamepad thumbstick.

Caret and media modes can be customized by `set navigationModeAction` command.

Expand Down
2 changes: 1 addition & 1 deletion lib/agent
Submodule agent updated 348 files
19 changes: 19 additions & 0 deletions right/src/config_parser/parse_keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@
SerializedMouseAction_Last = SerializedMouseAction_Button_8,
} serialized_mouse_action_t;

typedef enum {
SerializedGamepadAction_A = 0,
SerializedGamepadAction_B = 1,
SerializedGamepadAction_X = 2,
SerializedGamepadAction_Y = 3,
SerializedGamepadAction_Left_Bumper = 4,
SerializedGamepadAction_Right_Bumper = 5,
SerializedGamepadAction_Back = 8,
SerializedGamepadAction_Start = 9,
SerializedGamepadAction_Left_Stick_Press = 10,
SerializedGamepadAction_Right_Stick_Press = 11,
SerializedGamepadAction_Dpad_Up = 12,
SerializedGamepadAction_Dpad_Down = 13,
SerializedGamepadAction_Dpad_Left = 14,
SerializedGamepadAction_Dpad_Right = 15,
SerializedGamepadAction_Home = 16,
SerializedGamepadAction_Last = SerializedGamepadAction_Home,
} serialized_gamepad_action_t;

typedef enum {
SerializedLayerName_mod,
SerializedLayerName_fn,
Expand Down
6 changes: 6 additions & 0 deletions right/src/key_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
KeyActionType_SwitchLayer,
KeyActionType_SwitchKeymap,
KeyActionType_PlayMacro,
KeyActionType_Gamepad,
} key_action_type_t;

typedef enum {
Expand Down Expand Up @@ -50,6 +51,10 @@
uint8_t blue;
} rgb_t;

typedef struct {
uint8_t property;
} gamepad_action_t;

typedef struct {
uint8_t type;
union {
Expand All @@ -60,6 +65,7 @@
uint16_t scancode;
} ATTR_PACKED keystroke;
serialized_mouse_action_t mouseAction;
serialized_gamepad_action_t gamepadPropertyId;
struct {
switch_layer_mode_t mode;
uint8_t layer;
Expand Down
4 changes: 4 additions & 0 deletions right/src/ledmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rgb_t KeyActionColors[keyActionColor_Length] = {
RGB(0xFF, 0x00, 0x00), // KeyActionColor_SwitchKeymap
RGB(0x00, 0xFF, 0x00), // KeyActionColor_Mouse
RGB(0xFF, 0x00, 0xFF), // KeyActionColor_Macro
RGB(0x55, 0xFF, 0x00), // KeyActionColor_Gamepad
};

static rgb_t LedMap[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE] = {
Expand Down Expand Up @@ -193,6 +194,9 @@ static void updateLedsByFunctionalStrategy() {
case KeyActionType_Mouse:
keyActionColor = KeyActionColor_Mouse;
break;
case KeyActionType_Gamepad:
keyActionColor = KeyActionColor_Gamepad;
break;
case KeyActionType_SwitchKeymap:
keyActionColor = KeyActionColor_SwitchKeymap;
break;
Expand Down
3 changes: 2 additions & 1 deletion right/src/ledmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
KeyActionColor_SwitchKeymap,
KeyActionColor_Mouse,
KeyActionColor_Macro,
keyActionColor_Last = KeyActionColor_Macro,
KeyActionColor_Gamepad,
keyActionColor_Last = KeyActionColor_Gamepad,
keyActionColor_Length = keyActionColor_Last + 1,
} key_action_color_t;

Expand Down
13 changes: 11 additions & 2 deletions right/src/macro_set_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "layer.h"
#include "ledmap.h"
#include "macros.h"
#include "module.h"
#include "slave_protocol.h"
#include "timer.h"
#include "keymap.h"
#include "key_matrix.h"
Expand Down Expand Up @@ -31,7 +33,7 @@ static const char* proceedByDot(const char* cmd, const char *cmdEnd)
return cmd+1;
}

static void moduleNavigationMode(const char* arg1, const char *textEnd, module_configuration_t* module)
static void moduleNavigationMode(const char* arg1, const char *textEnd, module_id_t moduleId, module_configuration_t* module)
{
layer_id_t layerId = Macros_ParseLayerId(arg1, textEnd);
navigation_mode_t modeId = ParseNavigationModeId(NextTok(arg1, textEnd), textEnd);
Expand All @@ -41,6 +43,13 @@ static void moduleNavigationMode(const char* arg1, const char *textEnd, module_c
return;
}

bool isGamepadMode = modeId == NavigationMode_GamepadStickLeft || modeId == NavigationMode_GamepadStickRight;
bool isGamepadCompatible = moduleId == ModuleId_TrackpointRight;
if (isGamepadMode && !isGamepadCompatible) {
Macros_ReportError("This module is not compatible with gamepad stick output!", NULL, NULL);
return;
}

if (Macros_ParserError) {
return;
}
Expand Down Expand Up @@ -112,7 +121,7 @@ static void module(const char* arg1, const char *textEnd)

if (TokenMatches(arg2, textEnd, "navigationMode")) {
const char* arg3 = proceedByDot(arg2, textEnd);
moduleNavigationMode(arg3, textEnd, module);
moduleNavigationMode(arg3, textEnd, moduleId, module);
}
else {
moduleSpeed(arg2, textEnd, module, moduleId);
Expand Down
34 changes: 34 additions & 0 deletions right/src/macro_shortcut_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ const lookup_record_t lookup_table[] = {
{"f8", HID_KEYBOARD_SC_F8, scType_basic},
{"f9", HID_KEYBOARD_SC_F9, scType_basic},
{"find", HID_KEYBOARD_SC_FIND, scType_basic},
{"gamepad.a", GAMEPAD_A, scType_gamepad},
{"gamepad.b", GAMEPAD_B, scType_gamepad},
{"gamepad.back", GAMEPAD_BACK, scType_gamepad},
{"gamepad.dPadDown", GAMEPAD_DPAD_DOWN, scType_gamepad},
{"gamepad.dPadLeft", GAMEPAD_DPAD_LEFT, scType_gamepad},
{"gamepad.dPadRight", GAMEPAD_DPAD_RIGHT, scType_gamepad},
{"gamepad.dPadUp", GAMEPAD_DPAD_UP, scType_gamepad},
{"gamepad.home", GAMEPAD_HOME, scType_gamepad},
{"gamepad.leftBumper", GAMEPAD_LEFT_BUMPER, scType_gamepad},
{"gamepad.leftStick", GAMEPAD_LEFT_STICK_PRESS, scType_gamepad},
{"gamepad.rightBumper", GAMEPAD_RIGHT_BUMPER, scType_gamepad},
{"gamepad.rightStick", GAMEPAD_RIGHT_STICK_PRESS, scType_gamepad},
{"gamepad.start", GAMEPAD_START, scType_gamepad},
{"gamepad.x", GAMEPAD_X, scType_gamepad},
{"gamepad.y", GAMEPAD_Y, scType_gamepad},
{"graveAccentAndTilde", HID_KEYBOARD_SC_GRAVE_ACCENT_AND_TILDE, scType_basic},
{"help", HID_KEYBOARD_SC_HELP, scType_basic},
{"home", HID_KEYBOARD_SC_HOME, scType_basic},
Expand Down Expand Up @@ -281,6 +296,17 @@ const lookup_record_t lookup_table[] = {
{"mediaVolumeUp", MEDIA_VOLUME_UP, scType_media},
{"menu", HID_KEYBOARD_SC_MENU, scType_basic},
{"minusAndUnderscore", HID_KEYBOARD_SC_MINUS_AND_UNDERSCORE, scType_basic},
{"mouse.btn1", MouseButton_Left, scType_mouseBtn},
{"mouse.btn2", MouseButton_Right, scType_mouseBtn},
{"mouse.btn3", MouseButton_Middle, scType_mouseBtn},
{"mouse.btn4", MouseButton_4, scType_mouseBtn},
{"mouse.btn5", MouseButton_5, scType_mouseBtn},
{"mouse.btn6", MouseButton_6, scType_mouseBtn},
{"mouse.btn7", MouseButton_7, scType_mouseBtn},
{"mouse.btn8", MouseButton_8, scType_mouseBtn},
{"mouse.btnLeft", MouseButton_Left, scType_mouseBtn},
{"mouse.btnMiddle", MouseButton_Middle, scType_mouseBtn},
{"mouse.btnRight", MouseButton_Right, scType_mouseBtn},
{"mouseBtn1", MouseButton_Left, scType_mouseBtn},
{"mouseBtn2", MouseButton_Right, scType_mouseBtn},
{"mouseBtn3", MouseButton_Middle, scType_mouseBtn},
Expand Down Expand Up @@ -554,6 +580,10 @@ static bool parseAbbrev(const char* str, const char* strEnd, macro_action_t* out
outMacroAction->type = MacroActionType_MouseButton;
outMacroAction->mouseButton.mouseButtonsMask = record->scancode;
break;
case scType_gamepad:
outMacroAction->type = MacroActionType_GamepadButton;
outMacroAction->gamepadButton.propertyId = record->scancode;
break;
}
}

Expand All @@ -578,6 +608,10 @@ static bool parseAbbrev(const char* str, const char* strEnd, macro_action_t* out
outKeyAction->type = KeyActionType_Mouse;
outKeyAction->mouseAction = mouseBtnToSerializedMouseAction(record->scancode);
break;
case scType_gamepad:
outKeyAction->type = KeyActionType_Gamepad;
outKeyAction->gamepadPropertyId = record->scancode;
break;
}
}
return true;
Expand Down
3 changes: 2 additions & 1 deletion right/src/macro_shortcut_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
scType_basic,
scType_system,
scType_media,
scType_mouseBtn
scType_mouseBtn,
scType_gamepad,
} shortcut_type_t;

typedef struct {
Expand Down
62 changes: 62 additions & 0 deletions right/src/macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,66 @@ static macro_result_t processMouseButtonAction(void)
return processMouseButton(s->ms.currentMacroAction);
}


static macro_result_t processGamepadButton(macro_action_t macro_action)
{
s->ms.reportsUsed = true;
uint8_t propertyId = macro_action.gamepadButton.propertyId;
macro_sub_action_t action = macro_action.mouseButton.action;

uint16_t propertyMask = UsbGamepad_GetPropertyMask(propertyId);

s->as.actionPhase++;

switch (macro_action.mouseButton.action) {
case MacroSubAction_Hold:
case MacroSubAction_Tap:
switch(s->as.actionPhase) {
case 1:
s->ms.macroGamepadReportButtonMask |= propertyMask;
return MacroResult_Blocking;
case 2:
if (currentMacroKeyIsActive() && action == MacroSubAction_Hold) {
s->as.actionPhase--;
return sleepTillKeystateChange();
}
s->ms.macroGamepadReportButtonMask &= ~propertyMask;
return MacroResult_Blocking;
case 3:
s->as.actionPhase = 0;
return MacroResult_Finished;

}
break;
case MacroSubAction_Release:
switch(s->as.actionPhase) {
case 1:
s->ms.macroGamepadReportButtonMask &= ~propertyMask;
return MacroResult_Blocking;
case 2:
s->as.actionPhase = 0;
return MacroResult_Finished;
}
break;
case MacroSubAction_Press:
switch(s->as.actionPhase) {
case 1:
s->ms.macroGamepadReportButtonMask |= propertyMask;
return MacroResult_Blocking;
case 2:
s->as.actionPhase = 0;
return MacroResult_Finished;
}
break;
}
return MacroResult_Finished;
}

static macro_result_t processGamepadButtonAction(void)
{
return processGamepadButton(s->ms.currentMacroAction);
}

static macro_result_t processMoveMouseAction(void)
{
s->ms.reportsUsed = true;
Expand Down Expand Up @@ -2905,6 +2965,8 @@ static macro_result_t processCurrentMacroAction(void)
return processKeyAction();
case MacroActionType_MouseButton:
return processMouseButtonAction();
case MacroActionType_GamepadButton:
return processGamepadButtonAction();
case MacroActionType_MoveMouse:
return processMoveMouseAction();
case MacroActionType_ScrollMouse:
Expand Down
8 changes: 8 additions & 0 deletions right/src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

#include <stdint.h>
#include <stdbool.h>
#include "attributes.h"
#include "key_action.h"
#include "usb_device_config.h"
#include "key_states.h"
#include "usb_interfaces/usb_interface_gamepad.h"

// Macros:
#define MACRO_CYCLES_TO_POSTPONE 4
Expand Down Expand Up @@ -66,6 +68,7 @@
MacroActionType_Delay,
MacroActionType_Text,
MacroActionType_Command,
MacroActionType_GamepadButton,
} macro_action_type_t;

typedef enum {
Expand Down Expand Up @@ -100,6 +103,10 @@
int16_t x;
int16_t y;
} ATTR_PACKED moveMouse;
struct {
macro_sub_action_t action;
uint8_t propertyId;
} ATTR_PACKED gamepadButton;
struct {
int16_t x;
int16_t y;
Expand Down Expand Up @@ -160,6 +167,7 @@
macro_autorepeat_state_t autoRepeatPhase: 1;

uint8_t inputModifierMask;
uint16_t macroGamepadReportButtonMask;
usb_mouse_report_t macroMouseReport;
usb_basic_keyboard_report_t macroBasicKeyboardReport;
usb_media_keyboard_report_t macroMediaKeyboardReport;
Expand Down
2 changes: 2 additions & 0 deletions right/src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/* fixed behaviour */
NavigationMode_Cursor,
NavigationMode_Scroll,
NavigationMode_GamepadStickLeft,
NavigationMode_GamepadStickRight,
NavigationMode_Zoom,
NavigationMode_None,

Expand Down
Loading