From 9a9a3ab04475f2731697f1e1d0c49691486dd59b Mon Sep 17 00:00:00 2001 From: Rohit Sangwan Date: Wed, 24 Jul 2024 09:54:05 +0530 Subject: [PATCH] Add mouse invert (#8) --- lib/app/{data => client}/client.dart | 2 +- lib/app/{data => client}/client_screen.dart | 10 +++- lib/app/{data => client}/report_handler.dart | 0 .../ble/ble_peripheral_communication.dart | 2 +- .../ble/ble_peripheral_utils.dart | 2 +- .../uhid/uhid_communication.dart | 2 +- lib/app/communication/uhid/uhid_device.dart | 2 +- .../usb/usb_device_communication.dart | 4 +- lib/app/communication/usb/usb_hid_device.dart | 2 +- .../widgets/client_mouse_widget.dart | 2 +- .../dashboard/widgets/client_widget.dart | 2 +- .../setting/android_connection_mode_tile.dart | 60 +++++++++++++++++++ lib/app/modules/setting/settings_view.dart | 60 +++++-------------- lib/app/services/communication_service.dart | 2 +- lib/app/services/storage_service.dart | 4 ++ lib/app/services/synergy_service.dart | 2 + pubspec.yaml | 2 +- 17 files changed, 100 insertions(+), 60 deletions(-) rename lib/app/{data => client}/client.dart (98%) rename lib/app/{data => client}/client_screen.dart (96%) rename lib/app/{data => client}/report_handler.dart (100%) create mode 100644 lib/app/modules/setting/android_connection_mode_tile.dart diff --git a/lib/app/data/client.dart b/lib/app/client/client.dart similarity index 98% rename from lib/app/data/client.dart rename to lib/app/client/client.dart index 63bd0c7..f0f607a 100644 --- a/lib/app/data/client.dart +++ b/lib/app/client/client.dart @@ -1,6 +1,6 @@ import 'package:signals_flutter/signals_flutter.dart'; import 'package:synergy_client_dart/synergy_client_dart.dart'; -import 'package:uni_control_hub/app/data/client_screen.dart'; +import 'package:uni_control_hub/app/client/client_screen.dart'; import 'package:uni_control_hub/app/data/logger.dart'; import 'package:uni_control_hub/app/models/client_alias.dart'; import 'package:uni_control_hub/app/models/screen_link.dart'; diff --git a/lib/app/data/client_screen.dart b/lib/app/client/client_screen.dart similarity index 96% rename from lib/app/data/client_screen.dart rename to lib/app/client/client_screen.dart index cc499fb..ce05770 100644 --- a/lib/app/data/client_screen.dart +++ b/lib/app/client/client_screen.dart @@ -2,9 +2,9 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:synergy_client_dart/synergy_client_dart.dart'; -import 'package:uni_control_hub/app/data/report_handler.dart'; +import 'package:uni_control_hub/app/client/report_handler.dart'; import 'package:uni_control_hub/app/data/logger.dart'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/models/screen_link.dart'; import 'package:uni_control_hub/app/data/dialog_handler.dart'; import 'package:uni_control_hub/app/services/storage_service.dart'; @@ -62,7 +62,6 @@ class ClientScreen extends ScreenInterface { reportData[3] = y - relativeY; // Y movement reportData[4] = 0; // Wheel movement _addInputReport(reportData); - relativeX = x; relativeY = y; onMouseMove?.call(x, y); @@ -72,11 +71,16 @@ class ClientScreen extends ScreenInterface { void mouseWheel(int x, int y) { int wheel = x != 0 ? x : y; // convert wheel in +1 or -1 + if (client.storageService.invertMouseScroll) { + wheel = -wheel; + } + if (wheel > 0) { wheel = -1; } else if (wheel < 0) { wheel = 1; } + var reportData = Uint8List(5); reportData[0] = 0x02; // Report ID reportData[1] = 0; // Button state diff --git a/lib/app/data/report_handler.dart b/lib/app/client/report_handler.dart similarity index 100% rename from lib/app/data/report_handler.dart rename to lib/app/client/report_handler.dart diff --git a/lib/app/communication/ble/ble_peripheral_communication.dart b/lib/app/communication/ble/ble_peripheral_communication.dart index c579b98..b1478aa 100644 --- a/lib/app/communication/ble/ble_peripheral_communication.dart +++ b/lib/app/communication/ble/ble_peripheral_communication.dart @@ -7,7 +7,7 @@ import 'package:ble_peripheral/ble_peripheral.dart'; import 'package:uni_control_hub/app/communication/ble/ble_peripheral_utils.dart'; import 'package:uni_control_hub/app/services/communication_service.dart'; import 'package:uni_control_hub/app/data/capabilities.dart'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/data/logger.dart'; import 'package:uni_control_hub/app/data/dialog_handler.dart'; import 'package:uni_control_hub/app/services/storage_service.dart'; diff --git a/lib/app/communication/ble/ble_peripheral_utils.dart b/lib/app/communication/ble/ble_peripheral_utils.dart index d50dae3..9e29cb1 100644 --- a/lib/app/communication/ble/ble_peripheral_utils.dart +++ b/lib/app/communication/ble/ble_peripheral_utils.dart @@ -3,7 +3,7 @@ import 'dart:developer'; import 'dart:typed_data'; import 'package:ble_peripheral/ble_peripheral.dart'; -import 'package:uni_control_hub/app/data/report_handler.dart'; +import 'package:uni_control_hub/app/client/report_handler.dart'; class BlePeripheralUtils { /// Device diff --git a/lib/app/communication/uhid/uhid_communication.dart b/lib/app/communication/uhid/uhid_communication.dart index c58e424..e0d58ad 100644 --- a/lib/app/communication/uhid/uhid_communication.dart +++ b/lib/app/communication/uhid/uhid_communication.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:uni_control_hub/app/services/communication_service.dart'; import 'package:uni_control_hub/app/communication/uhid/uhid_device.dart'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/data/logger.dart'; import 'package:uni_control_hub/app/data/dialog_handler.dart'; import 'package:uni_control_hub/app/services/adb_service.dart'; diff --git a/lib/app/communication/uhid/uhid_device.dart b/lib/app/communication/uhid/uhid_device.dart index 6e9709f..44e4d10 100644 --- a/lib/app/communication/uhid/uhid_device.dart +++ b/lib/app/communication/uhid/uhid_device.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:uni_control_hub/app/data/report_handler.dart'; +import 'package:uni_control_hub/app/client/report_handler.dart'; import 'package:uni_control_hub/app/data/logger.dart'; class UhidDevice { diff --git a/lib/app/communication/usb/usb_device_communication.dart b/lib/app/communication/usb/usb_device_communication.dart index 0da5327..6f35195 100644 --- a/lib/app/communication/usb/usb_device_communication.dart +++ b/lib/app/communication/usb/usb_device_communication.dart @@ -5,10 +5,10 @@ import 'dart:io'; import 'package:uni_control_hub/app/data/file_manager.dart'; import 'package:uni_control_hub/app/services/adb_service.dart'; import 'package:uni_control_hub/app/services/communication_service.dart'; -import 'package:uni_control_hub/app/data/report_handler.dart'; +import 'package:uni_control_hub/app/client/report_handler.dart'; import 'package:uni_control_hub/app/communication/usb/usb_hid_device.dart'; import 'package:uni_control_hub/app/data/logger.dart'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/models/usb_device.dart'; import 'package:uni_control_hub/generated/generated_bindings.dart'; diff --git a/lib/app/communication/usb/usb_hid_device.dart b/lib/app/communication/usb/usb_hid_device.dart index 8415276..beec20f 100644 --- a/lib/app/communication/usb/usb_hid_device.dart +++ b/lib/app/communication/usb/usb_hid_device.dart @@ -1,6 +1,6 @@ import 'dart:ffi'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/models/usb_device.dart'; import 'package:uni_control_hub/generated/generated_bindings.dart'; import 'package:ffi/ffi.dart' as ffi; diff --git a/lib/app/modules/dashboard/widgets/client_mouse_widget.dart b/lib/app/modules/dashboard/widgets/client_mouse_widget.dart index d67a051..3612c7a 100644 --- a/lib/app/modules/dashboard/widgets/client_mouse_widget.dart +++ b/lib/app/modules/dashboard/widgets/client_mouse_widget.dart @@ -3,7 +3,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:signals_flutter/signals_flutter.dart'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/data/extensions.dart'; import 'package:uni_control_hub/app/services/storage_service.dart'; diff --git a/lib/app/modules/dashboard/widgets/client_widget.dart b/lib/app/modules/dashboard/widgets/client_widget.dart index f93554f..451313e 100644 --- a/lib/app/modules/dashboard/widgets/client_widget.dart +++ b/lib/app/modules/dashboard/widgets/client_widget.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:signals_flutter/signals_flutter.dart'; import 'package:uni_control_hub/app/data/extensions.dart'; import 'package:uni_control_hub/app/models/client_alias.dart'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/modules/dashboard/widgets/client_mouse_widget.dart'; import 'package:uni_control_hub/app/services/synergy_service.dart'; diff --git a/lib/app/modules/setting/android_connection_mode_tile.dart b/lib/app/modules/setting/android_connection_mode_tile.dart new file mode 100644 index 0000000..8893cf8 --- /dev/null +++ b/lib/app/modules/setting/android_connection_mode_tile.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_settings_ui/flutter_settings_ui.dart'; +import 'package:signals_flutter/signals_flutter.dart'; +import 'package:uni_control_hub/app/data/dialog_handler.dart'; +import 'package:uni_control_hub/app/data/info_data.dart'; +import 'package:uni_control_hub/app/models/android_connection_type.dart'; +import 'package:uni_control_hub/app/services/communication_service.dart'; +import 'package:uni_control_hub/app/services/storage_service.dart'; + +class AndroidConnectionModeTile extends StatelessWidget { + const AndroidConnectionModeTile({super.key}); + + @override + Widget build(BuildContext context) { + final StorageService storageService = StorageService.to; + final CommunicationService communicationService = CommunicationService.to; + return Watch( + (_) => SettingsTile( + title: Row( + children: [ + const Text('Android Connection Mode'), + const SizedBox(width: 10), + InkWell( + onTap: () { + DialogHandler.showInfoDialog( + context: context, + title: 'Android Connection Mode', + text: androidConnectionModeInfo, + ); + }, + child: const Icon(Icons.info_outline, size: 19), + ) + ], + ), + leading: const Icon(Icons.android), + trailing: DropdownButton( + value: communicationService.androidConnection.value, + elevation: 0, + underline: const SizedBox(), + enableFeedback: false, + focusColor: Colors.transparent, + items: AndroidConnectionType.values + .map((e) => DropdownMenuItem( + value: e, + child: Text( + e.name.toUpperCase(), + style: Theme.of(context).textTheme.labelMedium, + ), + )) + .toList(), + onChanged: (AndroidConnectionType? connection) { + if (connection == null) return; + storageService.androidConnection = connection; + communicationService.androidConnection.value = connection; + }, + ), + ), + ); + } +} diff --git a/lib/app/modules/setting/settings_view.dart b/lib/app/modules/setting/settings_view.dart index e46ffe8..46449b4 100644 --- a/lib/app/modules/setting/settings_view.dart +++ b/lib/app/modules/setting/settings_view.dart @@ -1,11 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_settings_ui/flutter_settings_ui.dart'; import 'package:signals_flutter/signals_flutter.dart'; +import 'package:uni_control_hub/app/modules/setting/android_connection_mode_tile.dart'; import 'package:uni_control_hub/app/services/communication_service.dart'; import 'package:uni_control_hub/app/data/capabilities.dart'; -import 'package:uni_control_hub/app/data/info_data.dart'; -import 'package:uni_control_hub/app/data/dialog_handler.dart'; -import 'package:uni_control_hub/app/models/android_connection_type.dart'; import 'package:uni_control_hub/app/services/storage_service.dart'; import 'package:uni_control_hub/app/services/synergy_service.dart'; @@ -73,49 +71,21 @@ class SettingsView extends StatelessWidget { SettingsSection( title: const Text('Client'), tiles: [ + const CustomSettingsTile( + child: AndroidConnectionModeTile(), + ), CustomSettingsTile( - child: Watch((_) => SettingsTile( - title: Row( - children: [ - const Text('Android Connection Mode'), - const SizedBox(width: 10), - InkWell( - onTap: () { - DialogHandler.showInfoDialog( - context: context, - title: 'Android Connection Mode', - text: androidConnectionModeInfo, - ); - }, - child: const Icon(Icons.info_outline, size: 19), - ) - ], - ), - leading: const Icon(Icons.android), - trailing: DropdownButton( - value: _communicationService.androidConnection.value, - elevation: 0, - underline: const SizedBox(), - enableFeedback: false, - focusColor: Colors.transparent, - items: AndroidConnectionType.values - .map((e) => DropdownMenuItem( - value: e, - child: Text( - e.name.toUpperCase(), - style: - Theme.of(context).textTheme.labelMedium, - ), - )) - .toList(), - onChanged: (AndroidConnectionType? connection) { - if (connection == null) return; - _storageService.androidConnection = connection; - _communicationService.androidConnection.value = - connection; - }, - ), - )), + child: Watch( + (_) => SettingsTile.switchTile( + title: const Text('Invert Mouse Scroll'), + initialValue: _synergyService.invertMouseScroll.value, + onToggle: (value) { + _synergyService.invertMouseScroll.value = value; + _storageService.invertMouseScroll = value; + }, + leading: const Icon(Icons.swap_vert), + ), + ), ), ], ), diff --git a/lib/app/services/communication_service.dart b/lib/app/services/communication_service.dart index fa7566c..f4f6389 100644 --- a/lib/app/services/communication_service.dart +++ b/lib/app/services/communication_service.dart @@ -1,6 +1,6 @@ import 'package:get_it/get_it.dart'; import 'package:signals_flutter/signals_flutter.dart'; -import 'package:uni_control_hub/app/data/client.dart'; +import 'package:uni_control_hub/app/client/client.dart'; import 'package:uni_control_hub/app/data/extensions.dart'; import 'package:uni_control_hub/app/data/logger.dart'; import 'package:uni_control_hub/app/models/android_connection_type.dart'; diff --git a/lib/app/services/storage_service.dart b/lib/app/services/storage_service.dart index 48dc91c..e522bef 100644 --- a/lib/app/services/storage_service.dart +++ b/lib/app/services/storage_service.dart @@ -28,6 +28,10 @@ class StorageService { set enableBluetoothConnection(bool value) => _storage.setBool('enableBluetoothConnection', value); + bool get invertMouseScroll => _storage.getBool('invertMouseScroll') ?? false; + set invertMouseScroll(bool value) => + _storage.setBool('invertMouseScroll', value); + bool get useInternalServer => _storage.getBool('useInternalServer') ?? true; set useInternalServer(bool value) => _storage.setBool('useInternalServer', value); diff --git a/lib/app/services/synergy_service.dart b/lib/app/services/synergy_service.dart index b3f51d6..1795d29 100644 --- a/lib/app/services/synergy_service.dart +++ b/lib/app/services/synergy_service.dart @@ -24,6 +24,7 @@ class SynergyService { Signal userInternalServer = Signal(true); Signal autoStartServer = Signal(false); Signal isServerRunning = Signal(false); + Signal invertMouseScroll = Signal(false); List clientAliases = [ ClientAlias.left(), @@ -36,6 +37,7 @@ class SynergyService { closeServerIfRunning(); userInternalServer.value = storageService.useInternalServer; autoStartServer.value = storageService.autoStartServer; + invertMouseScroll.value = storageService.invertMouseScroll; } Future toggleServer(BuildContext context) async { diff --git a/pubspec.yaml b/pubspec.yaml index 1ff8a22..a08a62d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: uni_control_hub -version: 0.0.2 +version: 0.0.3 publish_to: none description: Seamlessly Bridge Your Devices environment: