Skip to content

Commit

Permalink
Add mouse invert (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitsangwan01 authored Jul 24, 2024
1 parent 82f81d4 commit 9a9a3ab
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 60 deletions.
2 changes: 1 addition & 1 deletion lib/app/data/client.dart → lib/app/client/client.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion lib/app/communication/ble/ble_peripheral_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/app/communication/uhid/uhid_communication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion lib/app/communication/uhid/uhid_device.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/app/communication/usb/usb_device_communication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lib/app/communication/usb/usb_hid_device.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/app/modules/dashboard/widgets/client_mouse_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lib/app/modules/dashboard/widgets/client_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
60 changes: 60 additions & 0 deletions lib/app/modules/setting/android_connection_mode_tile.dart
Original file line number Diff line number Diff line change
@@ -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<AndroidConnectionType>(
value: communicationService.androidConnection.value,
elevation: 0,
underline: const SizedBox(),
enableFeedback: false,
focusColor: Colors.transparent,
items: AndroidConnectionType.values
.map((e) => DropdownMenuItem<AndroidConnectionType>(
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;
},
),
),
);
}
}
60 changes: 15 additions & 45 deletions lib/app/modules/setting/settings_view.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<AndroidConnectionType>(
value: _communicationService.androidConnection.value,
elevation: 0,
underline: const SizedBox(),
enableFeedback: false,
focusColor: Colors.transparent,
items: AndroidConnectionType.values
.map((e) => DropdownMenuItem<AndroidConnectionType>(
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),
),
),
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/app/services/communication_service.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 4 additions & 0 deletions lib/app/services/storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/app/services/synergy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SynergyService {
Signal<bool> userInternalServer = Signal(true);
Signal<bool> autoStartServer = Signal(false);
Signal<bool> isServerRunning = Signal(false);
Signal<bool> invertMouseScroll = Signal(false);

List<ClientAlias> clientAliases = <ClientAlias>[
ClientAlias.left(),
Expand All @@ -36,6 +37,7 @@ class SynergyService {
closeServerIfRunning();
userInternalServer.value = storageService.useInternalServer;
autoStartServer.value = storageService.autoStartServer;
invertMouseScroll.value = storageService.invertMouseScroll;
}

Future<void> toggleServer(BuildContext context) async {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 9a9a3ab

Please sign in to comment.