diff --git a/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyout.cs b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyout.cs new file mode 100644 index 0000000..eb11ab1 --- /dev/null +++ b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyout.cs @@ -0,0 +1,56 @@ +using Microsoft.UI.Xaml; + +namespace Hyperbar.Desktop.Controls; + +public class DesktopFlyout : + DependencyObject +{ + public static readonly DependencyProperty ContentProperty = + DependencyProperty.Register(nameof(Content), + typeof(object), typeof(DesktopFlyout), + new PropertyMetadata(null)); + + public static readonly DependencyProperty PlacementProperty = + DependencyProperty.Register(nameof(Placement), + typeof(DesktopFlyoutPlacement), typeof(DesktopFlyout), + new PropertyMetadata(DesktopFlyoutPlacement.Left, OnPlacementPropertyChanged)); + + private readonly DesktopFlyoutHost host; + private readonly DesktopFlyoutPresenter presenter; + + public DesktopFlyout() + { + presenter = new DesktopFlyoutPresenter + { + Parent = this + }; + + host = new DesktopFlyoutHost(presenter); + host.Activate(); + } + + public object Content + { + get => GetValue(ContentProperty); + set => SetValue(ContentProperty, value); + } + + public DesktopFlyoutPlacement Placement + { + get => (DesktopFlyoutPlacement)GetValue(PlacementProperty); + set => SetValue(PlacementProperty, value); + } + + private static void OnPlacementPropertyChanged(DependencyObject dependencyObject, + DependencyPropertyChangedEventArgs args) + { + if (dependencyObject is DesktopFlyout sender) + { + sender.OnPlacementPropertyChanged(); + } + } + + private void OnPlacementPropertyChanged() => UpdatePlacement(); + + private void UpdatePlacement() => host.UpdatePlacement(Placement); +} diff --git a/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutHost.cs b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutHost.cs new file mode 100644 index 0000000..ef60620 --- /dev/null +++ b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutHost.cs @@ -0,0 +1,90 @@ +using Microsoft.UI.Xaml; +using Hyperbar.Desktop.Win32; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Controls; +using Windows.Foundation; +using Microsoft.UI.Xaml.Media; + +namespace Hyperbar.Desktop.Controls; + +internal class DesktopFlyoutHost : Window +{ + private readonly DesktopFlyoutPresenter presenter; + private DesktopFlyoutPlacement placement; + private Popup popup; + + public DesktopFlyoutHost(DesktopFlyoutPresenter presenter) + { + Border root = new(); + root.Loaded += OnLoaded; + + this.presenter = presenter; + presenter.SizeChanged += OnChildSizeChanged; + + Content = root; + + this.SetOpacity(0); + this.SetStyle(WindowStyle.SysMenu | WindowStyle.Visible); + this.SetTopMost(true); + this.SetIsShownInSwitchers(false); + } + + internal void UpdatePlacement(DesktopFlyoutPlacement placement) + { + this.placement = placement; + + // Not ready + if (popup is null) + { + return; + } + + // presenter.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); + + double height = presenter.DesiredSize.Height; + double width = presenter.DesiredSize.Width; + + switch (placement) + { + case DesktopFlyoutPlacement.Left: + this.Snap(WindowPlacement.Left, 0, 0); + break; + case DesktopFlyoutPlacement.Top: + this.Snap(WindowPlacement.Top, width, height); + break; + case DesktopFlyoutPlacement.Right: + this.Snap(WindowPlacement.Right, 0, 0); + break; + case DesktopFlyoutPlacement.Bottom: + this.Snap(WindowPlacement.Bottom, width, height); + break; + default: + break; + } + + presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.HeightProperty, height); + presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.WidthProperty, width); + + presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeHeightProperty, -height); + presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeWidthProperty, -width); + + presenter.UpdatePlacementState(placement); + } + + private void OnChildSizeChanged(object sender, + SizeChangedEventArgs args) => UpdatePlacement(this.placement); + + private void OnLoaded(object sender, + RoutedEventArgs args) + { + popup = new Popup + { + Child = presenter, + XamlRoot = Content.XamlRoot, + ShouldConstrainToRootBounds = false, + IsOpen = true, + }; + + UpdatePlacement(placement); + } +} diff --git a/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPlacement.cs b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPlacement.cs new file mode 100644 index 0000000..9e45cd2 --- /dev/null +++ b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPlacement.cs @@ -0,0 +1,9 @@ +namespace Hyperbar.Desktop.Controls; + +public enum DesktopFlyoutPlacement +{ + Left, + Top, + Right, + Bottom +} diff --git a/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenter.cs b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenter.cs new file mode 100644 index 0000000..8dcec12 --- /dev/null +++ b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenter.cs @@ -0,0 +1,40 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; + +namespace Hyperbar.Desktop.Controls; + +public class DesktopFlyoutPresenter : + ContentControl +{ + public static readonly DependencyProperty TemplateSettingsProperty = + DependencyProperty.Register(nameof(TemplateSettings), + typeof(DesktopFlyoutPresenterTemplateSettings), typeof(DesktopFlyoutPresenter), + new PropertyMetadata(null)); + + internal new DesktopFlyout Parent; + + public DesktopFlyoutPresenter() + { + DefaultStyleKey = typeof(DesktopFlyoutPresenter); + TemplateSettings = new DesktopFlyoutPresenterTemplateSettings(); + } + + protected override void OnApplyTemplate() + { + SetBinding(ContentProperty, new Binding + { + Source = Parent, + Mode = BindingMode.TwoWay, + Path = new PropertyPath(nameof(Parent.Content)), + }); + } + + public DesktopFlyoutPresenterTemplateSettings TemplateSettings + { + get => (DesktopFlyoutPresenterTemplateSettings)GetValue(TemplateSettingsProperty); + set => SetValue(TemplateSettingsProperty, value); + } + + internal void UpdatePlacementState(DesktopFlyoutPlacement placement) => VisualStateManager.GoToState(this, $"{placement}Placement", true); +} diff --git a/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml new file mode 100644 index 0000000..5b63031 --- /dev/null +++ b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + diff --git a/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenterTemplateSettings.cs b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenterTemplateSettings.cs new file mode 100644 index 0000000..16b33ed --- /dev/null +++ b/Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenterTemplateSettings.cs @@ -0,0 +1,49 @@ +using Microsoft.UI.Xaml; + +namespace Hyperbar.Desktop.Controls; + +public class DesktopFlyoutPresenterTemplateSettings : DependencyObject +{ + public static readonly DependencyProperty HeightProperty = + DependencyProperty.Register(nameof(Height), + typeof(double), typeof(DesktopFlyoutPresenterTemplateSettings), + new PropertyMetadata(0d)); + + public static readonly DependencyProperty NegativeHeightProperty = + DependencyProperty.Register(nameof(NegativeHeight), + typeof(double), typeof(DesktopFlyoutPresenterTemplateSettings), + new PropertyMetadata(0d)); + + public static readonly DependencyProperty NegativeWidthProperty = + DependencyProperty.Register(nameof(NegativeWidth), + typeof(double), typeof(DesktopFlyoutPresenterTemplateSettings), + new PropertyMetadata(0d)); + + public static readonly DependencyProperty WidthProperty = + DependencyProperty.Register(nameof(Width), + typeof(double), typeof(DesktopFlyoutPresenterTemplateSettings), + new PropertyMetadata(0d)); + + public double Height + { + get => (double)GetValue(HeightProperty); + set => SetValue(HeightProperty, value); + } + public double NegativeHeight + { + get => (double)GetValue(NegativeHeightProperty); + set => SetValue(NegativeHeightProperty, value); + } + + public double NegativeWidth + { + get => (double)GetValue(NegativeWidthProperty); + set => SetValue(NegativeWidthProperty, value); + } + + public double Width + { + get => (double)GetValue(WidthProperty); + set => SetValue(WidthProperty, value); + } +} diff --git a/Hyperbar.Desktop.Controls/Hyperbar.Desktop.Controls.csproj b/Hyperbar.Desktop.Controls/Hyperbar.Desktop.Controls.csproj new file mode 100644 index 0000000..68bdadf --- /dev/null +++ b/Hyperbar.Desktop.Controls/Hyperbar.Desktop.Controls.csproj @@ -0,0 +1,35 @@ + + + net8.0-windows10.0.19041.0 + 10.0.17763.0 + Hyperbar.Desktop.Controls + win10-x86;win10-x64;win10-arm64 + true + true + + + + + + + + + + + MSBuild:Compile + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + diff --git a/Hyperbar.Desktop.Controls/Themes/Generic.xaml b/Hyperbar.Desktop.Controls/Themes/Generic.xaml new file mode 100644 index 0000000..6b3f471 --- /dev/null +++ b/Hyperbar.Desktop.Controls/Themes/Generic.xaml @@ -0,0 +1,6 @@ + + + + + + diff --git a/Hyperbar.Desktop.Win32/Extensions/HwndExtensions.cs b/Hyperbar.Desktop.Win32/Extensions/HwndExtensions.cs new file mode 100644 index 0000000..ba1e155 --- /dev/null +++ b/Hyperbar.Desktop.Win32/Extensions/HwndExtensions.cs @@ -0,0 +1,91 @@ +using System; +using Windows.Win32; +using Windows.Win32.Foundation; +using Windows.Win32.Graphics.Gdi; +using System.Runtime.InteropServices; +using Windows.Win32.UI.WindowsAndMessaging; + +namespace Hyperbar.Desktop.Win32; + +public static class HwndExtensions +{ + [Flags] + private enum WindowStyles + { + WS_EX_LAYERED = 0x80000 + } + + public static void SetWindowOpacity(this IntPtr hWnd, + byte value) + { + HWND hWND = new(hWnd); + WindowStyles windowLong = (WindowStyles)PInvoke.GetWindowLong(hWND, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); + if (!windowLong.HasFlag(WindowStyles.WS_EX_LAYERED)) + { + PInvoke.SetWindowLong(hWND, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)(windowLong | WindowStyles.WS_EX_LAYERED)); + } + + if (!PInvoke.SetLayeredWindowAttributes(hWND, 0u, value, LAYERED_WINDOW_ATTRIBUTES_FLAGS.LWA_ALPHA)) + { + Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); + } + } + + public static void SetWindowStyle(this IntPtr hwnd, + WindowStyle newStyle) + { + int windowLong = PInvoke.GetWindowLong(new HWND(hwnd), WINDOW_LONG_PTR_INDEX.GWL_STYLE); + if (PInvoke.SetWindowLong(new HWND(hwnd), WINDOW_LONG_PTR_INDEX.GWL_STYLE, (int)newStyle) != windowLong) + { + Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); + } + + PInvoke.SetWindowPos(new HWND(hwnd), new HWND(0), 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_DRAWFRAME | SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOOWNERZORDER | SET_WINDOW_POS_FLAGS.SWP_NOSIZE | SET_WINDOW_POS_FLAGS.SWP_NOZORDER); + } + + public static void SnapWindow(this IntPtr hwnd, + WindowPlacement placement, + double? width = null, + double? height = null) + { + HMONITOR hwndDesktop = PInvoke.MonitorFromWindow(new(hwnd), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST); + MONITORINFO info = new() + { + cbSize = 40 + }; + + PInvoke.GetMonitorInfo(hwndDesktop, ref info); + + uint dpi = PInvoke.GetDpiForWindow(new HWND(hwnd)); + PInvoke.GetWindowRect(new HWND(hwnd), out RECT windowRect); + + double scalingFactor = dpi / 96d; + int actualWidth = width.HasValue ? (int)(width * scalingFactor) : windowRect.right - windowRect.left; + int actualHeight = height.HasValue ? (int)(height * scalingFactor) : windowRect.bottom - windowRect.top; + + int left = 0; + int top = 0; + + switch (placement) + { + case WindowPlacement.Left: + left = 0; + top = (info.rcWork.bottom + info.rcWork.top) / 2 - actualHeight / 2; + break; + case WindowPlacement.Top: + left = (info.rcWork.left + info.rcWork.right) / 2 - actualWidth / 2; + top = 0; + break; + case WindowPlacement.Right: + left = info.rcWork.left + info.rcWork.right - actualWidth; + top = (info.rcWork.bottom + info.rcWork.top) / 2 - actualHeight / 2; + break; + case WindowPlacement.Bottom: + left = (info.rcWork.left + info.rcWork.right) / 2 - actualWidth / 2; + top = info.rcWork.bottom + info.rcWork.top - actualHeight; + break; + } + + PInvoke.SetWindowPos(new HWND(hwnd), new HWND(), left, top, actualWidth, actualHeight, 0); + } +} diff --git a/Hyperbar.Desktop.Win32/Extensions/WindowExtensions.cs b/Hyperbar.Desktop.Win32/Extensions/WindowExtensions.cs new file mode 100644 index 0000000..69214d6 --- /dev/null +++ b/Hyperbar.Desktop.Win32/Extensions/WindowExtensions.cs @@ -0,0 +1,37 @@ +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using System; +using Windows.UI.Popups; +using WinRT.Interop; + +namespace Hyperbar.Desktop.Win32; + +public static class WindowExtensions +{ + public static IntPtr GetHandle(this Window window) => + window is not null ? WindowNative.GetWindowHandle(window) : default; + + public static void SetIsShownInSwitchers(this Window window, + bool value) => window.AppWindow.IsShownInSwitchers = value; + + public static void SetOpacity(this Window window, + byte value) => window.GetHandle().SetWindowOpacity(value); + + public static void SetStyle(this Window window, + WindowStyle style) => window.GetHandle().SetWindowStyle(style); + + public static void SetTopMost(this Window window, + bool value) + { + AppWindow appWindow = window.AppWindow; + if (appWindow.Presenter is OverlappedPresenter presenter) + { + presenter.IsAlwaysOnTop = value; + } + } + + public static void Snap(this Window window, + WindowPlacement placement, + double? width = null, + double? height = null) => window.GetHandle().SnapWindow(placement, width, height); +} diff --git a/Hyperbar.Desktop.Win32/Extensions/WindowPlacement.cs b/Hyperbar.Desktop.Win32/Extensions/WindowPlacement.cs new file mode 100644 index 0000000..d484825 --- /dev/null +++ b/Hyperbar.Desktop.Win32/Extensions/WindowPlacement.cs @@ -0,0 +1,9 @@ +namespace Hyperbar.Desktop.Win32; + +public enum WindowPlacement +{ + Left, + Top, + Right, + Bottom +} \ No newline at end of file diff --git a/Hyperbar.Desktop.Win32/Extensions/WindowStyle.cs b/Hyperbar.Desktop.Win32/Extensions/WindowStyle.cs new file mode 100644 index 0000000..ae0d33a --- /dev/null +++ b/Hyperbar.Desktop.Win32/Extensions/WindowStyle.cs @@ -0,0 +1,33 @@ +using System; + +namespace Hyperbar.Desktop.Win32; + +[Flags] +public enum WindowStyle +{ + Border = 0x800000, + Caption = 0xC00000, + Child = 0x40000000, + ChildWindow = 0x40000000, + ChildChildren = 0x2000000, + ClipSiblings = 0x4000000, + Disabled = 0x8000000, + DlgFrame = 0x400000, + Group = 0x20000, + HScroll = 0x100000, + Iconic = 0x20000000, + Maximize = 0x1000000, + MaximizeBox = 0x10000, + Minimize = 0x20000000, + MinimizeBox = 0x20000, + Overlapped = 0, + OverlappedWindow = 0xCF0000, + SizeBox = 0x40000, + SysMenu = 0x80000, + TabStop = 0x10000, + ThickFrame = 0x40000, + Tiled = 0, + TiledWindow = 0xCF0000, + Visible = 0x10000000, + VScroll = 0x200000 +} diff --git a/Hyperbar.Desktop.Win32/Hyperbar.Desktop.Win32.csproj b/Hyperbar.Desktop.Win32/Hyperbar.Desktop.Win32.csproj new file mode 100644 index 0000000..13db1f4 --- /dev/null +++ b/Hyperbar.Desktop.Win32/Hyperbar.Desktop.Win32.csproj @@ -0,0 +1,18 @@ + + + net8.0-windows10.0.19041.0 + 10.0.17763.0 + Hyperbar.Desktop.Win32 + win10-x86;win10-x64;win10-arm64 + true + true + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + \ No newline at end of file diff --git a/Hyperbar.Desktop.Win32/Internals/PInvoke.cs b/Hyperbar.Desktop.Win32/Internals/PInvoke.cs new file mode 100644 index 0000000..7758bb9 --- /dev/null +++ b/Hyperbar.Desktop.Win32/Internals/PInvoke.cs @@ -0,0 +1,507 @@ +using System; +using System.Runtime.InteropServices; +using Windows.Win32.Foundation; +using Windows.Win32.UI.WindowsAndMessaging; + +namespace Windows.Win32 +{ + /// + /// Contains extern methods from "Shell32.dll". + /// + internal static partial class PInvoke + { + /// + internal static unsafe nuint SHAppBarMessage(uint dwMessage, ref APPBARDATA32 pData) + { + fixed (APPBARDATA32* pDataLocal = &pData) + { + nuint __result = PInvoke.SHAppBarMessage(dwMessage, pDataLocal); + return __result; + } + } + /// + internal static unsafe nuint SHAppBarMessage(uint dwMessage, ref APPBARDATA64 pData) + { + fixed (APPBARDATA64* pDataLocal = &pData) + { + nuint __result = PInvoke.SHAppBarMessage(dwMessage, pDataLocal); + return __result; + } + } + + /// Sends an appbar message to the system. + /// Type: DWORD + /// + /// Type: PAPPBARDATA + /// A pointer to an APPBARDATA structure. The content of the structure on entry and on exit depends on the value set in the dwMessage parameter. See the individual message pages for specifics. + /// Read more on docs.microsoft.com. + /// + /// + /// Type: UINT_PTR + /// This function returns a message-dependent value. For more information, see the Windows SDK documentation for the specific appbar message sent. Links to those documents are given in the See Also section. + /// + /// + /// Learn more about this API from docs.microsoft.com. + /// + [DllImport("Shell32", ExactSpelling = true)] + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + internal static extern unsafe nuint SHAppBarMessage(uint dwMessage, APPBARDATA32* pData); + + /// Sends an appbar message to the system. + /// Type: DWORD + /// + /// Type: PAPPBARDATA + /// A pointer to an APPBARDATA structure. The content of the structure on entry and on exit depends on the value set in the dwMessage parameter. See the individual message pages for specifics. + /// Read more on docs.microsoft.com. + /// + /// + /// Type: UINT_PTR + /// This function returns a message-dependent value. For more information, see the Windows SDK documentation for the specific appbar message sent. Links to those documents are given in the See Also section. + /// + /// + /// Learn more about this API from docs.microsoft.com. + /// + [DllImport("Shell32", ExactSpelling = true)] + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + internal static extern unsafe nuint SHAppBarMessage(uint dwMessage, APPBARDATA64* pData); + + /// + internal static unsafe bool Shell_NotifyIcon(uint dwMessage, in NOTIFYICONDATAW32 lpData) + { + fixed (NOTIFYICONDATAW32* lpDataLocal = &lpData) + { + bool __result = PInvoke.Shell_NotifyIcon(dwMessage, lpDataLocal); + return __result; + } + } + /// + internal static unsafe bool Shell_NotifyIcon(uint dwMessage, in NOTIFYICONDATAW64 lpData) + { + fixed (NOTIFYICONDATAW64* lpDataLocal = &lpData) + { + bool __result = PInvoke.Shell_NotifyIcon(dwMessage, lpDataLocal); + return __result; + } + } + + /// Sends a message to the taskbar's status area. + /// Type: DWORD + /// + /// Type: PNOTIFYICONDATA + /// A pointer to a NOTIFYICONDATA structure. The content of the structure depends on the value of dwMessage. It can define an icon to add to the notification area, cause that icon to display a notification, or identify an icon to modify or delete. + /// Read more on docs.microsoft.com. + /// + /// + /// Type: BOOL + /// Returns TRUE if successful, or FALSE otherwise. If dwMessage is set to NIM_SETVERSION, the function returns TRUE if the version was successfully changed, or FALSE if the requested version is not supported. + /// + /// + /// Learn more about this API from docs.microsoft.com. + /// + [DllImport("Shell32", ExactSpelling = true, EntryPoint = "Shell_NotifyIconW")] + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + internal static extern unsafe bool Shell_NotifyIcon(uint dwMessage, NOTIFYICONDATAW32* lpData); + + /// Sends a message to the taskbar's status area. + /// Type: DWORD + /// + /// Type: PNOTIFYICONDATA + /// A pointer to a NOTIFYICONDATA structure. The content of the structure depends on the value of dwMessage. It can define an icon to add to the notification area, cause that icon to display a notification, or identify an icon to modify or delete. + /// Read more on docs.microsoft.com. + /// + /// + /// Type: BOOL + /// Returns TRUE if successful, or FALSE otherwise. If dwMessage is set to NIM_SETVERSION, the function returns TRUE if the version was successfully changed, or FALSE if the requested version is not supported. + /// + /// + /// Learn more about this API from docs.microsoft.com. + /// + [DllImport("Shell32", ExactSpelling = true, EntryPoint = "Shell_NotifyIconW")] + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + internal static extern unsafe bool Shell_NotifyIcon(uint dwMessage, NOTIFYICONDATAW64* lpData); + } + + /// Contains information about a system appbar message. + /// + /// Learn more about this API from docs.microsoft.com. + /// + [StructLayout(LayoutKind.Sequential, Pack = 1)] + internal partial struct APPBARDATA32 + { + /// + /// Type: DWORD + /// The size of the structure, in bytes. + /// Read more on docs.microsoft.com. + /// + internal uint cbSize; + /// + /// Type: HWND + /// The handle to the appbar window. Not all messages use this member. See the individual message page to see if you need to provide an hWind value. + /// Read more on docs.microsoft.com. + /// + internal HWND hWnd; + /// + /// Type: UINT + /// An application-defined message identifier. The application uses the specified identifier for notification messages that it sends to the appbar identified by the hWnd member. This member is used when sending the ABM_NEW message. + /// Read more on docs.microsoft.com. + /// + internal uint uCallbackMessage; + /// + /// Type: UINT A value that specifies an edge of the screen. This member is used when sending one of these messages: + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal uint uEdge; + /// + /// Type: RECT A RECT structure whose use varies depending on the message: + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal RECT rc; + /// + /// Type: LPARAM A message-dependent value. This member is used with these messages: + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal LPARAM lParam; + } + + /// Contains information about a system appbar message. + /// + /// Learn more about this API from docs.microsoft.com. + /// + internal partial struct APPBARDATA64 + { + /// + /// Type: DWORD + /// The size of the structure, in bytes. + /// Read more on docs.microsoft.com. + /// + internal uint cbSize; + /// + /// Type: HWND + /// The handle to the appbar window. Not all messages use this member. See the individual message page to see if you need to provide an hWind value. + /// Read more on docs.microsoft.com. + /// + internal HWND hWnd; + /// + /// Type: UINT + /// An application-defined message identifier. The application uses the specified identifier for notification messages that it sends to the appbar identified by the hWnd member. This member is used when sending the ABM_NEW message. + /// Read more on docs.microsoft.com. + /// + internal uint uCallbackMessage; + /// + /// Type: UINT A value that specifies an edge of the screen. This member is used when sending one of these messages: + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal uint uEdge; + /// + /// Type: RECT A RECT structure whose use varies depending on the message: + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal RECT rc; + /// + /// Type: LPARAM A message-dependent value. This member is used with these messages: + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal LPARAM lParam; + } + internal struct __ushort_128 + { + internal ushort _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, _108, _109, _110, _111, _112, _113, _114, _115, _116, _117, _118, _119, _120, _121, _122, _123, _124, _125, _126, _127; + /// Always 128. + internal int Length => 128; + /// + /// Gets a ref to an individual element of the inline array. + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned reference outlive the stack frame that defines it. + /// + internal ref ushort this[int index] => ref AsSpan()[index]; + /// + /// Gets this inline array as a span. + /// + /// + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned span outlive the stack frame that defines it. + /// + internal Span AsSpan() => MemoryMarshal.CreateSpan(ref _0, 128); + } + + /// Contains information that the system needs to display notifications in the notification area. Used by Shell_NotifyIcon. + /// + /// See Notifications in the Windows User Experience Interaction Guidelines for more information on notification UI and content best practices. + /// If you set the NIF_INFO flag in the uFlags member, the balloon-style notification is used. For more discussion of these notifications, see Balloon tooltips. + /// No more than one balloon notification at a time can be displayed for the taskbar. If an application attempts to display a notification when one is already being displayed, the new notification is queued and displayed when the older notification goes away. In versions of Windows before Windows Vista, the new notification would not appear until the existing notification has been visible for at least the system minimum timeout length, regardless of the original notification's uTimeout value. If the user does not appear to be using the computer, the system does not count this time toward the timeout. + /// Several members of this structure are only supported for Windows 2000 and later. To enable these members, include one of the following lines in your header: + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + [StructLayout(LayoutKind.Sequential, Pack = 1)] + internal partial struct NOTIFYICONDATAW32 + { + /// + /// Type: DWORD + /// The size of this structure, in bytes. + /// Read more on docs.microsoft.com. + /// + internal uint cbSize; + /// + /// Type: HWND + /// A handle to the window that receives notifications associated with an icon in the notification area. + /// Read more on docs.microsoft.com. + /// + internal HWND hWnd; + /// + /// Type: UINT + /// The application-defined identifier of the taskbar icon. The Shell uses either (hWnd plus uID) or guidItem to identify which icon to operate on when Shell_NotifyIcon is invoked. You can have multiple icons associated with a single hWnd by assigning each a different uID. If guidItem is specified, uID is ignored. + /// Read more on docs.microsoft.com. + /// + internal uint uID; + /// Type: UINT + internal uint uFlags; + /// + /// Type: UINT + /// An application-defined message identifier. The system uses this identifier to send notification messages to the window identified in hWnd. These notification messages are sent when a mouse event or hover occurs in the bounding rectangle of the icon, when the icon is selected or activated with the keyboard, or when those actions occur in the balloon notification. + /// When the uVersion member is either 0 or NOTIFYICON_VERSION, the wParam parameter of the message contains the identifier of the taskbar icon in which the event occurred. This identifier can be 32 bits in length. The lParam parameter holds the mouse or keyboard message associated with the event. For example, when the pointer moves over a taskbar icon, lParam is set to WM_MOUSEMOVE. + /// When the uVersion member is NOTIFYICON_VERSION_4, applications continue to receive notification events in the form of application-defined messages through the uCallbackMessage member, but the interpretation of the lParam and wParam parameters of that message is changed as follows: + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal uint uCallbackMessage; + /// + /// Type: HICON + /// A handle to the icon to be added, modified, or deleted. Windows XP and later support icons of up to 32 BPP. + /// If only a 16x16 pixel icon is provided, it is scaled to a larger size in a system set to a high dpi value. This can lead to an unattractive result. It is recommended that you provide both a 16x16 pixel icon and a 32x32 icon in your resource file. Use LoadIconMetric to ensure that the correct icon is loaded and scaled appropriately. See Remarks for a code example. + /// Read more on docs.microsoft.com. + /// + internal HICON hIcon; + /// + /// Type: TCHAR[64] + /// A null-terminated string that specifies the text for a standard tooltip. It can have a maximum of 64 characters, including the terminating null character. + /// For Windows 2000 and later, szTip can have a maximum of 128 characters, including the terminating null character. + /// Read more on docs.microsoft.com. + /// + internal __ushort_128 szTip; + /// Type: DWORD + internal uint dwState; + /// + /// Type: DWORD + /// Windows 2000 and later. A value that specifies which bits of the dwState member are retrieved or modified. The possible values are the same as those for dwState. For example, setting this member to NIS_HIDDEN causes only the item's hidden state to be modified while the icon sharing bit is ignored regardless of its value. + /// Read more on docs.microsoft.com. + /// + internal uint dwStateMask; + /// + /// Type: TCHAR[256] + /// Windows 2000 and later. A null-terminated string that specifies the text to display in a balloon notification. It can have a maximum of 256 characters, including the terminating null character, but should be restricted to 200 characters in English to accommodate localization. To remove the balloon notification from the UI, either delete the icon (with NIM_DELETE) or set the NIF_INFO flag in uFlags and set szInfo to an empty string. + /// Read more on docs.microsoft.com. + /// + internal __ushort_256 szInfo; + internal _Anonymous_e__Union Anonymous; + /// + /// Type: TCHAR[64] + /// Windows 2000 and later. A null-terminated string that specifies a title for a balloon notification. This title appears in a larger font immediately above the text. It can have a maximum of 64 characters, including the terminating null character, but should be restricted to 48 characters in English to accommodate localization. + /// Read more on docs.microsoft.com. + /// + internal __ushort_64 szInfoTitle; + /// + /// Type: DWORD + /// Windows 2000 and later. Flags that can be set to modify the behavior and appearance of a balloon notification. The icon is placed to the left of the title. If the szInfoTitle member is zero-length, the icon is not shown. + /// Read more on docs.microsoft.com. + /// + internal uint dwInfoFlags; + /// + /// Type: GUID Windows XP and later. + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal global::System.Guid guidItem; + /// + /// Type: HICON + /// Windows Vista and later. The handle of a customized notification icon provided by the application that should be used independently of the notification area icon. If this member is non-NULL and the NIIF_USER flag is set in the dwInfoFlags member, this icon is used as the notification icon. If this member is NULL, the legacy behavior is carried out. + /// Read more on docs.microsoft.com. + /// + internal HICON hBalloonIcon; + + + internal struct __ushort_256 + { + internal ushort _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, _108, _109, _110, _111, _112, _113, _114, _115, _116, _117, _118, _119, _120, _121, _122, _123, _124, _125, _126, _127, _128, _129, _130, _131, _132, _133, _134, _135, _136, _137, _138, _139, _140, _141, _142, _143, _144, _145, _146, _147, _148, _149, _150, _151, _152, _153, _154, _155, _156, _157, _158, _159, _160, _161, _162, _163, _164, _165, _166, _167, _168, _169, _170, _171, _172, _173, _174, _175, _176, _177, _178, _179, _180, _181, _182, _183, _184, _185, _186, _187, _188, _189, _190, _191, _192, _193, _194, _195, _196, _197, _198, _199, _200, _201, _202, _203, _204, _205, _206, _207, _208, _209, _210, _211, _212, _213, _214, _215, _216, _217, _218, _219, _220, _221, _222, _223, _224, _225, _226, _227, _228, _229, _230, _231, _232, _233, _234, _235, _236, _237, _238, _239, _240, _241, _242, _243, _244, _245, _246, _247, _248, _249, _250, _251, _252, _253, _254, _255; + /// Always 256. + internal int Length => 256; + /// + /// Gets a ref to an individual element of the inline array. + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned reference outlive the stack frame that defines it. + /// + internal ref ushort this[int index] => ref AsSpan()[index]; + /// + /// Gets this inline array as a span. + /// + /// + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned span outlive the stack frame that defines it. + /// + internal Span AsSpan() => MemoryMarshal.CreateSpan(ref _0, 256); + } + + [StructLayout(LayoutKind.Explicit, Pack = 1)] + internal partial struct _Anonymous_e__Union + { + [FieldOffset(0)] + internal uint uTimeout; + [FieldOffset(0)] + internal uint uVersion; + } + } + + + internal struct __ushort_64 + { + internal ushort _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; + /// Always 64. + internal int Length => 64; + /// + /// Gets a ref to an individual element of the inline array. + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned reference outlive the stack frame that defines it. + /// + internal ref ushort this[int index] => ref AsSpan()[index]; + /// + /// Gets this inline array as a span. + /// + /// + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned span outlive the stack frame that defines it. + /// + internal Span AsSpan() => MemoryMarshal.CreateSpan(ref _0, 64); + } + + + /// Contains information that the system needs to display notifications in the notification area. Used by Shell_NotifyIcon. + /// + /// See Notifications in the Windows User Experience Interaction Guidelines for more information on notification UI and content best practices. + /// If you set the NIF_INFO flag in the uFlags member, the balloon-style notification is used. For more discussion of these notifications, see Balloon tooltips. + /// No more than one balloon notification at a time can be displayed for the taskbar. If an application attempts to display a notification when one is already being displayed, the new notification is queued and displayed when the older notification goes away. In versions of Windows before Windows Vista, the new notification would not appear until the existing notification has been visible for at least the system minimum timeout length, regardless of the original notification's uTimeout value. If the user does not appear to be using the computer, the system does not count this time toward the timeout. + /// Several members of this structure are only supported for Windows 2000 and later. To enable these members, include one of the following lines in your header: + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal partial struct NOTIFYICONDATAW64 + { + /// + /// Type: DWORD + /// The size of this structure, in bytes. + /// Read more on docs.microsoft.com. + /// + internal uint cbSize; + /// + /// Type: HWND + /// A handle to the window that receives notifications associated with an icon in the notification area. + /// Read more on docs.microsoft.com. + /// + internal HWND hWnd; + /// + /// Type: UINT + /// The application-defined identifier of the taskbar icon. The Shell uses either (hWnd plus uID) or guidItem to identify which icon to operate on when Shell_NotifyIcon is invoked. You can have multiple icons associated with a single hWnd by assigning each a different uID. If guidItem is specified, uID is ignored. + /// Read more on docs.microsoft.com. + /// + internal uint uID; + /// Type: UINT + internal uint uFlags; + /// + /// Type: UINT + /// An application-defined message identifier. The system uses this identifier to send notification messages to the window identified in hWnd. These notification messages are sent when a mouse event or hover occurs in the bounding rectangle of the icon, when the icon is selected or activated with the keyboard, or when those actions occur in the balloon notification. + /// When the uVersion member is either 0 or NOTIFYICON_VERSION, the wParam parameter of the message contains the identifier of the taskbar icon in which the event occurred. This identifier can be 32 bits in length. The lParam parameter holds the mouse or keyboard message associated with the event. For example, when the pointer moves over a taskbar icon, lParam is set to WM_MOUSEMOVE. + /// When the uVersion member is NOTIFYICON_VERSION_4, applications continue to receive notification events in the form of application-defined messages through the uCallbackMessage member, but the interpretation of the lParam and wParam parameters of that message is changed as follows: + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal uint uCallbackMessage; + /// + /// Type: HICON + /// A handle to the icon to be added, modified, or deleted. Windows XP and later support icons of up to 32 BPP. + /// If only a 16x16 pixel icon is provided, it is scaled to a larger size in a system set to a high dpi value. This can lead to an unattractive result. It is recommended that you provide both a 16x16 pixel icon and a 32x32 icon in your resource file. Use LoadIconMetric to ensure that the correct icon is loaded and scaled appropriately. See Remarks for a code example. + /// Read more on docs.microsoft.com. + /// + internal HICON hIcon; + /// + /// Type: TCHAR[64] + /// A null-terminated string that specifies the text for a standard tooltip. It can have a maximum of 64 characters, including the terminating null character. + /// For Windows 2000 and later, szTip can have a maximum of 128 characters, including the terminating null character. + /// Read more on docs.microsoft.com. + /// + internal __ushort_128 szTip; + /// Type: DWORD + internal uint dwState; + /// + /// Type: DWORD + /// Windows 2000 and later. A value that specifies which bits of the dwState member are retrieved or modified. The possible values are the same as those for dwState. For example, setting this member to NIS_HIDDEN causes only the item's hidden state to be modified while the icon sharing bit is ignored regardless of its value. + /// Read more on docs.microsoft.com. + /// + internal uint dwStateMask; + /// + /// Type: TCHAR[256] + /// Windows 2000 and later. A null-terminated string that specifies the text to display in a balloon notification. It can have a maximum of 256 characters, including the terminating null character, but should be restricted to 200 characters in English to accommodate localization. To remove the balloon notification from the UI, either delete the icon (with NIM_DELETE) or set the NIF_INFO flag in uFlags and set szInfo to an empty string. + /// Read more on docs.microsoft.com. + /// + internal __ushort_256 szInfo; + internal _Anonymous_e__Union Anonymous; + /// + /// Type: TCHAR[64] + /// Windows 2000 and later. A null-terminated string that specifies a title for a balloon notification. This title appears in a larger font immediately above the text. It can have a maximum of 64 characters, including the terminating null character, but should be restricted to 48 characters in English to accommodate localization. + /// Read more on docs.microsoft.com. + /// + internal __ushort_64 szInfoTitle; + /// + /// Type: DWORD + /// Windows 2000 and later. Flags that can be set to modify the behavior and appearance of a balloon notification. The icon is placed to the left of the title. If the szInfoTitle member is zero-length, the icon is not shown. + /// Read more on docs.microsoft.com. + /// + internal uint dwInfoFlags; + /// + /// Type: GUID Windows XP and later. + /// + /// This doc was truncated. + /// Read more on docs.microsoft.com. + /// + internal global::System.Guid guidItem; + /// + /// Type: HICON + /// Windows Vista and later. The handle of a customized notification icon provided by the application that should be used independently of the notification area icon. If this member is non-NULL and the NIIF_USER flag is set in the dwInfoFlags member, this icon is used as the notification icon. If this member is NULL, the legacy behavior is carried out. + /// Read more on docs.microsoft.com. + /// + internal HICON hBalloonIcon; + + internal struct __ushort_256 + { + internal ushort _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, _108, _109, _110, _111, _112, _113, _114, _115, _116, _117, _118, _119, _120, _121, _122, _123, _124, _125, _126, _127, _128, _129, _130, _131, _132, _133, _134, _135, _136, _137, _138, _139, _140, _141, _142, _143, _144, _145, _146, _147, _148, _149, _150, _151, _152, _153, _154, _155, _156, _157, _158, _159, _160, _161, _162, _163, _164, _165, _166, _167, _168, _169, _170, _171, _172, _173, _174, _175, _176, _177, _178, _179, _180, _181, _182, _183, _184, _185, _186, _187, _188, _189, _190, _191, _192, _193, _194, _195, _196, _197, _198, _199, _200, _201, _202, _203, _204, _205, _206, _207, _208, _209, _210, _211, _212, _213, _214, _215, _216, _217, _218, _219, _220, _221, _222, _223, _224, _225, _226, _227, _228, _229, _230, _231, _232, _233, _234, _235, _236, _237, _238, _239, _240, _241, _242, _243, _244, _245, _246, _247, _248, _249, _250, _251, _252, _253, _254, _255; + /// Always 256. + internal int Length => 256; + /// + /// Gets a ref to an individual element of the inline array. + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned reference outlive the stack frame that defines it. + /// + internal ref ushort this[int index] => ref AsSpan()[index]; + /// + /// Gets this inline array as a span. + /// + /// + /// ⚠ Important ⚠: When this struct is on the stack, do not let the returned span outlive the stack frame that defines it. + /// + internal Span AsSpan() => MemoryMarshal.CreateSpan(ref _0, 256); + } + + [StructLayout(LayoutKind.Explicit)] + internal partial struct _Anonymous_e__Union + { + [FieldOffset(0)] + internal uint uTimeout; + [FieldOffset(0)] + internal uint uVersion; + } + } +} \ No newline at end of file diff --git a/Hyperbar.Desktop.Win32/NativeMethods.txt b/Hyperbar.Desktop.Win32/NativeMethods.txt new file mode 100644 index 0000000..c2b8722 --- /dev/null +++ b/Hyperbar.Desktop.Win32/NativeMethods.txt @@ -0,0 +1,57 @@ +FindWindow +//SHAppBarMessage +SystemParametersInfo +//Shell_NotifyIcon +CreateWindowEx +DefWindowProc +RegisterClass +RegisterWindowMessage +DestroyWindow +SetForegroundWindow +GetDoubleClickTime +GetPhysicalCursorPos +GetCursorPos +GetActiveWindow +GetDpiForWindow +SetForegroundWindow +GetDpiForWindow +SetWindowPos +MonitorFromWindow +GetWindowRect +GetMonitorInfo +CreateIcon +GetModuleHandle +GetDesktopWindow +GetClientRect +LoadIcon +UpdateLayeredWindow +SetLayeredWindowAttributes +GetDpiForMonitor +ShowWindow +LoadImage +SendMessage +SetWindowLong +GetWindowLong +UpdateLayeredWindow +DestroyIcon +GetSystemMetrics +EnumDisplayMonitors +MONITORINFOEXW +SetWindowSubclass +RemoveWindowSubclass +DefSubclassProc +GetWindowPlacement +SetWindowPlacement +D3D11CreateDevice +D3D11_SDK_VERSION +IDXGIAdapter +IDXGIDevice +IDXGIFactory2 +CreateDirect3D11SurfaceFromDXGISurface +CreateDispatcherQueueController +DwmEnableBlurBehindWindow +DwmExtendFrameIntoClientArea +CreateRectRgn +CreateSolidBrush +FillRect +GetDC \ No newline at end of file diff --git a/Hyperbar.Desktop/App.xaml b/Hyperbar.Desktop/App.xaml new file mode 100644 index 0000000..f31e216 --- /dev/null +++ b/Hyperbar.Desktop/App.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/Hyperbar.Desktop/App.xaml.cs b/Hyperbar.Desktop/App.xaml.cs new file mode 100644 index 0000000..bc8a243 --- /dev/null +++ b/Hyperbar.Desktop/App.xaml.cs @@ -0,0 +1,37 @@ +using Hyperbar.Desktop.Controls; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.UI.Xaml; +using System; + +namespace Hyperbar.Desktop; + +public partial class App : + Application +{ + public App() => InitializeComponent(); + + protected override async void OnLaunched(LaunchActivatedEventArgs args) + { + base.OnLaunched(args); + + IHost? host = Host.CreateDefaultBuilder() + .UseContentRoot(AppContext.BaseDirectory) + .ConfigureServices(args => + { + args.AddTransient(); + args.AddTransient(); + + args.AddTransient(); + args.AddTransient(); + + args.AddDataTemplate("Commands"); + args.AddDataTemplate(); + + args.AddHostedService(); + }) + .Build(); + + await host.RunAsync(); + } +} diff --git a/Hyperbar.Desktop/AppInitializer.cs b/Hyperbar.Desktop/AppInitializer.cs new file mode 100644 index 0000000..a2156f2 --- /dev/null +++ b/Hyperbar.Desktop/AppInitializer.cs @@ -0,0 +1,21 @@ +using Hyperbar.Desktop.Controls; +using Microsoft.Extensions.DependencyInjection; +using System.Threading.Tasks; + +namespace Hyperbar.Desktop; + +public class AppInitializer([FromKeyedServices("Commands")] CommandView view, + [FromKeyedServices("Commands")] CommandViewModel viewModel, + DesktopFlyout desktopFlyout) : + IInitializer +{ + public Task InitializeAsync() + { + view.DataContext = viewModel; + + desktopFlyout.Placement = DesktopFlyoutPlacement.Top; + desktopFlyout.Content = view; + + return Task.CompletedTask; + } +} diff --git a/Hyperbar.Desktop/Assets/LockScreenLogo.scale-200.png b/Hyperbar.Desktop/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000..7440f0d Binary files /dev/null and b/Hyperbar.Desktop/Assets/LockScreenLogo.scale-200.png differ diff --git a/Hyperbar.Desktop/Assets/SplashScreen.scale-200.png b/Hyperbar.Desktop/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000..32f486a Binary files /dev/null and b/Hyperbar.Desktop/Assets/SplashScreen.scale-200.png differ diff --git a/Hyperbar.Desktop/Assets/Square150x150Logo.scale-200.png b/Hyperbar.Desktop/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000..53ee377 Binary files /dev/null and b/Hyperbar.Desktop/Assets/Square150x150Logo.scale-200.png differ diff --git a/Hyperbar.Desktop/Assets/Square44x44Logo.scale-200.png b/Hyperbar.Desktop/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000..f713bba Binary files /dev/null and b/Hyperbar.Desktop/Assets/Square44x44Logo.scale-200.png differ diff --git a/Hyperbar.Desktop/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/Hyperbar.Desktop/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000..dc9f5be Binary files /dev/null and b/Hyperbar.Desktop/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/Hyperbar.Desktop/Assets/StoreLogo.png b/Hyperbar.Desktop/Assets/StoreLogo.png new file mode 100644 index 0000000..a4586f2 Binary files /dev/null and b/Hyperbar.Desktop/Assets/StoreLogo.png differ diff --git a/Hyperbar.Desktop/Assets/Wide310x150Logo.scale-200.png b/Hyperbar.Desktop/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000..8b4a5d0 Binary files /dev/null and b/Hyperbar.Desktop/Assets/Wide310x150Logo.scale-200.png differ diff --git a/Hyperbar.Desktop/Hyperbar.Desktop.csproj b/Hyperbar.Desktop/Hyperbar.Desktop.csproj new file mode 100644 index 0000000..85810a1 --- /dev/null +++ b/Hyperbar.Desktop/Hyperbar.Desktop.csproj @@ -0,0 +1,60 @@ + + + WinExe + net8.0-windows10.0.19041.0 + 10.0.17763.0 + Hyperbar.Desktop + app.manifest + x86;x64;ARM64 + win-x86;win-x64;win-arm64 + win-$(Platform).pubxml + true + true + true + enable + + + + + + + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + + + + + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + true + + diff --git a/Hyperbar.Desktop/Package.appxmanifest b/Hyperbar.Desktop/Package.appxmanifest new file mode 100644 index 0000000..5d642c5 --- /dev/null +++ b/Hyperbar.Desktop/Package.appxmanifest @@ -0,0 +1,51 @@ + + + + + + + + + + Hyperbar.Desktop + dan_c + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Hyperbar.Desktop/Properties/launchSettings.json b/Hyperbar.Desktop/Properties/launchSettings.json new file mode 100644 index 0000000..297b2aa --- /dev/null +++ b/Hyperbar.Desktop/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Hyperbar.Desktop (Package)": { + "commandName": "MsixPackage" + }, + "Hyperbar.Desktop (Unpackaged)": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/Hyperbar.Desktop/Templates/ITemplateGeneratorFactory.cs b/Hyperbar.Desktop/Templates/ITemplateGeneratorFactory.cs new file mode 100644 index 0000000..2bd3eaf --- /dev/null +++ b/Hyperbar.Desktop/Templates/ITemplateGeneratorFactory.cs @@ -0,0 +1,9 @@ +using Microsoft.UI.Xaml; + +namespace Hyperbar.Desktop +{ + public interface ITemplateGeneratorFactory + { + DataTemplate Create(); + } +} \ No newline at end of file diff --git a/Hyperbar.Desktop/Templates/TemplateFactory.cs b/Hyperbar.Desktop/Templates/TemplateFactory.cs new file mode 100644 index 0000000..ed71211 --- /dev/null +++ b/Hyperbar.Desktop/Templates/TemplateFactory.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Hyperbar.Desktop; + +public class TemplateFactory(ITemplateGeneratorFactory factory, + IEnumerable descriptors, + IServiceProvider provider) : + DataTemplateSelector, + ITemplateFactory +{ + protected override DataTemplate SelectTemplateCore(object item) => factory.Create(); + + protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) => factory.Create(); + + public object? Create(object key) + { + if (descriptors.FirstOrDefault(x => x.Key == key) is IDataTemplateDescriptor descriptor) + { + if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key) is { } template) + { + return template; + } + } + + return default; + } +} \ No newline at end of file diff --git a/Hyperbar.Desktop/Templates/TemplateGeneratorControl.cs b/Hyperbar.Desktop/Templates/TemplateGeneratorControl.cs new file mode 100644 index 0000000..10dda65 --- /dev/null +++ b/Hyperbar.Desktop/Templates/TemplateGeneratorControl.cs @@ -0,0 +1,21 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; + +namespace Hyperbar.Desktop; + +public class TemplateGeneratorControl : + ContentControl +{ + public TemplateGeneratorControl() + { + DataContextChanged += OnDataContextChanged; + } + + private void OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args) + { + if (DataContext is ITemplatedViewModel templatedViewModel) + { + Content = templatedViewModel.TemplateFactory.Create(DataContext.GetType().Name); + } + } +} diff --git a/Hyperbar.Desktop/Templates/TemplateGeneratorFactory.cs b/Hyperbar.Desktop/Templates/TemplateGeneratorFactory.cs new file mode 100644 index 0000000..7be05df --- /dev/null +++ b/Hyperbar.Desktop/Templates/TemplateGeneratorFactory.cs @@ -0,0 +1,19 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Markup; + +namespace Hyperbar.Desktop; + +public class TemplateGeneratorFactory : + ITemplateGeneratorFactory +{ + public DataTemplate Create() + { + string xamlString = @" + + + "; + + return (DataTemplate)XamlReader.Load(xamlString); + } +} diff --git a/Hyperbar.Desktop/Views/CommandView.xaml b/Hyperbar.Desktop/Views/CommandView.xaml new file mode 100644 index 0000000..51581ad --- /dev/null +++ b/Hyperbar.Desktop/Views/CommandView.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/Hyperbar.Desktop/Views/CommandView.xaml.cs b/Hyperbar.Desktop/Views/CommandView.xaml.cs new file mode 100644 index 0000000..36bc9e2 --- /dev/null +++ b/Hyperbar.Desktop/Views/CommandView.xaml.cs @@ -0,0 +1,8 @@ +using Microsoft.UI.Xaml.Controls; + +namespace Hyperbar.Desktop; + +public sealed partial class CommandView : Page +{ + public CommandView() => InitializeComponent(); +} diff --git a/Hyperbar.Desktop/Views/CommandViewModel.cs b/Hyperbar.Desktop/Views/CommandViewModel.cs new file mode 100644 index 0000000..c8e4d56 --- /dev/null +++ b/Hyperbar.Desktop/Views/CommandViewModel.cs @@ -0,0 +1,21 @@ +namespace Hyperbar.Desktop; + +public partial class CommandViewModel : + ObservableCollectionViewModel, + ITemplatedViewModel +{ + public CommandViewModel(ITemplateFactory templateFactory) + { + TemplateFactory = templateFactory; + + this.Add(new ContextualCommandViewModel(templateFactory)); + this.Add(new ContextualCommandViewModel(templateFactory)); + this.Add(new ContextualCommandViewModel(templateFactory)); + this.Add(new ContextualCommandViewModel(templateFactory)); + this.Add(new ContextualCommandViewModel(templateFactory)); + + var d = Items; + } + + public ITemplateFactory TemplateFactory { get; } +} diff --git a/Hyperbar.Desktop/Views/ContextualCommandView.xaml b/Hyperbar.Desktop/Views/ContextualCommandView.xaml new file mode 100644 index 0000000..e608e52 --- /dev/null +++ b/Hyperbar.Desktop/Views/ContextualCommandView.xaml @@ -0,0 +1,15 @@ + + + + +