Skip to content

Commit

Permalink
full touch support for sunshine
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Feb 28, 2024
1 parent 3d41b99 commit d9edcf8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ static int app_event_filter(void *userdata, SDL_Event *event) {
}
return 1;
}
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION: {
if (app->session != NULL) {
session_handle_input_event(app->session, event);
return 0;
}
return 1;
}
default:
if (event->type == USER_REMOTEBUTTONEVENT) {
return 1;
Expand Down
1 change: 1 addition & 0 deletions src/app/stream/input/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target_sources(moonlight-lib PRIVATE
session_keyboard.c
session_gamepad.c
session_mouse.c
session_touch.c
session_virt_mouse.c)
if (FEATURE_INPUT_EVMOUSE)
target_sources(moonlight-lib PRIVATE session_evmouse.c)
Expand Down
2 changes: 2 additions & 0 deletions src/app/stream/input/session_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ void stream_input_handle_mmotion(stream_input_t *input, const SDL_MouseMotionEve
void stream_input_handle_mbutton(stream_input_t *input, const SDL_MouseButtonEvent *event);

void stream_input_handle_mwheel(stream_input_t *input, const SDL_MouseWheelEvent *event);

void stream_input_handle_touch(const stream_input_t *input, const SDL_TouchFingerEvent *event);
16 changes: 16 additions & 0 deletions src/app/stream/input/session_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,24 @@ void stream_input_handle_mbutton(stream_input_t *input, const SDL_MouseButtonEve
event->button);
return;
}
if (event->which == SDL_TOUCH_MOUSEID) {
if (LiGetHostFeatureFlags() & LI_FF_PEN_TOUCH_EVENTS) {
// Don't send mouse events from touch devices if the host supports pen/touch events
return;
}
LiSendMousePositionEvent((short) event->x, (short) event->y, (short) input->session->display_width,
(short) input->session->display_height);
}
LiSendMouseButtonEvent(event->state == SDL_PRESSED ? BUTTON_ACTION_PRESS : BUTTON_ACTION_RELEASE,
button);
}

void stream_input_handle_mwheel(stream_input_t *input, const SDL_MouseWheelEvent *event) {
(void) input;
if (event->which == SDL_TOUCH_MOUSEID && LiGetHostFeatureFlags() & LI_FF_PEN_TOUCH_EVENTS) {
// Don't send mouse events from touch devices if the host supports pen/touch events
return;
}
if (event->y != 0) {
LiSendScrollEvent((signed char) event->y);
}
Expand All @@ -51,6 +63,10 @@ void stream_input_handle_mmotion(stream_input_t *input, const SDL_MouseMotionEve
if (input->view_only || input->no_sdl_mouse) {
return;
}
if (event->which == SDL_TOUCH_MOUSEID && LiGetHostFeatureFlags() & LI_FF_PEN_TOUCH_EVENTS) {
// Don't send mouse events from touch devices if the host supports pen/touch events
return;
}
if (app_get_mouse_relative() && event->which != SDL_TOUCH_MOUSEID) {
LiSendMouseMoveEvent((short) event->xrel, (short) event->yrel);
} else {
Expand Down
22 changes: 22 additions & 0 deletions src/app/stream/input/session_touch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "stream/input/session_input.h"

void stream_input_handle_touch(const stream_input_t *input, const SDL_TouchFingerEvent *event) {
if (input->view_only) {
return;
}
uint8_t type;
switch (event->type) {
case SDL_FINGERDOWN:
type = LI_TOUCH_EVENT_DOWN;
break;
case SDL_FINGERUP:
type = LI_TOUCH_EVENT_UP;
break;
case SDL_FINGERMOTION:
type = LI_TOUCH_EVENT_MOVE;
break;
default:
return;
}
LiSendTouchEvent(type, event->fingerId, event->x, event->y, event->pressure, 0, 0, 0);
}
6 changes: 6 additions & 0 deletions src/app/stream/session_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ bool session_handle_input_event(session_t *session, const SDL_Event *event) {
stream_input_handle_text(input, &event->text);
break;
}
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION: {
stream_input_handle_touch(input, &event->tfinger);
break;
}
default:
return false;
}
Expand Down

0 comments on commit d9edcf8

Please sign in to comment.