Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现一些 Linux 的窗口信息和属性;修复命名空间 #1

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/WindowDebugger/Localizations/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ App.UI.WindowDetail.Pages.Windows.Operations.ThreadOperations.Kill.Action = "End
App.UI.WindowDetail.Pages.Windows.Others.Title = "Others"
App.UI.WindowDetail.Pages.Windows.Others.IsTouchWindow = "Is Touch Window"
App.UI.WindowDetail.Pages.Windows.Others.VirtualDesktopId = "Virtual Desktop ID"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Title = "Rect"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Description = "Screen coordinates"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Left = "Left"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Top = "Top"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Width = "Width"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Height = "Height"
App.UI.WindowDetail.Pages.Linux.Info.Title = "Info"
App.UI.WindowDetail.Pages.Linux.Properties.Title = "Properties"
App.UI.WindowDetail.Pages.Linux.Operations.Title = "Operations"
Expand Down
6 changes: 6 additions & 0 deletions src/WindowDebugger/Localizations/zh-hans.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ App.UI.WindowDetail.Pages.Windows.Operations.ThreadOperations.Kill.Action = "终
App.UI.WindowDetail.Pages.Windows.Others.Title = "其他"
App.UI.WindowDetail.Pages.Windows.Others.IsTouchWindow = "是否支持触摸"
App.UI.WindowDetail.Pages.Windows.Others.VirtualDesktopId = "虚拟桌面标识符"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Title = "位置和大小"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Description = "屏幕坐标系"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Height = "高"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Left = "左"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Top = "上"
App.UI.WindowDetail.Pages.Linux.Info.Bounds.Width = "宽"
App.UI.WindowDetail.Pages.Linux.Info.Title = "信息"
App.UI.WindowDetail.Pages.Linux.Properties.Title = "属性"
App.UI.WindowDetail.Pages.Linux.Operations.Title = "操作"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SeWzc.WinInfo.Models;
using SeWzc.X11Sharp;
using SeWzc.X11Sharp;
using WindowDebugger.Services.NativeWindows.Linux.Models;

namespace WindowDebugger.Services.NativeWindows.Linux;

Expand All @@ -14,6 +14,8 @@ public LinuxNativeWindowModel(X11DisplayWindow window) : base(window.Window.ToPt
{
ProcessId = (int)pid;
}

_windowAttributes = window.GetAttributes() ?? throw new ArgumentException("Failed to get window attributes.");
}

