mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
impl #1261
This commit is contained in:
16
src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml
Normal file
16
src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml
Normal file
@@ -0,0 +1,16 @@
|
||||
<Window
|
||||
x:Class="Snap.Hutao.IdentifyMonitorWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<Grid Padding="16">
|
||||
<TextBlock Text="当前显示器为:"/>
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{x:Bind Monitor}"
|
||||
TextAlignment="Center"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
18
src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml.cs
Normal file
18
src/Snap.Hutao/Snap.Hutao/IdentifyMonitorWindow.xaml.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao;
|
||||
|
||||
internal sealed partial class IdentifyMonitorWindow : Window
|
||||
{
|
||||
public IdentifyMonitorWindow(string monitor)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Monitor = monitor;
|
||||
}
|
||||
|
||||
public string Monitor { get; private set; }
|
||||
}
|
||||
@@ -107,6 +107,7 @@
|
||||
<None Remove="Control\Theme\Uri.xaml" />
|
||||
<None Remove="Control\Theme\WindowOverride.xaml" />
|
||||
<None Remove="GuideWindow.xaml" />
|
||||
<None Remove="IdentifyMonitorWindow.xaml" />
|
||||
<None Remove="IdentityStructs.json" />
|
||||
<None Remove="LaunchGameWindow.xaml" />
|
||||
<None Remove="Resource\BlurBackground.png" />
|
||||
@@ -544,7 +545,13 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="IdentifyMonitorWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="View\Control\HutaoStatisticsCard.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@@ -259,6 +259,10 @@
|
||||
</cwc:SettingsCard>
|
||||
<cwc:SettingsCard Description="{shcm:ResourceString Name=ViewPageLaunchGameMonitorsDescription}" Header="-monitor">
|
||||
<StackPanel Orientation="Horizontal" Spacing="16">
|
||||
<Button
|
||||
Width="120"
|
||||
Command="{Binding IdentifyMonitorsCommand}"
|
||||
Content="检测显示器"/>
|
||||
<shc:SizeRestrictedContentControl>
|
||||
<ComboBox
|
||||
DisplayMemberPath="Name"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using CommunityToolkit.WinUI.Collections;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.Diagnostics.CodeAnalysis;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
@@ -19,6 +20,7 @@ using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using Windows.Graphics;
|
||||
|
||||
namespace Snap.Hutao.ViewModel.Game;
|
||||
|
||||
@@ -338,4 +340,42 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Command("IdentifyMonitorsCommand")]
|
||||
private async Task IdentifyMonitorsAsync()
|
||||
{
|
||||
List<IdentifyMonitorWindow> windows = [];
|
||||
|
||||
IReadOnlyList<DisplayArea> displayAreas = DisplayArea.FindAll();
|
||||
for (int i = 0; i < displayAreas.Count; i++)
|
||||
{
|
||||
DisplayArea displayArea = displayAreas[i];
|
||||
int index = i + 1;
|
||||
|
||||
// Refresh thread to avoid access violation
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
IdentifyMonitorWindow window = new($"{displayArea.DisplayId.Value:X8}:{index}");
|
||||
AppWindow appWindow = window.AppWindow;
|
||||
|
||||
OverlappedPresenter presenter = OverlappedPresenter.Create();
|
||||
presenter.SetBorderAndTitleBar(false, false);
|
||||
presenter.IsAlwaysOnTop = true;
|
||||
appWindow.SetPresenter(presenter);
|
||||
|
||||
SizeInt32 size = new((int)(displayArea.WorkArea.Width * 0.15), (int)(displayArea.WorkArea.Height * 0.15));
|
||||
PointInt32 point = new(displayArea.WorkArea.X, displayArea.WorkArea.Y);
|
||||
appWindow.Resize(size);
|
||||
appWindow.Move(point);
|
||||
|
||||
window.Activate();
|
||||
|
||||
windows.Add(window);
|
||||
}
|
||||
|
||||
await Delay.FromSeconds(3).ConfigureAwait(false);
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
windows.ForEach(window => window.Close());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user