2022-11-24 22:37:24 +01:00
|
|
|
|
using CommonHelpers;
|
|
|
|
|
|
using ExternalHelpers;
|
|
|
|
|
|
using SteamController.Profiles;
|
|
|
|
|
|
using System.ComponentModel;
|
2022-11-25 07:48:01 +01:00
|
|
|
|
using System.Diagnostics;
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
|
|
namespace SteamController
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class Controller : IDisposable
|
|
|
|
|
|
{
|
|
|
|
|
|
public const String Title = "Steam Controller";
|
|
|
|
|
|
public readonly String TitleWithVersion = Title + " v" + Application.ProductVersion.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
Container components = new Container();
|
|
|
|
|
|
NotifyIcon notifyIcon;
|
|
|
|
|
|
StartupManager startupManager = new StartupManager(Title);
|
|
|
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
|
Context context = new Context()
|
|
|
|
|
|
{
|
|
|
|
|
|
Profiles = {
|
2022-11-25 21:28:43 +01:00
|
|
|
|
new Profiles.DesktopProfile() { Name = "Desktop" },
|
|
|
|
|
|
new Profiles.SteamProfile() { Name = "Steam", Visible = false },
|
|
|
|
|
|
new Profiles.SteamWithShorcutsProfile() { Name = "Steam with Shortcuts", Visible = false },
|
|
|
|
|
|
new Profiles.X360Profile() { Name = "X360" },
|
|
|
|
|
|
new Profiles.X360RumbleProfile() { Name = "X360 with Rumble" }
|
2022-11-25 10:56:17 +01:00
|
|
|
|
},
|
|
|
|
|
|
Managers = {
|
|
|
|
|
|
new Managers.ProcessManager(),
|
2022-11-29 21:39:54 +01:00
|
|
|
|
new Managers.SteamManager(),
|
|
|
|
|
|
new Managers.ProfileSwitcher()
|
2022-11-25 07:48:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-11-25 21:28:43 +01:00
|
|
|
|
SharedData<SteamControllerSetting> sharedData = SharedData<SteamControllerSetting>.CreateNew();
|
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
|
public Controller()
|
|
|
|
|
|
{
|
|
|
|
|
|
Instance.RunOnce(TitleWithVersion, "Global\\SteamController");
|
|
|
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
|
var contextMenu = new ContextMenuStrip(components);
|
|
|
|
|
|
|
|
|
|
|
|
var enabledItem = new ToolStripMenuItem("&Enabled");
|
2022-11-25 10:56:17 +01:00
|
|
|
|
enabledItem.Click += delegate { context.RequestEnable = !context.RequestEnable; };
|
|
|
|
|
|
contextMenu.Opening += delegate { enabledItem.Checked = context.RequestEnable; };
|
2022-11-25 07:48:01 +01:00
|
|
|
|
contextMenu.Items.Add(enabledItem);
|
2022-11-25 21:28:43 +01:00
|
|
|
|
contextMenu.Items.Add(new ToolStripSeparator());
|
2022-11-25 07:48:01 +01:00
|
|
|
|
|
2022-11-25 21:28:43 +01:00
|
|
|
|
foreach (var profile in context.Profiles)
|
2022-11-24 22:37:24 +01:00
|
|
|
|
{
|
2022-11-25 21:28:43 +01:00
|
|
|
|
if (profile.Name == "" || !profile.Visible)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
var profileItem = new ToolStripMenuItem(profile.Name);
|
2022-11-28 20:29:32 +01:00
|
|
|
|
profileItem.Click += delegate { context.SelectProfile(profile.Name); };
|
2022-11-28 23:43:46 +01:00
|
|
|
|
contextMenu.Opening += delegate { profileItem.Checked = context.CurrentProfile == profile; };
|
2022-11-25 21:28:43 +01:00
|
|
|
|
contextMenu.Items.Add(profileItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
|
contextMenu.Items.Add(new ToolStripSeparator());
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
2022-11-26 23:52:48 +01:00
|
|
|
|
#if DEBUG
|
2022-11-25 10:56:17 +01:00
|
|
|
|
var lizardMouseItem = new ToolStripMenuItem("Use Lizard &Mouse");
|
2022-11-25 21:28:43 +01:00
|
|
|
|
lizardMouseItem.Click += delegate { DefaultGuideShortcutsProfile.SteamModeLizardMouse = !DefaultGuideShortcutsProfile.SteamModeLizardMouse; };
|
|
|
|
|
|
contextMenu.Opening += delegate { lizardMouseItem.Checked = DefaultGuideShortcutsProfile.SteamModeLizardMouse; };
|
2022-11-25 10:56:17 +01:00
|
|
|
|
contextMenu.Items.Add(lizardMouseItem);
|
|
|
|
|
|
|
|
|
|
|
|
var lizardButtonsItem = new ToolStripMenuItem("Use Lizard &Buttons");
|
2022-11-25 21:28:43 +01:00
|
|
|
|
lizardButtonsItem.Click += delegate { DefaultGuideShortcutsProfile.SteamModeLizardButtons = !DefaultGuideShortcutsProfile.SteamModeLizardButtons; };
|
|
|
|
|
|
contextMenu.Opening += delegate { lizardButtonsItem.Checked = DefaultGuideShortcutsProfile.SteamModeLizardButtons; };
|
2022-11-25 10:56:17 +01:00
|
|
|
|
contextMenu.Items.Add(lizardButtonsItem);
|
|
|
|
|
|
|
|
|
|
|
|
contextMenu.Items.Add(new ToolStripSeparator());
|
2022-11-26 23:52:48 +01:00
|
|
|
|
#endif
|
2022-11-25 10:56:17 +01:00
|
|
|
|
|
2022-11-27 13:41:28 +01:00
|
|
|
|
AddSteamOptions(contextMenu);
|
2022-11-25 21:28:43 +01:00
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
|
if (startupManager.IsAvailable)
|
|
|
|
|
|
{
|
|
|
|
|
|
var startupItem = new ToolStripMenuItem("Run On Startup");
|
|
|
|
|
|
startupItem.Checked = startupManager.Startup;
|
2022-11-25 07:48:01 +01:00
|
|
|
|
startupItem.Click += delegate { startupItem.Checked = startupManager.Startup = !startupManager.Startup; };
|
2022-11-24 22:37:24 +01:00
|
|
|
|
contextMenu.Items.Add(startupItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-28 09:34:17 +01:00
|
|
|
|
var settingsItem = contextMenu.Items.Add("&Settings");
|
|
|
|
|
|
settingsItem.Click += Settings_Click;
|
|
|
|
|
|
|
|
|
|
|
|
contextMenu.Items.Add(new ToolStripSeparator());
|
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
|
var helpItem = contextMenu.Items.Add("&Help");
|
2022-11-28 09:34:17 +01:00
|
|
|
|
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"); };
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
|
|
contextMenu.Items.Add(new ToolStripSeparator());
|
|
|
|
|
|
|
|
|
|
|
|
var exitItem = contextMenu.Items.Add("&Exit");
|
2022-11-25 07:48:01 +01:00
|
|
|
|
exitItem.Click += delegate { Application.Exit(); };
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
|
|
notifyIcon = new NotifyIcon(components);
|
|
|
|
|
|
notifyIcon.Icon = Resources.microsoft_xbox_controller_off;
|
|
|
|
|
|
notifyIcon.Text = TitleWithVersion;
|
|
|
|
|
|
notifyIcon.Visible = true;
|
|
|
|
|
|
notifyIcon.ContextMenuStrip = contextMenu;
|
|
|
|
|
|
|
|
|
|
|
|
var contextStateUpdate = new System.Windows.Forms.Timer(components);
|
|
|
|
|
|
contextStateUpdate.Interval = 250;
|
|
|
|
|
|
contextStateUpdate.Enabled = true;
|
|
|
|
|
|
contextStateUpdate.Tick += ContextStateUpdate_Tick;
|
|
|
|
|
|
|
2022-11-28 23:43:46 +01:00
|
|
|
|
context.SelectDefault = () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
context.SelectProfile(Settings.Default.StartupProfile);
|
|
|
|
|
|
};
|
|
|
|
|
|
context.BackToDefault();
|
|
|
|
|
|
|
2022-11-26 14:27:21 +01:00
|
|
|
|
context.ProfileChanged += (profile) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
#if false
|
|
|
|
|
|
notifyIcon.ShowBalloonTip(
|
|
|
|
|
|
1000,
|
|
|
|
|
|
TitleWithVersion,
|
|
|
|
|
|
String.Format("Selected profile: {0}", profile.Name),
|
|
|
|
|
|
ToolTipIcon.Info
|
|
|
|
|
|
);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-12-02 11:10:58 +01:00
|
|
|
|
context.Start();
|
2022-11-24 22:37:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-25 21:28:43 +01:00
|
|
|
|
private void SharedData_Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sharedData.GetValue(out var value) && value.DesiredProfile != "")
|
|
|
|
|
|
{
|
2022-11-26 12:15:38 +01:00
|
|
|
|
context.SelectProfile(value.DesiredProfile);
|
2022-11-25 21:28:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sharedData.SetValue(new SteamControllerSetting()
|
|
|
|
|
|
{
|
2022-11-28 23:43:46 +01:00
|
|
|
|
CurrentProfile = context.CurrentProfile?.Name ?? "",
|
2022-11-25 21:28:43 +01:00
|
|
|
|
SelectableProfiles = context.Profiles.Where((profile) => profile.Selected(context) || profile.Visible).JoinWithN((profile) => profile.Name),
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
|
private void ContextStateUpdate_Tick(object? sender, EventArgs e)
|
|
|
|
|
|
{
|
2022-11-28 20:29:32 +01:00
|
|
|
|
context.Tick();
|
|
|
|
|
|
SharedData_Update();
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
2022-11-28 23:43:46 +01:00
|
|
|
|
var isDesktop = context.CurrentProfile?.IsDesktop ?? false;
|
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
|
if (!context.Mouse.Valid)
|
|
|
|
|
|
{
|
2022-11-25 07:48:01 +01:00
|
|
|
|
notifyIcon.Text = TitleWithVersion + ". Cannot send input.";
|
2022-11-24 22:37:24 +01:00
|
|
|
|
notifyIcon.Icon = Resources.microsoft_xbox_controller_off_red;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!context.X360.Valid)
|
|
|
|
|
|
{
|
|
|
|
|
|
notifyIcon.Text = TitleWithVersion + ". Missing ViGEm?";
|
|
|
|
|
|
notifyIcon.Icon = Resources.microsoft_xbox_controller_red;
|
|
|
|
|
|
}
|
2022-11-25 07:48:01 +01:00
|
|
|
|
else if (context.Enabled)
|
|
|
|
|
|
{
|
2022-11-29 22:50:07 +01:00
|
|
|
|
if (context.State.SteamUsesSteamInput)
|
2022-11-27 13:41:28 +01:00
|
|
|
|
{
|
2022-11-28 23:43:46 +01:00
|
|
|
|
notifyIcon.Icon = isDesktop ? Resources.monitor_off : Resources.microsoft_xbox_controller_off;
|
2022-11-27 13:41:28 +01:00
|
|
|
|
notifyIcon.Text = TitleWithVersion + ". Steam uses Steam Input";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-11-28 23:43:46 +01:00
|
|
|
|
notifyIcon.Icon = isDesktop ? Resources.monitor : Resources.microsoft_xbox_controller;
|
2022-11-27 13:41:28 +01:00
|
|
|
|
notifyIcon.Text = TitleWithVersion;
|
|
|
|
|
|
}
|
2022-11-25 21:28:43 +01:00
|
|
|
|
|
2022-11-28 23:43:46 +01:00
|
|
|
|
var profile = context.CurrentProfile;
|
2022-11-25 21:28:43 +01:00
|
|
|
|
if (profile is not null)
|
|
|
|
|
|
notifyIcon.Text = TitleWithVersion + ". Profile: " + profile.Name;
|
2022-11-25 07:48:01 +01:00
|
|
|
|
}
|
2022-11-24 22:37:24 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-11-28 23:43:46 +01:00
|
|
|
|
notifyIcon.Icon = isDesktop ? Resources.monitor_off : Resources.microsoft_xbox_controller_off;
|
2022-11-25 07:48:01 +01:00
|
|
|
|
notifyIcon.Text = TitleWithVersion + ". Disabled";
|
2022-11-24 22:37:24 +01:00
|
|
|
|
}
|
2022-11-25 07:48:01 +01:00
|
|
|
|
|
2022-12-02 11:10:58 +01:00
|
|
|
|
notifyIcon.Text += String.Format(". Updates: {0}/s", context.UpdatesPerSec);
|
2022-11-24 22:37:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
2022-11-25 07:48:01 +01:00
|
|
|
|
notifyIcon.Visible = false;
|
2022-12-02 11:10:58 +01:00
|
|
|
|
context.Stop();
|
2022-11-24 22:37:24 +01:00
|
|
|
|
using (context) { }
|
|
|
|
|
|
}
|
2022-11-27 13:41:28 +01:00
|
|
|
|
|
|
|
|
|
|
private void AddSteamOptions(ContextMenuStrip contextMenu)
|
|
|
|
|
|
{
|
|
|
|
|
|
var ignoreSteamItem = new ToolStripMenuItem("&Ignore Steam");
|
|
|
|
|
|
ignoreSteamItem.ToolTipText = "Disable Steam detection. Ensures that neither Steam Controller or X360 Controller are not blacklisted.";
|
|
|
|
|
|
ignoreSteamItem.Click += delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
ConfigureSteam(
|
|
|
|
|
|
"This will enable Steam Controller and X360 Controller in Steam.",
|
|
|
|
|
|
false, false, false
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
contextMenu.Items.Add(ignoreSteamItem);
|
|
|
|
|
|
|
|
|
|
|
|
var useX360WithSteamItem = new ToolStripMenuItem("Use &X360 Controller with Steam");
|
|
|
|
|
|
useX360WithSteamItem.ToolTipText = "Hide Steam Deck Controller from Steam, and uses X360 controller instead.";
|
|
|
|
|
|
useX360WithSteamItem.Click += delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
ConfigureSteam(
|
|
|
|
|
|
"This will hide Steam Controller from Steam and use X360 Controller for all games.",
|
|
|
|
|
|
true, true, false
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
contextMenu.Items.Add(useX360WithSteamItem);
|
|
|
|
|
|
|
|
|
|
|
|
var useSteamInputItem = new ToolStripMenuItem("Use &Steam Input with Steam");
|
|
|
|
|
|
useSteamInputItem.ToolTipText = "Uses Steam Input and hides X360 Controller from Steam. Requires disabling ALL Steam Desktop Mode shortcuts.";
|
|
|
|
|
|
useSteamInputItem.Click += delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
ConfigureSteam(
|
|
|
|
|
|
"This will hide X360 Controller from Steam, and will try to detect Steam presence " +
|
|
|
|
|
|
"to disable usage of this application when running Steam Games.\n\n" +
|
|
|
|
|
|
"This does REQUIRE disabling DESKTOP MODE shortcuts in Steam.\n" +
|
|
|
|
|
|
"Follow guide found at https://github.com/ayufan/steam-deck-tools.",
|
|
|
|
|
|
true, false, true
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
contextMenu.Items.Add(useSteamInputItem);
|
|
|
|
|
|
|
|
|
|
|
|
var steamSeparatorItem = new ToolStripSeparator();
|
|
|
|
|
|
contextMenu.Items.Add(steamSeparatorItem);
|
|
|
|
|
|
|
|
|
|
|
|
contextMenu.Opening += delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
var blacklistedSteamController = Helpers.SteamConfiguration.IsControllerBlacklisted(
|
|
|
|
|
|
Devices.SteamController.VendorID,
|
|
|
|
|
|
Devices.SteamController.ProductID
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
ignoreSteamItem.Visible = blacklistedSteamController is not null;
|
|
|
|
|
|
useX360WithSteamItem.Visible = blacklistedSteamController is not null;
|
|
|
|
|
|
steamSeparatorItem.Visible = blacklistedSteamController is not null;
|
|
|
|
|
|
useSteamInputItem.Visible = blacklistedSteamController is not null;
|
|
|
|
|
|
|
|
|
|
|
|
ignoreSteamItem.Checked = !Settings.Default.EnableSteamDetection || blacklistedSteamController == null;
|
|
|
|
|
|
useX360WithSteamItem.Checked = Settings.Default.EnableSteamDetection && blacklistedSteamController == true;
|
|
|
|
|
|
useSteamInputItem.Checked = Settings.Default.EnableSteamDetection && blacklistedSteamController == false;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ConfigureSteam(String message, bool steamDetection, bool blacklistSteamController, bool blacklistX360Controller)
|
|
|
|
|
|
{
|
|
|
|
|
|
String text;
|
|
|
|
|
|
|
|
|
|
|
|
text = "This will change Steam configuration.\n\n";
|
|
|
|
|
|
text += "Close Steam before confirming as otherwise Steam will be forcefully closed.\n\n";
|
|
|
|
|
|
text += message;
|
|
|
|
|
|
|
|
|
|
|
|
var result = MessageBox.Show(
|
|
|
|
|
|
text,
|
|
|
|
|
|
TitleWithVersion,
|
|
|
|
|
|
MessageBoxButtons.OKCancel,
|
|
|
|
|
|
MessageBoxIcon.Exclamation
|
|
|
|
|
|
);
|
|
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
Helpers.SteamConfiguration.KillSteam();
|
|
|
|
|
|
Helpers.SteamConfiguration.WaitForSteamClose(5000);
|
|
|
|
|
|
Helpers.SteamConfiguration.BackupSteamConfig();
|
|
|
|
|
|
var steamControllerUpdate = Helpers.SteamConfiguration.UpdateControllerBlacklist(
|
|
|
|
|
|
Devices.SteamController.VendorID,
|
|
|
|
|
|
Devices.SteamController.ProductID,
|
|
|
|
|
|
blacklistSteamController
|
|
|
|
|
|
);
|
|
|
|
|
|
var x360ControllerUpdate = Helpers.SteamConfiguration.UpdateControllerBlacklist(
|
|
|
|
|
|
Devices.Xbox360Controller.VendorID,
|
|
|
|
|
|
Devices.Xbox360Controller.ProductID,
|
|
|
|
|
|
blacklistX360Controller
|
|
|
|
|
|
);
|
|
|
|
|
|
Settings.Default.EnableSteamDetection = steamDetection;
|
|
|
|
|
|
Settings.Default.Save();
|
|
|
|
|
|
|
|
|
|
|
|
if (steamControllerUpdate && x360ControllerUpdate)
|
|
|
|
|
|
{
|
|
|
|
|
|
notifyIcon.ShowBalloonTip(
|
|
|
|
|
|
3000, TitleWithVersion,
|
|
|
|
|
|
"Steam Configuration changed. You can start Steam now.",
|
|
|
|
|
|
ToolTipIcon.Info
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
notifyIcon.ShowBalloonTip(
|
|
|
|
|
|
3000, TitleWithVersion,
|
|
|
|
|
|
"Steam Configuration was not updated. Maybe Steam is open?",
|
|
|
|
|
|
ToolTipIcon.Warning
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-28 09:34:17 +01:00
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
2022-11-24 22:37:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|