Skip to content

Commit 3b3e432

Browse files
committed
OpenVRBackend: Add support for hacky escape codes in SteamVR
1 parent 08a4595 commit 3b3e432

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/Backends/OpenVRBackend.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,46 @@ namespace gamescope
11391139
{
11401140
if (m_pIME)
11411141
{
1142-
type_text(m_pIME, vrEvent.data.keyboard.cNewInput);
1142+
const char *pchText = vrEvent.data.keyboard.cNewInput;
1143+
size_t unStrLen = strlen( pchText );
1144+
bool bEscaped = false;
1145+
if ( unStrLen > 2 && pchText[0] == '\x1b' && pchText[1] == '[' )
1146+
{
1147+
bEscaped = true;
1148+
}
1149+
1150+
if ( bEscaped )
1151+
{
1152+
const char chControlChar = pchText[2];
1153+
gamescope_input_method_action eAction = GAMESCOPE_INPUT_METHOD_ACTION_NONE;
1154+
switch (chControlChar)
1155+
{
1156+
case 'D': eAction = GAMESCOPE_INPUT_METHOD_ACTION_MOVE_LEFT; break;
1157+
case 'C': eAction = GAMESCOPE_INPUT_METHOD_ACTION_MOVE_RIGHT; break;
1158+
case 'A': eAction = GAMESCOPE_INPUT_METHOD_ACTION_MOVE_UP; break;
1159+
case 'B': eAction = GAMESCOPE_INPUT_METHOD_ACTION_MOVE_DOWN; break;
1160+
}
1161+
1162+
if ( eAction != GAMESCOPE_INPUT_METHOD_ACTION_NONE )
1163+
{
1164+
perform_action( m_pIME, eAction );
1165+
}
1166+
}
1167+
else
1168+
{
1169+
if ( unStrLen == 1 && pchText[0] == '\n' )
1170+
{
1171+
perform_action( m_pIME, GAMESCOPE_INPUT_METHOD_ACTION_SUBMIT );
1172+
}
1173+
else if ( unStrLen == 1 && pchText[0] == '\b' )
1174+
{
1175+
perform_action( m_pIME, GAMESCOPE_INPUT_METHOD_ACTION_DELETE_LEFT );
1176+
}
1177+
else
1178+
{
1179+
type_text( m_pIME, pchText );
1180+
}
1181+
}
11431182
}
11441183
break;
11451184
}

src/ime.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include <wlr/types/wlr_seat.h>
1919
#include "wlr_end.hpp"
2020

21-
#include "gamescope-input-method-protocol.h"
22-
2321
struct wlserver_input_method_manager *global_manager = nullptr;
2422

2523
/* The C/C++ standard library doesn't expose a reliable way to decode UTF-8,
@@ -407,7 +405,7 @@ void type_text(struct wlserver_input_method *ime, const char *text)
407405
wl_event_source_timer_update(ime->ime_reset_ime_keyboard_event_source, 100 /* ms */);
408406
}
409407

410-
static void perform_action(struct wlserver_input_method *ime, enum gamescope_input_method_action action)
408+
void perform_action(struct wlserver_input_method *ime, enum gamescope_input_method_action action)
411409
{
412410
if (actions.count(action) == 0) {
413411
ime_log.errorf("unsupported action %d", action);

src/ime.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#pragma once
44

55
#include "wlserver.hpp"
6+
#include "gamescope-input-method-protocol.h"
67

78
void create_ime_manager(struct wlserver_t *wlserver);
89

910
struct wlserver_input_method *create_local_ime();
1011
void destroy_ime(struct wlserver_input_method * ime);
1112
void type_text(struct wlserver_input_method *ime, const char *text);
13+
void perform_action(struct wlserver_input_method *ime, enum gamescope_input_method_action action);

0 commit comments

Comments
 (0)