-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from Freeesia/feature/target_window
ターゲットウィンドウダイアログを開く機能を追加
- Loading branch information
Showing
10 changed files
with
474 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Windows; | ||
using Kamishibai; | ||
|
||
namespace VdLabel; | ||
|
||
public partial interface IPresentationService : IPresentationServiceBase | ||
{ | ||
Task<WindowInfo?> OpenTargetWindowDialogAsync(); | ||
} | ||
|
||
public class PresentationService(IServiceProvider serviceProvider, INavigationFrameProvider navigationFrameProvider, IWindowService windowService) | ||
: PresentationServiceBase(serviceProvider, navigationFrameProvider, windowService), IPresentationService | ||
{ | ||
private readonly IServiceProvider _serviceProvider = serviceProvider; | ||
|
||
public async Task<WindowInfo?> OpenTargetWindowDialogAsync() | ||
{ | ||
var current = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive); | ||
current?.Hide(); | ||
try | ||
{ | ||
var vm = new TargetWindowViewModel(); | ||
if (await OpenDialogAsync(vm) == true) | ||
{ | ||
return vm.SelectedWindow; | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
finally | ||
{ | ||
current?.Show(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Diagnostics; | ||
using System.Management; | ||
using PInvoke; | ||
|
||
namespace VdLabel; | ||
public static class ProcessUtility | ||
{ | ||
public static string? GetWindowTitle(nint hWnd) | ||
{ | ||
try | ||
{ | ||
return User32.GetWindowText(hWnd); | ||
} | ||
catch (Win32Exception) | ||
{ | ||
// 仮想デスクトップを切り替えるタイミングで例外が発生することがある | ||
return null; | ||
} | ||
} | ||
|
||
public static string? GetProcessPath(int processId) | ||
{ | ||
try | ||
{ | ||
using var process = Process.GetProcessById(processId); | ||
using var module = process.MainModule; | ||
return module?.FileName ?? string.Empty; | ||
} | ||
catch (Exception) | ||
{ | ||
// プロセスが終了している場合がある | ||
return null; | ||
} | ||
} | ||
|
||
public static string? GetCommandLine(int processId) | ||
{ | ||
using var searcher = new ManagementObjectSearcher($"SELECT CommandLine FROM Win32_Process WHERE ProcessId = '{processId}'"); | ||
using var mo = searcher.Get().Cast<ManagementBaseObject>().SingleOrDefault(); | ||
return mo?["CommandLine"] as string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<Window | ||
x:Class="VdLabel.TargetWindowOverlay" | ||
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:local="clr-namespace:VdLabel" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
d:DataContext="{d:DesignInstance local:TargetWindowViewModel}" | ||
AllowsTransparency="True" | ||
Background="#11808080" | ||
Cursor="Cross" | ||
Loaded="Window_Loaded" | ||
ResizeMode="NoResize" | ||
ShowActivated="False" | ||
ShowInTaskbar="False" | ||
Topmost="True" | ||
WindowStartupLocation="Manual" | ||
WindowState="Normal" | ||
WindowStyle="None" | ||
mc:Ignorable="d"> | ||
<Grid> | ||
<ListBox SelectedItem="{Binding SelectedWindow}"> | ||
<ListBox.ItemsSource> | ||
<MultiBinding Converter="{x:Static local:WindowOffsetConverter.Default}"> | ||
<Binding Path="Windows" /> | ||
<Binding RelativeSource="{RelativeSource AncestorType=Window}" /> | ||
</MultiBinding> | ||
</ListBox.ItemsSource> | ||
<ListBox.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<Canvas /> | ||
</ItemsPanelTemplate> | ||
</ListBox.ItemsPanel> | ||
<ListBox.ItemContainerStyle> | ||
<Style TargetType="ListBoxItem"> | ||
<Setter Property="Canvas.Left" Value="{Binding Left, Mode=OneWay}" /> | ||
<Setter Property="Canvas.Top" Value="{Binding Top, Mode=OneWay}" /> | ||
<Setter Property="Width" Value="{Binding Width, Mode=OneWay}" /> | ||
<Setter Property="Height" Value="{Binding Height, Mode=OneWay}" /> | ||
<Setter Property="Panel.ZIndex" Value="{Binding ZOrder, Mode=OneWay}" /> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="ListBoxItem"> | ||
<Border | ||
Name="Bd" | ||
Background="Transparent" | ||
BorderBrush="Transparent" | ||
BorderThickness="4" | ||
SnapsToDevicePixels="True"> | ||
<ContentPresenter | ||
Name="Content" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
Content="{TemplateBinding Content}" | ||
ContentStringFormat="{TemplateBinding ContentStringFormat}" | ||
ContentTemplate="{TemplateBinding ContentTemplate}" | ||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" | ||
Visibility="Hidden" /> | ||
</Border> | ||
<ControlTemplate.Triggers> | ||
<MultiTrigger> | ||
<MultiTrigger.Conditions> | ||
<Condition Property="Selector.IsSelectionActive" Value="False" /> | ||
<Condition Property="Selector.IsSelected" Value="True" /> | ||
</MultiTrigger.Conditions> | ||
</MultiTrigger> | ||
<MultiTrigger> | ||
<MultiTrigger.Conditions> | ||
<Condition Property="Selector.IsSelectionActive" Value="True" /> | ||
<Condition Property="Selector.IsSelected" Value="True" /> | ||
</MultiTrigger.Conditions> | ||
</MultiTrigger> | ||
<Trigger Property="IsMouseOver" Value="True"> | ||
<Setter TargetName="Bd" Property="Border.BorderBrush" Value="GreenYellow" /> | ||
<Setter TargetName="Content" Property="FrameworkElement.Visibility" Value="Visible" /> | ||
</Trigger> | ||
</ControlTemplate.Triggers> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ListBox.ItemContainerStyle> | ||
<ListBox.ItemTemplate> | ||
<DataTemplate DataType="local:WindowInfo"> | ||
<Grid HorizontalAlignment="Center" VerticalAlignment="Center"> | ||
<Border Background="{DynamicResource ApplicationBackgroundBrush}" CornerRadius="4"> | ||
<Border.Effect> | ||
<BlurEffect Radius="8" /> | ||
</Border.Effect> | ||
</Border> | ||
<TextBlock | ||
Padding="4" | ||
Foreground="{DynamicResource TextFillColorPrimaryBrush}" | ||
Text="{Binding Title, Mode=OneWay}" /> | ||
</Grid> | ||
</DataTemplate> | ||
</ListBox.ItemTemplate> | ||
</ListBox> | ||
<ui:Button | ||
HorizontalAlignment="Right" | ||
VerticalAlignment="Top" | ||
Background="Red" | ||
Command="{Binding CancelCommand, Mode=OneWay}" | ||
CornerRadius="0" | ||
Cursor="Arrow" | ||
Icon="{ui:SymbolIcon Dismiss48}" | ||
MouseOverBackground="OrangeRed" /> | ||
</Grid> | ||
</Window> |
Oops, something went wrong.