From 68f51ff4f0af01b4ee14e192a1fddf6dada96122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Mon, 28 Nov 2022 09:34:17 +0100 Subject: [PATCH] Add configurable BackPanel keys (allowed mappings are subject to change) --- RELEASE.md | 1 + SteamController/Controller.cs | 35 +++++++++++- SteamController/Devices/KeyboardController.cs | 3 + .../DefaultBackPanelShortcutsProfile.cs | 29 ++++++++++ SteamController/Profiles/DesktopProfile.cs | 7 ++- SteamController/Profiles/X360Profile.cs | 7 ++- SteamController/Profiles/X360RumbleProfile.cs | 14 ++++- .../ProfilesSettings/BackPanelSettings.cs | 57 +++++++++++++++++++ .../ProfilesSettings/BaseSettings.cs | 23 ++++++++ .../ProfilesSettings/X360RumbleSettings.cs | 44 ++++++++++++++ 10 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs create mode 100644 SteamController/ProfilesSettings/BackPanelSettings.cs create mode 100644 SteamController/ProfilesSettings/BaseSettings.cs create mode 100644 SteamController/ProfilesSettings/X360RumbleSettings.cs diff --git a/RELEASE.md b/RELEASE.md index 534bad8..df6f926 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -27,3 +27,4 @@ It does help this project on being supported. - Fix detection of SAS to switch into full lizard - STEAM + 3 dots brings Task Manager (CTRL+SHIFT+ESCAPE) - Append `controller_blacklist` to `config.vdf` if missing +- Add configurable BackPanel keys (allowed mappings are subject to change) diff --git a/SteamController/Controller.cs b/SteamController/Controller.cs index 579ecdb..88a5b8a 100644 --- a/SteamController/Controller.cs +++ b/SteamController/Controller.cs @@ -92,8 +92,16 @@ namespace SteamController contextMenu.Items.Add(startupItem); } + var settingsItem = contextMenu.Items.Add("&Settings"); + settingsItem.Click += Settings_Click; + + contextMenu.Items.Add(new ToolStripSeparator()); + var helpItem = contextMenu.Items.Add("&Help"); - helpItem.Click += delegate { Process.Start("explorer.exe", "http://github.com/ayufan-research/steam-deck-tools"); }; + helpItem.Click += delegate { Process.Start("explorer.exe", "http://github.com/ayufan/steam-deck-tools"); }; + + var mappingItem = contextMenu.Items.Add("&Mappings"); + mappingItem.Click += delegate { Process.Start("explorer.exe", "https://github.com/ayufan/steam-deck-tools#42-mappings"); }; contextMenu.Items.Add(new ToolStripSeparator()); @@ -338,5 +346,30 @@ namespace SteamController ); } } + + private void Settings_Click(object? sender, EventArgs e) + { + var form = new Form() + { + Text = TitleWithVersion + " Settings", + StartPosition = FormStartPosition.CenterScreen, + Size = new Size(400, 600) + }; + + var propertyGrid = new PropertyGrid() + { + Dock = DockStyle.Fill, + SelectedObject = new + { + Desktop = ProfilesSettings.BackPanelSettings.Desktop, + X360 = ProfilesSettings.BackPanelSettings.X360, + X360Rumble = ProfilesSettings.X360RumbleSettings.Default + } + }; + + propertyGrid.ExpandAllGridItems(); + form.Controls.Add(propertyGrid); + form.ShowDialog(); + } } } diff --git a/SteamController/Devices/KeyboardController.cs b/SteamController/Devices/KeyboardController.cs index 0b8665f..442d9f8 100644 --- a/SteamController/Devices/KeyboardController.cs +++ b/SteamController/Devices/KeyboardController.cs @@ -26,6 +26,9 @@ namespace SteamController.Devices get { return keyCodes.ContainsKey(button); } set { + if (button == VirtualKeyCode.None) + return; + if (value) { if (keyCodes.ContainsKey(button)) diff --git a/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs b/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs new file mode 100644 index 0000000..f6decda --- /dev/null +++ b/SteamController/Profiles/DefaultBackPanelShortcutsProfile.cs @@ -0,0 +1,29 @@ +namespace SteamController.Profiles +{ + public abstract class DefaultBackPanelShortcutsProfile : DefaultGuideShortcutsProfile + { + internal abstract ProfilesSettings.BackPanelSettings BackPanelSettings { get; } + + public override Status Run(Context c) + { + if (base.Run(c).IsDone) + { + return Status.Done; + } + + BackPanelShortcuts(c); + + return Status.Continue; + } + + private void BackPanelShortcuts(Context c) + { + var settings = BackPanelSettings; + + c.Keyboard[settings.L4] = c.Steam.BtnL4; + c.Keyboard[settings.L5] = c.Steam.BtnL5; + c.Keyboard[settings.R4] = c.Steam.BtnR4; + c.Keyboard[settings.R5] = c.Steam.BtnR5; + } + } +} diff --git a/SteamController/Profiles/DesktopProfile.cs b/SteamController/Profiles/DesktopProfile.cs index e0ae8e3..f43337b 100644 --- a/SteamController/Profiles/DesktopProfile.cs +++ b/SteamController/Profiles/DesktopProfile.cs @@ -2,7 +2,7 @@ using WindowsInput; namespace SteamController.Profiles { - public sealed class DesktopProfile : DefaultGuideShortcutsProfile + public sealed class DesktopProfile : DefaultBackPanelShortcutsProfile { private const String Consumed = "DesktopProfileOwner"; @@ -11,6 +11,11 @@ namespace SteamController.Profiles IsDesktop = true; } + internal override ProfilesSettings.BackPanelSettings BackPanelSettings + { + get { return ProfilesSettings.BackPanelSettings.Desktop; } + } + public override bool Selected(Context context) { return context.Enabled && context.DesktopMode; diff --git a/SteamController/Profiles/X360Profile.cs b/SteamController/Profiles/X360Profile.cs index 411d71f..f51753c 100644 --- a/SteamController/Profiles/X360Profile.cs +++ b/SteamController/Profiles/X360Profile.cs @@ -2,13 +2,18 @@ using Nefarius.ViGEm.Client.Targets.Xbox360; namespace SteamController.Profiles { - public class X360Profile : DefaultGuideShortcutsProfile + public class X360Profile : DefaultBackPanelShortcutsProfile { public override bool Selected(Context context) { return context.Enabled && !context.DesktopMode && !context.SteamUsesSteamInput; } + internal override ProfilesSettings.BackPanelSettings BackPanelSettings + { + get { return ProfilesSettings.BackPanelSettings.Desktop; } + } + public override Status Run(Context context) { context.Steam.LizardButtons = false; diff --git a/SteamController/Profiles/X360RumbleProfile.cs b/SteamController/Profiles/X360RumbleProfile.cs index fb1bbf0..95da882 100644 --- a/SteamController/Profiles/X360RumbleProfile.cs +++ b/SteamController/Profiles/X360RumbleProfile.cs @@ -9,6 +9,11 @@ namespace SteamController.Profiles public const ushort FeedbackPeriod = 10; public const ushort FeedbackCount = 1; + private ProfilesSettings.X360RumbleSettings RumbleSettings + { + get { return ProfilesSettings.X360RumbleSettings.Default; } + } + public override Status Run(Context context) { if (base.Run(context).IsDone) @@ -20,14 +25,14 @@ namespace SteamController.Profiles { Log.TraceLine("X360: Feedback Large: {0}", context.X360.FeedbackLargeMotor.Value); context.Steam.SetHaptic( - 1, GetHapticAmplitude(context.X360.FeedbackLargeMotor), FeedbackPeriod, FeedbackCount); + 1, GetHapticAmplitude(context.X360.FeedbackLargeMotor), RumbleSettings.Period, FeedbackCount); } if (context.X360.FeedbackSmallMotor.HasValue) { Log.TraceLine("X360: Feedback Small: {0}", context.X360.FeedbackSmallMotor.Value); context.Steam.SetHaptic( - 0, GetHapticAmplitude(context.X360.FeedbackSmallMotor), FeedbackPeriod, FeedbackCount); + 0, GetHapticAmplitude(context.X360.FeedbackSmallMotor), RumbleSettings.Period, FeedbackCount); } context.X360.ResetFeedback(); @@ -37,7 +42,10 @@ namespace SteamController.Profiles private ushort GetHapticAmplitude(byte? value) { - return (ushort)(FeedbackMaxAmplitude * (value ?? 0) / byte.MaxValue); + if (RumbleSettings.FixedAmplitude > 0) + return value is not null ? (ushort)RumbleSettings.FixedAmplitude : (ushort)0; + else + return (ushort)(RumbleSettings.MaxAmplitude * (value ?? 0) / byte.MaxValue); } } } diff --git a/SteamController/ProfilesSettings/BackPanelSettings.cs b/SteamController/ProfilesSettings/BackPanelSettings.cs new file mode 100644 index 0000000..7ed0403 --- /dev/null +++ b/SteamController/ProfilesSettings/BackPanelSettings.cs @@ -0,0 +1,57 @@ +using System.ComponentModel; +using System.Configuration; +using WindowsInput; + +namespace SteamController.ProfilesSettings +{ + [Category("Mappings")] + internal sealed class BackPanelSettings : BaseSettings + { + private const String MappingsDescription = @"Only some of those keys do work. Allowed mappings are to be changed in future release."; + + public static BackPanelSettings X360 { get; } = (BackPanelSettings)ApplicationSettingsBase.Synchronized( + new BackPanelSettings("X360BackPanelSettings")); + public static BackPanelSettings Desktop { get; } = (BackPanelSettings)ApplicationSettingsBase.Synchronized( + new BackPanelSettings("DesktopBackPanelSettings")); + + public BackPanelSettings(String settingsKey) : base(settingsKey) + { + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualKeyCode L4 + { + get { return ((VirtualKeyCode)(this["L4"])); } + set { this["L4"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualKeyCode L5 + { + get { return ((VirtualKeyCode)(this["L5"])); } + set { this["L5"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualKeyCode R4 + { + get { return ((VirtualKeyCode)(this["R4"])); } + set { this["R4"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("None")] + [Description(MappingsDescription)] + public VirtualKeyCode R5 + { + get { return ((VirtualKeyCode)(this["R5"])); } + set { this["R5"] = value; } + } + } +} \ No newline at end of file diff --git a/SteamController/ProfilesSettings/BaseSettings.cs b/SteamController/ProfilesSettings/BaseSettings.cs new file mode 100644 index 0000000..d8ef376 --- /dev/null +++ b/SteamController/ProfilesSettings/BaseSettings.cs @@ -0,0 +1,23 @@ +using System.ComponentModel; +using System.Configuration; +using WindowsInput; + +namespace SteamController.ProfilesSettings +{ + [TypeConverter(typeof(ExpandableObjectConverter))] + internal abstract class BaseSettings : ApplicationSettingsBase + { + public BaseSettings(String settingsKey) : base(settingsKey) + { + PropertyChanged += delegate + { + Save(); + }; + } + + public override string ToString() + { + return ""; + } + } +} \ No newline at end of file diff --git a/SteamController/ProfilesSettings/X360RumbleSettings.cs b/SteamController/ProfilesSettings/X360RumbleSettings.cs new file mode 100644 index 0000000..12b529c --- /dev/null +++ b/SteamController/ProfilesSettings/X360RumbleSettings.cs @@ -0,0 +1,44 @@ +using System.ComponentModel; +using System.Configuration; +using WindowsInput; + +namespace SteamController.ProfilesSettings +{ + [Category("Settings")] + internal sealed class X360RumbleSettings : BaseSettings + { + public static X360RumbleSettings Default { get; } = (X360RumbleSettings)ApplicationSettingsBase.Synchronized( + new X360RumbleSettings("X360RumbleSettings")); + + public X360RumbleSettings(String settingsKey) : base(settingsKey) + { + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("0")] + [Description("Use Fixed Amplitude when configured. Set to 0 to disable")] + public byte FixedAmplitude + { + get { return ((byte)(this["FixedAmplitude"])); } + set { this["FixedAmplitude"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("255")] + [Description("Scale rumble intensity up to Maximum Amplitude based on feedback request received")] + public byte MaxAmplitude + { + get { return ((byte)(this["MaxAmplitude"])); } + set { this["MaxAmplitude"] = value; } + } + + [UserScopedSettingAttribute()] + [DefaultSettingValueAttribute("10")] + [Description("Rumble feedback period")] + public byte Period + { + get { return ((byte)(this["Period"])); } + set { this["Period"] = value; } + } + } +}