mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 01:36:31 +02:00
Add support for a "dock" window in CmdPal. The dock is a toolbar powered by the `APPBAR` APIs. This gives you a persistent region to display commands for quick shortcuts or glanceable widgets. The dock can be pinned to any side of the screen. The dock can be independently styled with any of the theming controls cmdpal already has The dock has three "regions" to pin to - the "start", the "center", and the "end". Elements on the dock are grouped as "bands", which contains a set of "items". Each "band" is one atomic unit. For example, the Media Player extension produces 4 items, but one _band_. The dock has only one size (for now) The dock will only appear on your primary display (for now) This PR includes support for pinning arbitrary top-level commands to the dock - however, we're planning on replacing that with a more universal ability to pin any command to the dock or top level. (see #45191). This is at least usable for now. This is definitely still _even more preview_ than usual PowerToys features, but it's more than usable. I'd love to get it out there and start collecting feedback on where to improve next. I'll probably add a follow-up issue for tracking the remaining bugs & nits. closes #45201 --------- Co-authored-by: Niels Laute <niels.laute@live.nl>
85 lines
3.8 KiB
C#
85 lines
3.8 KiB
C#
// Copyright (c) Microsoft Corporation
|
||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||
// See the LICENSE file in the project root for more information.
|
||
|
||
using Microsoft.CmdPal.UI.Controls;
|
||
using Microsoft.CmdPal.UI.ViewModels;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
|
||
namespace Microsoft.CmdPal.UI.Helpers;
|
||
|
||
/// <summary>
|
||
/// Common async event handler provides the cache lookup function for the <see cref="IconBox.SourceRequested"/> deferred event.
|
||
/// </summary>
|
||
public static partial class IconCacheProvider
|
||
{
|
||
/*
|
||
Memory Usage Considerations (raw estimates):
|
||
| Icon Size | Per Icon | Count | Total | Per Icon @ 200% | Total @ 200% | Per Icon @ 300% | Total @ 300% |
|
||
| --------- | -------: | ----: | -------: | --------------: | -----------: | --------------: | -----------: |
|
||
| 20×20 | 1.6 KB | 1024 | 1.6 MB | 6.4 KB | 6.4 MB | 14.4 KB | 14.4 MB |
|
||
| 32×32 | 4.0 KB | 512 | 2.0 MB | 16 KB | 8.0 MB | 36.0 KB | 18.0 MB |
|
||
| 48×48 | 9.0 KB | 256 | 2.3 MB | 36 KB | 9.0 MB | 81.0 KB | 20.3 MB |
|
||
| 64×64 | 16.0 KB | 64 | 1.0 MB | 64 KB | 4.0 MB | 144.0 KB | 9.0 MB |
|
||
| 256×256 | 256.0 KB | 64 | 16.0 MB | 1 MB | 64.0 MB | 2.3 MB | 144 MB |
|
||
*/
|
||
|
||
private static IIconSourceProvider _provider16 = null!;
|
||
private static IIconSourceProvider _provider20 = null!;
|
||
private static IIconSourceProvider _provider32 = null!;
|
||
private static IIconSourceProvider _provider64 = null!;
|
||
private static IIconSourceProvider _provider256 = null!;
|
||
|
||
public static void Initialize(IServiceProvider serviceProvider)
|
||
{
|
||
_provider16 = serviceProvider.GetRequiredKeyedService<IIconSourceProvider>(WellKnownIconSize.Size16);
|
||
_provider20 = serviceProvider.GetRequiredKeyedService<IIconSourceProvider>(WellKnownIconSize.Size20);
|
||
_provider32 = serviceProvider.GetRequiredKeyedService<IIconSourceProvider>(WellKnownIconSize.Size32);
|
||
_provider64 = serviceProvider.GetRequiredKeyedService<IIconSourceProvider>(WellKnownIconSize.Size64);
|
||
_provider256 = serviceProvider.GetRequiredKeyedService<IIconSourceProvider>(WellKnownIconSize.Size256);
|
||
}
|
||
|
||
private static async void SourceRequestedCore(IIconSourceProvider service, SourceRequestedEventArgs args)
|
||
{
|
||
if (args.Key is null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
var deferral = args.GetDeferral();
|
||
|
||
try
|
||
{
|
||
args.Value = args.Key switch
|
||
{
|
||
IconDataViewModel iconData => await service.GetIconSource(iconData, args.Scale),
|
||
IconInfoViewModel iconInfo => await service.GetIconSource(
|
||
args.Theme == Microsoft.UI.Xaml.ElementTheme.Light ? iconInfo.Light : iconInfo.Dark,
|
||
args.Scale),
|
||
_ => null,
|
||
};
|
||
}
|
||
finally
|
||
{
|
||
deferral.Complete();
|
||
}
|
||
}
|
||
|
||
#pragma warning disable IDE0060 // Remove unused parameter
|
||
public static void SourceRequested16(IconBox sender, SourceRequestedEventArgs args)
|
||
=> SourceRequestedCore(_provider16, args);
|
||
|
||
public static void SourceRequested20(IconBox sender, SourceRequestedEventArgs args)
|
||
=> SourceRequestedCore(_provider20, args);
|
||
|
||
public static void SourceRequested32(IconBox sender, SourceRequestedEventArgs args)
|
||
=> SourceRequestedCore(_provider32, args);
|
||
|
||
public static void SourceRequested64(IconBox sender, SourceRequestedEventArgs args)
|
||
=> SourceRequestedCore(_provider64, args);
|
||
|
||
public static void SourceRequested256(IconBox sender, SourceRequestedEventArgs args)
|
||
=> SourceRequestedCore(_provider256, args);
|
||
#pragma warning restore IDE0060 // Remove unused parameter
|
||
}
|