mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-03 09:03:42 -04:00
feat: cosmetic overhaul of native notification popup (#13)
* feat: cosmetic overhaul of native notification popup * fix: use correct screen default * feat: move notification test from debug build type to button press * fix: not debug anymore * fix: rearrange native notification settings controls * fix: account for display scaling when positioning notification * fix: guard against a screen that no longer exists * fix: safer way to get screens, in case control tree changes
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Observatory.UI.Views
|
||||
{
|
||||
@ -10,11 +13,53 @@ namespace Observatory.UI.Views
|
||||
{
|
||||
InitializeComponent();
|
||||
SystemDecorations = SystemDecorations.None;
|
||||
var screenBounds = Screens.Primary.Bounds;
|
||||
Position = screenBounds.BottomRight - new PixelPoint((int)Width, (int)Height);
|
||||
|
||||
MakeClickThrough(); //Platform specific, currently windows only.
|
||||
|
||||
int screen = Properties.Core.Default.NativeNotifyScreen;
|
||||
int corner = Properties.Core.Default.NativeNotifyCorner;
|
||||
string font = Properties.Core.Default.NativeNotifyFont;
|
||||
|
||||
if (font.Length > 0)
|
||||
{
|
||||
var titleText = this.Find<TextBlock>("Title");
|
||||
var detailText = this.Find<TextBlock>("Detail");
|
||||
var fontFamily = new Avalonia.Media.FontFamily(font);
|
||||
|
||||
titleText.FontFamily = fontFamily;
|
||||
detailText.FontFamily = fontFamily;
|
||||
}
|
||||
|
||||
PixelRect screenBounds;
|
||||
|
||||
if (screen == -1 || screen > Screens.All.Count)
|
||||
screenBounds = Screens.Primary.Bounds;
|
||||
else
|
||||
screenBounds = Screens.All[screen - 1].Bounds;
|
||||
|
||||
double scale = LayoutHelper.GetLayoutScale(this);
|
||||
double scaleWidth = Width * scale;
|
||||
double scaleHeight = Height * scale;
|
||||
|
||||
switch (corner)
|
||||
{
|
||||
default: case 0:
|
||||
Position = screenBounds.BottomRight - new PixelPoint((int)scaleWidth + 50, (int)scaleHeight + 50);
|
||||
break;
|
||||
case 1:
|
||||
Position = screenBounds.BottomLeft - new PixelPoint(-50, (int)scaleHeight + 50);
|
||||
break;
|
||||
case 2:
|
||||
Position = screenBounds.TopRight - new PixelPoint((int)scaleWidth + 50, -50);
|
||||
break;
|
||||
case 3:
|
||||
Position = screenBounds.TopLeft + new PixelPoint(50, 50);
|
||||
break;
|
||||
}
|
||||
|
||||
var timer = new System.Timers.Timer();
|
||||
timer.Elapsed += CloseNotification;
|
||||
timer.Interval = 5000;
|
||||
timer.Interval = 8000;
|
||||
timer.Start();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
@ -33,5 +78,31 @@ namespace Observatory.UI.Views
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void MakeClickThrough()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var style = GetWindowLong(this.PlatformImpl.Handle.Handle, GWL_EXSTYLE);
|
||||
|
||||
//PlatformImpl not part of formal Avalonia API and may not be available in future versions.
|
||||
SetWindowLong(this.PlatformImpl.Handle.Handle, GWL_EXSTYLE, style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
|
||||
SetLayeredWindowAttributes(this.PlatformImpl.Handle.Handle, 0, 255, LWA_ALPHA);
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
|
||||
[DllImport("user32.dll")]
|
||||
static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
|
||||
[DllImport("user32.dll")]
|
||||
static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
|
||||
|
||||
internal const int GWL_EXSTYLE = -20;
|
||||
internal const int WS_EX_LAYERED = 0x80000;
|
||||
internal const int LWA_ALPHA = 0x2;
|
||||
internal const int WS_EX_TRANSPARENT = 0x00000020;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user