From 622d5695d9f5d6e59dde41b562e4aa78021a785b Mon Sep 17 00:00:00 2001 From: Marcel Behlau Date: Mon, 6 Mar 2023 17:17:56 +0100 Subject: [PATCH 1/3] fix: add default values for cal_res_x/cal_res_y --- plugins/linear.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/linear.c b/plugins/linear.c index aeb22ade..cb035bc8 100644 --- a/plugins/linear.c +++ b/plugins/linear.c @@ -323,6 +323,8 @@ TSAPI struct tslib_module_info *linear_mod_init(__attribute__ ((unused)) struct lin->p_div = 1; lin->swap_xy = 0; lin->rot = 0; + lin->cal_res_x = 0; + lin->cal_res_y = 0; /* * Check calibration file From 3f9bfce3c5ec1d60792666520f770a0c7078f4a0 Mon Sep 17 00:00:00 2001 From: Marcel Behlau Date: Mon, 6 Mar 2023 17:19:02 +0100 Subject: [PATCH 2/3] feature: add option to limit coordinates to calibration resolution This fixes problems within QT (at least in 5.14.2), which does not accept input events outside of the screen. --- plugins/linear.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plugins/linear.c b/plugins/linear.c index cb035bc8..769bc1a0 100644 --- a/plugins/linear.c +++ b/plugins/linear.c @@ -45,6 +45,18 @@ struct tslib_linear { unsigned int rot; }; +#ifdef PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION +int min(int a, int b) +{ + return a < b ? a : b; +} + +int max(int a, int b) +{ + return a > b ? a : b; +} +#endif + static int linear_read(struct tslib_module_info *info, struct ts_sample *samp, int nr_samples) { @@ -106,6 +118,20 @@ static int linear_read(struct tslib_module_info *info, struct ts_sample *samp, default: break; } + + #ifdef PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION + samp->x = max(samp->x, 0); + samp->y = max(samp->y, 0); + if(lin->cal_res_x) + { + samp->x = min(samp->x, lin->cal_res_x - 1); + } + + if(lin->cal_res_y) + { + samp->y = min(samp->y, lin->cal_res_y - 1); + } + #endif } } From 558f067a85725e83da7832154656a147ab0cf5f3 Mon Sep 17 00:00:00 2001 From: Marcel Behlau Date: Mon, 6 Mar 2023 17:39:29 +0100 Subject: [PATCH 3/3] feature: add cmake option to enbale PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION option --- CMakeLists.txt | 1 + plugins/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d57ceda..bd0eaa42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ include(GNUInstallDirs) option(BUILD_SHARED_LIBS "ON: tslib is build as shared; OFF: tslib is build as static" ON) option(ENABLE_TOOLS "build additional tools" ON) +option(PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION "Limit coordinates to calibration resolution" OFF) set(LIBTS_VERSION_CURRENT 10) set(LIBTS_VERSION_REVISION 3) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 37a7a3ce..31e1ade3 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -21,11 +21,17 @@ macro(TSLIB_CHECK_MODULE module_name default_option help_string) string(REPLACE "-" "_" module_name_uc_ul ${module_name_uc}) target_sources(tslib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${module_sources}) target_compile_definitions(tslib PRIVATE TSLIB_STATIC_${module_name_uc_ul}_MODULE) + if (PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + target_compile_definitions(tslib PUBLIC PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + endif () else() add_library(${module_name} MODULE ${module_sources}) list(APPEND plugin_targets ${module_name}) target_link_libraries(${module_name} PUBLIC tslib) SET_TARGET_PROPERTIES(${module_name} PROPERTIES PREFIX "") + if (${module_name} STREQUAL "linear" AND PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + target_compile_definitions(${module_name} PRIVATE PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + endif () endif() endif()