| | |
| | | private readonly Border _editBorder; |
| | | private readonly Border _resizeGrip; |
| | | private WidgetLayout _layout; |
| | | private MonitorInfo? _monitorInfo; |
| | | private double? _requestedHeight; |
| | | private bool _editMode; |
| | | private bool _safeInputMode; |
| | |
| | | ApplyWin32Styles(); |
| | | } |
| | | |
| | | public void SetMonitorInfo(MonitorInfo? monitorInfo) |
| | | { |
| | | _monitorInfo = monitorInfo; |
| | | ApplyWin32Styles(); |
| | | } |
| | | |
| | | protected override async void OnClosed(EventArgs e) |
| | | { |
| | | await _webView.DisposeAsync(); |
| | |
| | | var bounds = new RectD(Left, Top, Width, Height); |
| | | _dragStart = null; |
| | | _resizing = false; |
| | | await _commitLayoutAsync(_layout.InstanceId, new WidgetLayoutPatch { Bounds = bounds }, CancellationToken.None); |
| | | |
| | | var patch = new WidgetLayoutPatch { Bounds = bounds }; |
| | | try |
| | | { |
| | | var monitors = _interop.GetMonitors(); |
| | | if (monitors.Count > 0) |
| | | { |
| | | var bestMonitor = monitors |
| | | .Select(m => new { Monitor = m, Overlap = ComputeOverlapArea(bounds, m.Bounds) }) |
| | | .MaxBy(x => x.Overlap); |
| | | if (bestMonitor is not null && bestMonitor.Monitor.Id != _layout.MonitorId) |
| | | { |
| | | patch = patch with { MonitorId = bestMonitor.Monitor.Id }; |
| | | } |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | } |
| | | |
| | | await _commitLayoutAsync(_layout.InstanceId, patch, CancellationToken.None); |
| | | } |
| | | |
| | | private void BeginPointerOperation(MouseButtonEventArgs e) |
| | |
| | | DisplayLayer = _layout.DisplayLayer |
| | | }; |
| | | |
| | | private static double ComputeOverlapArea(RectD a, RectD b) |
| | | { |
| | | var overlapX = Math.Max(0, Math.Min(a.Right, b.Right) - Math.Max(a.X, b.X)); |
| | | var overlapY = Math.Max(0, Math.Min(a.Bottom, b.Bottom) - Math.Max(a.Y, b.Y)); |
| | | return overlapX * overlapY; |
| | | } |
| | | |
| | | private void ApplyWin32Styles() |
| | | { |
| | | var hwnd = _interop.GetWindowHandle(this); |
| | |
| | | try |
| | | { |
| | | _interop.SetToolWindow(hwnd, true); |
| | | _interop.SetLayered(hwnd, true, ToAlpha(_layout.Opacity)); |
| | | _interop.SetLayered(hwnd, true); |
| | | _interop.SetClickThrough(hwnd, !_editMode && !_safeInputMode && _layout.ClickThrough); |
| | | switch (_layout.DisplayLayer) |
| | | { |
| | | case DisplayLayer.Desktop: |
| | | Topmost = false; |
| | | _interop.MoveToDesktopLayer(hwnd, DesktopLayerMode.WorkerW, _layout.Bounds); |
| | | if (_monitorInfo is not null) |
| | | { |
| | | _interop.MoveToDesktopLayer(hwnd, DesktopLayerMode.WorkerW, _monitorInfo, _layout.Bounds); |
| | | } |
| | | |
| | | break; |
| | | case DisplayLayer.GlobalTop: |
| | | _interop.RestoreTopLevelWindow(hwnd); |
| | |
| | | new Dictionary<string, string> { ["instanceId"] = _layout.InstanceId.Value, ["exception"] = ex.GetType().Name }); |
| | | } |
| | | } |
| | | |
| | | private static byte ToAlpha(double opacity) => (byte)Math.Round(Math.Clamp(opacity, 0.1, 1.0) * 255); |
| | | } |