diff --git a/App.xaml.cs b/App.xaml.cs index 8f64b0b..0bcb75b 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,50 +1,79 @@ -using Microsoft.UI.Xaml; +using H.NotifyIcon; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; -using Microsoft.UI.Xaml.Data; -using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Navigation; -using Microsoft.UI.Xaml.Shapes; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.ApplicationModel; -using Windows.ApplicationModel.Activation; -using Windows.Foundation; -using Windows.Foundation.Collections; - -// To learn more about WinUI, the WinUI project structure, -// and more about our project templates, see: http://aka.ms/winui-project-info. - -namespace ThreeFingersDragOnWindows +using System.Diagnostics; +using ThreeFingersDragOnWindows.src.settings; +using ThreeFingersDragOnWindows.src.touchpad; +using ThreeFingersDragOnWindows.src.Utils; + +namespace ThreeFingersDragOnWindows; + +public partial class App : Application { - /// - /// Provides application-specific behavior to supplement the default Application class. - /// - public partial class App : Application + + public static SettingsData SettingsData; + private SettingsWindow _settingsWindow; + + + public HandlerWindow HandlerWindow; + + + public App() + { + Debug.WriteLine("Starting ThreeFingersDragOnWindows..."); + this.InitializeComponent(); + + SettingsData = SettingsData.load(); + + + HandlerWindow = new HandlerWindow(this); + //if (SettingsData.IsFirstRun) ShowSettingsWindow(); + + + //_notifyIcon.Icon = new Icon("Resources/icon.ico"); + //_notifyIcon.Text = "ThreeFingersDragOnWindows"; + //_notifyIcon.Click += (_, _) => ShowSettingsWindow(); + + //var button = new ToolStripButton("Quit"); + //button.Click += (_, _) => Quit(); + //_notifyIcon.ContextMenuStrip = new ContextMenuStrip(); + //_notifyIcon.ContextMenuStrip.Items.Add(button); + //_notifyIcon.Visible = true; + } + + + public void OpenSettingsWindow() + { + _settingsWindow = new SettingsWindow(this); + _settingsWindow.Activate(); + } + + public void OnClosePrefsWindow() + { + SettingsData = null; + } + + public void Quit() { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() - { - this.InitializeComponent(); - } - - /// - /// Invoked when the application is launched. - /// - /// Details about the launch request and process. - protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) - { - m_window = new SettingsWindow(); - m_window.Activate(); - } - - private Window m_window; + HandlerWindow?.Close(); + _settingsWindow?.Close(); } + + public void OnTouchpadContact(TouchpadContact[] contacts) + { + _settingsWindow?.OnTouchpadContact(contacts); + } + + public bool DoTouchpadExist() + { + return HandlerWindow.TouchpadExists; + } + + public bool DoTouchpadRegistered() + { + return HandlerWindow.TouchpadRegistered; + } + + } + diff --git a/Assets/icon.ico b/Assets/icon.ico index 19eeec3..caf0a50 100644 Binary files a/Assets/icon.ico and b/Assets/icon.ico differ diff --git a/Assets/icon.png b/Assets/icon.png new file mode 100644 index 0000000..77ecfa9 Binary files /dev/null and b/Assets/icon.png differ diff --git a/SettingsData.cs b/SettingsData.cs new file mode 100644 index 0000000..01cfddd --- /dev/null +++ b/SettingsData.cs @@ -0,0 +1,52 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Xml.Serialization; +using Windows.Storage; + +namespace ThreeFingersDragOnWindows.src.settings; + +public class SettingsData +{ + public bool AllowReleaseAndRestart { get; set; } = true; + public int ReleaseDelay { get; set; } = 500; + + public bool ThreeFingersMove { get; set; } = true; + public float MouseSpeed { get; set; } = 30; + public float MouseAcceleration { get; set; } = 1; + + public static bool IsFirstRun { get; set; } = true; + + public static SettingsData load() + { + var mySerializer = new XmlSerializer(typeof(SettingsData)); + var myFileStream = new FileStream(getPath(true), FileMode.Open); + var up = (SettingsData) mySerializer.Deserialize(myFileStream); + myFileStream.Close(); + return up; + } + + public void save() + { + var mySerializer = new XmlSerializer(typeof(SettingsData)); + var myWriter = new StreamWriter(getPath(false)); + mySerializer.Serialize(myWriter, this); + myWriter.Close(); + } + + private static string getPath(bool createIfEmpty) + { + var dirPath = ApplicationData.Current.LocalFolder.Path; + var filePath = Path.Combine(dirPath, "preferences.xml"); + + if (!Directory.Exists(dirPath) || !File.Exists(filePath)) + { + Debug.WriteLine("First run: creating settings file"); + Directory.CreateDirectory(dirPath); + IsFirstRun = true; + if (createIfEmpty) new SettingsData().save(); + } + + return filePath; + } +} \ No newline at end of file diff --git a/SettingsWindow.xaml b/SettingsWindow.xaml index a5cef89..c30646a 100644 --- a/SettingsWindow.xaml +++ b/SettingsWindow.xaml @@ -1,13 +1,12 @@ - - + mc:Ignorable="d" + Closed="Window_Closed"> diff --git a/SettingsWindow.xaml.cs b/SettingsWindow.xaml.cs index 0dcf27d..515d9d6 100644 --- a/SettingsWindow.xaml.cs +++ b/SettingsWindow.xaml.cs @@ -1,36 +1,107 @@ -using Microsoft.UI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; -using Microsoft.UI.Xaml.Data; -using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Navigation; using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.ApplicationModel.Core; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI.ViewManagement; - -namespace ThreeFingersDragOnWindows +using System.Diagnostics; +using ThreeFingersDragOnWindows.src.Utils; + +namespace ThreeFingersDragOnWindows.src.settings; + + +public sealed partial class SettingsWindow : Window { - public sealed partial class SettingsWindow : Window + private readonly App _app; + + public SettingsWindow(App app) { - public SettingsWindow() - { - this.InitializeComponent(); - ExtendsContentIntoTitleBar = true; // enable custom titlebar - SetTitleBar(TitleBar); // set user ui element as titlebar - } + _app = app; + Debug.WriteLine("Starting SettingssWindow..."); + + + this.InitializeComponent(); + //ExtendsContentIntoTitleBar = true; // enable custom titlebar + //SetTitleBar(TitleBar); // set TitleBar element as titlebar + + /* TouchpadExists.Text = _app.DoTouchpadExist() ? "Yes" : "No"; + TouchpadRegistered.Text = _app.DoTouchpadRegistered() ? "Yes" : "No"; + + AllowReleaseAndRestart.IsChecked = App.Prefs.AllowReleaseAndRestart; + AllowReleaseAndRestart.Checked += (_, _) => App.Prefs.AllowReleaseAndRestart = true; + AllowReleaseAndRestart.Unchecked += (_, _) => App.Prefs.AllowReleaseAndRestart = false; + ReleaseDelay.Text = App.Prefs.ReleaseDelay.ToString(); + ReleaseDelay.TextChanged += (_, _) => { + if (!int.TryParse(ReleaseDelay.Text, out var delay)) + { + ReleaseDelay.Text = App.Prefs.ReleaseDelay.ToString(); + return; + } + + App.Prefs.ReleaseDelay = delay; + }; + + ThreeFingersMove.IsChecked = App.Prefs.ThreeFingersMove; + ThreeFingersMove.Checked += (_, _) => App.Prefs.ThreeFingersMove = true; + ThreeFingersMove.Unchecked += (_, _) => App.Prefs.ThreeFingersMove = false; + MouseSpeed.Value = App.Prefs.MouseSpeed; + MouseSpeed.ValueChanged += (_, _) => App.Prefs.MouseSpeed = (float)MouseSpeed.Value; + MouseAcceleration.Value = App.Prefs.MouseAcceleration; + MouseAcceleration.ValueChanged += (_, _) => App.Prefs.MouseAcceleration = (float)MouseAcceleration.Value; */ + } + + + private void NavigationView_SelectionChanged(object sender, NavigationViewSelectionChangedEventArgs e) + { + Debug.WriteLine("Selection Changed"); + } + + + ////////// Close & quit ////////// - private void NavigationView_SelectionChanged(object sender, NavigationViewSelectionChangedEventArgs e) + private void CloseButton_Click(object sender, RoutedEventArgs e) + { + Close(); + } + + private void QuitButton_Click(object sender, RoutedEventArgs e) + { + _app.Quit(); + } + + private void Window_Closed(object sender, WindowEventArgs e) + { + Debug.WriteLine("Hiding PrefsWindow, saving data..."); + //App.SettingsData.save(); + //_app.OnClosePrefsWindow(); + } + + + ////////// UI Tools ////////// + + /*private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) + { + var regex = new Regex("[^0-9]+"); + e.Handled = regex.IsMatch(e.Text); + }*/ + + private long _lastContact = 0; + private int _inputCount = 0; + private long _lastEventSpeed = 0; + public void OnTouchpadContact(TouchpadContact[] contacts) + { + _inputCount++; + + if (_inputCount >= 20) { - Console.WriteLine("Selection Changed"); + _inputCount = 0; + _lastEventSpeed = (Ctms() - _lastContact) / 20; + _lastContact = Ctms(); } + //TouchpadContacts = string.Join(" | ", contacts.Select(c => c.ToString())) + " | Event speed: " + _lastEventSpeed + "ms"; } + + private long Ctms() + { + return new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds(); + } + } diff --git a/ThreeFingersDragOnWindows.csproj b/ThreeFingersDragOnWindows.csproj index bada873..44ebd01 100755 --- a/ThreeFingersDragOnWindows.csproj +++ b/ThreeFingersDragOnWindows.csproj @@ -13,6 +13,8 @@ + + @@ -23,8 +25,9 @@ - - + + + @@ -34,7 +37,12 @@ package has not yet been restored. --> - + + + + + MSBuild:Compile +