From 2b6994a31e5584eb8c8955a1797e52b4dc869e5a Mon Sep 17 00:00:00 2001 From: hawku Date: Mon, 19 Mar 2018 20:20:58 +0200 Subject: [PATCH] Run and --hide at Window startup --- TabletDriverGUI/Configuration.cs | 7 +- TabletDriverGUI/MainWindow.xaml | 148 ++++++++++++++++++++--------- TabletDriverGUI/MainWindow.xaml.cs | 101 ++++++++++++++++++-- 3 files changed, 202 insertions(+), 54 deletions(-) diff --git a/TabletDriverGUI/Configuration.cs b/TabletDriverGUI/Configuration.cs index feacdb1..9f91ed9 100644 --- a/TabletDriverGUI/Configuration.cs +++ b/TabletDriverGUI/Configuration.cs @@ -49,8 +49,10 @@ public enum OutputModes public int WindowWidth; public int WindowHeight; + public bool RunAtStartup; + public string DriverPath; - public string DriverArguments; + public string DriverArguments; public bool DeveloperMode; @@ -85,6 +87,9 @@ public Configuration() WindowWidth = 800; WindowHeight = 690; + + RunAtStartup = false; + DriverPath = "bin/TabletDriverService.exe"; DriverArguments = "config/init.cfg"; DeveloperMode = false; diff --git a/TabletDriverGUI/MainWindow.xaml b/TabletDriverGUI/MainWindow.xaml index 3896f15..4bc8fae 100644 --- a/TabletDriverGUI/MainWindow.xaml +++ b/TabletDriverGUI/MainWindow.xaml @@ -27,6 +27,24 @@ + + + + + Screen Map + + + - You can drag the screen area with a mouse. + + - Drag + Control = Move area in X direction. + + - Drag + Shift = Move area Y direction. + + - Use the "Set Area" to set the screen area to single monitor or full desktop. + + + + - - - You can drag the area with a mouse. - - Left Control = Only in X direction. - - Left Shift = Only Y direction. - - - - @@ -108,6 +115,25 @@ + + + + Tablet Area + + + - You can drag the tablet area with a mouse. + + - Drag + Control = Move area in X direction. + + - Drag + Shift = Move area Y direction. + + - For left handed mode, use rotation value of 180 degrees. + + - Click Wacom Area button to type in the Wacom driver area settings. + + + + @@ -144,15 +170,6 @@ MouseMove="Canvas_MouseMove" MouseUp="Canvas_MouseUp" > - - - You can drag the area with a mouse. - - Left Control = Only in X direction. - - Left Shift = Only Y direction. - - @@ -164,10 +181,10 @@ - - @@ -236,12 +253,25 @@ - + - + + + + + Button Mapping + + + - You can disable single button by selecting "Disable" from the list. + + - The "Disable buttons" checkbox will disable all tablet buttons. + + + + @@ -274,25 +304,44 @@ - + + + + + Cursor position smoothing filter + + + - Smoothing filter adds latency to the input, so don't enable it if you want to have the lowest possible input lag. + + - On Wacom tablets you can use latency value between 15 and 25 to have a similar smoothing as in the Wacom drivers. + + - You can test out different filter values, but recommended maximum for osu! is around 50 milliseconds. + + - Filter latency value lower than 4 milliseconds isn't recommended. It is just better to disable the smoothing filter. + + - You don't have to change the filter rate, but you can use the highest rate your computer can run without performance problems. + + + + 0 - + - - + + 500 Hz 333 Hz 250 Hz @@ -305,11 +354,6 @@ VerticalAlignment="Center" Margin="5" Checked="CheckboxChanged" Unchecked="CheckboxChanged"> - - - Enables cursor position filter - - Enabled @@ -320,14 +364,24 @@ - + + + + + Desktop Size + + + - In some cases you may have to disable the auto size and manually type in the main monitor resolution. + + - If you don't have problems with screen mapping, leave the automatic desktop size enabled. + + + @@ -446,10 +500,18 @@ - - - - + + + + + + Run at Windows startup + @@ -457,8 +519,8 @@ - - 0.0.0 + + 0.0.0 diff --git a/TabletDriverGUI/MainWindow.xaml.cs b/TabletDriverGUI/MainWindow.xaml.cs index 159b219..089182b 100644 --- a/TabletDriverGUI/MainWindow.xaml.cs +++ b/TabletDriverGUI/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Win32; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -160,6 +161,10 @@ public MainWindow() }; timerConsoleUpdate.Tick += TimerConsoleUpdate_Tick; + // Tooltip timeout + ToolTipService.ShowDurationProperty.OverrideMetadata( + typeof(DependencyObject), new FrameworkPropertyMetadata(60000)); + // // Buttom Map ComboBoxes @@ -167,9 +172,9 @@ public MainWindow() comboBoxButton1.Items.Clear(); comboBoxButton2.Items.Clear(); comboBoxButton3.Items.Clear(); - comboBoxButton1.Items.Add("Disabled"); - comboBoxButton2.Items.Add("Disabled"); - comboBoxButton3.Items.Add("Disabled"); + comboBoxButton1.Items.Add("Disable"); + comboBoxButton2.Items.Add("Disable"); + comboBoxButton3.Items.Add("Disable"); for (int i = 1; i <= 5; i++) { comboBoxButton1.Items.Add("Mouse " + i); @@ -191,6 +196,8 @@ public MainWindow() } comboBoxFilterRate.SelectedIndex = 2; + // Process command line arguments + ProcessCommandLineArguments(); // Events Closing += MainWindow_Closing; @@ -259,14 +266,50 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) // Load settings from configuration LoadSettingsFromConfiguration(); - // + // Update the settings back to the configuration UpdateSettingsToConfiguration(); + // Console timer timerConsoleUpdate.Start(); + // Set run at startup + SetRunAtStartup(config.RunAtStartup); + + // Hide the window if the GUI is started as minimized + if (WindowState == WindowState.Minimized) + { + Hide(); + } + + // Start the driver Start(); } + + // + // Process command line arguments + // + void ProcessCommandLineArguments() + { + string[] args = Environment.GetCommandLineArgs(); + for (int i = 0; i < args.Length; i++) + { + // Skip values + if (!args[i].StartsWith("-") && !args[i].StartsWith("/")) continue; + + // Remove '-' and '/' characters at the start of the argument + string parameter = Regex.Replace(args[i], "^[\\-/]+", "").ToLower(); + + // + // Parameter: --hide + // + if (parameter == "hide") + { + WindowState = WindowState.Minimized; + } + } + } + #endregion @@ -453,6 +496,10 @@ private void LoadSettingsFromConfiguration() } + // Run at startup + checkRunAtStartup.IsChecked = config.RunAtStartup; + + // // Custom commands // @@ -485,6 +532,8 @@ private void UpdateSettingsToConfiguration() if (isLoadingSettings) return; + bool oldValue; + // Tablet area if (ParseNumber(textTabletAreaWidth.Text, out double value)) config.TabletArea.Width = value; @@ -588,6 +637,14 @@ private void UpdateSettingsToConfiguration() comboBoxFilterRate.IsEnabled = false; } + // + // Run at startup + // + oldValue = config.RunAtStartup; + config.RunAtStartup = (bool)checkRunAtStartup.IsChecked; + if (config.RunAtStartup != oldValue) + SetRunAtStartup(config.RunAtStartup); + // Custom commands List commandList = new List(); @@ -608,7 +665,6 @@ private void UpdateSettingsToConfiguration() } - // // String to Number // @@ -636,6 +692,28 @@ private string GetNumberString(double value, string format) } + // + // Set run at startup + // + private void SetRunAtStartup(bool enabled) + { + try + { + string path = System.Reflection.Assembly.GetExecutingAssembly().Location; + string entryName = "TabletDriverGUI"; + RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); + if (enabled) + rk.SetValue(entryName, "\"" + path + "\" --hide"); + else + rk.DeleteValue(entryName, false); + + rk.Close(); + } + catch (Exception) + { + } + } + // // Get desktop size // @@ -1049,7 +1127,7 @@ private void Canvas_MouseMove(object sender, MouseEventArgs e) if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) dx = 0; - if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.LeftCtrl)) + if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) dy = 0; // Screen map canvas @@ -1168,8 +1246,11 @@ private void ItemSelectionChanged(object sender, SelectionChangedEventArgs e) private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e) { if (!IsLoaded || isLoadingSettings) return; - config.WindowWidth = (int)e.NewSize.Width; - config.WindowHeight = (int)e.NewSize.Height; + if (WindowState != WindowState.Maximized) + { + config.WindowWidth = (int)e.NewSize.Width; + config.WindowHeight = (int)e.NewSize.Height; + } } // Monitor combobox clicked -> create new monitor list @@ -1293,7 +1374,7 @@ private void SetStatusWarning(string text) timerStatusbar.Stop(); timerStatusbar.Start(); } - + // // Statusbar warning text click