Skip to content

Commit

Permalink
Automatically hide main settings window when sensor is repositioned.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leapward-Koex committed Nov 8, 2024
1 parent 2033b5e commit a0cfa9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MaiTouchComConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Action<string>? OnDataRecieved
internal set;
}

public async Task StartTouchSensorPolling()
public void StartTouchSensorPolling()
{
if (!_connected && _shouldReconnect)
{
Expand Down
14 changes: 6 additions & 8 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public MainWindow()
_touchPanel = new TouchPanel();
_touchPanel.onTouch = (value) => { buttonState.PressButton(value); };
_touchPanel.onRelease = (value) => { buttonState.ReleaseButton(value); };
_touchPanel.onInitialReposition = () => { WindowState = WindowState.Minimized; };
_touchPanel.Show();
_touchPanel.Owner = this;

var dataContext = (MainWindowViewModel)DataContext;
_touchPanel.DataContext = dataContext;
Expand All @@ -90,12 +90,10 @@ private async void MainWindow_Closing(object? sender, System.ComponentModel.Canc
{
e.Cancel = true;
await connector.Disconnect();
foreach (Window childWindow in OwnedWindows)
{
childWindow.Close();
}
_touchPanel.Close();
Closing -= MainWindow_Closing;
e.Cancel = false;
Application.Current.Shutdown();
}

private async void ExitWithSinmaiLoop()
Expand Down Expand Up @@ -168,16 +166,16 @@ private async void AutomaticPortConnectingLoop()
{
if (dataContext.IsAutomaticPortConnectingEnabled)
{
await connector.StartTouchSensorPolling();
connector.StartTouchSensorPolling();
}
await Task.Delay(1000);
}
}


private async void ConnectToPortButton_Click(object sender, RoutedEventArgs e)
private void ConnectToPortButton_Click(object sender, RoutedEventArgs e)
{
await connector.StartTouchSensorPolling();
connector.StartTouchSensorPolling();
}

private void debugMode_Click(object sender, RoutedEventArgs e)
Expand Down
8 changes: 8 additions & 0 deletions TouchPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public partial class TouchPanel : Window
{
internal Action<TouchValue>? onTouch;
internal Action<TouchValue>? onRelease;
internal Action? onInitialReposition;

private readonly Dictionary<int, Polygon> activeTouches = [];
private readonly TouchPanelPositionManager _positionManager;
private List<Polygon> buttons = [];
private bool isDebugEnabled = Properties.Settings.Default.IsDebugEnabled;
private bool isRingButtonEmulationEnabled = Properties.Settings.Default.IsRingButtonEmulationEnabled;
private bool hasRepositioned = false;

private enum ResizeDirection
{
Expand Down Expand Up @@ -75,6 +77,12 @@ public void PositionTouchPanel()
Left = position.Value.Left;
Width = position.Value.Width;
Height = position.Value.Height;

if (!hasRepositioned)
{
hasRepositioned = true;
onInitialReposition?.Invoke();
}
}
}

Expand Down

0 comments on commit a0cfa9c

Please sign in to comment.