same shit- windows
This commit is contained in:
parent
1ea7cfc632
commit
ab23a4a885
|
|
@ -2,14 +2,12 @@ using System;
|
|||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Composition.SystemBackdrops;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Windows.Graphics;
|
||||
using Windows.Foundation;
|
||||
using WinRT.Interop;
|
||||
|
||||
namespace LayersShell;
|
||||
|
|
@ -17,8 +15,6 @@ namespace LayersShell;
|
|||
public sealed partial class MainWindow : Window
|
||||
{
|
||||
private IntPtr _handle = IntPtr.Zero;
|
||||
private MicaController? _mica;
|
||||
private SystemBackdropConfiguration? _backdropConfig;
|
||||
private IntPtr _hwnd = IntPtr.Zero;
|
||||
|
||||
private const double DefaultLogicalWidth = 480;
|
||||
|
|
@ -36,7 +32,6 @@ public sealed partial class MainWindow : Window
|
|||
var appWindow = AppWindow.GetFromWindowId(Win32Interop.GetWindowIdFromWindow(_hwnd));
|
||||
if (appWindow is not null)
|
||||
{
|
||||
// Borderless chrome + topmost + default size.
|
||||
appWindow.SetPresenter(AppWindowPresenterKind.Overlapped);
|
||||
if (appWindow.Presenter is OverlappedPresenter op)
|
||||
{
|
||||
|
|
@ -49,7 +44,8 @@ public sealed partial class MainWindow : Window
|
|||
appWindow.ResizeClient(new SizeInt32((int)DefaultLogicalWidth, (int)DefaultLogicalHeight));
|
||||
}
|
||||
|
||||
SetupMica();
|
||||
// Windows App SDK 1.3+: assign a backdrop directly, no MicaController wiring needed.
|
||||
SystemBackdrop = new MicaBackdrop { Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base };
|
||||
|
||||
Activated += OnActivated;
|
||||
Closed += OnClosed;
|
||||
|
|
@ -63,39 +59,16 @@ public sealed partial class MainWindow : Window
|
|||
});
|
||||
}
|
||||
|
||||
private void SetupMica()
|
||||
{
|
||||
if (!MicaController.IsSupported())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_backdropConfig = new SystemBackdropConfiguration
|
||||
{
|
||||
IsInputActive = true,
|
||||
Theme = SystemBackdropTheme.Dark,
|
||||
};
|
||||
_mica = new MicaController
|
||||
{
|
||||
Kind = MicaKind.Base,
|
||||
};
|
||||
_mica.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
|
||||
_mica.SetSystemBackdropConfiguration(_backdropConfig);
|
||||
}
|
||||
|
||||
private void OnActivated(object sender, WindowActivatedEventArgs e)
|
||||
{
|
||||
_isFocused = e.WindowActivationState != WindowActivationState.Deactivated;
|
||||
if (_backdropConfig is not null)
|
||||
{
|
||||
_backdropConfig.IsInputActive = _isFocused;
|
||||
}
|
||||
ApplyFade();
|
||||
}
|
||||
|
||||
private void OnClosed(object sender, WindowEventArgs args)
|
||||
{
|
||||
_mica?.Dispose();
|
||||
_mica = null;
|
||||
_renderTimer?.Stop();
|
||||
_renderTimer = null;
|
||||
if (_handle != IntPtr.Zero)
|
||||
{
|
||||
LayersNative.layers_destroy(_handle);
|
||||
|
|
@ -105,7 +78,6 @@ public sealed partial class MainWindow : Window
|
|||
|
||||
private void PointToRust()
|
||||
{
|
||||
// Resolve <plugin_root> from the shell exe's parent/parent path: ...\bin\Layers.exe
|
||||
var exe = System.Reflection.Assembly.GetEntryAssembly()?.Location;
|
||||
if (string.IsNullOrEmpty(exe)) return;
|
||||
var binDir = Path.GetDirectoryName(exe) ?? string.Empty;
|
||||
|
|
@ -122,22 +94,28 @@ public sealed partial class MainWindow : Window
|
|||
var height = (float)RenderSurface.ActualHeight;
|
||||
if (width <= 0 || height <= 0 || scale <= 0) return;
|
||||
|
||||
var native = RenderSurface.As<ISwapChainPanelNative>();
|
||||
var panelPtr = Marshal.GetIUnknownForObject(RenderSurface);
|
||||
// wgpu's dx12 backend wants an ISwapChainPanelNative*. Query it off the XAML element's
|
||||
// IUnknown rather than passing the raw WinRT object pointer.
|
||||
var iid = typeof(ISwapChainPanelNative).GUID;
|
||||
var unknown = Marshal.GetIUnknownForObject(RenderSurface);
|
||||
IntPtr native = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
_handle = LayersNative.layers_create_from_swap_chain_panel(panelPtr, width, height, scale);
|
||||
int hr = Marshal.QueryInterface(unknown, in iid, out native);
|
||||
if (hr < 0 || native == IntPtr.Zero) return;
|
||||
_handle = LayersNative.layers_create_from_swap_chain_panel(native, width, height, scale);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.Release(panelPtr);
|
||||
if (native != IntPtr.Zero) Marshal.Release(native);
|
||||
Marshal.Release(unknown);
|
||||
}
|
||||
}
|
||||
|
||||
private Microsoft.UI.Xaml.DispatcherTimer? _renderTimer;
|
||||
private DispatcherTimer? _renderTimer;
|
||||
private void StartRenderLoop()
|
||||
{
|
||||
_renderTimer = new Microsoft.UI.Xaml.DispatcherTimer
|
||||
_renderTimer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(1000.0 / 60.0),
|
||||
};
|
||||
|
|
@ -153,12 +131,10 @@ public sealed partial class MainWindow : Window
|
|||
|
||||
private void ApplyFade()
|
||||
{
|
||||
// Swift-shell parity: focused+hovered = 1.0, focused xor hovered = 0.5, neither = 0.1.
|
||||
double target = (_isFocused && _isHovered) ? 1.0
|
||||
: (_isFocused || _isHovered) ? 0.5
|
||||
: 0.1;
|
||||
var root = Content as FrameworkElement;
|
||||
if (root is not null)
|
||||
if (Content is FrameworkElement root)
|
||||
{
|
||||
root.Opacity = target;
|
||||
}
|
||||
|
|
@ -212,7 +188,6 @@ public sealed partial class MainWindow : Window
|
|||
{
|
||||
if (_handle == IntPtr.Zero) return;
|
||||
var p = e.GetCurrentPoint(RenderSurface);
|
||||
// Wheel delta in Windows is multiples of 120 per notch; convert to pixel-ish deltas.
|
||||
var dy = (float)p.Properties.MouseWheelDelta / 3.0f;
|
||||
LayersNative.layers_mouse_scroll(_handle, (float)p.Position.X, (float)p.Position.Y, 0.0f, dy);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue