Repository navigation
feat(tray): quick-access panel on tray icon left click #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| using Microsoft.UI.Composition; | ||
| using Microsoft.UI.Composition.SystemBackdrops; | ||
| using Microsoft.UI.Xaml.Media; | ||
| using Windows.UI.ViewManagement; | ||
|
|
||
| namespace XrayUI.Helpers | ||
| { | ||
| /// <summary> | ||
| /// Desktop acrylic that keeps its blur while the window is inactive and takes its light/dark | ||
| /// from the window's own content. The stock DesktopAcrylicBackdrop does neither: it drops to a | ||
| /// flat fallback color the moment its window loses activation — which is exactly how the tray | ||
| /// panel's slide-out begins — and it can disagree with an app theme forced against the system's. | ||
| /// </summary> | ||
| internal sealed partial class ActiveAcrylicBackdrop : SystemBackdrop | ||
| { | ||
| private DesktopAcrylicController? _controller; | ||
| private SystemBackdropConfiguration? _configuration; | ||
|
|
||
| protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot) | ||
| { | ||
| base.OnTargetConnected(connectedTarget, xamlRoot); | ||
| if (!DesktopAcrylicController.IsSupported()) return; | ||
|
|
||
| _configuration = new SystemBackdropConfiguration | ||
| { | ||
| IsInputActive = true, | ||
| IsHighContrast = new AccessibilitySettings().HighContrast, | ||
| Theme = ToBackdropTheme((xamlRoot.Content as FrameworkElement)?.ActualTheme), | ||
| }; | ||
| // Base rather than Default: the more opaque kind, so text stays legible over whatever | ||
| // happens to be behind the panel. | ||
| _controller = new DesktopAcrylicController { Kind = DesktopAcrylicKind.Base }; | ||
| _controller.SetSystemBackdropConfiguration(_configuration); | ||
| _controller.AddSystemBackdropTarget(connectedTarget); | ||
| } | ||
|
|
||
| protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget) | ||
| { | ||
| base.OnTargetDisconnected(disconnectedTarget); | ||
| if (_controller is null) return; | ||
|
|
||
| _controller.RemoveSystemBackdropTarget(disconnectedTarget); | ||
| _controller.Dispose(); | ||
| _controller = null; | ||
| _configuration = null; | ||
| } | ||
|
|
||
| // The base implementation would install the default configuration, bringing back the | ||
| // activation tracking this class exists to drop; only the theme is meant to follow. | ||
| protected override void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot) | ||
| => SyncTheme((xamlRoot.Content as FrameworkElement)?.ActualTheme); | ||
|
|
||
| /// <summary>Re-reads the theme for a window whose content theme changed while hidden.</summary> | ||
| public void SyncTheme(ElementTheme? actualTheme) | ||
| { | ||
| if (_configuration is not null) | ||
| _configuration.Theme = ToBackdropTheme(actualTheme); | ||
| } | ||
|
|
||
| private static SystemBackdropTheme ToBackdropTheme(ElementTheme? theme) => theme switch | ||
| { | ||
| ElementTheme.Dark => SystemBackdropTheme.Dark, | ||
| ElementTheme.Light => SystemBackdropTheme.Light, | ||
| _ => SystemBackdropTheme.Default, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the panel loses activation within the double-click interval while the pointer remains over the tray icon, this handler treats any light dismiss as a second click because
IsSecondTrayClickchecks only elapsed time and cursor position. For example, right-clicking the icon to open its context menu or quickly pressing Alt+Tab after opening the panel restores the full main window and steals focus even though no second left-click occurred. Track an actual tray-button event rather than inferring one from every deactivation.Useful? React with 👍 / 👎.