Screen
Read the physical display's size, available working area, color depth and multi-monitor status, and react to screen changes - all from injected C# with no JavaScript.
@inject Bit.Butil.Screen screenMDN reference
The full width and height of the screen in pixels, regardless of what the operating system or browser occupies.
var width = await screen.GetWidth();
var height = await screen.GetHeight();The screen area actually available to windows, excluding permanent or semipermanent OS interface features such as the Windows Taskbar or the macOS Dock.
var availableWidth = await screen.GetAvailableWidth();
var availableHeight = await screen.GetAvailableHeight();The color depth and bit depth of the screen, in bits per pixel. On virtually all modern hardware both report 24 or 30.
var colorDepth = await screen.GetColorDepth();
var pixelDepth = await screen.GetPixelDepth();Reports whether the user's desktop spans more than one screen - useful before offering multi-window or presentation features.
var isExtended = await screen.IsExtended();Fires when the screen changes in some way - width or height, available area, color depth or orientation. The returned subscription detaches the listener when disposed.
var subscription = await screen.SubscribeChange(() =>
{
// width, height, color depth or orientation changed
});
// later, when no longer needed:
await subscription.DisposeAsync();If you prefer explicit ids over disposable subscriptions, AddChange returns a Guid that can later be passed to RemoveChange, and RemoveAllChanges drops every listener registered on this instance.
// register and keep the id
var id = await screen.AddChange(OnScreenChange);
// remove a single listener by id
await screen.RemoveChange(id);
// or drop every registered listener at once
await screen.RemoveAllChanges();API reference
Task<float> GetWidth()Task<float> GetHeight()Task<float> GetAvailableWidth()Task<float> GetAvailableHeight()Task<byte> GetColorDepth()Task<byte> GetPixelDepth()Task<bool> IsExtended()ValueTask<Guid> AddChange(Action handler)ValueTask<ButilSubscription> SubscribeChange(Action handler)ValueTask<Guid[]> RemoveChange(Action handler)ValueTask RemoveChange(Guid id)ValueTask RemoveAllChanges()void InvokeScreenChange(Guid id)ValueTask DisposeAsync()Task<float> GetAvailableLeft()Task<float> GetAvailableTop()