Skip to content

Commit

Permalink
Maintenance commit:
Browse files Browse the repository at this point in the history
- Added some documentation,
- Made modifications  to the build scripts to build the UX on Windows, Linux & MacOS.
- Updated OTD.EnhancedOutputMode so that touch & this plugin can be used at the same time
  • Loading branch information
Mrcubix committed Mar 22, 2024
1 parent cc2082b commit f986f40
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "Wheel-Addon.sln"
}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<AvaloniaVersion>11.0.0</AvaloniaVersion>
<AvaloniaVersion>11.0.10</AvaloniaVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Wheel Addon

A plugin for OTD that add support for the touch wheel present in some Wacom tablets
A plugin for OTD that add support for the Absolute Touch Wheel present in some Wacom tablets

## Supported Versions

Expand Down
14 changes: 11 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# TODO
## TODO

- Installer
- README.md
- 2 Way communication between plugin & UX (server on both ends)
- Plugin pipe name : WheelDaemon,
- UX pipe name : WheelDaemonUX
- Profiles
- Notifications on :
- Profile changes,
- Successful Apply,
- Successful Save
- LED blink on profile change (PTHs)
- Display changes on profile changes (PTKs)
10 changes: 4 additions & 6 deletions Wheel-Addon.UX/Controls/BindingDisplay.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using Avalonia;
using Avalonia.Controls;
using OpenTabletDriver.Desktop.Reflection;
using WheelAddon.UX.ViewModels;
using WheelAddon.UX.Views;

