touch: avoid calling is_touch_available too early (#289)

## Link to GitHub Issue, if one exists
Fixes #120 

## Description of change
Don't call `is_touch_available` in launcher before RawInput stack is
initialized. This causes us to incorrectly fall back to the Win7/Win8
touch handler.

The desired behavior is to use rawinput touch by default for all games,
unless overridden by the user via `-wintouch`.

Add a bunch of logging so we can spot who's calling
`is_touch_available`.

As a side effect, a handful of games that previously used Win7/8 touch
will now use RawInput touch instead. If this causes any issues, they can
turn `-wintouch` on to force Win7/8 touch logic again.

## Compiling
👍 

## Testing
Test:

* RB
* -wintouch
* TDJ, UFC subscreen and native touch
* overlay, especially in multi-mon
This commit is contained in:
bicarus-dev
2025-04-04 21:31:18 -07:00
committed by GitHub
parent bd6c8d3f3c
commit ae06652148
9 changed files with 46 additions and 51 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ namespace games::qma {
touch_attach_dx_hook(); touch_attach_dx_hook();
// cursor // cursor
if (!is_touch_available()) { if (!is_touch_available("QMATouchDevice::open")) {
ShowCursor(true); ShowCursor(true);
} }
} }
+1 -1
View File
@@ -86,7 +86,7 @@ bool games::rb::ReflecBeatTouchDeviceHandle::open(LPCWSTR lpFileName) {
} }
// show cursor on window if mouse is used // show cursor on window if mouse is used
if (!is_touch_available()) { if (!is_touch_available("ReflecBeatTouchDeviceHandle::open")) {
ShowCursor(TRUE); ShowCursor(TRUE);
} }
+1 -1
View File
@@ -72,7 +72,7 @@ public:
touch_attach_dx_hook(); touch_attach_dx_hook();
// cursor // cursor
if (!is_touch_available()) { if (!is_touch_available("TwTouchDevice::open")) {
ShowCursor(true); ShowCursor(true);
} }
} }
+14 -39
View File
@@ -217,6 +217,7 @@ int main_implementation(int argc, char *argv[]) {
bool attach_qks = false; bool attach_qks = false;
bool attach_mfg = false; bool attach_mfg = false;
bool attach_museca = false; bool attach_museca = false;
bool show_cursor_if_no_touch = false;
// misc settings // misc settings
size_t user_heap_size = 0; size_t user_heap_size = 0;
@@ -1291,11 +1292,7 @@ int main_implementation(int argc, char *argv[]) {
avs::game::DLL_NAME = "system.dll"; avs::game::DLL_NAME = "system.dll";
attach_io = true; attach_io = true;
attach_shogikai = true; attach_shogikai = true;
show_cursor_if_no_touch = true;
// automatically show cursor when no touchscreen is available
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1338,12 +1335,7 @@ int main_implementation(int argc, char *argv[]) {
// game crash fix // game crash fix
easrv_maint = false; easrv_maint = false;
show_cursor_if_no_touch = true;
// automatically show cursor when no touchscreen is available
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1458,12 +1450,7 @@ int main_implementation(int argc, char *argv[]) {
avs::game::DLL_NAME = "nostalgia.dll"; avs::game::DLL_NAME = "nostalgia.dll";
attach_io = true; attach_io = true;
attach_nostalgia = true; attach_nostalgia = true;
show_cursor_if_no_touch = true;
// automatically show cursor when no touchscreen is available
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1569,12 +1556,7 @@ int main_implementation(int argc, char *argv[]) {
avs::game::DLL_NAME = "arknck.dll"; avs::game::DLL_NAME = "arknck.dll";
attach_io = true; attach_io = true;
attach_we = true; attach_we = true;
show_cursor_if_no_touch = true;
// automatically show cursor when no touchscreen is available
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1607,10 +1589,7 @@ int main_implementation(int argc, char *argv[]) {
avs::game::DLL_NAME = "kamunity.dll"; avs::game::DLL_NAME = "kamunity.dll";
attach_io = true; attach_io = true;
attach_ccj = true; attach_ccj = true;
// automatically show cursor when no touchscreen is available show_cursor_if_no_touch = true;
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1619,10 +1598,7 @@ int main_implementation(int argc, char *argv[]) {
avs::game::DLL_NAME = "kamunity.dll"; avs::game::DLL_NAME = "kamunity.dll";
attach_io = true; attach_io = true;
attach_qks = true; attach_qks = true;
// automatically show cursor when no touchscreen is available show_cursor_if_no_touch = true;
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1632,10 +1608,7 @@ int main_implementation(int argc, char *argv[]) {
attach_io = true; attach_io = true;
attach_mfg = true; attach_mfg = true;
launcher::signal::USE_VEH_WORKAROUND = true; launcher::signal::USE_VEH_WORKAROUND = true;
// automatically show cursor when no touchscreen is available show_cursor_if_no_touch = true;
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1644,10 +1617,7 @@ int main_implementation(int argc, char *argv[]) {
avs::game::DLL_NAME = "kamunity.dll"; avs::game::DLL_NAME = "kamunity.dll";
attach_io = true; attach_io = true;
attach_bc = true; attach_bc = true;
// automatically show cursor when no touchscreen is available show_cursor_if_no_touch = true;
if (!is_touch_available()) {
GRAPHICS_SHOW_CURSOR = true;
}
break; break;
} }
@@ -1843,6 +1813,11 @@ int main_implementation(int argc, char *argv[]) {
// print devices // print devices
RI_MGR->devices_print(); RI_MGR->devices_print();
// for certain games, show cursor if no touch is available (must be called after RI_MGR is available)
if (show_cursor_if_no_touch && !is_touch_available("launcher::main_implementation")) {
GRAPHICS_SHOW_CURSOR = true;
}
// cardio // cardio
if (cardio_enabled) { if (cardio_enabled) {
cardio_runner_start(true); cardio_runner_start(true);
+1 -1
View File
@@ -36,7 +36,7 @@ namespace wintouchemu {
bool LOG_FPS = false; bool LOG_FPS = false;
static inline bool is_emu_enabled() { static inline bool is_emu_enabled() {
return FORCE || !is_touch_available() || GRAPHICS_SHOW_CURSOR; return FORCE || !is_touch_available("wintouchemu::is_emu_enabled") || GRAPHICS_SHOW_CURSOR;
} }
static decltype(GetSystemMetrics) *GetSystemMetrics_orig = nullptr; static decltype(GetSystemMetrics) *GetSystemMetrics_orig = nullptr;
+1 -1
View File
@@ -247,7 +247,7 @@ void overlay::SpiceOverlay::init() {
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
} }
if (is_touch_available()) { if (is_touch_available("SpiceOverlay::init")) {
io.ConfigFlags |= ImGuiConfigFlags_IsTouchScreen; io.ConfigFlags |= ImGuiConfigFlags_IsTouchScreen;
} }
+1 -1
View File
@@ -751,7 +751,7 @@ namespace overlay::windows {
if (ImGui::CollapsingHeader("Touch")) { if (ImGui::CollapsingHeader("Touch")) {
// status // status
ImGui::Text("Status: %s", is_touch_available() ? "available" : "unavailable"); ImGui::Text("Status: %s", is_touch_available("Control::touch_view") ? "available" : "unavailable");
// touch points // touch points
ImGui::SetNextItemOpen(true, ImGuiCond_Once); ImGui::SetNextItemOpen(true, ImGuiCond_Once);
+25 -5
View File
@@ -138,8 +138,15 @@ static void touch_initialize() {
} }
SPICETOUCH_INITIALIZED = true; SPICETOUCH_INITIALIZED = true;
if (!RI_MGR) {
log_fatal(
LOG_MODULE_NAME,
"touch_initialize() - RI Manager not available, called too early! "
"This is a BUG in spice, please file a bug report with log.txt.");
}
// initialize handler // initialize handler
if (RI_MGR && rawinput::touch::is_enabled(RI_MGR.get())) { if (rawinput::touch::is_enabled(RI_MGR.get())) {
TOUCH_HANDLER = new RawInputTouchHandler(); TOUCH_HANDLER = new RawInputTouchHandler();
} else if (Win8Handler::is_available()) { } else if (Win8Handler::is_available()) {
TOUCH_HANDLER = new Win8Handler(); TOUCH_HANDLER = new Win8Handler();
@@ -166,13 +173,26 @@ static inline void touch_unregister_window(HWND hWnd) {
} }
} }
bool is_touch_available() { bool is_touch_available(LPCSTR caller) {
static bool called_once = false;
if (!RI_MGR) {
log_fatal(
LOG_MODULE_NAME,
"is_touch_available({}) - RI Manager not available, called too early! "
"This is a BUG in spice, please file a bug report with log.txt.",
caller);
}
// initialize touch handler // initialize touch handler
touch_initialize(); touch_initialize();
// Check if a touch handler has been set. No need to call `is_available` here if (!called_once) {
// as `touch_initialize` does that. log_misc("touch", "is_touch_available called by: {}, returning {}",
caller, (TOUCH_HANDLER != nullptr) ? "TRUE" : "false");
called_once = true;
}
return TOUCH_HANDLER != nullptr; return TOUCH_HANDLER != nullptr;
} }
@@ -202,7 +222,7 @@ static LRESULT CALLBACK SpiceTouchWndProc(HWND hWnd, UINT msg, WPARAM wParam, LP
SPICETOUCH_REGISTERED_TOUCH = true; SPICETOUCH_REGISTERED_TOUCH = true;
// check if touch is available // check if touch is available
if (is_touch_available()) { if (is_touch_available("SpiceTouchWndProc")) {
// notify the handler of our window // notify the handler of our window
TOUCH_HANDLER->window_register(hWnd); TOUCH_HANDLER->window_register(hWnd);
+1 -1
View File
@@ -27,7 +27,7 @@ extern int SPICETOUCH_TOUCH_Y;
extern int SPICETOUCH_TOUCH_WIDTH; extern int SPICETOUCH_TOUCH_WIDTH;
extern int SPICETOUCH_TOUCH_HEIGHT; extern int SPICETOUCH_TOUCH_HEIGHT;
bool is_touch_available(); bool is_touch_available(LPCSTR caller);
void touch_attach_wnd(HWND hWnd); void touch_attach_wnd(HWND hWnd);
void touch_attach_dx_hook(); void touch_attach_dx_hook();