diff --git a/sunshine/input.cpp b/sunshine/input.cpp index 31a02ded..f8ba308d 100644 --- a/sunshine/input.cpp +++ b/sunshine/input.cpp @@ -46,10 +46,6 @@ void free_id(std::bitset &gamepad_mask, int id) { gamepad_mask[id] = false; } -platf::touch_port_t touch_port { - 0, 0, 0, 0 -}; - static util::TaskPool::task_id_t task_id {}; static std::unordered_map key_press {}; static std::array mouse_press {}; @@ -88,15 +84,21 @@ struct gamepad_t { }; struct input_t { - input_t(safe::mail_raw_t::event_t touch_port_event) - : active_gamepad_state {}, gamepads(MAX_GAMEPADS), touch_port_event { std::move(touch_port_event) }, mouse_left_button_timeout {} {} + input_t(safe::mail_raw_t::event_t touch_port_event) + : active_gamepad_state {}, + gamepads(MAX_GAMEPADS), + touch_port_event { std::move(touch_port_event) }, + mouse_left_button_timeout {}, + touch_port { 0, 0, 0, 0, 0, 0, 1.0f } {} std::uint16_t active_gamepad_state; std::vector gamepads; - safe::mail_raw_t::event_t touch_port_event; + safe::mail_raw_t::event_t touch_port_event; util::ThreadPool::task_id_t mouse_left_button_timeout; + + input::touch_port_t touch_port; }; using namespace std::literals; @@ -204,6 +206,7 @@ void passthrough(std::shared_ptr &input, PNV_ABS_MOUSE_MOVE_PACKET pack } auto &touch_port_event = input->touch_port_event; + auto &touch_port = input->touch_port; if(touch_port_event->peek()) { touch_port = *touch_port_event->pop(); } @@ -233,7 +236,7 @@ void passthrough(std::shared_ptr &input, PNV_ABS_MOUSE_MOVE_PACKET pack touch_port.env_width, touch_port.env_height }; - platf::abs_mouse(platf_input, abs_port, x - offsetX, y - offsetY); //touch_port, x * scale_x + offsetX, y * scale_y + offsetY); + platf::abs_mouse(platf_input, abs_port, (x - offsetX) * touch_port.scalar_inv, (y - offsetY) * touch_port.scalar_inv); } void passthrough(std::shared_ptr &input, PNV_MOUSE_BUTTON_PACKET packet) { @@ -567,7 +570,7 @@ void init() { } std::shared_ptr alloc(safe::mail_t mail) { - auto input = std::make_shared(mail->event(mail::touch_port)); + auto input = std::make_shared(mail->event(mail::touch_port)); // Workaround to ensure new frames will be captured when a client connects task_pool.pushDelayed([]() { diff --git a/sunshine/input.h b/sunshine/input.h index 5c9cfb75..285828d9 100644 --- a/sunshine/input.h +++ b/sunshine/input.h @@ -7,6 +7,7 @@ #include "platform/common.h" #include "thread_safe.h" + namespace input { struct input_t; @@ -19,6 +20,13 @@ void passthrough(std::shared_ptr &input, std::vector &&in void init(); std::shared_ptr alloc(safe::mail_t mail); + +struct touch_port_t : public platf::touch_port_t { + int env_width, env_height; + + // inverse of scalar used for aspect ratio + float scalar_inv; +}; } // namespace input #endif //SUNSHINE_INPUT_H diff --git a/sunshine/platform/common.h b/sunshine/platform/common.h index a47937b8..2686c72c 100644 --- a/sunshine/platform/common.h +++ b/sunshine/platform/common.h @@ -106,8 +106,6 @@ inline std::string_view from_pix_fmt(pix_fmt_e pix_fmt) { // Dimensions for touchscreen input struct touch_port_t { int offset_x, offset_y; - int env_width, env_height; - int width, height; }; diff --git a/sunshine/platform/linux/input.cpp b/sunshine/platform/linux/input.cpp index f7750462..ad3397d5 100644 --- a/sunshine/platform/linux/input.cpp +++ b/sunshine/platform/linux/input.cpp @@ -145,8 +145,8 @@ struct input_raw_t { void abs_mouse(input_t &input, const touch_port_t &touch_port, float x, float y) { auto touchscreen = ((input_raw_t *)input.get())->touch_input.get(); - auto scaled_x = (int)std::lround((x + touch_port.offset_x) * ((float)target_touch_port.env_width / (float)touch_port.env_width)); - auto scaled_y = (int)std::lround((y + touch_port.offset_y) * ((float)target_touch_port.env_height / (float)touch_port.env_height)); + auto scaled_x = (int)std::lround((x + touch_port.offset_x) * ((float)target_touch_port.width / (float)touch_port.width)); + auto scaled_y = (int)std::lround((y + touch_port.offset_y) * ((float)target_touch_port.height / (float)touch_port.height)); libevdev_uinput_write_event(touchscreen, EV_ABS, ABS_X, scaled_x); libevdev_uinput_write_event(touchscreen, EV_ABS, ABS_Y, scaled_y); @@ -470,7 +470,7 @@ evdev_t touchscreen() { input_absinfo absx { 0, 0, - target_touch_port.env_width, + target_touch_port.width, 1, 0, 28 @@ -479,7 +479,7 @@ evdev_t touchscreen() { input_absinfo absy { 0, 0, - target_touch_port.env_height, + target_touch_port.height, 1, 0, 28 diff --git a/sunshine/platform/windows/input.cpp b/sunshine/platform/windows/input.cpp index e0466398..9eb6667b 100755 --- a/sunshine/platform/windows/input.cpp +++ b/sunshine/platform/windows/input.cpp @@ -123,8 +123,8 @@ void abs_mouse(input_t &input, const touch_port_t &touch_port, float x, float y) // MOUSEEVENTF_VIRTUALDESK maps to the entirety of the desktop rather than the primary desktop MOUSEEVENTF_VIRTUALDESK; - auto scaled_x = std::lround((x + touch_port.offset_x) * ((float)target_touch_port.env_width / (float)touch_port.env_width)); - auto scaled_y = std::lround((y + touch_port.offset_y) * ((float)target_touch_port.env_height / (float)touch_port.env_height)); + auto scaled_x = std::lround((x + touch_port.offset_x) * ((float)target_touch_port.width / (float)touch_port.width)); + auto scaled_y = std::lround((y + touch_port.offset_y) * ((float)target_touch_port.height / (float)touch_port.height)); mi.dx = scaled_x; mi.dy = scaled_y; diff --git a/sunshine/video.cpp b/sunshine/video.cpp index fcaa1c1e..1807edca 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -12,6 +12,7 @@ extern "C" { #include "cbs.h" #include "config.h" +#include "input.h" #include "main.h" #include "platform/common.h" #include "round_robin.h" @@ -353,7 +354,7 @@ struct sync_session_ctx_t { safe::mail_raw_t::event_t shutdown_event; safe::mail_raw_t::queue_t packets; safe::mail_raw_t::event_t idr_events; - safe::mail_raw_t::event_t touch_port_events; + safe::mail_raw_t::event_t touch_port_events; config_t config; int frame_nr; @@ -1061,7 +1062,7 @@ void encode_run( } } -platf::touch_port_t make_port(platf::display_t *display, const config_t &config) { +input::touch_port_t make_port(platf::display_t *display, const config_t &config) { float wd = display->width; float hd = display->height; @@ -1073,13 +1074,14 @@ platf::touch_port_t make_port(platf::display_t *display, const config_t &config) auto w2 = scalar * wd; auto h2 = scalar * hd; - return platf::touch_port_t { + return input::touch_port_t { display->offset_x, display->offset_y, - display->env_width, - display->env_height, (int)w2, (int)h2, + display->env_width, + display->env_height, + 1.0f / scalar, }; } @@ -1315,7 +1317,7 @@ void capture_async( int frame_nr = 1; int key_frame_nr = 1; - auto touch_port_event = mail->event(mail::touch_port); + auto touch_port_event = mail->event(mail::touch_port); while(!shutdown_event->peek() && images->running()) { // Wait for the main capture event when the display is being reinitialized @@ -1379,7 +1381,7 @@ void capture( mail->event(mail::shutdown), mail::man->queue(mail::video_packets), std::move(idr_events), - mail->event(mail::touch_port), + mail->event(mail::touch_port), config, 1, 1,