Skip to content

Commit

Permalink
improve single touch responsiveness, add dpi awareness
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Nov 11, 2021
1 parent 56476d3 commit 70d86cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
30 changes: 24 additions & 6 deletions ControllerService/DS4Touch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using System.Timers;
using Timer = System.Timers.Timer;

namespace ControllerService
Expand All @@ -15,13 +16,18 @@ public class DS4Touch
{
private IKeyboardMouseEvents m_Events;
private Thread m_Hook;
private Timer m_Timer;

private float RatioWidth;
private float RatioHeight;

private const int TOUCHPAD_WIDTH = 1920;
private const int TOUCHPAD_HEIGHT = 943;

private const int TOUCH0_ID = 126;
private const int TOUCH1_ID = 127;
private const int TOUCH_DISABLE = 128;

public struct TrackPadTouch
{
public bool IsActive;
Expand All @@ -45,8 +51,12 @@ public DS4Touch()
RatioHeight = (float)TOUCHPAD_HEIGHT / (float)Screen.PrimaryScreen.Bounds.Height;

// default values
TrackPadTouch0.RawTrackingNum = 126;
TrackPadTouch1.RawTrackingNum = 127;
TrackPadTouch0.RawTrackingNum = TOUCH0_ID;
TrackPadTouch1.RawTrackingNum = TOUCH1_ID;

// send MouseUp after 50ms (needed ?)
m_Timer = new Timer() { Enabled = false, Interval = 50, AutoReset = false };
m_Timer.Elapsed += SendMouseUp;

m_Hook = new Thread(Subscribe) { IsBackground = true };
m_Hook.Start();
Expand All @@ -62,23 +72,31 @@ private void Subscribe()
}

private void OnMouseUp(object sender, MouseEventExtArgs e)
{
m_Timer.Start();
}

private void SendMouseUp(object sender, ElapsedEventArgs e)
{
TouchDown = false;

// release touch inputs
TrackPadTouch0.RawTrackingNum += 128;
TrackPadTouch1.RawTrackingNum += 128;
TrackPadTouch0.RawTrackingNum += TOUCH_DISABLE;
TrackPadTouch1.RawTrackingNum += TOUCH_DISABLE;

TouchPacketCounter++;
}

private void OnMouseDown(object sender, MouseEventExtArgs e)
{
TouchDown = true;
m_Timer.Stop();

TrackPadTouch0.RawTrackingNum = 126;
TrackPadTouch0.RawTrackingNum = TOUCH0_ID;
TrackPadTouch0.X = TouchX;
TrackPadTouch0.Y = TouchY;

TrackPadTouch1.RawTrackingNum = 127;
TrackPadTouch1.RawTrackingNum = TOUCH1_ID;
TrackPadTouch1.X = TouchX;
TrackPadTouch1.Y = TouchY;
}
Expand Down
3 changes: 1 addition & 2 deletions ControllerService/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@
également affecter la valeur 'true' au paramètre 'EnableWindowsFormsHighDpiAutoResizing' dans leur fichier app.config.
Permet à l'application de prendre en charge les chemins longs. Consultez https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->

<!-- Activer les thèmes pour les contrôles et boîtes de dialogue communes de Windows (Windows XP et version ultérieure) -->
<!--
Expand Down

0 comments on commit 70d86cb

Please sign in to comment.