2022-07-23 19:23:32 +00:00
|
|
|
|
using MSFSPopoutPanelManager.Shared;
|
|
|
|
|
using MSFSPopoutPanelManager.UserDataAgent;
|
|
|
|
|
using MSFSPopoutPanelManager.WindowsAgent;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
2022-06-13 03:49:56 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
namespace MSFSPopoutPanelManager.Orchestration
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
public class PanelConfigurationOrchestrator : ObservableObject
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
private static PInvoke.WinEventProc _winEvent; // keep this as static to prevent garbage collect or the app will crash
|
2022-07-23 19:23:32 +00:00
|
|
|
|
private static IntPtr _winEventHook;
|
2022-06-13 03:49:56 +00:00
|
|
|
|
private uint _prevWinEvent = PInvokeConstant.EVENT_SYSTEM_CAPTUREEND;
|
|
|
|
|
private int _winEventClickLock = 0;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
private Rectangle _lastWindowRectangle;
|
|
|
|
|
private object _hookLock = new object();
|
|
|
|
|
private bool _isHookMouseDown = false;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
public PanelConfigurationOrchestrator()
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
_winEvent = new PInvoke.WinEventProc(EventCallback);
|
|
|
|
|
AllowEdit = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
internal ProfileData ProfileData { get; set; }
|
|
|
|
|
|
|
|
|
|
internal AppSettingData AppSettingData { get; set; }
|
|
|
|
|
|
|
|
|
|
private Profile ActiveProfile { get { return ProfileData == null ? null : ProfileData.ActiveProfile; } }
|
|
|
|
|
|
|
|
|
|
public bool AllowEdit { get; set; }
|
|
|
|
|
|
|
|
|
|
public void StartConfiguration()
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
HookWinEvent();
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
public void EndConfiguration()
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
UnhookWinEvent();
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
public void LockStatusUpdated()
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
ActiveProfile.IsLocked = !ActiveProfile.IsLocked;
|
|
|
|
|
ProfileData.WriteProfiles();
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
public void PanelConfigPropertyUpdated(int panelIndex, PanelConfigPropertyName configPropertyName)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (panelIndex == -1 || !AllowEdit || ActiveProfile.IsLocked)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelIndex == panelIndex);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig != null)
|
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (configPropertyName == PanelConfigPropertyName.FullScreen)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-04-18 19:52:39 +00:00
|
|
|
|
InputEmulationManager.ToggleFullScreenPanel(panelConfig.PanelHandle);
|
|
|
|
|
panelConfig.HideTitlebar = false;
|
|
|
|
|
panelConfig.AlwaysOnTop = false;
|
|
|
|
|
}
|
2022-07-23 19:23:32 +00:00
|
|
|
|
else if (configPropertyName == PanelConfigPropertyName.PanelName)
|
2022-04-18 19:52:39 +00:00
|
|
|
|
{
|
|
|
|
|
var name = panelConfig.PanelName;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig.PanelType == PanelType.CustomPopout && name.IndexOf("(Custom)") == -1)
|
|
|
|
|
{
|
2022-04-18 19:52:39 +00:00
|
|
|
|
name = name + " (Custom)";
|
2022-07-23 19:23:32 +00:00
|
|
|
|
PInvoke.SetWindowText(panelConfig.PanelHandle, name);
|
|
|
|
|
}
|
2022-04-18 19:52:39 +00:00
|
|
|
|
}
|
2022-06-30 23:53:08 +00:00
|
|
|
|
else if (!panelConfig.FullScreen)
|
2022-04-18 19:52:39 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
switch (configPropertyName)
|
2022-04-18 19:52:39 +00:00
|
|
|
|
{
|
|
|
|
|
case PanelConfigPropertyName.Left:
|
|
|
|
|
case PanelConfigPropertyName.Top:
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.MoveWindow(panelConfig.PanelHandle, panelConfig.PanelType, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height);
|
2022-04-18 19:52:39 +00:00
|
|
|
|
break;
|
|
|
|
|
case PanelConfigPropertyName.Width:
|
|
|
|
|
case PanelConfigPropertyName.Height:
|
|
|
|
|
if (panelConfig.HideTitlebar)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panelConfig.PanelHandle, false);
|
2022-04-18 19:52:39 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.MoveWindowWithMsfsBugOverrirde(panelConfig.PanelHandle, panelConfig.PanelType, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height);
|
2022-04-18 19:52:39 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig.HideTitlebar)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panelConfig.PanelHandle, true);
|
2022-04-18 19:52:39 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case PanelConfigPropertyName.AlwaysOnTop:
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyAlwaysOnTop(panelConfig.PanelHandle, panelConfig.PanelType, panelConfig.AlwaysOnTop, new Rectangle(panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height));
|
2022-04-18 19:52:39 +00:00
|
|
|
|
break;
|
|
|
|
|
case PanelConfigPropertyName.HideTitlebar:
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panelConfig.PanelHandle, panelConfig.HideTitlebar);
|
2022-04-18 19:52:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
ProfileData.WriteProfiles();
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
public void PanelConfigIncreaseDecrease(int panelIndex, PanelConfigPropertyName configPropertyName, int changeAmount)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (panelIndex == -1 || !AllowEdit || ActiveProfile.IsLocked || ActiveProfile.PanelConfigs == null || ActiveProfile.PanelConfigs.Count == 0)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelIndex == panelIndex);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (panelConfig != null)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
// Should not apply any other settings if panel is full screen mode
|
2022-04-18 19:52:39 +00:00
|
|
|
|
if (panelConfig.FullScreen)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
int orignalLeft = panelConfig.Left;
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
switch (configPropertyName)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
case PanelConfigPropertyName.Left:
|
|
|
|
|
panelConfig.Left += changeAmount;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.MoveWindow(panelConfig.PanelHandle, panelConfig.PanelType, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case PanelConfigPropertyName.Top:
|
|
|
|
|
panelConfig.Top += changeAmount;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.MoveWindow(panelConfig.PanelHandle, panelConfig.PanelType, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case PanelConfigPropertyName.Width:
|
|
|
|
|
panelConfig.Width += changeAmount;
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig.HideTitlebar)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panelConfig.PanelHandle, false);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.MoveWindowWithMsfsBugOverrirde(panelConfig.PanelHandle, panelConfig.PanelType, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig.HideTitlebar)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panelConfig.PanelHandle, true);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case PanelConfigPropertyName.Height:
|
|
|
|
|
panelConfig.Height += changeAmount;
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig.HideTitlebar)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panelConfig.PanelHandle, false);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.MoveWindowWithMsfsBugOverrirde(panelConfig.PanelHandle, panelConfig.PanelType, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig.HideTitlebar)
|
2022-07-23 19:23:32 +00:00
|
|
|
|
WindowActionManager.ApplyHidePanelTitleBar(panelConfig.PanelHandle, true);
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
ProfileData.WriteProfiles();
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
private void HookWinEvent()
|
|
|
|
|
{
|
|
|
|
|
// Setup panel config event hooks
|
|
|
|
|
_winEventHook = PInvoke.SetWinEventHook(PInvokeConstant.EVENT_SYSTEM_CAPTURESTART, PInvokeConstant.EVENT_OBJECT_LOCATIONCHANGE, IntPtr.Zero, _winEvent, 0, 0, PInvokeConstant.WINEVENT_OUTOFCONTEXT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UnhookWinEvent()
|
|
|
|
|
{
|
|
|
|
|
// Unhook all Win API events
|
|
|
|
|
PInvoke.UnhookWinEvent(_winEventHook);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EventCallback(IntPtr hWinEventHook, uint iEvent, IntPtr hwnd, int idObject, int idChild, int dwEventThread, int dwmsEventTime)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-06-30 23:53:08 +00:00
|
|
|
|
switch (iEvent)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-06-13 03:49:56 +00:00
|
|
|
|
case PInvokeConstant.EVENT_OBJECT_LOCATIONCHANGE:
|
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_MOVESIZEEND:
|
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_CAPTURESTART:
|
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_CAPTUREEND:
|
|
|
|
|
// check by priority to speed up comparing of escaping constraints
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (hwnd == IntPtr.Zero
|
2022-06-13 03:49:56 +00:00
|
|
|
|
|| idObject != 0
|
|
|
|
|
|| hWinEventHook != _winEventHook
|
|
|
|
|
|| !AllowEdit
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|| ActiveProfile == null
|
|
|
|
|
|| ActiveProfile.PanelConfigs == null
|
|
|
|
|
|| ActiveProfile.PanelConfigs.Count == 0)
|
2022-06-13 03:49:56 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
HandleEventCallback(hwnd, iEvent);
|
2022-06-13 03:49:56 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
2022-06-13 03:49:56 +00:00
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
private void HandleEventCallback(IntPtr hwnd, uint iEvent)
|
2022-06-13 03:49:56 +00:00
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(panel => panel.PanelHandle == hwnd);
|
2022-06-13 03:49:56 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig == null)
|
|
|
|
|
return;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
// Should not apply any other settings if panel is full screen mode
|
|
|
|
|
if (panelConfig.FullScreen)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (panelConfig.IsLockable && ActiveProfile.IsLocked)
|
2022-06-13 03:49:56 +00:00
|
|
|
|
{
|
|
|
|
|
switch (iEvent)
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
2022-06-13 03:49:56 +00:00
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_MOVESIZEEND:
|
|
|
|
|
// Move window back to original location
|
2022-01-27 13:40:04 +00:00
|
|
|
|
PInvoke.MoveWindow(panelConfig.PanelHandle, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height, false);
|
2022-06-13 03:49:56 +00:00
|
|
|
|
break;
|
|
|
|
|
case PInvokeConstant.EVENT_OBJECT_LOCATIONCHANGE:
|
2022-01-27 13:40:04 +00:00
|
|
|
|
// Detect if window is maximized, if so, save settings
|
|
|
|
|
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
|
|
|
|
|
wp.length = System.Runtime.InteropServices.Marshal.SizeOf(wp);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
PInvoke.GetWindowPlacement(hwnd, ref wp);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
if (wp.showCmd == PInvokeConstant.SW_SHOWMAXIMIZED || wp.showCmd == PInvokeConstant.SW_SHOWMINIMIZED || wp.showCmd == PInvokeConstant.SW_SHOWNORMAL)
|
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
PInvoke.ShowWindow(hwnd, PInvokeConstant.SW_RESTORE);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
2022-06-13 03:49:56 +00:00
|
|
|
|
break;
|
2022-07-23 19:23:32 +00:00
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_CAPTURESTART:
|
|
|
|
|
if (!panelConfig.HasTouchableEvent || _prevWinEvent == PInvokeConstant.EVENT_SYSTEM_CAPTURESTART)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
HandleTouchDownEvent(panelConfig);
|
|
|
|
|
break;
|
2022-06-13 03:49:56 +00:00
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_CAPTUREEND:
|
|
|
|
|
if (!panelConfig.TouchEnabled || _prevWinEvent == PInvokeConstant.EVENT_OBJECT_LOCATIONCHANGE)
|
|
|
|
|
break;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-06-13 03:49:56 +00:00
|
|
|
|
if (!panelConfig.HasTouchableEvent || _prevWinEvent == PInvokeConstant.EVENT_SYSTEM_CAPTUREEND)
|
|
|
|
|
break;
|
2022-01-27 13:40:04 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
HandleTouchUpEvent(panelConfig);
|
2022-06-13 03:49:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2022-01-27 13:40:04 +00:00
|
|
|
|
{
|
|
|
|
|
switch (iEvent)
|
|
|
|
|
{
|
|
|
|
|
case PInvokeConstant.EVENT_OBJECT_LOCATIONCHANGE:
|
|
|
|
|
Rectangle winRectangle;
|
|
|
|
|
PInvoke.GetWindowRect(panelConfig.PanelHandle, out winRectangle);
|
|
|
|
|
|
|
|
|
|
if (_lastWindowRectangle == winRectangle) // ignore duplicate callback messages
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_lastWindowRectangle = winRectangle;
|
|
|
|
|
Rectangle clientRectangle;
|
|
|
|
|
PInvoke.GetClientRect(panelConfig.PanelHandle, out clientRectangle);
|
|
|
|
|
|
|
|
|
|
panelConfig.Left = winRectangle.Left;
|
|
|
|
|
panelConfig.Top = winRectangle.Top;
|
2022-04-18 03:38:33 +00:00
|
|
|
|
|
|
|
|
|
if (panelConfig.HideTitlebar)
|
|
|
|
|
{
|
|
|
|
|
panelConfig.Width = clientRectangle.Width;
|
|
|
|
|
panelConfig.Height = clientRectangle.Height;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
panelConfig.Width = clientRectangle.Width + 16;
|
|
|
|
|
panelConfig.Height = clientRectangle.Height + 39;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 13:40:04 +00:00
|
|
|
|
// Detect if window is maximized, if so, save settings
|
|
|
|
|
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
|
|
|
|
|
wp.length = System.Runtime.InteropServices.Marshal.SizeOf(wp);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
PInvoke.GetWindowPlacement(hwnd, ref wp);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
if (wp.showCmd == PInvokeConstant.SW_SHOWMAXIMIZED || wp.showCmd == PInvokeConstant.SW_SHOWMINIMIZED)
|
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
ProfileData.WriteProfiles();
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_MOVESIZEEND:
|
2022-07-23 19:23:32 +00:00
|
|
|
|
ProfileData.WriteProfiles();
|
|
|
|
|
break;
|
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_CAPTURESTART:
|
|
|
|
|
if (!panelConfig.HasTouchableEvent || _prevWinEvent == PInvokeConstant.EVENT_SYSTEM_CAPTURESTART)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
HandleTouchDownEvent(panelConfig);
|
2022-01-27 13:40:04 +00:00
|
|
|
|
break;
|
2022-06-13 03:49:56 +00:00
|
|
|
|
case PInvokeConstant.EVENT_SYSTEM_CAPTUREEND:
|
|
|
|
|
if (!panelConfig.TouchEnabled || _prevWinEvent == PInvokeConstant.EVENT_OBJECT_LOCATIONCHANGE)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (!panelConfig.HasTouchableEvent || _prevWinEvent == PInvokeConstant.EVENT_SYSTEM_CAPTUREEND)
|
|
|
|
|
break;
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
HandleTouchUpEvent(panelConfig);
|
2022-06-13 03:49:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_prevWinEvent = iEvent;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
private void HandleTouchDownEvent(PanelConfig panelConfig)
|
|
|
|
|
{
|
|
|
|
|
Point point;
|
|
|
|
|
PInvoke.GetCursorPos(out point);
|
|
|
|
|
|
|
|
|
|
// Disable left clicking if user is touching the title bar area
|
|
|
|
|
if (point.Y - panelConfig.Top > (panelConfig.HideTitlebar ? 5 : 31))
|
|
|
|
|
{
|
|
|
|
|
if (!_isHookMouseDown)
|
|
|
|
|
{
|
|
|
|
|
lock (_hookLock)
|
|
|
|
|
{
|
|
|
|
|
_isHookMouseDown = true;
|
|
|
|
|
InputEmulationManager.LeftClickMouseDown(point.X, point.Y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void HandleTouchUpEvent(PanelConfig panelConfig)
|
2022-06-13 03:49:56 +00:00
|
|
|
|
{
|
|
|
|
|
Point point;
|
|
|
|
|
PInvoke.GetCursorPos(out point);
|
|
|
|
|
|
|
|
|
|
// Disable left clicking if user is touching the title bar area
|
|
|
|
|
if (point.Y - panelConfig.Top > (panelConfig.HideTitlebar ? 5 : 31))
|
|
|
|
|
{
|
|
|
|
|
var prevWinEventClickLock = ++_winEventClickLock;
|
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (_isHookMouseDown)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(AppSettingData.AppSetting.TouchScreenSettings.MouseUpDownDelay);
|
|
|
|
|
|
|
|
|
|
lock (_hookLock)
|
|
|
|
|
{
|
|
|
|
|
_isHookMouseDown = false;
|
|
|
|
|
UnhookWinEvent();
|
|
|
|
|
InputEmulationManager.LeftClickMouseUp(0, 0);
|
|
|
|
|
HookWinEvent();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-13 03:49:56 +00:00
|
|
|
|
|
2022-07-23 19:23:32 +00:00
|
|
|
|
if (prevWinEventClickLock == _winEventClickLock && AppSettingData.AppSetting.TouchScreenSettings.RefocusGameWindow)
|
2022-06-13 03:49:56 +00:00
|
|
|
|
{
|
|
|
|
|
Task.Run(() => RefocusMsfs(prevWinEventClickLock));
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-13 03:49:56 +00:00
|
|
|
|
|
2022-06-30 23:53:08 +00:00
|
|
|
|
private void RefocusMsfs(int prevWinEventClickLock)
|
2022-06-13 03:49:56 +00:00
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
if (prevWinEventClickLock == _winEventClickLock)
|
|
|
|
|
{
|
2022-07-23 19:23:32 +00:00
|
|
|
|
var simulatorProcess = WindowProcessManager.GetSimulatorProcess();
|
2022-06-13 03:49:56 +00:00
|
|
|
|
|
|
|
|
|
Rectangle rectangle;
|
|
|
|
|
PInvoke.GetWindowRect(simulatorProcess.Handle, out rectangle);
|
2022-07-23 19:23:32 +00:00
|
|
|
|
|
|
|
|
|
if (!_isHookMouseDown)
|
|
|
|
|
{
|
|
|
|
|
PInvoke.SetCursorPos(rectangle.X + 18, rectangle.Y + 80);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-13 03:49:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-27 13:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|