From e94cb5e581a36f2541d4c54ad1d4d2c7c7b847eb Mon Sep 17 00:00:00 2001 From: hawkeye Date: Tue, 22 Oct 2024 23:08:40 -0400 Subject: [PATCH] Add touch for full screen pop out --- DomainModel/Profile/PanelConfig.cs | 10 +-- DomainModel/Profile/PanelType.cs | 1 - DomainModel/Profile/ProfileSetting.cs | 2 - DomainModel/Profile/SwitchWindowConfig.cs | 19 ---- MainApp/App.xaml.cs | 1 - .../AppUserControl/PopOutPanelConfigCard.xaml | 2 +- MainApp/AppUserControl/ProfileCard.xaml | 10 --- MainApp/AppUserControl/ProfileCard.xaml.cs | 11 --- MainApp/AppWindow/SwitchWindow.xaml | 49 ----------- MainApp/AppWindow/SwitchWindow.xaml.cs | 86 ------------------- .../Styles/CustomMaterialDesignExpander.xaml | 2 +- MainApp/ViewModel/OrchestratorUIHelper.cs | 19 ---- MainApp/ViewModel/ProfileCardViewModel.cs | 34 +------- MainApp/ViewModel/SwitchWindowViewModel.cs | 32 ------- .../PanelConfigurationOrchestrator.cs | 9 +- Orchestration/PanelPopOutOrchestrator.cs | 18 +--- WindowsAgent/TouchEventManager.cs | 22 ++++- WindowsAgent/WindowActionManager.cs | 22 ++++- 18 files changed, 55 insertions(+), 294 deletions(-) delete mode 100644 DomainModel/Profile/SwitchWindowConfig.cs delete mode 100644 MainApp/AppWindow/SwitchWindow.xaml delete mode 100644 MainApp/AppWindow/SwitchWindow.xaml.cs delete mode 100644 MainApp/ViewModel/SwitchWindowViewModel.cs diff --git a/DomainModel/Profile/PanelConfig.cs b/DomainModel/Profile/PanelConfig.cs index 5f9a89c..d39a010 100644 --- a/DomainModel/Profile/PanelConfig.cs +++ b/DomainModel/Profile/PanelConfig.cs @@ -94,11 +94,11 @@ namespace MSFSPopoutPanelManager.DomainModel.Profile [JsonIgnore] public bool IsDeletablePanel => PanelType != PanelType.HudBarWindow && PanelType != PanelType.RefocusDisplay && - PanelType != PanelType.NumPadWindow && PanelType != PanelType.SwitchWindow; + PanelType != PanelType.NumPadWindow; [JsonIgnore] public bool IsTouchEnablePanel => PanelType != PanelType.HudBarWindow && PanelType != PanelType.RefocusDisplay && - PanelType != PanelType.NumPadWindow && PanelType != PanelType.SwitchWindow; + PanelType != PanelType.NumPadWindow; [JsonIgnore] public bool IsCustomPopOut => PanelType == PanelType.CustomPopout; @@ -116,9 +116,6 @@ namespace MSFSPopoutPanelManager.DomainModel.Profile [JsonIgnore] public bool IsNumPadWindow => PanelType == PanelType.NumPadWindow; - [JsonIgnore] - public bool IsSwitchWindow => PanelType == PanelType.SwitchWindow; - [JsonIgnore] public string PanelSourceCoordinateText { @@ -130,5 +127,8 @@ namespace MSFSPopoutPanelManager.DomainModel.Profile return $"Left: {PanelSource.X} / Top: {PanelSource.Y}"; } } + + [JsonIgnore] + public MonitorInfo FullScreenMonitorInfo { get; set; } } } diff --git a/DomainModel/Profile/PanelType.cs b/DomainModel/Profile/PanelType.cs index 5b4943f..9fc1d9a 100644 --- a/DomainModel/Profile/PanelType.cs +++ b/DomainModel/Profile/PanelType.cs @@ -12,7 +12,6 @@ StatusMessageWindow = 7, RefocusDisplay = 8, NumPadWindow = 9, - SwitchWindow = 20, Unknown = 100 } } diff --git a/DomainModel/Profile/ProfileSetting.cs b/DomainModel/Profile/ProfileSetting.cs index 85d4eca..d5157ea 100644 --- a/DomainModel/Profile/ProfileSetting.cs +++ b/DomainModel/Profile/ProfileSetting.cs @@ -18,7 +18,5 @@ namespace MSFSPopoutPanelManager.DomainModel.Profile public RefocusOnDisplay RefocusOnDisplay { get; set; } = new(); public NumPadConfig NumPadConfig { get; set; } = new(); - - public SwitchWindowConfig SwitchWindowConfig { get; set; } = new(); } } diff --git a/DomainModel/Profile/SwitchWindowConfig.cs b/DomainModel/Profile/SwitchWindowConfig.cs deleted file mode 100644 index cbc0aa5..0000000 --- a/DomainModel/Profile/SwitchWindowConfig.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using MSFSPopoutPanelManager.Shared; - -namespace MSFSPopoutPanelManager.DomainModel.Profile -{ - public class SwitchWindowConfig : ObservableObject - { - public bool IsEnabled { get; set; } = false; - - public List Panels { get; set; } - } - - public class SwitchWindowPanel - { - public string DisplayName { get; set; } - - public string PanelCaption { get; set; } - } -} \ No newline at end of file diff --git a/MainApp/App.xaml.cs b/MainApp/App.xaml.cs index 519d330..6604a77 100644 --- a/MainApp/App.xaml.cs +++ b/MainApp/App.xaml.cs @@ -82,7 +82,6 @@ namespace MSFSPopoutPanelManager.MainApp services.AddTransient(s => new MessageWindowViewModel(SharedStorage, s.GetRequiredService(), s.GetRequiredService())); services.AddTransient(s => new HudBarViewModel(SharedStorage, s.GetRequiredService())); services.AddTransient(_ => new NumPadViewModel(SharedStorage)); - services.AddTransient(_ => new SwitchWindowViewModel(SharedStorage)); }).Build(); diff --git a/MainApp/AppUserControl/PopOutPanelConfigCard.xaml b/MainApp/AppUserControl/PopOutPanelConfigCard.xaml index f6e17dd..6e176c2 100644 --- a/MainApp/AppUserControl/PopOutPanelConfigCard.xaml +++ b/MainApp/AppUserControl/PopOutPanelConfigCard.xaml @@ -224,7 +224,7 @@ x:Name="StackPanelAdjustment" Width="440" Orientation="Horizontal" - Visibility="{c:Binding 'DataItem.IsBuiltInPopOut or DataItem.IsHudBarWindow or DataItem.IsNumPadWindow or DataItem.IsSwitchWindow or (DataItem.IsCustomPopOut and DataItem.PanelSource.X != null)'}"> + Visibility="{c:Binding 'DataItem.IsBuiltInPopOut or DataItem.IsHudBarWindow or DataItem.IsNumPadWindow or (DataItem.IsCustomPopOut and DataItem.PanelSource.X != null)'}"> Add a virtual keyboard NumPad - - - Add a switch window command bar - - (); Loaded += (_, _) => { DataContext = _viewModel; }; - -#if LOCAL || DEBUG - this.WrapPanelSwitchWindow.Visibility = Visibility.Visible; -#else - this.WrapPanelSwitchWindow.Visibility = Visibility.Collapsed; -#endif } private void ToggleButtonEditProfileTitle_Click(object sender, RoutedEventArgs e) @@ -69,11 +63,6 @@ namespace MSFSPopoutPanelManager.MainApp.AppUserControl { _viewModel.AddNumPadUpdatedCommand?.Execute(null); } - - private void AddSwitchWindow_TargetUpdated(object sender, DataTransferEventArgs e) - { - _viewModel.AddSwitchWindowUpdatedCommand?.Execute(null); - } } diff --git a/MainApp/AppWindow/SwitchWindow.xaml b/MainApp/AppWindow/SwitchWindow.xaml deleted file mode 100644 index fb20a8f..0000000 --- a/MainApp/AppWindow/SwitchWindow.xaml +++ /dev/null @@ -1,49 +0,0 @@ - - - 28 - - - - - - - - - - - - - - - diff --git a/MainApp/AppWindow/SwitchWindow.xaml.cs b/MainApp/AppWindow/SwitchWindow.xaml.cs deleted file mode 100644 index 60e9138..0000000 --- a/MainApp/AppWindow/SwitchWindow.xaml.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using MSFSPopoutPanelManager.MainApp.ViewModel; -using System; -using System.ComponentModel; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Interop; -using System.Windows.Media; - -namespace MSFSPopoutPanelManager.MainApp.AppWindow -{ - public partial class SwitchWindow : Window - { - private readonly SwitchWindowViewModel _viewModel; - - public SwitchWindow(Guid panelId, int initialWidth, int initialHeight) - { - InitializeComponent(); - if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) - return; - - _viewModel = App.AppHost.Services.GetRequiredService(); - _viewModel.PanelId = panelId; - - Loaded += (_, _) => - { - DataContext = _viewModel; - - var window = Window.GetWindow(this); - if (window == null) - throw new ApplicationException("Unable to instantiate switchWindow window"); - - _viewModel.PanelConfig.PanelHandle = new WindowInteropHelper(window).Handle; - - if (initialWidth == 0 && initialHeight == 0) - { - this.Width = 410; - this.Height = 60; - _viewModel.PanelConfig.Width = Convert.ToInt16(this.Width); - _viewModel.PanelConfig.Height = Convert.ToInt32(this.Height); - } - else - { - this.Width = initialWidth; - this.Height = initialHeight; - } - }; - - this.MouseLeftButtonDown += SwitchWindow_MouseLeftButtonDown; - this.Topmost = true; - - if (_viewModel.ProfileData.ActiveProfile.ProfileSetting.SwitchWindowConfig.Panels != null) - { - var style = Application.Current.TryFindResource("MaterialDesignOutlinedButton") as Style; - - WrapPanelCustomButtons.Children.Clear(); - - foreach (var panel in _viewModel.ProfileData.ActiveProfile.ProfileSetting.SwitchWindowConfig.Panels) - { - WrapPanelCustomButtons.Children.Add(new Button() - { - Height = 45, - Margin = new Thickness(5, 5, 5, 5), - Content = panel.DisplayName, - Foreground = new SolidColorBrush(Colors.White), - FontSize = 28, - Style = style, - Command = _viewModel.ButtonCommand, - CommandParameter = panel.PanelCaption - }); - } - } - } - - private void SwitchWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - DragMove(); - } - - private void BtnClose_Click(object sender, RoutedEventArgs e) - { - this.Close(); - } - } -} diff --git a/MainApp/Styles/CustomMaterialDesignExpander.xaml b/MainApp/Styles/CustomMaterialDesignExpander.xaml index 1e7932e..f8c3697 100644 --- a/MainApp/Styles/CustomMaterialDesignExpander.xaml +++ b/MainApp/Styles/CustomMaterialDesignExpander.xaml @@ -25,7 +25,7 @@ Kind="ChevronDown" Opacity="0.5" RenderTransformOrigin="0.5 0.5" - Visibility="{c:Binding '!DataItem.IsHudBarWindow and !DataItem.IsRefocusDisplay and !DataItem.IsNumPadWindow and !DataItem.IsSwitchWindow and !ActiveProfile.IsEditingPanelSource'}"> + Visibility="{c:Binding '!DataItem.IsHudBarWindow and !DataItem.IsRefocusDisplay and !DataItem.IsNumPadWindow and !ActiveProfile.IsEditingPanelSource'}"> diff --git a/MainApp/ViewModel/OrchestratorUIHelper.cs b/MainApp/ViewModel/OrchestratorUIHelper.cs index 20c2e51..bd0bc66 100644 --- a/MainApp/ViewModel/OrchestratorUIHelper.cs +++ b/MainApp/ViewModel/OrchestratorUIHelper.cs @@ -36,9 +36,6 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel panelPopOutOrchestrator.OnNumPadOpened -= HandleOnNumPadOpened; panelPopOutOrchestrator.OnNumPadOpened += HandleOnNumPadOpened; - - panelPopOutOrchestrator.OnSwitchWindowOpened -= HandleOnSwitchWindowOpened; - panelPopOutOrchestrator.OnSwitchWindowOpened += HandleOnSwitchWindowOpened; } private void HandleShowOverlay(object sender, PanelConfig panelConfig) @@ -102,22 +99,6 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel }); } - private void HandleOnSwitchWindowOpened(object sender, PanelConfig panelConfig) - { - Application.Current.Dispatcher.Invoke(async () => - { - var switchWindow = new SwitchWindow(panelConfig.Id, panelConfig.Width, panelConfig.Height); - switchWindow.Show(); - - await Task.Run(() => - { - Thread.Sleep(1000); - WindowActionManager.MoveWindow(panelConfig.PanelHandle, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height); - WindowActionManager.MoveWindow(panelConfig.PanelHandle, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height); - }); - }); - } - private void HandleOnPopOutStarted(object sender, EventArgs e) { if (!AppSettingData.ApplicationSetting.PopOutSetting.MinimizeDuringPopOut) diff --git a/MainApp/ViewModel/ProfileCardViewModel.cs b/MainApp/ViewModel/ProfileCardViewModel.cs index 6bfbf1e..c93c74f 100644 --- a/MainApp/ViewModel/ProfileCardViewModel.cs +++ b/MainApp/ViewModel/ProfileCardViewModel.cs @@ -41,8 +41,6 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel public ICommand AddNumPadUpdatedCommand { get; } - public ICommand AddSwitchWindowUpdatedCommand { get; } - public ICommand RefocusDisplayRefreshedCommand { get; } public DelegateCommand RefocusDisplaySelectionUpdatedCommand { get; } @@ -102,9 +100,7 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel AddHudBarUpdatedCommand = new DelegateCommand(OnAddHudBarUpdated); AddNumPadUpdatedCommand = new DelegateCommand(OnAddNumPadUpdated); -#if LOCAL - AddSwitchWindowUpdatedCommand = new DelegateCommand(OnAddSwitchWindowUpdated); -#endif + RefocusDisplayUpdatedCommand = new DelegateCommand(OnRefocusDisplayUpdated); RefocusDisplayRefreshedCommand = new DelegateCommand(OnRefocusDisplayRefreshed); @@ -243,34 +239,6 @@ namespace MSFSPopoutPanelManager.MainApp.ViewModel } } - private void OnAddSwitchWindowUpdated() - { - if (ActiveProfile == null) - return; - - if (ActiveProfile.ProfileSetting.SwitchWindowConfig.IsEnabled) - { - if (ActiveProfile.PanelConfigs.Any(p => p.PanelType == PanelType.SwitchWindow)) - return; - - ActiveProfile.PanelConfigs.Add(new PanelConfig - { - PanelName = "Switch Window", - PanelType = PanelType.SwitchWindow, - Left = 0, - Top = 0, - Width = 0, - Height = 0, - AutoGameRefocus = false - }); - } - else - { - ActiveProfile.PanelConfigs.RemoveAll(p => p.PanelType == PanelType.SwitchWindow); - ActiveProfile.ProfileSetting.SwitchWindowConfig.Panels = null; - } - } - private void OnRefocusDisplayUpdated() { if (ActiveProfile == null) diff --git a/MainApp/ViewModel/SwitchWindowViewModel.cs b/MainApp/ViewModel/SwitchWindowViewModel.cs deleted file mode 100644 index 9bd8e76..0000000 --- a/MainApp/ViewModel/SwitchWindowViewModel.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Linq; -using MSFSPopoutPanelManager.DomainModel.Profile; -using MSFSPopoutPanelManager.Orchestration; -using MSFSPopoutPanelManager.WindowsAgent; -using Prism.Commands; - -namespace MSFSPopoutPanelManager.MainApp.ViewModel -{ - public class SwitchWindowViewModel : BaseViewModel - { - public DelegateCommand ButtonCommand { get; private set; } - - public Guid PanelId { get; set; } - - public PanelConfig PanelConfig => ActiveProfile.PanelConfigs.FirstOrDefault(p => p.Id == PanelId); - - - public SwitchWindowViewModel(SharedStorage sharedStorage) : base(sharedStorage) - { - ButtonCommand = new DelegateCommand(OnButtonActivated); - } - - private void OnButtonActivated(string commandParameter) - { - var handle = PInvoke.GetWindowHandle(commandParameter); - - if(handle != IntPtr.Zero) - PInvoke.SwitchToThisWindow(handle, true); - } - } -} diff --git a/Orchestration/PanelConfigurationOrchestrator.cs b/Orchestration/PanelConfigurationOrchestrator.cs index 7589b03..2c554c7 100644 --- a/Orchestration/PanelConfigurationOrchestrator.cs +++ b/Orchestration/PanelConfigurationOrchestrator.cs @@ -130,8 +130,15 @@ namespace MSFSPopoutPanelManager.Orchestration { InputEmulationManager.ToggleFullScreenPanel(panelConfig.PanelHandle); - if (!panelConfig.FullScreen) + if (panelConfig.FullScreen) + { + WindowActionManager.SetHostMonitor(panelConfig); + } + else + { WindowActionManager.MoveWindow(panelConfig.PanelHandle, panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height); + panelConfig.FullScreenMonitorInfo = null; + } } else if (configPropertyName == PanelConfigPropertyName.PanelName) { diff --git a/Orchestration/PanelPopOutOrchestrator.cs b/Orchestration/PanelPopOutOrchestrator.cs index 422ce0b..749890f 100644 --- a/Orchestration/PanelPopOutOrchestrator.cs +++ b/Orchestration/PanelPopOutOrchestrator.cs @@ -50,7 +50,6 @@ namespace MSFSPopoutPanelManager.Orchestration public event EventHandler OnPopOutCompleted; public event EventHandler OnHudBarOpened; public event EventHandler OnNumPadOpened; - public event EventHandler OnSwitchWindowOpened; public async Task ManualPopOut() { @@ -124,8 +123,6 @@ namespace MSFSPopoutPanelManager.Orchestration StepAddNumPad(); - StepAddSwitchWindow(); - SetupRefocusDisplay(); StepApplyPanelConfig(); @@ -393,18 +390,6 @@ namespace MSFSPopoutPanelManager.Orchestration }); } - private void StepAddSwitchWindow() - { - if (!ActiveProfile.ProfileSetting.SwitchWindowConfig.IsEnabled) - return; - - WorkflowStepWithMessage.Execute("Opening Switch Window", () => - { - var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.PanelType == PanelType.SwitchWindow); - OnSwitchWindowOpened?.Invoke(this, panelConfig); - }); - } - public void SetupRefocusDisplay() { if (!ActiveProfile.ProfileSetting.RefocusOnDisplay.IsEnabled) @@ -551,6 +536,9 @@ namespace MSFSPopoutPanelManager.Orchestration Thread.Sleep(500); InputEmulationManager.ToggleFullScreenPanel(panel.PanelHandle); Thread.Sleep(250); + + if (panel.TouchEnabled) + WindowActionManager.SetHostMonitor(panel); // Set full screen coordinate for touch } if (panel.FloatingPanel.IsEnabled && panel.FloatingPanel.HasKeyboardBinding && panel.FloatingPanel.IsHiddenOnStart) diff --git a/WindowsAgent/TouchEventManager.cs b/WindowsAgent/TouchEventManager.cs index 99c7640..8260e40 100644 --- a/WindowsAgent/TouchEventManager.cs +++ b/WindowsAgent/TouchEventManager.cs @@ -92,10 +92,8 @@ namespace MSFSPopoutPanelManager.WindowsAgent // If touch point is within pop out panel boundaries and have touch enabled var panelConfig = ActiveProfile.PanelConfigs.FirstOrDefault(p => p.TouchEnabled && - (info.pt.X > p.Left - && info.pt.X < p.Left + p.Width - && info.pt.Y > p.Top + (p.HideTitlebar ? 5 : PANEL_MENUBAR_HEIGHT) - && info.pt.Y < p.Top + p.Height)); + ((p.FullScreen && CheckWithinFullScreenCoordinate(p, info)) || CheckWithinWindowCoordinate(p, info))); + if (panelConfig == null) return PInvoke.CallNextHookEx(_hHook, code, wParam, lParam); @@ -218,5 +216,21 @@ namespace MSFSPopoutPanelManager.WindowsAgent return PInvoke.CallNextHookEx(_hHook, code, wParam, lParam); } + + private static bool CheckWithinWindowCoordinate(PanelConfig panelConfig, MSLLHOOKSTRUCT coor) + { + return coor.pt.X > panelConfig.Left + && coor.pt.X < panelConfig.Left + panelConfig.Width + && coor.pt.Y > panelConfig.Top + (panelConfig.HideTitlebar ? 5 : PANEL_MENUBAR_HEIGHT) + && coor.pt.Y < panelConfig.Top + panelConfig.Height; + } + + private static bool CheckWithinFullScreenCoordinate(PanelConfig panelConfig, MSLLHOOKSTRUCT coor) + { + return coor.pt.X > panelConfig.FullScreenMonitorInfo.X + && coor.pt.X < panelConfig.FullScreenMonitorInfo.X + panelConfig.FullScreenMonitorInfo.Width + && coor.pt.Y > panelConfig.FullScreenMonitorInfo.Y + && coor.pt.Y < panelConfig.FullScreenMonitorInfo.Y + panelConfig.FullScreenMonitorInfo.Height; + } } } diff --git a/WindowsAgent/WindowActionManager.cs b/WindowsAgent/WindowActionManager.cs index 7c33d57..2a1ffa6 100644 --- a/WindowsAgent/WindowActionManager.cs +++ b/WindowsAgent/WindowActionManager.cs @@ -183,9 +183,6 @@ namespace MSFSPopoutPanelManager.WindowsAgent if (caption.IndexOf("Virtual NumPad", StringComparison.Ordinal) > -1) return PanelType.NumPadWindow; - - if (caption.IndexOf("Switch Window", StringComparison.Ordinal) > -1) - return PanelType.SwitchWindow; return PanelType.PopOutManager; } @@ -199,7 +196,7 @@ namespace MSFSPopoutPanelManager.WindowsAgent { var panelType = GetWindowPanelType(hwnd); - if (panelType == PanelType.CustomPopout || panelType == PanelType.HudBarWindow || panelType == PanelType.NumPadWindow || panelType == PanelType.SwitchWindow) + if (panelType == PanelType.CustomPopout || panelType == PanelType.HudBarWindow || panelType == PanelType.NumPadWindow) CloseWindow(hwnd); return true; @@ -314,5 +311,22 @@ namespace MSFSPopoutPanelManager.WindowsAgent return text.Substring(0, 26).Equals("Microsoft Flight Simulator", StringComparison.InvariantCultureIgnoreCase); } + + public static void SetHostMonitor(PanelConfig panelConfig) + { + foreach (var screen in System.Windows.Forms.Screen.AllScreens) + { + if (screen.Bounds.IntersectsWith(new Rectangle(panelConfig.Left, panelConfig.Top, panelConfig.Width, panelConfig.Height))) + panelConfig.FullScreenMonitorInfo = + new MonitorInfo + { + Name = screen.DeviceName.Substring(screen.DeviceName.LastIndexOf("\\", StringComparison.Ordinal) + 1), + X = screen.Bounds.X, + Y = screen.Bounds.Y, + Width = screen.Bounds.Width, + Height = screen.Bounds.Height + }; + } + } } }