internal X11DisplayWindow Window { get; }
Expand All @@ -24,6 +26,32 @@ public LinuxNativeWindowModel(X11DisplayWindow window) : base(window.Window.ToPt

public int Handle { get; }

#region attributes

private readonly WindowAttributes _windowAttributes;

public int Left => _windowAttributes.X;

public int Top => _windowAttributes.Y;

public int Width => _windowAttributes.Width;

public int Height => _windowAttributes.Height;

public int Depth => _windowAttributes.Depth;

public int BorderWidth => _windowAttributes.BorderWidth;

public WindowClasses WindowClasses => _windowAttributes.WindowClass;

public MapState MapState => _windowAttributes.MapState;

public bool OverrideRedirect => _windowAttributes.OverrideRedirect;

#endregion

public IEnumerable<IGrouping<string, WindowProperty>> WindowPropertyGroups => GetWindowValuesGrouped();

public IReadOnlyList<LinuxNativeWindowModel> GetChildren()
{
return Window.QueryTree(out _, out _, out var children)
Expand All @@ -39,4 +67,17 @@ public IReadOnlyList<WindowProperty> GetWindowValues()
select new WindowProperty(Window, property);
return windowProperties.ToList();
}

public IEnumerable<IGrouping<string, WindowProperty>> GetWindowValuesGrouped()
{
return GetWindowValues()
.ToLookup(x =>
{
var name = x.Name;
if (!name.StartsWith('_'))
return "普通属性";
var index = name.IndexOf('_', 1);
return "扩展属性:" + (index > 0 ? name[1..index] : name[1..]);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SeWzc.X11Sharp;

namespace SeWzc.WinInfo.Models;
namespace WindowDebugger.Services.NativeWindows.Linux.Models;

public class LinuxNativeWindowCollectionManager
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Avalonia;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using SeWzc.X11Sharp;
using SeWzc.X11Sharp.Structs;

namespace SeWzc.WinInfo.Models;
namespace WindowDebugger.Services.NativeWindows.Linux.Models;

public class WindowProperty(X11DisplayWindow window, X11DisplayAtom property)
{
public string Name { get; } = property.GetAtomName() ?? "(null)";

public IReadOnlyWindowPropertyValue Value => GetValue();

public IReadOnlyWindowPropertyValue GetValue()
{
var propertyData = window.GetProperty(property);
Expand Down Expand Up @@ -242,4 +241,4 @@ public PropertyData ToPropertyData()
{
return new PropertyData.Format32Array(_propertyType, _propertyType.Display.InternAtoms(Atoms).Select(x => (Long)(int)x.Atom).ToArray());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using SeWzc.X11Sharp;

namespace SeWzc.WinInfo.Models;
namespace WindowDebugger.Services.NativeWindows.Linux.Models;

public class WindowProxy
{
Expand Down Expand Up @@ -34,4 +32,4 @@ public IReadOnlyList<WindowProperty> GetWindowValues()
select new WindowProperty(Window, property);
return windowProperties.ToList();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ReactiveUI;

namespace SeWzc.WinInfo.ViewModels;
namespace WindowDebugger.Services.NativeWindows.Linux.ViewModels;

public abstract class ViewModelBase : ReactiveObject;
public abstract class ViewModelBase : ReactiveObject;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using ReactiveUI;

namespace SeWzc.WinInfo.ViewModels;
namespace WindowDebugger.Services.NativeWindows.Linux.ViewModels;

public class WindowInfoTabViewModel : ViewModelBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using SeWzc.WinInfo.Models;
using WindowDebugger.Services.NativeWindows.Linux.Models;

namespace SeWzc.WinInfo.ViewModels;
namespace WindowDebugger.Services.NativeWindows.Linux.ViewModels;

public class WindowProxyViewModel : ViewModelBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ReactiveUI;
using SeWzc.WinInfo.Models;
using WindowDebugger.Services.NativeWindows.Linux.Models;

namespace SeWzc.WinInfo.ViewModels;
namespace WindowDebugger.Services.NativeWindows.Linux.ViewModels;

public class WindowValueViewModel(WindowProperty model) : ViewModelBase
{
Expand All @@ -23,4 +23,4 @@ public IReadOnlyWindowPropertyValue Value
this.RaisePropertyChanged();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ partial class NativeWindowCollectionManager
{
[SupportedOSPlatform("linux")]
private X11Display? _display;

[SupportedOSPlatform("linux")]
private LinuxNativeWindowModel[] FindWindowsOnLinux(WindowSearchingFilter filter)
{
var display = _display ??= X11Display.Open();

return [..new LinuxNativeWindowModel(display.DefaultRootWindow)
.GetChildren()
.Select(x=>new LinuxNativeWindowModel(x.Window))];
Expand Down
71 changes: 71 additions & 0 deletions src/WindowDebugger/Views/Details/Linux/WindowInfosPage.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
xmlns:linux="clr-namespace:WindowDebugger.Services.NativeWindows.Linux"
xmlns:l="clr-namespace:WindowDebugger.Localizations"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="WindowDebugger.Views.Details.Linux.WindowInfosPage"
x:DataType="linux:LinuxNativeWindowModel">

<UserControl.Styles>
<Style Selector="TextBlock">
<Setter Property="Margin" Value="0 4 12 4" />
<Setter Property="Foreground" Value="#EEEEEE" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style Selector="ComboBox">
<Setter Property="Margin" Value="0 4" />
<Setter Property="Height" Value="32" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
<Style Selector="Button">
<Setter Property="Margin" Value="8 0 0 0" />
<Setter Property="Padding" Value="12 0" />
<Setter Property="MinWidth" Value="64" />
<Setter Property="Height" Value="32" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</UserControl.Styles>

<ScrollViewer>
<StackPanel Margin="32 4 32 32">
<Grid Margin="0 12 0 0"
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*,Auto">

<TextBlock Grid.Row="0" Grid.Column="0">
<Run Text="{Binding App.UI.WindowDetail.Pages.Linux.Info.Bounds.Title, Source={x:Static l:Lang.Current}}" />
<LineBreak />
<Run Foreground="#666666" FontSize="12" Text="{Binding App.UI.WindowDetail.Pages.Linux.Info.Bounds.Description, Source={x:Static l:Lang.Current}}" />
</TextBlock>
<UniformGrid Grid.Row="0" Grid.Column="1" x:Name="GridRect" Columns="4">
<TextBlock Text="{Binding App.UI.WindowDetail.Pages.Linux.Info.Bounds.Left, Source={x:Static l:Lang.Current}}" HorizontalAlignment="Center"/>
<TextBox x:Name="RectLeftTextBox" Text="{Binding Left, Mode=OneWay}"/>
<TextBlock Text="{Binding App.UI.WindowDetail.Pages.Linux.Info.Bounds.Top, Source={x:Static l:Lang.Current}}" HorizontalAlignment="Center"/>
<TextBox x:Name="RectTopTextBox" Text="{Binding Top, Mode=OneWay}"/>
<TextBlock Text="{Binding App.UI.WindowDetail.Pages.Linux.Info.Bounds.Width, Source={x:Static l:Lang.Current}}" HorizontalAlignment="Center"/>
<TextBox x:Name="RectWidthTextBox" Text="{Binding Width, Mode=OneWay}"/>
<TextBlock Text="{Binding App.UI.WindowDetail.Pages.Linux.Info.Bounds.Height, Source={x:Static l:Lang.Current}}" HorizontalAlignment="Center"/>
<TextBox x:Name="RectHeightTextBox" Text="{Binding Height, Mode=OneWay}"/>
</UniformGrid>

<TextBlock Grid.Row="1" Grid.Column="0" Text="颜色深度 Depth"/>
<TextBox Grid.Row="1" Grid.Column="1" Classes="Code" Text="{Binding Depth, Mode=OneWay}"/>

<TextBlock Grid.Row="2" Grid.Column="0" Text="边框宽度"/>
<TextBox Grid.Row="2" Grid.Column="1" Classes="Code" Text="{Binding BorderWidth, StringFormat='0x{0:X}', Mode=OneWay}"/>

<TextBlock Grid.Row="3" Grid.Column="0" Text="窗口类型"/>
<TextBox Grid.Row="3" Grid.Column="1" Classes="Code" Text="{Binding WindowClasses, Mode=OneWay}"/>

<TextBlock Grid.Row="4" Grid.Column="0" Text="窗口映射状态"/>
<TextBox Grid.Row="4" Grid.Column="1" Classes="Code" Text="{Binding MapState, Mode=OneWay}"/>

<TextBlock Grid.Row="5" Grid.Column="0" Text="OverrideRedirect"/>
<TextBox Grid.Row="5" Grid.Column="1" Classes="Code" Text="{Binding OverrideRedirect, Mode=OneWay}"/>

</Grid>
</StackPanel>
</ScrollViewer>
</UserControl>
11 changes: 11 additions & 0 deletions src/WindowDebugger/Views/Details/Linux/WindowInfosPage.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;

namespace WindowDebugger.Views.Details.Linux;

public partial class WindowInfosPage : UserControl
{
public WindowInfosPage()
{
InitializeComponent();
}
}
Loading