From b6bb2c37a14bba00dc7d1e43dff85bed61459638 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Mon, 13 Oct 2025 15:26:59 +0200 Subject: [PATCH] adjust touch placements on Android and macOS --- CHANGELOG.md | 5 ++++ lib/utils/actions/base_actions.dart | 36 ++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 293a81a..3968319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 3.0.4 (not released yet) +- adjusted MyWhoosh keyboard navigation mapping (thanks @bin101) +- initial support for Wahook Kickr Bike Shift (thanks @MattW2) +- initial support for Elite Square Smart Frame + ### 3.0.3 (2025-10-12) - SwiftControl now supports iOS! - Note that you can't run SwiftControl and your trainer app on the same iPhone due to iOS limitations but...: diff --git a/lib/utils/actions/base_actions.dart b/lib/utils/actions/base_actions.dart index 4ff1aee..53b10cd 100644 --- a/lib/utils/actions/base_actions.dart +++ b/lib/utils/actions/base_actions.dart @@ -1,5 +1,8 @@ import 'package:accessibility/accessibility.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:swift_control/utils/actions/android.dart'; +import 'package:swift_control/utils/actions/desktop.dart'; import 'package:swift_control/utils/keymap/buttons.dart'; import '../keymap/apps/supported_app.dart'; @@ -21,17 +24,38 @@ abstract class BaseActions { final keyPair = supportedApp!.keymap.getKeyPair(action); if (keyPair != null && keyPair.touchPosition != Offset.zero) { // convert relative position to absolute position based on window info - if (windowInfo != null && windowInfo.right != 0) { + + if (windowInfo != null && windowInfo.top > 0) { final x = windowInfo.left + (keyPair.touchPosition.dx / 100) * (windowInfo.right - windowInfo.left); final y = windowInfo.top + (keyPair.touchPosition.dy / 100) * (windowInfo.bottom - windowInfo.top); + + if (kDebugMode) { + print("Window info: ${windowInfo.encode()} => Touch at: $x, $y"); + } return Offset(x, y); } else { // TODO support multiple screens - final screenSize = - WidgetsBinding.instance.platformDispatcher.views.first.display.size / - WidgetsBinding.instance.platformDispatcher.views.first.devicePixelRatio; - final x = (keyPair.touchPosition.dx / 100) * screenSize.width; - final y = (keyPair.touchPosition.dy / 100) * screenSize.height; + final display = WidgetsBinding.instance.platformDispatcher.views.first.display; + final displaySize = display.size; + + late final Size physicalSize; + if (this is AndroidActions) { + // display size is already in physical pixels + physicalSize = displaySize; + } else if (this is DesktopActions) { + // display size is in logical pixels, convert to physical pixels + // TODO on macOS the notch is included here, but it's not part of the usable screen area, so we should exclude it + physicalSize = displaySize / display.devicePixelRatio; + } else { + physicalSize = displaySize; + } + + final x = (keyPair.touchPosition.dx / 100.0) * physicalSize.width; + final y = (keyPair.touchPosition.dy / 100.0) * physicalSize.height; + + if (kDebugMode) { + print("Screen size: $physicalSize => Touch at: $x, $y"); + } return Offset(x, y); } }