From a8d48325d5e6fe0466502b865c82317b6f7410a2 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Mon, 6 Sep 2021 23:24:51 -0400 Subject: get grapher building --- grapher/Models/Serialized/SettingsManager.cs | 118 +++++++++++++++------------ 1 file changed, 66 insertions(+), 52 deletions(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 346bc9b..d92f18a 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Text; using System.Drawing; using grapher.Models.Devices; +using System.Collections.Generic; namespace grapher.Models.Serialized { @@ -14,14 +15,13 @@ namespace grapher.Models.Serialized #region Constructors public SettingsManager( - ManagedAccel activeAccel, Field dpiField, Field pollRateField, ToolStripMenuItem autoWrite, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain, ToolStripMenuItem streamingMode, - DeviceIDManager deviceIDManager) + ToolStripMenuItem deviceMenuItem) { DpiField = dpiField; PollRateField = pollRateField; @@ -29,9 +29,14 @@ namespace grapher.Models.Serialized ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; StreamingModeMenuItem = streamingMode; - DeviceIDManager = deviceIDManager; + deviceMenuItem.Click += (s, e) => new DeviceMenuForm(this).ShowDialog(); - SetActiveFields(activeAccel); + SystemDevices = new List(); + ActiveHandles = new List(); + + // TODO - remove ActiveConfig/AutoWrite entirely? + // shouldn't be needed with internal profiles support + ActiveConfig = DriverConfig.GetActive(); GuiSettings = GUISettings.MaybeLoad(); @@ -45,7 +50,7 @@ namespace grapher.Models.Serialized UpdateFieldsFromGUISettings(); } - UserSettings = InitUserSettings(); + UserConfig = InitUserSettings(); } #endregion Constructors @@ -54,23 +59,39 @@ namespace grapher.Models.Serialized public GUISettings GuiSettings { get; private set; } - public ManagedAccel ActiveAccel { get; private set; } + public DriverConfig ActiveConfig { get; private set; } + + public Profile ActiveProfile + { + get => ActiveConfig.profiles[0]; + } - public ExtendedSettings ActiveSettings { get; private set; } + public ManagedAccel ActiveAccel + { + get => ActiveConfig.accels[0]; + } - public DriverSettings UserSettings { get; private set; } + public DriverConfig UserConfig { get; private set; } + + public Profile UserProfile + { + get => UserConfig.profiles[0]; + } public Field DpiField { get; private set; } public Field PollRateField { get; private set; } - public DeviceIDManager DeviceIDManager { get; } + public IList SystemDevices { get; private set; } + + public List ActiveHandles { get; private set; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } + private ToolStripMenuItem StreamingModeMenuItem{ get; set; } #endregion Properties @@ -78,10 +99,8 @@ namespace grapher.Models.Serialized public void DisableDriver() { - var defaultSettings = new ExtendedSettings(); - ActiveSettings = defaultSettings; - ActiveAccel.Settings = defaultSettings; - new Thread(() => ActiveAccel.Activate()).Start(); + ActiveConfig = DriverConfig.GetDefault(); + new Thread(() => DriverConfig.Deactivate()).Start(); } public void UpdateFieldsFromGUISettings() @@ -94,36 +113,31 @@ namespace grapher.Models.Serialized AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup; } - public SettingsErrors TryActivate(DriverSettings settings) + public bool TryActivate(DriverConfig settings, out string errors) { - var errors = new SettingsErrors(settings); + errors = settings.Errors(); - if (errors.Empty()) + if (errors == null) { GuiSettings = MakeGUISettingsFromFields(); GuiSettings.Save(); - UserSettings = settings; - File.WriteAllText(Constants.DefaultSettingsFileName, RaConvert.Settings(settings)); + UserConfig = settings; + ActiveConfig = settings; + File.WriteAllText(Constants.DefaultSettingsFileName, settings.ToJSON()); - ActiveSettings = new ExtendedSettings(settings); - ActiveAccel.Settings = ActiveSettings; - - new Thread(() => ActiveAccel.Activate()).Start(); + new Thread(() => ActiveConfig.Activate()).Start(); } - return errors; + return errors == null; } - public void SetHiddenOptions(DriverSettings settings) + public void SetHiddenOptions(Profile settings) { - settings.snap = UserSettings.snap; - settings.maximumSpeed = UserSettings.maximumSpeed; - settings.minimumSpeed = UserSettings.minimumSpeed; - settings.minimumTime = UserSettings.minimumTime; - settings.maximumTime = UserSettings.maximumTime; - settings.ignore = UserSettings.ignore; - settings.directionalMultipliers = UserSettings.directionalMultipliers; + settings.snap = UserProfile.snap; + settings.maximumSpeed = UserProfile.maximumSpeed; + settings.minimumSpeed = UserProfile.minimumSpeed; + settings.directionalMultipliers = UserProfile.directionalMultipliers; } public GUISettings MakeGUISettingsFromFields() @@ -139,31 +153,40 @@ namespace grapher.Models.Serialized }; } - public bool TableActive() + private void SetActiveHandles() + { + ActiveHandles.Clear(); + // TODO + foreach (var sysDev in SystemDevices) + { + ActiveHandles.AddRange(sysDev.handles); + } + } + + private void OnProfileSwitch() { - return ActiveSettings.tables.x != null || ActiveSettings.tables.y != null; + SetActiveHandles(); } - public void SetActiveFields(ManagedAccel activeAccel) + public void OnDeviceChangeMessage() { - ActiveAccel = activeAccel; - ActiveSettings = activeAccel.Settings; + SystemDevices = MultiHandleDevice.GetList(); + SetActiveHandles(); } - private DriverSettings InitUserSettings() + private DriverConfig InitUserSettings() { var path = Constants.DefaultSettingsFileName; if (File.Exists(path)) { try { - DriverSettings settings = RaConvert.Settings(File.ReadAllText(path)); + var (cfg, err) = DriverConfig.Convert(File.ReadAllText(path)); if (!GuiSettings.AutoWriteToDriverOnStartup || - TableActive() || - TryActivate(settings).Empty()) + (err == null && TryActivate(cfg, out string _))) { - return settings; + return cfg; } } @@ -173,17 +196,8 @@ namespace grapher.Models.Serialized } } - if (!TableActive()) - { - File.WriteAllText(path, RaConvert.Settings(ActiveSettings.baseSettings)); - return ActiveSettings.baseSettings; - } - else - { - var defaultSettings = new DriverSettings(); - File.WriteAllText(path, RaConvert.Settings(defaultSettings)); - return defaultSettings; - } + File.WriteAllText(path, ActiveConfig.ToJSON()); + return ActiveConfig; } #endregion Methods -- cgit v1.2.3 From 00d39102b469b459c5803fe1a20e52d8217add08 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 7 Sep 2021 19:53:00 -0400 Subject: update SettingsManager load active config from driver only when necessary ignore devices that aren't running the active profile (in mousewatcher) --- grapher/Models/Serialized/SettingsManager.cs | 97 +++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 16 deletions(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index d92f18a..3789c05 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -7,6 +7,7 @@ using System.Text; using System.Drawing; using grapher.Models.Devices; using System.Collections.Generic; +using System.Linq; namespace grapher.Models.Serialized { @@ -34,10 +35,6 @@ namespace grapher.Models.Serialized SystemDevices = new List(); ActiveHandles = new List(); - // TODO - remove ActiveConfig/AutoWrite entirely? - // shouldn't be needed with internal profiles support - ActiveConfig = DriverConfig.GetActive(); - GuiSettings = GUISettings.MaybeLoad(); if (GuiSettings is null) @@ -50,20 +47,39 @@ namespace grapher.Models.Serialized UpdateFieldsFromGUISettings(); } - UserConfig = InitUserSettings(); + UserConfig = InitActiveAndGetUserConfig(); } #endregion Constructors + #region Fields + + private DriverConfig ActiveConfigField; + + #endregion Fields + #region Properties public GUISettings GuiSettings { get; private set; } - public DriverConfig ActiveConfig { get; private set; } + public DriverConfig ActiveConfig + { + get => ActiveConfigField; + + private set + { + if (ActiveConfigField != value) + { + ActiveConfigField = value; + ActiveProfileNamesSet = new HashSet(value.profiles.Select(p => p.name)); + } + } + } public Profile ActiveProfile { - get => ActiveConfig.profiles[0]; + get => ActiveConfigField.profiles[0]; + private set => ActiveConfigField.SetProfileAt(0, value); } public ManagedAccel ActiveAccel @@ -78,13 +94,15 @@ namespace grapher.Models.Serialized get => UserConfig.profiles[0]; } + public HashSet ActiveProfileNamesSet { get; private set; } + public Field DpiField { get; private set; } public Field PollRateField { get; private set; } public IList SystemDevices { get; private set; } - public List ActiveHandles { get; private set; } + public List ActiveHandles { get; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } @@ -113,6 +131,18 @@ namespace grapher.Models.Serialized AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup; } + public bool TryActivate(Profile settings, out string errors) + { + var old = ActiveProfile; + ActiveProfile = settings; + bool success = TryActivate(ActiveConfig, out errors); + if (!success) + { + ActiveProfile = old; + } + return success; + } + public bool TryActivate(DriverConfig settings, out string errors) { errors = settings.Errors(); @@ -156,14 +186,38 @@ namespace grapher.Models.Serialized private void SetActiveHandles() { ActiveHandles.Clear(); - // TODO - foreach (var sysDev in SystemDevices) + + bool ActiveProfileIsFirst = ActiveProfile == ActiveConfig.profiles[0]; + + foreach (var dev in SystemDevices) MaybeAdd(dev); + + void MaybeAdd(MultiHandleDevice dev) { - ActiveHandles.AddRange(sysDev.handles); + foreach (var settings in ActiveConfig.devices) + { + if (settings.id == dev.id) + { + if (!settings.config.disable && + ((ActiveProfileIsFirst && + (string.IsNullOrEmpty(settings.profile) || + !ActiveProfileNamesSet.Contains(settings.profile))) || + ActiveProfile.name == settings.profile)) + { + ActiveHandles.AddRange(dev.handles); + } + + return; + } + } + + if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) + { + ActiveHandles.AddRange(dev.handles); + } } } - private void OnProfileSwitch() + public void OnProfileSelectionChange() { SetActiveHandles(); } @@ -174,7 +228,7 @@ namespace grapher.Models.Serialized SetActiveHandles(); } - private DriverConfig InitUserSettings() + private DriverConfig InitActiveAndGetUserConfig() { var path = Constants.DefaultSettingsFileName; if (File.Exists(path)) @@ -183,12 +237,22 @@ namespace grapher.Models.Serialized { var (cfg, err) = DriverConfig.Convert(File.ReadAllText(path)); - if (!GuiSettings.AutoWriteToDriverOnStartup || - (err == null && TryActivate(cfg, out string _))) + if (err == null) { + if (GuiSettings.AutoWriteToDriverOnStartup) + { + if (!TryActivate(cfg, out string _)) + { + throw new Exception("deserialization succeeded but TryActivate failed"); + } + } + else + { + ActiveConfig = DriverConfig.GetActive(); + } + return cfg; } - } catch (JsonException e) { @@ -196,6 +260,7 @@ namespace grapher.Models.Serialized } } + ActiveConfig = DriverConfig.GetActive(); File.WriteAllText(path, ActiveConfig.ToJSON()); return ActiveConfig; } -- cgit v1.2.3 From 7c0305ae2c99c191baf61eb920025826057d5753 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Wed, 15 Sep 2021 06:41:57 -0400 Subject: add device menu --- grapher/Models/Serialized/SettingsManager.cs | 67 +++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 11 deletions(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 3789c05..8c8bf15 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -21,8 +21,7 @@ namespace grapher.Models.Serialized ToolStripMenuItem autoWrite, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain, - ToolStripMenuItem streamingMode, - ToolStripMenuItem deviceMenuItem) + ToolStripMenuItem streamingMode) { DpiField = dpiField; PollRateField = pollRateField; @@ -30,7 +29,6 @@ namespace grapher.Models.Serialized ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; StreamingModeMenuItem = streamingMode; - deviceMenuItem.Click += (s, e) => new DeviceMenuForm(this).ShowDialog(); SystemDevices = new List(); ActiveHandles = new List(); @@ -47,14 +45,17 @@ namespace grapher.Models.Serialized UpdateFieldsFromGUISettings(); } - UserConfig = InitActiveAndGetUserConfig(); + UserConfigField = InitActiveAndGetUserConfig(); } #endregion Constructors #region Fields + private EventHandler DeviceChangeField; + private DriverConfig ActiveConfigField; + private DriverConfig UserConfigField; #endregion Fields @@ -62,6 +63,12 @@ namespace grapher.Models.Serialized public GUISettings GuiSettings { get; private set; } + public event EventHandler DeviceChange + { + add => DeviceChangeField += value; + remove => DeviceChangeField -= value; + } + public DriverConfig ActiveConfig { get => ActiveConfigField; @@ -87,11 +94,16 @@ namespace grapher.Models.Serialized get => ActiveConfig.accels[0]; } - public DriverConfig UserConfig { get; private set; } + public DriverConfig UserConfig + { + get => UserConfigField; + private set => UserConfigField = value; + } public Profile UserProfile { - get => UserConfig.profiles[0]; + get => UserConfigField.profiles[0]; + private set => UserConfigField.SetProfileAt(0, value); } public HashSet ActiveProfileNamesSet { get; private set; } @@ -133,12 +145,12 @@ namespace grapher.Models.Serialized public bool TryActivate(Profile settings, out string errors) { - var old = ActiveProfile; - ActiveProfile = settings; - bool success = TryActivate(ActiveConfig, out errors); + var old = UserProfile; + UserProfile = settings; + bool success = TryActivate(UserConfig, out errors); if (!success) { - ActiveProfile = old; + UserProfile = old; } return success; } @@ -183,7 +195,7 @@ namespace grapher.Models.Serialized }; } - private void SetActiveHandles() + public void SetActiveHandles() { ActiveHandles.Clear(); @@ -217,6 +229,37 @@ namespace grapher.Models.Serialized } } + public void Submit(DeviceConfig newDefaultConfig, DeviceDialogItem[] items) + { + UserConfig.defaultDeviceConfig = newDefaultConfig; + foreach (var item in items) + { + if (item.overrideDefaultConfig) + { + if (item.oldSettings is null) + { + UserConfig.devices.Add( + new DeviceSettings + { + name = item.device.name, + profile = item.newProfile, + id = item.device.id, + config = item.newConfig + }); + } + else + { + item.oldSettings.config = item.newConfig; + item.oldSettings.profile = item.newProfile; + } + } + else if (!(item.oldSettings is null)) + { + UserConfig.devices.Remove(item.oldSettings); + } + } + } + public void OnProfileSelectionChange() { SetActiveHandles(); @@ -226,6 +269,8 @@ namespace grapher.Models.Serialized { SystemDevices = MultiHandleDevice.GetList(); SetActiveHandles(); + + DeviceChangeField?.Invoke(this, EventArgs.Empty); } private DriverConfig InitActiveAndGetUserConfig() -- cgit v1.2.3 From 62d9e1da9cfb5b1b85f8d6d4a7efc8828bbb1e8b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 16 Sep 2021 21:15:56 -0400 Subject: refactor SetActiveHandles method --- grapher/Models/Serialized/SettingsManager.cs | 30 +++++++++++----------------- 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 8c8bf15..cb42c4e 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -201,30 +201,24 @@ namespace grapher.Models.Serialized bool ActiveProfileIsFirst = ActiveProfile == ActiveConfig.profiles[0]; - foreach (var dev in SystemDevices) MaybeAdd(dev); - - void MaybeAdd(MultiHandleDevice dev) + foreach (var sysDev in SystemDevices) { - foreach (var settings in ActiveConfig.devices) + var settings = ActiveConfig.devices.Find(d => d.id == sysDev.id); + + if (settings is null) { - if (settings.id == dev.id) + if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) { - if (!settings.config.disable && - ((ActiveProfileIsFirst && - (string.IsNullOrEmpty(settings.profile) || - !ActiveProfileNamesSet.Contains(settings.profile))) || - ActiveProfile.name == settings.profile)) - { - ActiveHandles.AddRange(dev.handles); - } - - return; + ActiveHandles.AddRange(sysDev.handles); } } - - if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) + else if (!settings.config.disable && + ((ActiveProfileIsFirst && + (string.IsNullOrEmpty(settings.profile) || + !ActiveProfileNamesSet.Contains(settings.profile))) || + ActiveProfile.name == settings.profile)) { - ActiveHandles.AddRange(dev.handles); + ActiveHandles.AddRange(sysDev.handles); } } } -- cgit v1.2.3 From 94ce1542b03090b81a4250f7f799895c58ab286c Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 18 Sep 2021 05:34:59 -0400 Subject: rename directional multipliers changes profile layout --- grapher/Models/Serialized/SettingsManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index cb42c4e..aac0f3e 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -179,7 +179,8 @@ namespace grapher.Models.Serialized settings.snap = UserProfile.snap; settings.maximumSpeed = UserProfile.maximumSpeed; settings.minimumSpeed = UserProfile.minimumSpeed; - settings.directionalMultipliers = UserProfile.directionalMultipliers; + settings.lrSensRatio = UserProfile.lrSensRatio; + settings.udSensRatio = UserProfile.udSensRatio; } public GUISettings MakeGUISettingsFromFields() -- cgit v1.2.3 From fdab3cf830e1bf87bc0bd3b72339be14265c7338 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 20 Sep 2021 23:41:36 -0700 Subject: Change disable button to reset, update doc text --- grapher/Models/Serialized/SettingsManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index aac0f3e..1c8608f 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -127,7 +127,7 @@ namespace grapher.Models.Serialized #region Methods - public void DisableDriver() + public void ResetDriver() { ActiveConfig = DriverConfig.GetDefault(); new Thread(() => DriverConfig.Deactivate()).Start(); -- cgit v1.2.3 From 79c6a885fc732a0fff0fe694a86ed6450b00794b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 23 Sep 2021 00:21:57 -0400 Subject: add indicator to last move on normalized dev read --- grapher/Models/Serialized/SettingsManager.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'grapher/Models/Serialized') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 1c8608f..43550c5 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -31,7 +31,7 @@ namespace grapher.Models.Serialized StreamingModeMenuItem = streamingMode; SystemDevices = new List(); - ActiveHandles = new List(); + ActiveNormTaggedHandles = new List<(IntPtr, bool)>(); GuiSettings = GUISettings.MaybeLoad(); @@ -114,7 +114,7 @@ namespace grapher.Models.Serialized public IList SystemDevices { get; private set; } - public List ActiveHandles { get; } + public List<(IntPtr, bool)> ActiveNormTaggedHandles { get; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } @@ -198,19 +198,24 @@ namespace grapher.Models.Serialized public void SetActiveHandles() { - ActiveHandles.Clear(); + ActiveNormTaggedHandles.Clear(); bool ActiveProfileIsFirst = ActiveProfile == ActiveConfig.profiles[0]; foreach (var sysDev in SystemDevices) { + void AddHandlesFromSysDev(bool normalized) + { + ActiveNormTaggedHandles.AddRange(sysDev.handles.Select(h => (h, normalized))); + } + var settings = ActiveConfig.devices.Find(d => d.id == sysDev.id); if (settings is null) { if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) { - ActiveHandles.AddRange(sysDev.handles); + AddHandlesFromSysDev(ActiveConfig.defaultDeviceConfig.dpi > 0); } } else if (!settings.config.disable && @@ -219,7 +224,7 @@ namespace grapher.Models.Serialized !ActiveProfileNamesSet.Contains(settings.profile))) || ActiveProfile.name == settings.profile)) { - ActiveHandles.AddRange(sysDev.handles); + AddHandlesFromSysDev(settings.config.dpi > 0); } } } -- cgit v1.2.3