Skip to content

Commit

Permalink
Add resetGamePadStick*Formula
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jul 20, 2024
1 parent c3169c1 commit d47d5b4
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 24 deletions.
33 changes: 29 additions & 4 deletions src/apps/SettingsWindow/src/View/DevicesGamePadSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
82 changes: 62 additions & 20 deletions src/apps/share/swift/LibKrbn/Models/ConnectedDeviceSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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] = []

Expand Down

0 comments on commit d47d5b4

Please sign in to comment.