Correct dimensions for touchscreen when single monitor attached
This commit is contained in:
@@ -58,6 +58,18 @@ using namespace std::literals;
|
||||
return "unknown"sv;
|
||||
}
|
||||
|
||||
// Dimensions for touchscreen input
|
||||
struct touch_port_t {
|
||||
std::uint32_t offset_x, offset_y;
|
||||
std::uint32_t width, height;
|
||||
|
||||
constexpr touch_port_t(
|
||||
std::uint32_t offset_x, std::uint32_t offset_y,
|
||||
std::uint32_t width, std::uint32_t height) noexcept :
|
||||
offset_x { offset_x }, offset_y { offset_y },
|
||||
width { width }, height { height } {};
|
||||
};
|
||||
|
||||
struct gamepad_state_t {
|
||||
std::uint16_t buttonFlags;
|
||||
std::uint8_t lt;
|
||||
@@ -146,7 +158,7 @@ std::shared_ptr<display_t> display(dev_type_e hwdevice_type);
|
||||
|
||||
input_t input();
|
||||
void move_mouse(input_t &input, int deltaX, int deltaY);
|
||||
void abs_mouse(input_t &input, int x, int y);
|
||||
void abs_mouse(input_t &input, const touch_port_t &touch_port, float x, float y);
|
||||
void button_mouse(input_t &input, int button, bool release);
|
||||
void scroll(input_t &input, int distance);
|
||||
void keyboard(input_t &input, uint16_t modcode, bool release);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/XTest.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
|
||||
@@ -29,6 +30,11 @@ using uinput_t = util::safe_ptr<libevdev_uinput, libevdev_uinput_destroy>;
|
||||
|
||||
using keyboard_t = util::safe_ptr_v2<Display, int, XCloseDisplay>;
|
||||
|
||||
constexpr touch_port_t target_touch_port {
|
||||
0, 0,
|
||||
19200, 12000
|
||||
};
|
||||
|
||||
struct input_raw_t {
|
||||
public:
|
||||
void clear_touchscreen() {
|
||||
@@ -136,11 +142,14 @@ public:
|
||||
keyboard_t keyboard;
|
||||
};
|
||||
|
||||
void abs_mouse(input_t &input, int x, int y) {
|
||||
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();
|
||||
|
||||
libevdev_uinput_write_event(touchscreen, EV_ABS, ABS_X, x);
|
||||
libevdev_uinput_write_event(touchscreen, EV_ABS, ABS_Y, y);
|
||||
auto scaled_x = (int)std::lround(x * ((float)target_touch_port.width / (float)touch_port.width));
|
||||
auto scaled_y = (int)std::lround(y * ((float)target_touch_port.height / (float)touch_port.height));
|
||||
|
||||
libevdev_uinput_write_event(touchscreen, EV_ABS, ABS_X, scaled_x + touch_port.offset_x);
|
||||
libevdev_uinput_write_event(touchscreen, EV_ABS, ABS_Y, scaled_y + touch_port.offset_y);
|
||||
libevdev_uinput_write_event(touchscreen, EV_KEY, BTN_TOOL_FINGER, 1);
|
||||
libevdev_uinput_write_event(touchscreen, EV_KEY, BTN_TOOL_FINGER, 0);
|
||||
|
||||
@@ -461,7 +470,7 @@ evdev_t touchscreen() {
|
||||
input_absinfo absx {
|
||||
0,
|
||||
0,
|
||||
1919,
|
||||
target_touch_port.width,
|
||||
1,
|
||||
0,
|
||||
28
|
||||
@@ -470,7 +479,7 @@ evdev_t touchscreen() {
|
||||
input_absinfo absy {
|
||||
0,
|
||||
0,
|
||||
1199,
|
||||
target_touch_port.height,
|
||||
1,
|
||||
0,
|
||||
28
|
||||
|
||||
Reference in New Issue
Block a user