namespace WheelAddon.UX.Controls
{
public partial class BindingDisplay : UserControl
{
private string? _description;
/*private string? _description;
private PluginSettingStore? _store;
// --------------------------------- Description --------------------------------- //
Expand Down Expand Up @@ -38,7 +36,7 @@ public PluginSettingStore? Store
{
get => _store;
set => this.SetAndRaise(StoreProperty, ref _store, value);
}
}*/

// --------------------------------- Constructor --------------------------------- //

Expand All @@ -60,7 +58,7 @@ protected override void OnDataContextChanged(EventArgs e)

private void ShowBindingEditorDialog(object? sender, BindingDisplayViewModel e)
{
if (this.DataContext is BindingDisplayViewModel vm)
if (DataContext is BindingDisplayViewModel vm)
{
if (TopLevel.GetTopLevel(this) is MainWindow window)
{
Expand All @@ -71,7 +69,7 @@ private void ShowBindingEditorDialog(object? sender, BindingDisplayViewModel e)

private void ShowAdvancedBindingEditorDialog(object? sender, BindingDisplayViewModel e)
{
if (this.DataContext is BindingDisplayViewModel vm)
if (DataContext is BindingDisplayViewModel vm)
{
if (TopLevel.GetTopLevel(this) is MainWindow window)
{
Expand Down
3 changes: 1 addition & 2 deletions Wheel-Addon.UX/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ namespace WheelAddon.UX;

public class ViewLocator : IDataTemplate
{
public Control Build(object? data)
public Control? Build(object? data)
{
if (data is null)
return null!;

var name = data.GetType().FullName!.Replace("ViewModel", "View");

var type = Type.GetType(name);

if (type != null)
Expand Down
133 changes: 69 additions & 64 deletions Wheel-Addon.UX/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Threading;
using WheelAddon.Lib.Serializables;
Expand All @@ -18,80 +19,84 @@ public MainWindow()
public void ShowBindingEditorDialog(object? sender, BindingDisplayViewModel e)
{
// instantiate and show dialog on UI thread
Dispatcher.UIThread.Post(async () =>
_ = Dispatcher.UIThread.InvokeAsync(() => ShowBindingEditorDialogCore(e));
}

private async Task ShowBindingEditorDialogCore(BindingDisplayViewModel e)
{
if (DataContext is MainViewModel vm)
{
if (DataContext is MainViewModel vm)
var dialog = new BindingEditorDialog()
{
DataContext = new BindingEditorDialogViewModel(),
Plugins = vm.Plugins
};

var res = await dialog.ShowDialog<SerializablePluginSettings>(this);

if (res == null)
return;

if (res.Identifier == -1 || res.Value == "None")
{
e.PluginProperty = null;
e.Content = "";
}
else
{
var dialog = new BindingEditorDialog()
{
DataContext = new BindingEditorDialogViewModel(),
Plugins = vm.Plugins
};
var res = await dialog.ShowDialog<SerializablePluginSettings>(this);
if (res == null)
return;
if (res.Identifier == -1 || res.Value == "None")
{
e.PluginProperty = null;
e.Content = "";
}
else
{
e.PluginProperty = res;
e.Content = vm.GetFriendlyContentFromProperty(res);
}
e.PluginProperty = res;
e.Content = vm.GetFriendlyContentFromProperty(res);
}
});
}
}

public void ShowAdvancedBindingEditorDialog(object? sender, BindingDisplayViewModel e)
{
// instantiate and show dialog on UI thread
Dispatcher.UIThread.Post(async () =>
_ = Dispatcher.UIThread.InvokeAsync(() => ShowAdvancedBindingEditorDialogCore(e));
}

private async Task ShowAdvancedBindingEditorDialogCore(BindingDisplayViewModel e)
{
if (DataContext is MainViewModel vm)
{
if (DataContext is MainViewModel vm)
var types = vm.Plugins.Select(p => p.PluginName ?? p.FullName ?? "Unknown").ToList();

var currentPlugin = vm.Plugins.FirstOrDefault(p => p.Identifier == e.PluginProperty?.Identifier);
var selectedType = currentPlugin?.PluginName ?? currentPlugin?.FullName ?? "Unknown";

var validProperties = currentPlugin?.ValidProperties ?? new string[0];
var selectedProperty = e.PluginProperty?.Value ?? "";

var dialogVM = new AdvancedBindingEditorDialogViewModel()
{
Types = new ObservableCollection<string>(types),
SelectedType = selectedType,
ValidProperties = new ObservableCollection<string>(validProperties),
SelectedProperty = selectedProperty
};

var dialog = new AdvancedBindingEditorDialog()
{
DataContext = dialogVM,
Plugins = vm.Plugins
};

var res = await dialog.ShowDialog<SerializablePluginSettings>(this);

if (res == null)
return;

if (res.Identifier == -1 || res.Value == "None")
{
e.PluginProperty = null;
e.Content = "";
}
else
{
var types = vm.Plugins.Select(p => p.PluginName ?? p.FullName ?? "Unknown").ToList();
var currentPlugin = vm.Plugins.FirstOrDefault(p => p.Identifier == e.PluginProperty?.Identifier);
var selectedType = currentPlugin?.PluginName ?? currentPlugin?.FullName ?? "Unknown";
var validProperties = currentPlugin?.ValidProperties ?? new string[0];
var selectedProperty = e.PluginProperty?.Value ?? "";
var dialogVM = new AdvancedBindingEditorDialogViewModel()
{
Types = new ObservableCollection<string>(types),
SelectedType = selectedType,
ValidProperties = new ObservableCollection<string>(validProperties),
SelectedProperty = selectedProperty
};
var dialog = new AdvancedBindingEditorDialog()
{
DataContext = dialogVM,
Plugins = vm.Plugins
};
var res = await dialog.ShowDialog<SerializablePluginSettings>(this);
if (res == null)
return;
if (res.Identifier == -1 || res.Value == "None")
{
e.PluginProperty = null;
e.Content = "";
}
else
{
e.PluginProperty = res;
e.Content = vm.GetFriendlyContentFromProperty(res);
}
e.PluginProperty = res;
e.Content = vm.GetFriendlyContentFromProperty(res);
}
});
}
}
}
2 changes: 1 addition & 1 deletion Wheel-Addon.UX/Wheel-Addon.UX.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<NoWarn>NETSDK1138</NoWarn>
<NoWarn>NETSDK1138; VSTHRD200; VSTHRD100</NoWarn>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
Expand Down
11 changes: 10 additions & 1 deletion Wheel-Addon/WheelDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public Task<bool> ApplyWheelBindings(SerializableSettings bindings)

var serializableSimpleModeBindings = bindings.SimpleMode;

// Grab the plugin identifiers and values
var clockwisePluginIdentifier = serializableSimpleModeBindings.Clockwise.PluginProperty?.Identifier;
var counterClockwisePluginIdentifier = serializableSimpleModeBindings.CounterClockwise.PluginProperty?.Identifier;

Expand Down Expand Up @@ -146,13 +147,15 @@ public Task<bool> ApplyWheelBindings(SerializableSettings bindings)

Settings.AdvancedMode.Clear();

// Grab the plugin identifiers and values for each advanced mode binding
var serializableAdvancedModeBindings = bindings.AdvancedMode;

foreach (var serializableAdvancedModeBinding in serializableAdvancedModeBindings)
{
var pluginIdentifier = serializableAdvancedModeBinding.PluginProperty?.Identifier;
var pluginValue = serializableAdvancedModeBinding.PluginProperty?.Value;

// convert the advanced mode bindings
var advancedModeBinding = new RangedWheelBinding()
{
Store = pluginIdentifier != null ?
Expand All @@ -161,6 +164,7 @@ public Task<bool> ApplyWheelBindings(SerializableSettings bindings)
End = serializableAdvancedModeBinding.End
};

// set the properties values of each stores settings
if (pluginIdentifier != null)
advancedModeBinding.Store?.Settings.SingleOrDefault(x => x.Property == "Property")!.SetValue(pluginValue!);

Expand All @@ -179,14 +183,17 @@ public Task<List<SerializablePlugin>> GetPlugins()

List<SerializablePlugin> plugins = new();

// iterate through each plugin and add it to the list
foreach (var IdentifierPluginPair in identifierToPlugin)
{
var plugin = IdentifierPluginPair.Value;

var store = new PluginSettingStore(plugin);

// Construct the binding plugin so we can get the valid properties
var validateBinding = store.Construct<IValidateBinding>();

// Convert the plugin to a serializable plugin, so it can be transferred over RPC
var serializablePlugin = new SerializablePlugin(plugin.GetCustomAttribute<PluginNameAttribute>()?.Name,
plugin.FullName,
IdentifierPluginPair.Key,
Expand Down Expand Up @@ -268,7 +275,9 @@ private void OnWheelReport(object? sender, IWheelReport report)
if (report.Wheel > Settings.MaxWheelValue)
{
Settings.MaxWheelValue = report.Wheel;
//WheelHandler.HandlerLog(this, NAME, $"New max wheel value: {Settings.MaxWheelValue}");
#if DEBUG
WheelHandler.HandlerLog(this, NAME, $"New max wheel value: {Settings.MaxWheelValue}", LogLevel.Debug);
#endif
}
}

Expand Down
3 changes: 3 additions & 0 deletions Wheel-Addon/WheelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ public void OnWheelUsed(object? sender, IWheelReport report)
if (rpcServer.Instance.IsCalibrating || rpcServer.Instance.HasErrored)
return;

// Wheel isn't in use (anymore?)
if (report.Wheel == -1)
{
// We need a debounce mechanism to detect when the wheel is no longer in use
if (RemainingTouchesDebounce-- > 0)
{
LastValue = -1;
Expand Down Expand Up @@ -206,6 +208,7 @@ public void HandleSimpleModeAction(object? sender, bool isClockwise)

public void HandleAdvancedMode(object? sender, IWheelReport report)
{
// if the mode is not Advanced (true), return
if (ModeToggle != true)
return;

Expand Down
14 changes: 13 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ Write-Output ""
Write-Output "Building UX"
Write-Output ""

dotnet publish Wheel-Addon.UX.Desktop -c Release -r win-x64 --self-contained='false' -o ./build/win-x64
dotnet publish Wheel-Addon.UX.Desktop -c Release -r win-x64 --self-contained='false' -o ./build/UX/win-x64
dotnet publish Wheel-Addon.UX.Desktop -c Release -r win-x86 --self-contained='false' -o ./build/UX/win-x86
dotnet publish Wheel-Addon.UX.Desktop -c Release -r win-arm64 --self-contained='false' -o ./build/UX/win-arm64

dotnet publish Wheel-Addon.UX.Desktop -c Release -r linux-x64 --self-contained='false' -o ./build/UX/linux-x64
dotnet publish Wheel-Addon.UX.Desktop -c Release -r linux-arm64 --self-contained='false' -o ./build/UX/linux-arm64

dotnet publish Wheel-Addon.UX.Desktop -c Release -r osx-x64 --self-contained='false' -o ./build/UX/osx-x64
dotnet publish Wheel-Addon.UX.Desktop -c Release -r osx-arm64 --self-contained='false' -o ./build/UX/osx-arm64

if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
Expand All @@ -52,6 +60,10 @@ Remove-Item ./build/installer/* -Recurse -Force

Move-Item ./temp/installer/Wheel-Addon.Installer.dll ./build/installer/Wheel-Addon.Installer.dll

# zip the installer

Compress-Archive -Path ./build/installer/* -DestinationPath ./build/installer/Wheel-Addon.Installer.zip

Remove-Item ./temp -Recurse -Force

Write-Output ""
Expand Down
Loading

0 comments on commit f986f40

Please sign in to comment.