Add configurable BackPanel keys (allowed mappings are subject to change)

This commit is contained in:
Kamil Trzciński 2022-11-28 09:34:17 +01:00
parent 8c26efa334
commit 68f51ff4f0
10 changed files with 214 additions and 6 deletions

View file

@ -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)

View file

@ -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();
}
}
}

View file

@ -26,6 +26,9 @@ namespace SteamController.Devices
get { return keyCodes.ContainsKey(button); }
set
{
if (button == VirtualKeyCode.None)
return;
if (value)
{
if (keyCodes.ContainsKey(button))

View file

@ -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;
}
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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; }
}
}
}

View file

@ -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 "";
}
}
}

View file

@ -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; }
}
}
}