-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add v1.0 code files & setup tray icon and hidden window.
- Loading branch information
1 parent
b231dd8
commit 8182676
Showing
15 changed files
with
692 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Provides application-specific behavior to supplement the default Application class. | ||
/// </summary> | ||
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() | ||
{ | ||
/// <summary> | ||
/// 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(). | ||
/// </summary> | ||
public App() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
/// <summary> | ||
/// Invoked when the application is launched. | ||
/// </summary> | ||
/// <param name="args">Details about the launch request and process.</param> | ||
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; | ||
} | ||
|
||
|
||
} | ||
|
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.