Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pointing_motion_xy_multiplier, pointing_motion_wheels_multiplier #4081

Merged
merged 11 commits into from
Dec 30, 2024
2 changes: 1 addition & 1 deletion src/apps/SettingsWindow/src/View/DeviceSelectorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct DeviceSelectorView: View {
Image(systemName: "keyboard")
}
if connectedDevice.isPointingDevice {
Image(systemName: "capsule.portrait")
Image(systemName: "computermouse")
}
if connectedDevice.isGamePad {
Image(systemName: "gamecontroller")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ struct DevicesGamePadSettingsView: View {
@ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting
@Binding var showing: Bool

@ObservedObject private var settings = LibKrbn.Settings.shared

var body: some View {
ZStack(alignment: .topLeading) {
VStack(alignment: .leading, spacing: 12.0) {
Expand Down Expand Up @@ -156,7 +154,7 @@ struct DevicesGamePadSettingsView: View {
@ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting

var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 40.0) {
HStack {
Toggle(isOn: $connectedDeviceSetting.gamePadSwapSticks) {
Text("Swap gamepad XY and wheels sticks")
Expand All @@ -166,6 +164,8 @@ struct DevicesGamePadSettingsView: View {
Spacer()
}

DevicesMouseFlagsView(connectedDeviceSetting: connectedDeviceSetting)

Spacer()
}
}
Expand Down
104 changes: 104 additions & 0 deletions src/apps/SettingsWindow/src/View/DevicesMouseFlagsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import SwiftUI

struct DevicesMouseFlagsView: View {
@ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting

var body: some View {
GroupBox(label: Text("Mouse Flags")) {
HStack(alignment: .top, spacing: 60.0) {
VStack(alignment: .leading, spacing: 6.0) {
Toggle(isOn: $connectedDeviceSetting.mouseFlipX) {
Text("Flip mouse X")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseFlipY) {
Text("Flip mouse Y")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseFlipVerticalWheel) {
Text("Flip mouse vertical wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseFlipHorizontalWheel) {
Text("Flip mouse horizontal wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 200.0)

VStack(alignment: .leading, spacing: 6.0) {
Toggle(isOn: $connectedDeviceSetting.mouseDiscardX) {
Text("Discard mouse X")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseDiscardY) {
Text("Discard mouse Y")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseDiscardVerticalWheel) {
Text("Discard mouse vertical wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseDiscardHorizontalWheel) {
Text("Discard mouse horizontal wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 220.0)

VStack(alignment: .leading, spacing: 6.0) {
Toggle(isOn: $connectedDeviceSetting.mouseSwapXY) {
Text("Swap mouse X and Y")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseSwapWheels) {
Text("Swap mouse wheels")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 160.0)
}
.padding()
}
}
}

struct DevicesMouseFlagsView_Previews: PreviewProvider {
@State static var connectedDevice = LibKrbn.ConnectedDevice(
index: 0,
manufacturerName: "",
productName: "",
transport: "",
vendorId: 0,
productId: 0,
deviceAddress: "",
isKeyboard: false,
isPointingDevice: true,
isGamePad: false,
isVirtualDevice: false,
isBuiltInKeyboard: false,
isAppleDevice: false
)
@State static var connectedDeviceSetting = LibKrbn.ConnectedDeviceSetting(connectedDevice)

static var previews: some View {
DevicesMouseFlagsView(connectedDeviceSetting: connectedDeviceSetting)
}
}
91 changes: 91 additions & 0 deletions src/apps/SettingsWindow/src/View/DevicesMouseSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import SwiftUI

struct DevicesMouseSettingsView: View {
@ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting
@Binding var showing: Bool

@ObservedObject private var settings = LibKrbn.Settings.shared

var body: some View {
ZStack(alignment: .topLeading) {
VStack(alignment: .leading, spacing: 40.0) {
Text(
"\(connectedDeviceSetting.connectedDevice.productName) (\(connectedDeviceSetting.connectedDevice.manufacturerName))"
)
.padding(.leading, 40)
.padding(.top, 20)

GroupBox(label: Text("Multiplier")) {
Grid(alignment: .leadingFirstTextBaseline) {
GridRow {
Text("XY movement multiplier:")

DoubleTextField(
value: $connectedDeviceSetting.pointingMotionXYMultiplier,
range: 0...10000,
step: 0.1,
maximumFractionDigits: 1,
width: 60)

Text(
"(Default: \(String(format: "%.01f", libkrbn_core_configuration_pointing_motion_xy_multiplier_default_value()))"
)
}

GridRow {
Text("Wheels multiplier:")

DoubleTextField(
value: $connectedDeviceSetting.pointingMotionWheelsMultiplier,
range: 0...10000,
step: 0.1,
maximumFractionDigits: 1,
width: 60)

Text(
"(Default: \(String(format: "%.01f", libkrbn_core_configuration_pointing_motion_wheels_multiplier_default_value()))"
)
}
}
.padding()
}

DevicesMouseFlagsView(connectedDeviceSetting: connectedDeviceSetting)

Spacer()
}

SheetCloseButton {
showing = false
}
}
.padding()
.frame(width: 1000, height: 600)
}
}

struct DevicesMouseSettingsView_Previews: PreviewProvider {
@State static var connectedDevice = LibKrbn.ConnectedDevice(
index: 0,
manufacturerName: "",
productName: "",
transport: "",
vendorId: 0,
productId: 0,
deviceAddress: "",
isKeyboard: false,
isPointingDevice: true,
isGamePad: false,
isVirtualDevice: false,
isBuiltInKeyboard: false,
isAppleDevice: false
)
@State static var connectedDeviceSetting = LibKrbn.ConnectedDeviceSetting(connectedDevice)
@State static var showing = true

static var previews: some View {
DevicesMouseSettingsView(
connectedDeviceSetting: connectedDeviceSetting,
showing: $showing)
}
}
100 changes: 18 additions & 82 deletions src/apps/SettingsWindow/src/View/DevicesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct DevicesView: View {
Image(systemName: "keyboard")
}
if connectedDevice.isPointingDevice {
Image(systemName: "capsule.portrait")
Image(systemName: "computermouse")
}
if connectedDevice.isGamePad {
Image(systemName: "gamecontroller")
Expand Down Expand Up @@ -241,91 +241,27 @@ struct DevicesView: View {

struct MouseSettings: View {
@ObservedObject var connectedDeviceSetting: LibKrbn.ConnectedDeviceSetting

@ObservedObject private var settings = LibKrbn.Settings.shared
@State var showing = false

var body: some View {
VStack {
if connectedDeviceSetting.connectedDevice.isPointingDevice
|| connectedDeviceSetting.connectedDevice.isGamePad
if connectedDeviceSetting.modifyEvents
&& connectedDeviceSetting.connectedDevice.isPointingDevice
{
if connectedDeviceSetting.modifyEvents {
HStack(alignment: .top, spacing: 15.0) {
VStack(alignment: .leading, spacing: 2.0) {
Toggle(isOn: $connectedDeviceSetting.mouseFlipX) {
Text("Flip mouse X")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseFlipY) {
Text("Flip mouse Y")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseFlipVerticalWheel) {
Text("Flip mouse vertical wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseFlipHorizontalWheel) {
Text("Flip mouse horizontal wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 200.0)

Divider()

VStack(alignment: .leading, spacing: 2.0) {
Toggle(isOn: $connectedDeviceSetting.mouseDiscardX) {
Text("Discard mouse X")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseDiscardY) {
Text("Discard mouse Y")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseDiscardVerticalWheel) {
Text("Discard mouse vertical wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseDiscardHorizontalWheel) {
Text("Discard mouse horizontal wheel")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 220.0)

Divider()

VStack(alignment: .leading, spacing: 2.0) {
Toggle(isOn: $connectedDeviceSetting.mouseSwapXY) {
Text("Swap mouse X and Y")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)

Toggle(isOn: $connectedDeviceSetting.mouseSwapWheels) {
Text("Swap mouse wheels")
.frame(maxWidth: .infinity, alignment: .leading)
}
.switchToggleStyle(controlSize: .mini, font: .callout)
}
.frame(width: 160.0)

Spacer()
Button(
action: {
showing = true
},
label: {
Label("Open mouse settings", systemImage: "computermouse")
.buttonLabelStyle()
}
)
.sheet(isPresented: $showing) {
DevicesMouseSettingsView(
connectedDeviceSetting: connectedDeviceSetting,
showing: $showing
)
}
}
}
Expand All @@ -338,7 +274,7 @@ struct DevicesView: View {

var body: some View {
VStack {
if connectedDeviceSetting.connectedDevice.isGamePad {
if connectedDeviceSetting.modifyEvents && connectedDeviceSetting.connectedDevice.isGamePad {
Button(
action: {
showing = true
Expand Down
Loading