diff --git a/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift b/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift index 6264f88f9..0a9725395 100644 --- a/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift +++ b/src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift @@ -88,12 +88,18 @@ struct DevicesGamePadSettingsView: View { HStack(spacing: 20.0) { FormulaView( name: "X formula", - value: $connectedDeviceSetting.gamePadStickXFormula + value: $connectedDeviceSetting.gamePadStickXFormula, + resetFunction: { + connectedDeviceSetting.resetGamePadStickXFormula() + } ) FormulaView( name: "Y formula", - value: $connectedDeviceSetting.gamePadStickYFormula + value: $connectedDeviceSetting.gamePadStickYFormula, + resetFunction: { + connectedDeviceSetting.resetGamePadStickYFormula() + } ) } .padding(.top, 20.0) @@ -130,12 +136,18 @@ struct DevicesGamePadSettingsView: View { HStack(spacing: 20.0) { FormulaView( name: "vertical wheel formula", - value: $connectedDeviceSetting.gamePadStickVerticalWheelFormula + value: $connectedDeviceSetting.gamePadStickVerticalWheelFormula, + resetFunction: { + connectedDeviceSetting.resetGamePadStickVerticalWheelFormula() + } ) FormulaView( name: "horizontal wheel formula", - value: $connectedDeviceSetting.gamePadStickHorizontalWheelFormula + value: $connectedDeviceSetting.gamePadStickHorizontalWheelFormula, + resetFunction: { + connectedDeviceSetting.resetGamePadStickHorizontalWheelFormula() + } ) } .padding(.top, 20.0) @@ -222,6 +234,7 @@ struct DevicesGamePadSettingsView: View { struct FormulaView: View { let name: String @Binding var value: String + let resetFunction: () -> Void @State private var error = false var body: some View { @@ -236,6 +249,18 @@ struct DevicesGamePadSettingsView: View { } Spacer() + + Button( + role: .destructive, + action: { + resetFunction() + }, + label: { + Label("Reset to the default formula", systemImage: "trash") + .buttonLabelStyle() + } + ) + .deleteButtonStyle() } TextEditor(text: $value) diff --git a/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift b/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift index 34ba8029f..f2d79c3ba 100644 --- a/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift +++ b/src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift @@ -10,71 +10,77 @@ extension LibKrbn { init(_ connectedDevice: ConnectedDevice) { self.connectedDevice = connectedDevice + updateProperties() + } + + public func updateProperties() { + didSetEnabled = false + let ignore = libkrbn_core_configuration_get_selected_profile_device_ignore( connectedDevice.libkrbnDeviceIdentifiers) modifyEvents = !ignore - self.manipulateCapsLockLed = + manipulateCapsLockLed = libkrbn_core_configuration_get_selected_profile_device_manipulate_caps_lock_led( connectedDevice.libkrbnDeviceIdentifiers) - self.treatAsBuiltInKeyboard = + treatAsBuiltInKeyboard = libkrbn_core_configuration_get_selected_profile_device_treat_as_built_in_keyboard( connectedDevice.libkrbnDeviceIdentifiers) - self.disableBuiltInKeyboardIfExists = + disableBuiltInKeyboardIfExists = libkrbn_core_configuration_get_selected_profile_device_disable_built_in_keyboard_if_exists( connectedDevice.libkrbnDeviceIdentifiers) - self.mouseFlipX = + mouseFlipX = libkrbn_core_configuration_get_selected_profile_device_mouse_flip_x( connectedDevice.libkrbnDeviceIdentifiers) - self.mouseFlipY = + mouseFlipY = libkrbn_core_configuration_get_selected_profile_device_mouse_flip_y( connectedDevice.libkrbnDeviceIdentifiers) - self.mouseFlipVerticalWheel = + mouseFlipVerticalWheel = libkrbn_core_configuration_get_selected_profile_device_mouse_flip_vertical_wheel( connectedDevice.libkrbnDeviceIdentifiers) - self.mouseFlipHorizontalWheel = + mouseFlipHorizontalWheel = libkrbn_core_configuration_get_selected_profile_device_mouse_flip_horizontal_wheel( connectedDevice.libkrbnDeviceIdentifiers) - self.mouseSwapXY = + mouseSwapXY = libkrbn_core_configuration_get_selected_profile_device_mouse_swap_xy( connectedDevice.libkrbnDeviceIdentifiers) - self.mouseSwapWheels = + mouseSwapWheels = libkrbn_core_configuration_get_selected_profile_device_mouse_swap_wheels( connectedDevice.libkrbnDeviceIdentifiers) - self.gamePadSwapSticks = + gamePadSwapSticks = libkrbn_core_configuration_get_selected_profile_device_game_pad_swap_sticks( connectedDevice.libkrbnDeviceIdentifiers) - self.gamePadXYStickContinuedMovementAbsoluteMagnitudeThreshold = + gamePadXYStickContinuedMovementAbsoluteMagnitudeThreshold = libkrbn_core_configuration_get_selected_profile_device_game_pad_xy_stick_continued_movement_absolute_magnitude_threshold( connectedDevice.libkrbnDeviceIdentifiers) - self.gamePadXYStickContinuedMovementIntervalMilliseconds = Int( + gamePadXYStickContinuedMovementIntervalMilliseconds = Int( libkrbn_core_configuration_get_selected_profile_device_game_pad_xy_stick_continued_movement_interval_milliseconds( connectedDevice.libkrbnDeviceIdentifiers)) - self.gamePadXYStickFlickingInputWindowMilliseconds = Int( + gamePadXYStickFlickingInputWindowMilliseconds = Int( libkrbn_core_configuration_get_selected_profile_device_game_pad_xy_stick_flicking_input_window_milliseconds( connectedDevice.libkrbnDeviceIdentifiers)) - self.gamePadWheelsStickContinuedMovementAbsoluteMagnitudeThreshold = + gamePadWheelsStickContinuedMovementAbsoluteMagnitudeThreshold = libkrbn_core_configuration_get_selected_profile_device_game_pad_wheels_stick_continued_movement_absolute_magnitude_threshold( connectedDevice.libkrbnDeviceIdentifiers) - self.gamePadWheelsStickContinuedMovementIntervalMilliseconds = Int( + gamePadWheelsStickContinuedMovementIntervalMilliseconds = Int( libkrbn_core_configuration_get_selected_profile_device_game_pad_wheels_stick_continued_movement_interval_milliseconds( connectedDevice.libkrbnDeviceIdentifiers)) - self.gamePadWheelsStickFlickingInputWindowMilliseconds = Int( + gamePadWheelsStickFlickingInputWindowMilliseconds = Int( libkrbn_core_configuration_get_selected_profile_device_game_pad_wheels_stick_flicking_input_window_milliseconds( connectedDevice.libkrbnDeviceIdentifiers)) @@ -83,28 +89,28 @@ extension LibKrbn { if libkrbn_core_configuration_get_selected_profile_device_game_pad_stick_x_formula( connectedDevice.libkrbnDeviceIdentifiers, &buffer, buffer.count) { - self.gamePadStickXFormula = String(cString: buffer).trimmingCharacters( + gamePadStickXFormula = String(cString: buffer).trimmingCharacters( in: .whitespacesAndNewlines) } if libkrbn_core_configuration_get_selected_profile_device_game_pad_stick_y_formula( connectedDevice.libkrbnDeviceIdentifiers, &buffer, buffer.count) { - self.gamePadStickYFormula = String(cString: buffer).trimmingCharacters( + gamePadStickYFormula = String(cString: buffer).trimmingCharacters( in: .whitespacesAndNewlines) } if libkrbn_core_configuration_get_selected_profile_device_game_pad_stick_vertical_wheel_formula( connectedDevice.libkrbnDeviceIdentifiers, &buffer, buffer.count) { - self.gamePadStickVerticalWheelFormula = String(cString: buffer).trimmingCharacters( + gamePadStickVerticalWheelFormula = String(cString: buffer).trimmingCharacters( in: .whitespacesAndNewlines) } if libkrbn_core_configuration_get_selected_profile_device_game_pad_stick_horizontal_wheel_formula( connectedDevice.libkrbnDeviceIdentifiers, &buffer, buffer.count) { - self.gamePadStickHorizontalWheelFormula = String(cString: buffer).trimmingCharacters( + gamePadStickHorizontalWheelFormula = String(cString: buffer).trimmingCharacters( in: .whitespacesAndNewlines) } @@ -319,6 +325,15 @@ extension LibKrbn { } } + public func resetGamePadStickXFormula() { + libkrbn_core_configuration_reset_selected_profile_device_game_pad_stick_x_formula( + connectedDevice.libkrbnDeviceIdentifiers) + + Settings.shared.save() + + updateProperties() + } + @Published var gamePadStickYFormula = "" { didSet { if didSetEnabled { @@ -332,6 +347,15 @@ extension LibKrbn { } } + public func resetGamePadStickYFormula() { + libkrbn_core_configuration_reset_selected_profile_device_game_pad_stick_y_formula( + connectedDevice.libkrbnDeviceIdentifiers) + + Settings.shared.save() + + updateProperties() + } + @Published var gamePadStickVerticalWheelFormula = "" { didSet { if didSetEnabled { @@ -345,6 +369,15 @@ extension LibKrbn { } } + public func resetGamePadStickVerticalWheelFormula() { + libkrbn_core_configuration_reset_selected_profile_device_game_pad_stick_vertical_wheel_formula( + connectedDevice.libkrbnDeviceIdentifiers) + + Settings.shared.save() + + updateProperties() + } + @Published var gamePadStickHorizontalWheelFormula = "" { didSet { if didSetEnabled { @@ -358,6 +391,15 @@ extension LibKrbn { } } + public func resetGamePadStickHorizontalWheelFormula() { + libkrbn_core_configuration_reset_selected_profile_device_game_pad_stick_horizontal_wheel_formula( + connectedDevice.libkrbnDeviceIdentifiers) + + Settings.shared.save() + + updateProperties() + } + @Published var simpleModifications: [SimpleModification] = [] @Published var fnFunctionKeys: [SimpleModification] = []