Skip to content

Commit

Permalink
delay changing BlockTouchInputThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
TransposonY committed Jul 12, 2017
1 parent 5c52f0a commit 69985ba
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions GestureSign.Daemon/Input/PointCapture.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsInput;
using GestureSign.Common;
using GestureSign.Common;
using GestureSign.Common.Applications;
using GestureSign.Common.Configuration;
using GestureSign.Common.Gestures;
Expand All @@ -17,6 +8,15 @@
using GestureSign.PointPatterns;
using ManagedWinapi.Hooks;
using ManagedWinapi.Windows;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using WindowsInput;
using Timer = System.Windows.Forms.Timer;

namespace GestureSign.Daemon.Input
Expand All @@ -35,6 +35,7 @@ public class PointCapture : ILoadable, IPointCapture, IDisposable
private readonly PointerInputTargetWindow _pointerInputTargetWindow;
private readonly List<IPointPattern> _pointPatternCache = new List<IPointPattern>();
private readonly Timer _timeoutTimer = new Timer();
private readonly System.Threading.Timer _blockTouchDelayTimer;

private Dictionary<int, List<Point>> _pointsCaptured;
// Create variable to hold the only allowed instance of this class
Expand All @@ -51,6 +52,8 @@ public class PointCapture : ILoadable, IPointCapture, IDisposable

private bool disposedValue = false; // To detect redundant calls

private int? _blockTouchInputThreshold;

#endregion

#region PInvoke
Expand Down Expand Up @@ -195,6 +198,7 @@ protected PointCapture()

if (AppConfig.UiAccess)
{
_blockTouchDelayTimer = new System.Threading.Timer(UpdateBlockTouchInputThresholdCallback, null, Timeout.Infinite, Timeout.Infinite);
ForegroundApplicationsChanged += PointCapture_ForegroundApplicationsChanged;
}

Expand All @@ -220,6 +224,7 @@ protected virtual void Dispose(bool disposing)
_pointerInputTargetWindow?.Dispose();
_inputProvider?.Dispose();
_timeoutTimer?.Dispose();
_blockTouchDelayTimer?.Dispose();
}

if (_hWinEventHook != IntPtr.Zero)
Expand Down Expand Up @@ -266,9 +271,7 @@ private void PointCapture_ForegroundApplicationsChanged(object sender, IApplicat
{
var userAppList = apps.Where(application => application is UserApp).ToList();
if (userAppList.Count == 0) return;
int maxBlockTouchInputThreshold = userAppList.Cast<UserApp>().Max(app => app.BlockTouchInputThreshold);

_pointerInputTargetWindow.BlockTouchInputThreshold = maxBlockTouchInputThreshold;
UpdateBlockTouchInputThreshold(userAppList.Cast<UserApp>().Max(app => app.BlockTouchInputThreshold));
}
}

Expand Down Expand Up @@ -301,6 +304,7 @@ protected void PointEventTranslator_PointMove(object sender, InputPointsEventArg

AddPoint(e.InputPointList);
}
UpdateBlockTouchInputThreshold();
}

protected void PointEventTranslator_PointUp(object sender, InputPointsEventArgs e)
Expand Down Expand Up @@ -355,12 +359,32 @@ protected void PointEventTranslator_PointUp(object sender, InputPointsEventArgs
}

SourceDevice = Device.None;

UpdateBlockTouchInputThreshold();
}

#endregion

#region Private Methods

private void UpdateBlockTouchInputThreshold(int? threshold = null)
{
if (!AppConfig.UiAccess) return;

if (threshold != null)
_blockTouchInputThreshold = threshold;
if (_blockTouchInputThreshold != null)
_blockTouchDelayTimer.Change(100, Timeout.Infinite);
}

private void UpdateBlockTouchInputThresholdCallback(object o)
{
if (!_blockTouchInputThreshold.HasValue) return;

_pointerInputTargetWindow.BlockTouchInputThreshold = _blockTouchInputThreshold.Value;
_blockTouchInputThreshold = null;
}

private void GestureRecognizedCallback(object sender, EventArgs e)
{
_timeoutTimer.Stop();
Expand All @@ -374,7 +398,7 @@ private bool TryBeginCapture(List<InputPoint> firstPoint)
PointsCapturedEventArgs captureStartedArgs = new PointsCapturedEventArgs(firstPoint.Select(p => p.Point).ToList());
OnCaptureStarted(captureStartedArgs);

_pointerInputTargetWindow.BlockTouchInputThreshold = Mode == CaptureMode.Normal ? captureStartedArgs.BlockTouchInputThreshold : 0;
UpdateBlockTouchInputThreshold(Mode == CaptureMode.Normal ? captureStartedArgs.BlockTouchInputThreshold : 0);

if (captureStartedArgs.Cancel)
return false;
Expand Down

0 comments on commit 69985ba

Please sign in to comment.