Set up IHostEnvironment
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
|
||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public static class FileConfigurationExtensions
|
||||||
|
{
|
||||||
|
public static IConfigurationBuilder SetBasePath(this IConfigurationBuilder builder,
|
||||||
|
string basePath, bool createDirectory)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(basePath) && createDirectory)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.SetFileProvider(new PhysicalFileProvider(basePath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public static class HostingHostBuilderExtensions
|
||||||
|
{
|
||||||
|
public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder, string contentRoot, bool createDirectory)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(contentRoot) && createDirectory)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(contentRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hostBuilder.UseContentRoot(contentRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,23 @@
|
|||||||
|
|
||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
{
|
{
|
||||||
|
public static class PointerLocationExtensions
|
||||||
|
{
|
||||||
|
public static bool IsWithinBounds(this PointerLocation args, Rect bounds)
|
||||||
|
{
|
||||||
|
if (args.X >= bounds.X
|
||||||
|
&& args.X <= bounds.X + bounds.Width
|
||||||
|
&& args.Y >= bounds.Y
|
||||||
|
&& args.Y <= bounds.Y + bounds.Height)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public static class IServiceCollectionExtensions
|
public static class IServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddAsyncHandler<TAsyncMessageHandle>(this IServiceCollection serviceCollection)
|
public static IServiceCollection AddAsyncHandler<TAsyncMessageHandle>(this IServiceCollection serviceCollection)
|
||||||
@@ -55,11 +72,12 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
.AddSingleton<IMessageInvoker, MessageInvoker>()
|
.AddSingleton<IMessageInvoker, MessageInvoker>()
|
||||||
.AddSingleton<IMessenger, Messenger>()
|
.AddSingleton<IMessenger, Messenger>()
|
||||||
.AddSingleton<IMediator, Mediator>()
|
.AddSingleton<IMediator, Mediator>()
|
||||||
.AddSingleton<IInitializable, WndProcMonitor>()
|
.AddSingleton<IWndProcMonitor, WndProcMonitor>()
|
||||||
.AddSingleton<ITaskbar, Taskbar>()
|
.AddSingleton<ITaskbar, Taskbar>()
|
||||||
.AddSingleton<IInitializable, TaskbarMonitor>()
|
.AddSingleton<ITaskbarList, TaskbarList>()
|
||||||
.AddSingleton<IInitializable, PointerMonitor>()
|
.AddSingleton<IPointerMonitor, PointerMonitor>()
|
||||||
.AddSingleton<IInitializable, TaskbarButtonMonitor>();
|
.AddSingleton<ITaskbarButtonMonitor, TaskbarButtonMonitor>()
|
||||||
|
.AddSingleton<ITaskbarButtonShortcutMonitor, TaskbarButtonShortcutMonitor>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
|
||||||
{
|
{
|
||||||
public interface ITaskbar
|
public interface ITaskbar : IInitializable, IDisposable
|
||||||
{
|
{
|
||||||
TaskbarState GetCurrentState();
|
TaskbarState GetCurrentState();
|
||||||
|
|
||||||
|
IntPtr GetHandle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
public interface ITaskbarButton : IDisposable
|
public interface ITaskbarButton : IDisposable
|
||||||
{
|
{
|
||||||
TaskbarButtonBounds Bounds { get; }
|
Rect Rect { get; }
|
||||||
|
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public interface ITaskbarButtonShortcutMonitor : IInitializable
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public interface ITaskbarList
|
||||||
|
{
|
||||||
|
IntPtr GetHandle();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
|
||||||
{
|
|
||||||
public interface ITaskbarMonitor : IInitializable
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Windows.Win32.Foundation;
|
||||||
|
|
||||||
|
namespace Windows.Win32
|
||||||
|
{
|
||||||
|
public static partial class PInvoke
|
||||||
|
{
|
||||||
|
public static readonly int SPI_SETWORKAREA = 0x002F;
|
||||||
|
public static readonly uint WM_TASKBARCREATED = PInvoke.RegisterWindowMessage("TaskbarCreated");
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct AppBarData
|
||||||
|
{
|
||||||
|
public uint cbSize;
|
||||||
|
public IntPtr hWnd;
|
||||||
|
public uint uCallbackMessage;
|
||||||
|
public AppBarEdge uEdge;
|
||||||
|
public RECT rect;
|
||||||
|
public int lParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AppBarMessage : uint
|
||||||
|
{
|
||||||
|
New = 0x00000000,
|
||||||
|
Remove = 0x00000001,
|
||||||
|
QueryPos = 0x00000002,
|
||||||
|
SetPos = 0x00000003,
|
||||||
|
GetState = 0x00000004,
|
||||||
|
GetTaskbarPos = 0x00000005,
|
||||||
|
Activate = 0x00000006,
|
||||||
|
GetAutoHideBar = 0x00000007,
|
||||||
|
SetAutoHideBar = 0x00000008,
|
||||||
|
WindowPosChanged = 0x00000009,
|
||||||
|
SetState = 0x0000000A,
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
|
public static extern IntPtr DefWindowProcW(IntPtr handle, uint msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[DllImport("shell32.dll", SetLastError = true)]
|
||||||
|
public static extern IntPtr SHAppBarMessage(AppBarMessage dwMessage, ref AppBarData pData);
|
||||||
|
|
||||||
|
public static AppBarData GetAppBarData(IntPtr handle)
|
||||||
|
{
|
||||||
|
return new AppBarData
|
||||||
|
{
|
||||||
|
cbSize = (uint)Marshal.SizeOf(typeof(AppBarData)),
|
||||||
|
hWnd = handle
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AppBarEdge : uint
|
||||||
|
{
|
||||||
|
Left = 0,
|
||||||
|
Top = 1,
|
||||||
|
Right = 2,
|
||||||
|
Bottom = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GetAppBarPosition(ref AppBarData appBarData) => SHAppBarMessage(AppBarMessage.GetTaskbarPos, ref appBarData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,10 +5,10 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
{
|
{
|
||||||
internal static class RECTExtensions
|
internal static class RECTExtensions
|
||||||
{
|
{
|
||||||
internal static Rect ToRect(this RECT rect)
|
internal static Windows.Foundation.Rect ToRect(this RECT rect)
|
||||||
{
|
{
|
||||||
if (rect.right - rect.left < 0 || rect.bottom - rect.top < 0) return new Rect(rect.left, rect.top, 0, 0);
|
if (rect.right - rect.left < 0 || rect.bottom - rect.top < 0) return new Windows.Foundation.Rect(rect.left, rect.top, 0, 0);
|
||||||
return new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
|
return new Windows.Foundation.Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
{
|
{
|
||||||
public record TaskbarButtonBounds
|
public record Rect
|
||||||
{
|
{
|
||||||
public TaskbarButtonBounds()
|
public Rect()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskbarButtonBounds(int x, int y, int width, int height)
|
public Rect(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
X = x;
|
X = x;
|
||||||
Y = y;
|
Y = y;
|
||||||
@@ -32,7 +32,7 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
{
|
{
|
||||||
var monitorData = GetMonitorData(monitorHandle);
|
var monitorData = GetMonitorData(monitorHandle);
|
||||||
|
|
||||||
Bounds = new Rect(monitorData.MonitorRect.left, monitorData.MonitorRect.top, monitorData.MonitorRect.right - monitorData.MonitorRect.left, monitorData.MonitorRect.bottom - monitorData.MonitorRect.top);
|
Bounds = new Windows.Foundation.Rect(monitorData.MonitorRect.left, monitorData.MonitorRect.top, monitorData.MonitorRect.right - monitorData.MonitorRect.left, monitorData.MonitorRect.bottom - monitorData.MonitorRect.top);
|
||||||
Primary = (monitorData.Flags & (int)MonitorFlag.MONITOR_DEFAULTTOPRIMARY) != 0;
|
Primary = (monitorData.Flags & (int)MonitorFlag.MONITOR_DEFAULTTOPRIMARY) != 0;
|
||||||
DeviceName = monitorData.DeviceName;
|
DeviceName = monitorData.DeviceName;
|
||||||
}
|
}
|
||||||
@@ -47,13 +47,13 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
MONITOR_DEFAULTTONEAREST = 2
|
MONITOR_DEFAULTTONEAREST = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rect Bounds { get; }
|
public Windows.Foundation.Rect Bounds { get; }
|
||||||
|
|
||||||
public string DeviceName { get; }
|
public string DeviceName { get; }
|
||||||
|
|
||||||
public bool Primary { get; }
|
public bool Primary { get; }
|
||||||
|
|
||||||
public Rect WorkingArea => GetWorkingArea();
|
public Windows.Foundation.Rect WorkingArea => GetWorkingArea();
|
||||||
|
|
||||||
public static Screen FromHandle(IntPtr handle)
|
public static Screen FromHandle(IntPtr handle)
|
||||||
{
|
{
|
||||||
@@ -83,7 +83,7 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
return monitorData;
|
return monitorData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rect GetWorkingArea()
|
private Windows.Foundation.Rect GetWorkingArea()
|
||||||
{
|
{
|
||||||
if (!_multiMonitorSupport || _monitorHandle == (IntPtr)PRIMARY_MONITOR)
|
if (!_multiMonitorSupport || _monitorHandle == (IntPtr)PRIMARY_MONITOR)
|
||||||
{
|
{
|
||||||
@@ -91,7 +91,7 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
var monitorData = GetMonitorData(_monitorHandle);
|
var monitorData = GetMonitorData(_monitorHandle);
|
||||||
return new Rect(monitorData.WorkAreaRect.left, monitorData.WorkAreaRect.top, monitorData.WorkAreaRect.right - monitorData.WorkAreaRect.left, monitorData.WorkAreaRect.bottom - monitorData.WorkAreaRect.top);
|
return new Windows.Foundation.Rect(monitorData.WorkAreaRect.left, monitorData.WorkAreaRect.top, monitorData.WorkAreaRect.right - monitorData.WorkAreaRect.left, monitorData.WorkAreaRect.bottom - monitorData.WorkAreaRect.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
{
|
{
|
||||||
private const int SPI_GETWORKAREA = 48;
|
private const int SPI_GETWORKAREA = 48;
|
||||||
|
|
||||||
public static Rect VirtualScreen => GetVirtualScreen();
|
public static Windows.Foundation.Rect VirtualScreen => GetVirtualScreen();
|
||||||
public static Rect WorkingArea => GetWorkingArea();
|
public static Windows.Foundation.Rect WorkingArea => GetWorkingArea();
|
||||||
|
|
||||||
private static Rect GetVirtualScreen()
|
private static Windows.Foundation.Rect GetVirtualScreen()
|
||||||
{
|
{
|
||||||
var size = new Size(PInvoke.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_CXSCREEN), PInvoke.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_CYSCREEN));
|
var size = new Size(PInvoke.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_CXSCREEN), PInvoke.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_CYSCREEN));
|
||||||
return new Rect(0, 0, size.Width, size.Height);
|
return new Windows.Foundation.Rect(0, 0, size.Width, size.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Rect GetWorkingArea()
|
private static Windows.Foundation.Rect GetWorkingArea()
|
||||||
{
|
{
|
||||||
var rect = new RECT();
|
var rect = new RECT();
|
||||||
|
|
||||||
SystemParametersInfo(SPI_GETWORKAREA, 0, ref rect, 0);
|
SystemParametersInfo(SPI_GETWORKAREA, 0, ref rect, 0);
|
||||||
return new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
|
return new Windows.Foundation.Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public record TaskButtonShortcutCreated;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public record TaskButtonShortcutRemoved;
|
||||||
|
}
|
||||||
@@ -1,45 +1,37 @@
|
|||||||
using System.Runtime.InteropServices;
|
using Windows.Win32;
|
||||||
using Windows.Win32.Foundation;
|
|
||||||
|
|
||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
{
|
{
|
||||||
public class Taskbar : ITaskbar
|
public partial class Taskbar : ITaskbar
|
||||||
{
|
{
|
||||||
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
private readonly IDisposer disposer;
|
||||||
|
private readonly IMessenger messenger;
|
||||||
|
private bool isDrag;
|
||||||
|
private bool isWithinBounds;
|
||||||
|
|
||||||
private enum AppBarEdge : uint
|
public Taskbar(IMessenger messenger,
|
||||||
|
IDisposer disposer)
|
||||||
{
|
{
|
||||||
Left = 0,
|
this.messenger = messenger;
|
||||||
Top = 1,
|
this.disposer = disposer;
|
||||||
Right = 2,
|
|
||||||
Bottom = 3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum AppBarMessage : uint
|
public void Dispose()
|
||||||
{
|
{
|
||||||
New = 0x00000000,
|
disposer.Dispose(this);
|
||||||
Remove = 0x00000001,
|
GC.SuppressFinalize(this);
|
||||||
QueryPos = 0x00000002,
|
|
||||||
SetPos = 0x00000003,
|
|
||||||
GetState = 0x00000004,
|
|
||||||
GetTaskbarPos = 0x00000005,
|
|
||||||
Activate = 0x00000006,
|
|
||||||
GetAutoHideBar = 0x00000007,
|
|
||||||
SetAutoHideBar = 0x00000008,
|
|
||||||
WindowPosChanged = 0x00000009,
|
|
||||||
SetState = 0x0000000A,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskbarState GetCurrentState()
|
public TaskbarState GetCurrentState()
|
||||||
{
|
{
|
||||||
var handle = GetSystemTrayHandle();
|
var handle = GetHandle();
|
||||||
var state = new TaskbarState
|
var state = new TaskbarState
|
||||||
{
|
{
|
||||||
Screen = Screen.FromHandle(handle)
|
Screen = Screen.FromHandle(handle)
|
||||||
};
|
};
|
||||||
|
|
||||||
var appBarData = GetAppBarData(handle);
|
var appBarData = PInvoke.GetAppBarData(handle);
|
||||||
GetAppBarPosition(ref appBarData);
|
PInvoke.GetAppBarPosition(ref appBarData);
|
||||||
|
|
||||||
state.Rect = appBarData.rect.ToRect();
|
state.Rect = appBarData.rect.ToRect();
|
||||||
state.Placement = (TaskbarPlacement)appBarData.uEdge;
|
state.Placement = (TaskbarPlacement)appBarData.uEdge;
|
||||||
@@ -47,34 +39,77 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
public IntPtr GetHandle()
|
||||||
private static extern IntPtr DefWindowProcW(IntPtr handle, uint msg, IntPtr wParam, IntPtr lParam);
|
|
||||||
|
|
||||||
private static IntPtr GetSystemTrayHandle() => WindowHelper.Find(ShellTrayHandleName);
|
|
||||||
|
|
||||||
[DllImport("shell32.dll", SetLastError = true)]
|
|
||||||
private static extern IntPtr SHAppBarMessage(AppBarMessage dwMessage, ref AppBarData pData);
|
|
||||||
|
|
||||||
private AppBarData GetAppBarData(IntPtr handle)
|
|
||||||
{
|
{
|
||||||
return new AppBarData
|
return WindowHelper.Find("Shell_TrayWnd");
|
||||||
{
|
|
||||||
cbSize = (uint)Marshal.SizeOf(typeof(AppBarData)),
|
|
||||||
hWnd = handle
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetAppBarPosition(ref AppBarData appBarData) => SHAppBarMessage(AppBarMessage.GetTaskbarPos, ref appBarData);
|
public void Initialize()
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
private struct AppBarData
|
|
||||||
{
|
{
|
||||||
public uint cbSize;
|
disposer.Add(this, messenger.Subscribe<WndProc>(OnWndProc));
|
||||||
public IntPtr hWnd;
|
disposer.Add(this, messenger.Subscribe<PointerReleased>(OnPointerReleased));
|
||||||
public uint uCallbackMessage;
|
disposer.Add(this, messenger.Subscribe<PointerMoved>(OnPointerMoved));
|
||||||
public AppBarEdge uEdge;
|
disposer.Add(this, messenger.Subscribe<PointerDrag>(OnPointerDrag));
|
||||||
public RECT rect;
|
}
|
||||||
public int lParam;
|
|
||||||
|
private void OnPointerDrag(PointerDrag args)
|
||||||
|
{
|
||||||
|
if (isWithinBounds)
|
||||||
|
{
|
||||||
|
if (isDrag)
|
||||||
|
{
|
||||||
|
messenger.Send<TaskbarDragOver>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messenger.Send<TaskbarDragEnter>();
|
||||||
|
}
|
||||||
|
|
||||||
|
isDrag = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isDrag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPointerMoved(PointerMoved args)
|
||||||
|
{
|
||||||
|
var taskbarHandle = GetHandle();
|
||||||
|
if (WindowHelper.TryGetBounds(taskbarHandle, out var rect))
|
||||||
|
{
|
||||||
|
if (args.Location.IsWithinBounds(rect))
|
||||||
|
{
|
||||||
|
if (isWithinBounds)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isWithinBounds = true;
|
||||||
|
messenger.Send<TaskbarEnter>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isDrag = false;
|
||||||
|
isWithinBounds = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPointerReleased(PointerReleased args)
|
||||||
|
{
|
||||||
|
if (isDrag)
|
||||||
|
{
|
||||||
|
isDrag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnWndProc(WndProc args)
|
||||||
|
{
|
||||||
|
if (args.Message == PInvoke.WM_TASKBARCREATED || args.Message == (int)WndProcMessages.WM_SETTINGCHANGE && (int)args.WParam == PInvoke.SPI_SETWORKAREA)
|
||||||
|
{
|
||||||
|
messenger.Send<TaskbarChanged>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,22 +7,22 @@
|
|||||||
private bool isWithinBounds;
|
private bool isWithinBounds;
|
||||||
private bool isDrag;
|
private bool isDrag;
|
||||||
|
|
||||||
public TaskbarButton(IMessenger messenger,
|
public TaskbarButton(string name,
|
||||||
IDisposer disposer,
|
Rect rect,
|
||||||
string name,
|
IMessenger messenger,
|
||||||
TaskbarButtonBounds bounds)
|
IDisposer disposer)
|
||||||
{
|
{
|
||||||
this.messenger = messenger;
|
this.messenger = messenger;
|
||||||
this.disposer = disposer;
|
this.disposer = disposer;
|
||||||
Name = name;
|
Name = name;
|
||||||
Bounds = bounds;
|
Rect = rect;
|
||||||
|
|
||||||
disposer.Add(this, messenger.Subscribe<PointerReleased>(OnPointerReleased));
|
disposer.Add(this, messenger.Subscribe<PointerReleased>(OnPointerReleased));
|
||||||
disposer.Add(this, messenger.Subscribe<PointerMoved>(OnPointerMoved));
|
disposer.Add(this, messenger.Subscribe<PointerMoved>(OnPointerMoved));
|
||||||
disposer.Add(this, messenger.Subscribe<PointerDrag>(OnPointerDrag));
|
disposer.Add(this, messenger.Subscribe<PointerDrag>(OnPointerDrag));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskbarButtonBounds Bounds { get; internal set; }
|
public Rect Rect { get; internal set; }
|
||||||
|
|
||||||
public string Name { get; internal set; }
|
public string Name { get; internal set; }
|
||||||
|
|
||||||
@@ -32,21 +32,6 @@
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsWithinBounds(PointerLocation args)
|
|
||||||
{
|
|
||||||
if (args.X >= Bounds.X
|
|
||||||
&& args.X <= Bounds.X + Bounds.Width
|
|
||||||
&& args.Y >= Bounds.Y
|
|
||||||
&& args.Y <= Bounds.Y + Bounds.Height)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPointerDrag(PointerDrag args)
|
private void OnPointerDrag(PointerDrag args)
|
||||||
{
|
{
|
||||||
if (isWithinBounds)
|
if (isWithinBounds)
|
||||||
@@ -70,7 +55,7 @@
|
|||||||
|
|
||||||
private void OnPointerMoved(PointerMoved args)
|
private void OnPointerMoved(PointerMoved args)
|
||||||
{
|
{
|
||||||
if (IsWithinBounds(args.Location))
|
if (args.Location.IsWithinBounds(Rect))
|
||||||
{
|
{
|
||||||
if (isWithinBounds)
|
if (isWithinBounds)
|
||||||
{
|
{
|
||||||
@@ -78,7 +63,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
isWithinBounds = true;
|
isWithinBounds = true;
|
||||||
messenger.Send(new TaskbarButtonEntered(this));
|
messenger.Send(new TaskbarButtonEnter(this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public class TaskbarButtonConfiguration
|
||||||
|
{
|
||||||
|
public string? PinnedShortcutDirectory { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public record TaskbarButtonEnter(TaskbarButton Button);
|
||||||
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
|
||||||
{
|
|
||||||
public record TaskbarButtonEntered(TaskbarButton Button);
|
|
||||||
}
|
|
||||||
@@ -4,27 +4,34 @@ using System.Diagnostics;
|
|||||||
|
|
||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
{
|
{
|
||||||
|
|
||||||
public class TaskbarButtonMonitor : ITaskbarButtonMonitor
|
public class TaskbarButtonMonitor : ITaskbarButtonMonitor
|
||||||
{
|
{
|
||||||
private readonly IDispatcherTimer dispatcherTimer;
|
private readonly IDispatcherTimer dispatcherTimer;
|
||||||
private readonly IDispatcherTimerFactory dispatcherTimerFactory;
|
private readonly IDispatcherTimerFactory dispatcherTimerFactory;
|
||||||
private readonly IServiceFactory serviceFactory;
|
private readonly ITaskbarList taskbarList;
|
||||||
private readonly IMessenger messenger;
|
private readonly IMessenger messenger;
|
||||||
|
private readonly IServiceFactory serviceFactory;
|
||||||
|
private readonly IDisposer disposer;
|
||||||
private readonly Dictionary<string, TaskbarButton> taskbarButtons = new();
|
private readonly Dictionary<string, TaskbarButton> taskbarButtons = new();
|
||||||
private RECT taskbarBoundsCache;
|
private Rect? taskbarRectCache;
|
||||||
private IUIAutomationCondition? taskListCondition;
|
private IUIAutomationCondition? taskListCondition;
|
||||||
private IUIAutomationElement? taskListElement;
|
private IUIAutomationElement? taskListElement;
|
||||||
private HWND taskListHandle;
|
private IntPtr taskListHandle;
|
||||||
|
|
||||||
public TaskbarButtonMonitor(IMessenger messenger,
|
public TaskbarButtonMonitor(ITaskbarList taskbarList,
|
||||||
|
IMessenger messenger,
|
||||||
IDispatcherTimerFactory dispatcherTimerFactory,
|
IDispatcherTimerFactory dispatcherTimerFactory,
|
||||||
IServiceFactory serviceFactory)
|
IServiceFactory serviceFactory,
|
||||||
|
IDisposer disposer)
|
||||||
{
|
{
|
||||||
|
this.taskbarList = taskbarList;
|
||||||
this.messenger = messenger;
|
this.messenger = messenger;
|
||||||
this.dispatcherTimerFactory = dispatcherTimerFactory;
|
this.dispatcherTimerFactory = dispatcherTimerFactory;
|
||||||
this.serviceFactory = serviceFactory;
|
this.serviceFactory = serviceFactory;
|
||||||
|
this.disposer = disposer;
|
||||||
|
|
||||||
dispatcherTimer = dispatcherTimerFactory.Create(OnDispatcher, TimeSpan.FromMilliseconds(500));
|
disposer.Add(this, dispatcherTimer = dispatcherTimerFactory.Create(OnDispatcher, TimeSpan.FromMilliseconds(500)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
@@ -32,17 +39,12 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
var clientUIAutomation = new CUIAutomation();
|
var clientUIAutomation = new CUIAutomation();
|
||||||
taskListCondition = clientUIAutomation.CreateTrueCondition();
|
taskListCondition = clientUIAutomation.CreateTrueCondition();
|
||||||
|
|
||||||
var trayHandle = WindowHelper.Find("Shell_TrayWnd");
|
taskListHandle = taskbarList.GetHandle();
|
||||||
|
|
||||||
var rebarHandle = WindowHelper.Find("ReBarWindow32", trayHandle);
|
|
||||||
var taskHandle = WindowHelper.Find("MSTaskSwWClass", rebarHandle);
|
|
||||||
taskListHandle = WindowHelper.Find("MSTaskListWClass", taskHandle);
|
|
||||||
|
|
||||||
taskListElement = clientUIAutomation.ElementFromHandle(taskListHandle);
|
taskListElement = clientUIAutomation.ElementFromHandle(taskListHandle);
|
||||||
|
|
||||||
if (WindowHelper.TryGetBounds(taskListHandle, out var bounds))
|
if (WindowHelper.TryGetBounds(taskListHandle, out var rect))
|
||||||
{
|
{
|
||||||
taskbarBoundsCache = bounds;
|
taskbarRectCache = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatcherTimer.Start();
|
dispatcherTimer.Start();
|
||||||
@@ -51,17 +53,11 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
|
|
||||||
private bool CheckDirtyTaskbarRegion()
|
private bool CheckDirtyTaskbarRegion()
|
||||||
{
|
{
|
||||||
if (WindowHelper.TryGetBounds(taskListHandle, out var bounds))
|
if (WindowHelper.TryGetBounds(taskListHandle, out var rect))
|
||||||
{
|
{
|
||||||
var width = taskbarBoundsCache.right - taskbarBoundsCache.left;
|
if (taskbarRectCache?.Width != rect.Width || taskbarRectCache?.Height != rect.Height)
|
||||||
var height = taskbarBoundsCache.bottom - taskbarBoundsCache.top;
|
|
||||||
|
|
||||||
var deltaWidth = bounds.right - bounds.left;
|
|
||||||
var deltaHeight = bounds.bottom - bounds.top;
|
|
||||||
|
|
||||||
if (width != deltaWidth || height != deltaHeight)
|
|
||||||
{
|
{
|
||||||
taskbarBoundsCache = bounds;
|
taskbarRectCache = rect;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +72,7 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
var buttons = new Dictionary<string, tagRECT>();
|
var buttons = new Dictionary<string, tagRECT>();
|
||||||
if (taskElements is not null)
|
if (taskElements is not null)
|
||||||
{
|
{
|
||||||
for (int index = 0; index <= taskElements.Length - 1; index++)
|
for (var index = 0; index <= taskElements.Length - 1; index++)
|
||||||
{
|
{
|
||||||
var taskUIElement = taskElements.GetElement(index);
|
var taskUIElement = taskElements.GetElement(index);
|
||||||
var name = taskUIElement.CurrentName;
|
var name = taskUIElement.CurrentName;
|
||||||
@@ -128,7 +124,7 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
var name = button.Key;
|
var name = button.Key;
|
||||||
var bounds = button.Value;
|
var bounds = button.Value;
|
||||||
|
|
||||||
var buttonBounds = new TaskbarButtonBounds(bounds.left,
|
var rect = new Rect(bounds.left,
|
||||||
bounds.top,
|
bounds.top,
|
||||||
bounds.right - bounds.left,
|
bounds.right - bounds.left,
|
||||||
bounds.bottom - bounds.top);
|
bounds.bottom - bounds.top);
|
||||||
@@ -137,14 +133,14 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
{
|
{
|
||||||
Debug.WriteLine($"{name} button updated");
|
Debug.WriteLine($"{name} button updated");
|
||||||
|
|
||||||
taskbarButtons[name].Bounds = buttonBounds;
|
taskbarButtons[name].Rect = rect;
|
||||||
messenger.Send(new TaskbarButtonUpdated(taskbarButtons[name]));
|
messenger.Send(new TaskbarButtonUpdated(taskbarButtons[name]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{name} button added");
|
Debug.WriteLine($"{name} button added");
|
||||||
|
|
||||||
taskbarButtons.Add(name, serviceFactory.Create<TaskbarButton>(name, buttonBounds));
|
taskbarButtons.Add(name, serviceFactory.Create<TaskbarButton>(name, rect));
|
||||||
messenger.Send(new TaskbarButtonCreated(taskbarButtons[name]));
|
messenger.Send(new TaskbarButtonCreated(taskbarButtons[name]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public class TaskbarButtonShortcutMonitor : ITaskbarButtonShortcutMonitor
|
||||||
|
{
|
||||||
|
private readonly IMessenger messenger;
|
||||||
|
private FileSystemWatcher? _watcher;
|
||||||
|
private readonly TaskbarButtonConfiguration configuration;
|
||||||
|
|
||||||
|
public TaskbarButtonShortcutMonitor(
|
||||||
|
IMessenger messenger)
|
||||||
|
{
|
||||||
|
this.messenger = messenger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
//_watcher = new FileSystemWatcher(configuration.PinnedShortcutDirectory)
|
||||||
|
//{
|
||||||
|
// NotifyFilter = NotifyFilters.FileName,
|
||||||
|
// Filter = "*.ink",
|
||||||
|
// IncludeSubdirectories = true,
|
||||||
|
// EnableRaisingEvents = true
|
||||||
|
//};
|
||||||
|
|
||||||
|
//_watcher.Changed += OnChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnChanged(object sender, FileSystemEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.ChangeType is WatcherChangeTypes.Created)
|
||||||
|
{
|
||||||
|
messenger.Send<TaskButtonShortcutRemoved>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.ChangeType is WatcherChangeTypes.Deleted)
|
||||||
|
{
|
||||||
|
messenger.Send<TaskButtonShortcutRemoved>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public record TaskbarDragEnter();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public record TaskbarDragOver();
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public record TaskbarEnter();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup.Core
|
||||||
|
{
|
||||||
|
public class TaskbarList : ITaskbarList
|
||||||
|
{
|
||||||
|
private readonly ITaskbar taskbar;
|
||||||
|
|
||||||
|
public TaskbarList(ITaskbar taskbar)
|
||||||
|
{
|
||||||
|
this.taskbar = taskbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr GetHandle()
|
||||||
|
{
|
||||||
|
var trayHandle = taskbar.GetHandle();
|
||||||
|
|
||||||
|
var rebarHandle = WindowHelper.Find("ReBarWindow32", trayHandle);
|
||||||
|
var taskHandle = WindowHelper.Find("MSTaskSwWClass", rebarHandle);
|
||||||
|
return WindowHelper.Find("MSTaskListWClass", taskHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
using Windows.Win32;
|
|
||||||
|
|
||||||
namespace TheXamlGuy.TaskbarGroup.Core
|
|
||||||
{
|
|
||||||
public class TaskbarMonitor : ITaskbarMonitor
|
|
||||||
{
|
|
||||||
private const int SPI_SETWORKAREA = 0x002F;
|
|
||||||
|
|
||||||
private readonly uint WM_TASKBARCREATED = PInvoke.RegisterWindowMessage("TaskbarCreated");
|
|
||||||
private readonly IMessenger messenger;
|
|
||||||
|
|
||||||
public TaskbarMonitor(IMessenger messenger)
|
|
||||||
{
|
|
||||||
this.messenger = messenger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Initialize()
|
|
||||||
{
|
|
||||||
messenger.Subscribe<WndProc>(OnWndProc);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnWndProc(WndProc args)
|
|
||||||
{
|
|
||||||
if (args.Message == WM_TASKBARCREATED || args.Message == (int)WndProcMessages.WM_SETTINGCHANGE && (int)args.WParam == SPI_SETWORKAREA)
|
|
||||||
{
|
|
||||||
messenger.Send<TaskbarChanged>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
public struct TaskbarState
|
public struct TaskbarState
|
||||||
{
|
{
|
||||||
public TaskbarPlacement Placement;
|
public TaskbarPlacement Placement;
|
||||||
public Rect Rect;
|
public Windows.Foundation.Rect Rect;
|
||||||
public Screen Screen;
|
public Screen Screen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview2" />
|
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview2" />
|
||||||
|
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.635-beta">
|
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.635-beta">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Windows.Win32;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Windows.Win32;
|
||||||
using Windows.Win32.Foundation;
|
using Windows.Win32.Foundation;
|
||||||
using Windows.Win32.UI.WindowsAndMessaging;
|
using Windows.Win32.UI.WindowsAndMessaging;
|
||||||
|
|
||||||
@@ -6,27 +7,42 @@ namespace TheXamlGuy.TaskbarGroup.Core
|
|||||||
{
|
{
|
||||||
public class WindowHelper
|
public class WindowHelper
|
||||||
{
|
{
|
||||||
public static void MoveAndResize(HWND handle, int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
PInvoke.SetWindowPos(handle, new HWND(), x, y, width, height, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BringToForeground(HWND handle)
|
public static void BringToForeground(HWND handle)
|
||||||
{
|
{
|
||||||
if (TryGetBounds(handle, out var bounds))
|
if (TryGetBoundsUnsafe(handle, out var bounds))
|
||||||
{
|
{
|
||||||
PInvoke.SetWindowPos(handle, new HWND(), bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top, SET_WINDOW_POS_FLAGS.SWP_SHOWWINDOW | SET_WINDOW_POS_FLAGS.SWP_NOACTIVATE);
|
PInvoke.SetWindowPos(handle, new HWND(), bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top, SET_WINDOW_POS_FLAGS.SWP_SHOWWINDOW | SET_WINDOW_POS_FLAGS.SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HWND Find(string windowName) => PInvoke.FindWindow(windowName, null);
|
public static IntPtr Find(string windowName)
|
||||||
|
|
||||||
public static HWND Find(string windowName, HWND parentHandle)
|
|
||||||
{
|
{
|
||||||
return PInvoke.FindWindowEx(parentHandle, new HWND(), windowName, null);
|
return PInvoke.FindWindow(windowName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe bool TryGetBounds(IntPtr handle, out RECT rect)
|
public static IntPtr Find(string windowName, IntPtr parentHandle)
|
||||||
|
{
|
||||||
|
return PInvoke.FindWindowEx(new HWND(parentHandle), new HWND(), windowName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MoveAndResize(HWND handle, int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
PInvoke.SetWindowPos(handle, new HWND(), x, y, width, height, 0);
|
||||||
|
}
|
||||||
|
public static bool TryGetBounds(IntPtr handle, [MaybeNullWhen(false)]out Rect rect)
|
||||||
|
{
|
||||||
|
if (TryGetBoundsUnsafe(handle, out var unsafeRect))
|
||||||
|
{
|
||||||
|
rect = new Rect(unsafeRect.left, unsafeRect.top, unsafeRect.right - unsafeRect.left, unsafeRect.bottom - unsafeRect.top);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
rect = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static unsafe bool TryGetBoundsUnsafe(IntPtr handle, out RECT rect)
|
||||||
{
|
{
|
||||||
fixed (RECT* lpRectLocal = &rect)
|
fixed (RECT* lpRectLocal = &rect)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using TheXamlGuy.TaskbarGroup.Core;
|
using TheXamlGuy.TaskbarGroup.Core;
|
||||||
using TheXamlGuy.TaskbarGroup.Flyout;
|
using TheXamlGuy.TaskbarGroup.Flyout;
|
||||||
@@ -17,15 +16,11 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
|
|
||||||
protected override async void OnStartup(StartupEventArgs args)
|
protected override async void OnStartup(StartupEventArgs args)
|
||||||
{
|
{
|
||||||
var appLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
host = new HostBuilder()
|
||||||
|
.UseContentRoot(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
|
||||||
host = Host.CreateDefaultBuilder()
|
"TheXamlGuy", "TaskbarGroup"), true)
|
||||||
.ConfigureAppConfiguration(config =>
|
.ConfigureServices(ConfigureServices)
|
||||||
{
|
.Build();
|
||||||
config.SetBasePath(appLocation);
|
|
||||||
})
|
|
||||||
.ConfigureServices(ConfigureServices)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
await host.StartAsync();
|
await host.StartAsync();
|
||||||
}
|
}
|
||||||
@@ -36,6 +31,7 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
.AddRequiredCore()
|
.AddRequiredCore()
|
||||||
.AddRequiredFoundation()
|
.AddRequiredFoundation()
|
||||||
.AddRequiredFlyoutFoundation()
|
.AddRequiredFlyoutFoundation()
|
||||||
|
.AddHandler<TaskbarButtonFlyoutWindowActivationHandler>()
|
||||||
.AddHandler<TaskbarButtonFlyoutActivationHandler>()
|
.AddHandler<TaskbarButtonFlyoutActivationHandler>()
|
||||||
.AddSingleton<TaskbarButtonFlyoutWindow>()
|
.AddSingleton<TaskbarButtonFlyoutWindow>()
|
||||||
.AddTransient<TaskbarButtonView>()
|
.AddTransient<TaskbarButtonView>()
|
||||||
|
|||||||
@@ -8,15 +8,24 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
{
|
{
|
||||||
public sealed class ApplicationHost : IHostedService
|
public sealed class ApplicationHost : IHostedService
|
||||||
{
|
{
|
||||||
private readonly TaskbarButtonFlyoutWindow flyoutWindow;
|
private readonly IMediator mediator;
|
||||||
private readonly IEnumerable<IInitializable> initializables;
|
private readonly List<IInitializable> initializables = new();
|
||||||
private bool isInitialized;
|
private bool isInitialized;
|
||||||
|
|
||||||
public ApplicationHost(IEnumerable<IInitializable> initializables,
|
public ApplicationHost(IWndProcMonitor wndProcMonitor,
|
||||||
TaskbarButtonFlyoutWindow flyoutWindow)
|
ITaskbar taskbar,
|
||||||
|
IPointerMonitor pointerMonitor,
|
||||||
|
ITaskbarButtonMonitor taskbarButtonMonitor,
|
||||||
|
ITaskbarButtonShortcutMonitor taskbarButtonShortcutMonitor,
|
||||||
|
IMediator mediator)
|
||||||
{
|
{
|
||||||
this.initializables = initializables;
|
initializables.Add(wndProcMonitor);
|
||||||
this.flyoutWindow = flyoutWindow;
|
initializables.Add(taskbar);
|
||||||
|
initializables.Add(pointerMonitor);
|
||||||
|
initializables.Add(taskbarButtonMonitor);
|
||||||
|
initializables.Add(taskbarButtonShortcutMonitor);
|
||||||
|
|
||||||
|
this.mediator = mediator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
@@ -27,7 +36,6 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken cancellationToken)
|
public async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
@@ -50,7 +58,7 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
{
|
{
|
||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
{
|
{
|
||||||
flyoutWindow.Show();
|
mediator.Handle<TaskbarButtonFlyoutWindowActivation>();
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
|
|
||||||
case TaskbarPlacement.Bottom:
|
case TaskbarPlacement.Bottom:
|
||||||
placement = TaskbarButtonFlyoutPlacement.Bottom;
|
placement = TaskbarButtonFlyoutPlacement.Bottom;
|
||||||
window.Left = ((button.Bounds.X + (button.Bounds.Width / 2)) / dpiX) - (window.Width / 2);
|
window.Left = ((button.Rect.X + (button.Rect.Width / 2)) / dpiX) - (window.Width / 2);
|
||||||
window.Top = (button.Bounds.Y / dpiY) - window.Height;
|
window.Top = (button.Rect.Y / dpiY) - window.Height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace TheXamlGuy.TaskbarGroup
|
||||||
|
{
|
||||||
|
public record TaskbarButtonFlyoutWindowActivation();
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using TheXamlGuy.TaskbarGroup.Core;
|
||||||
|
|
||||||
|
namespace TheXamlGuy.TaskbarGroup
|
||||||
|
{
|
||||||
|
public class TaskbarButtonFlyoutWindowActivationHandler : IMessageHandler<TaskbarButtonFlyoutWindowActivation>
|
||||||
|
{
|
||||||
|
private readonly TaskbarButtonFlyoutWindow flyoutWindow;
|
||||||
|
|
||||||
|
public TaskbarButtonFlyoutWindowActivationHandler(TaskbarButtonFlyoutWindow flyoutWindow)
|
||||||
|
{
|
||||||
|
this.flyoutWindow = flyoutWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Handle(TaskbarButtonFlyoutWindowActivation message)
|
||||||
|
{
|
||||||
|
flyoutWindow.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,3 +26,4 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace TheXamlGuy.TaskbarGroup
|
||||||
|
{
|
||||||
|
public class CreateTaskbarButtonGroupWindow : Window
|
||||||
|
{
|
||||||
|
public CreateTaskbarButtonGroupWindow()
|
||||||
|
{
|
||||||
|
Height = 0;
|
||||||
|
Width = 0;
|
||||||
|
WindowStyle = WindowStyle.None;
|
||||||
|
ResizeMode = ResizeMode.NoResize;
|
||||||
|
AllowsTransparency = true;
|
||||||
|
Background = new SolidColorBrush(Colors.Transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using TheXamlGuy.TaskbarGroup.Core;
|
using TheXamlGuy.TaskbarGroup.Core;
|
||||||
using TheXamlGuy.TaskbarGroup.Flyout.Controls;
|
using TheXamlGuy.TaskbarGroup.Flyout.Controls;
|
||||||
@@ -23,10 +24,16 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
Hide();
|
Hide();
|
||||||
}), DispatcherPriority.ContextIdle, null);
|
}), DispatcherPriority.ContextIdle, null);
|
||||||
|
|
||||||
|
messenger.Subscribe<TaskbarDragEnter>(OnTaskbarDragEnter);
|
||||||
messenger.Subscribe<TaskbarButtonInvoked>(OnTaskbarButtonInvoked);
|
messenger.Subscribe<TaskbarButtonInvoked>(OnTaskbarButtonInvoked);
|
||||||
messenger.Subscribe<TaskbarButtonDragEnter>(OnTaskbarButtonDragEnter);
|
messenger.Subscribe<TaskbarButtonDragEnter>(OnTaskbarButtonDragEnter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnTaskbarDragEnter(TaskbarDragEnter obj)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("fff");
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnDeactivated(EventArgs args)
|
protected override void OnDeactivated(EventArgs args)
|
||||||
{
|
{
|
||||||
if (XamlContent is TaskbarButtonFlyout flyout)
|
if (XamlContent is TaskbarButtonFlyout flyout)
|
||||||
@@ -52,6 +59,5 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
{
|
{
|
||||||
Dispatcher.Invoke(() => Open(args.Button));
|
Dispatcher.Invoke(() => Open(args.Button));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,7 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
{
|
{
|
||||||
public class TransparentXamlWindow<TXamlContent> : XamlWindow<TXamlContent> where TXamlContent : Windows.UI.Xaml.UIElement
|
public class TransparentXamlWindow<TXamlContent> : XamlWindow<TXamlContent> where TXamlContent : Windows.UI.Xaml.UIElement
|
||||||
{
|
{
|
||||||
public TransparentXamlWindow() => PrepareDefaultWindow();
|
public TransparentXamlWindow()
|
||||||
|
|
||||||
protected override WindowsXamlHost OnInitializing(WindowsXamlHost xamlHost)
|
|
||||||
{
|
|
||||||
return base.OnInitializing(xamlHost);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PrepareDefaultWindow()
|
|
||||||
{
|
{
|
||||||
ShowInTaskbar = false;
|
ShowInTaskbar = false;
|
||||||
WindowStyle = WindowStyle.None;
|
WindowStyle = WindowStyle.None;
|
||||||
@@ -21,5 +14,10 @@ namespace TheXamlGuy.TaskbarGroup
|
|||||||
AllowsTransparency = true;
|
AllowsTransparency = true;
|
||||||
Background = new SolidColorBrush(Colors.Transparent);
|
Background = new SolidColorBrush(Colors.Transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override WindowsXamlHost OnInitializing(WindowsXamlHost xamlHost)
|
||||||
|
{
|
||||||
|
return base.OnInitializing(xamlHost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user