2022-08-26 18:01:50 +02:00
|
|
|
|
// 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 System;
|
2022-12-02 15:45:49 +01:00
|
|
|
|
using System.ComponentModel;
|
2022-08-26 18:01:50 +02:00
|
|
|
|
using System.Windows;
|
2024-09-16 16:09:43 -04:00
|
|
|
|
|
2023-11-16 18:40:04 +01:00
|
|
|
|
using Wpf.Ui.Controls;
|
2024-09-16 16:09:43 -04:00
|
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
|
using Point = PowerAccent.Core.Point;
|
|
|
|
|
|
using Size = PowerAccent.Core.Size;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PowerAccent.UI;
|
|
|
|
|
|
|
2023-11-16 18:40:04 +01:00
|
|
|
|
public partial class Selector : FluentWindow, IDisposable, INotifyPropertyChanged
|
2022-08-26 18:01:50 +02:00
|
|
|
|
{
|
2022-12-18 14:27:14 +01:00
|
|
|
|
private readonly Core.PowerAccent _powerAccent = new();
|
2022-12-02 15:45:49 +01:00
|
|
|
|
|
|
|
|
|
|
private Visibility _characterNameVisibility = Visibility.Visible;
|
|
|
|
|
|
|
2023-03-16 15:51:31 +01:00
|
|
|
|
private int _selectedIndex;
|
2022-12-16 11:36:55 +02:00
|
|
|
|
|
2022-12-02 15:45:49 +01:00
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
|
|
public Visibility CharacterNameVisibility
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _characterNameVisibility;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_characterNameVisibility = value;
|
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CharacterNameVisibility)));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-08-26 18:01:50 +02:00
|
|
|
|
|
|
|
|
|
|
public Selector()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2023-12-07 10:57:30 +01:00
|
|
|
|
|
2023-12-21 13:56:48 +01:00
|
|
|
|
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this);
|
2023-12-07 10:57:30 +01:00
|
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
|
Application.Current.MainWindow.ShowActivated = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnSourceInitialized(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnSourceInitialized(e);
|
|
|
|
|
|
_powerAccent.OnChangeDisplay += PowerAccent_OnChangeDisplay;
|
|
|
|
|
|
_powerAccent.OnSelectCharacter += PowerAccent_OnSelectionCharacter;
|
|
|
|
|
|
this.Visibility = Visibility.Hidden;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-18 00:15:53 +08:00
|
|
|
|
private void PowerAccent_OnSelectionCharacter(int index, string character)
|
2022-08-26 18:01:50 +02:00
|
|
|
|
{
|
2022-12-16 11:36:55 +02:00
|
|
|
|
_selectedIndex = index;
|
|
|
|
|
|
characters.SelectedIndex = _selectedIndex;
|
|
|
|
|
|
characterName.Text = _powerAccent.CharacterDescriptions[_selectedIndex];
|
Quotation mark (#30481)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Add Quotation mark
Add local quotation based on ~~VK_OEM_7(0xDE)~~ VK_OEM_COMMA(0xBC) key.
Not all quotes have been added, only `‟ „ ” « » ‚ , ‘ ’ › ‹ '「 」 《 》 『
』〈 〉″ ‴ ⁗`
Why not added :
- ` ⹂ ⌜ ⌝ ❛ ❜ ❝ ❞ 🙶 🙷 🙸 ' 「 」 ` its redundant and would make too much
and not readable.
- ` ﹁ ﹂ ﹃ ﹄ ` I did not put them because there use for horizontal text
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [x] Closes: https://github.com/microsoft/PowerToys/issues/29371
https://github.com/microsoft/PowerToys/issues/24832
- [ ] **Communication:** I've discussed this with core contributors
already. If work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end user facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places (None)
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed
or any additional comments/features here -->
This PR is currently a draft, I still need to know if adding
language-related keyboard management is a good idea or specifying the
use of a gobal key to make it easier to manage all the keyboards in one.
Some languages can use different keyboards, I think this would become
problematic if the keyboard does not match the key used by default.
However, using a universal key can also pose an issue to finding the
key. that remains to be discussed
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2025-12-05 11:57:01 +01:00
|
|
|
|
characters.ScrollIntoView(character);
|
2022-08-26 18:01:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-18 00:15:53 +08:00
|
|
|
|
private void PowerAccent_OnChangeDisplay(bool isActive, string[] chars)
|
2022-08-26 18:01:50 +02:00
|
|
|
|
{
|
[QuickAccent] Update Topmost logic to attempt to fix hybrid graphics issues (#41044)
An attempt to fix a Quick Accent issue affecting laptops with 'Optimus'
hybrid graphics modes, where the utility locks the machine into discrete
graphics mode permanently.
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
This PR changes the Topmost behaviour for Quick Accent from always true
to only being true when the selection window is displayed.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [x] Closes: #34849 (NB: requires testing on laptop with hybrid
graphics)
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
Topmost was set to `true` for the main application window on start,
which persisted for the lifetime of the application. This PR change
removes that, and instead dynamically toggles Topmost for the selection
window as it is activated/deactivated. The assumption is that the
FluentWindow-derived window is retaining graphics resources and
presenting as an active GPU consumer because of the main application
window's Topmost status, even if the selection window is hidden.
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
I've confirmed with manual tests that the existing QuickAccent
functionality appears to function identically with this change. However,
I do not own a laptop with a hybrid graphics capability, so am unable to
test whether this fixes the underlying problem. I will keep my fingers
crossed though 🤞😊
---------
Co-authored-by: Gleb Khmyznikov <gleb.khmyznikov@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-22 07:18:16 +01:00
|
|
|
|
// Topmost is conditionally set here to address hybrid graphics issues on laptops.
|
|
|
|
|
|
this.Topmost = isActive;
|
|
|
|
|
|
|
2022-12-02 15:45:49 +01:00
|
|
|
|
CharacterNameVisibility = _powerAccent.ShowUnicodeDescription ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
|
if (isActive)
|
|
|
|
|
|
{
|
|
|
|
|
|
characters.ItemsSource = chars;
|
2022-12-16 11:36:55 +02:00
|
|
|
|
characters.SelectedIndex = _selectedIndex;
|
2022-12-05 00:28:05 +02:00
|
|
|
|
this.UpdateLayout(); // Required for filling the actual width/height before positioning.
|
Quotation mark (#30481)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Add Quotation mark
Add local quotation based on ~~VK_OEM_7(0xDE)~~ VK_OEM_COMMA(0xBC) key.
Not all quotes have been added, only `‟ „ ” « » ‚ , ‘ ’ › ‹ '「 」 《 》 『
』〈 〉″ ‴ ⁗`
Why not added :
- ` ⹂ ⌜ ⌝ ❛ ❜ ❝ ❞ 🙶 🙷 🙸 ' 「 」 ` its redundant and would make too much
and not readable.
- ` ﹁ ﹂ ﹃ ﹄ ` I did not put them because there use for horizontal text
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [x] Closes: https://github.com/microsoft/PowerToys/issues/29371
https://github.com/microsoft/PowerToys/issues/24832
- [ ] **Communication:** I've discussed this with core contributors
already. If work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end user facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places (None)
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed
or any additional comments/features here -->
This PR is currently a draft, I still need to know if adding
language-related keyboard management is a good idea or specifying the
use of a gobal key to make it easier to manage all the keyboards in one.
Some languages can use different keyboards, I think this would become
problematic if the keyboard does not match the key used by default.
However, using a universal key can also pose an issue to finding the
key. that remains to be discussed
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2025-12-05 11:57:01 +01:00
|
|
|
|
SetWindowsSize();
|
2022-12-05 00:28:05 +02:00
|
|
|
|
SetWindowPosition();
|
|
|
|
|
|
Show();
|
2022-08-26 18:01:50 +02:00
|
|
|
|
Microsoft.PowerToys.Telemetry.PowerToysTelemetry.Log.WriteEvent(new PowerAccent.Core.Telemetry.PowerAccentShowAccentMenuEvent());
|
|
|
|
|
|
}
|
2022-12-05 00:28:05 +02:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
}
|
2022-08-26 18:01:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MenuExit_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-05 00:28:05 +02:00
|
|
|
|
private void SetWindowPosition()
|
2022-08-26 18:01:50 +02:00
|
|
|
|
{
|
2022-12-18 14:27:14 +01:00
|
|
|
|
Size windowSize = new(((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth, ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight);
|
2022-12-05 00:28:05 +02:00
|
|
|
|
Point position = _powerAccent.GetDisplayCoordinates(windowSize);
|
2022-08-26 18:01:50 +02:00
|
|
|
|
this.Left = position.X;
|
|
|
|
|
|
this.Top = position.Y;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Quotation mark (#30481)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Add Quotation mark
Add local quotation based on ~~VK_OEM_7(0xDE)~~ VK_OEM_COMMA(0xBC) key.
Not all quotes have been added, only `‟ „ ” « » ‚ , ‘ ’ › ‹ '「 」 《 》 『
』〈 〉″ ‴ ⁗`
Why not added :
- ` ⹂ ⌜ ⌝ ❛ ❜ ❝ ❞ 🙶 🙷 🙸 ' 「 」 ` its redundant and would make too much
and not readable.
- ` ﹁ ﹂ ﹃ ﹄ ` I did not put them because there use for horizontal text
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [x] Closes: https://github.com/microsoft/PowerToys/issues/29371
https://github.com/microsoft/PowerToys/issues/24832
- [ ] **Communication:** I've discussed this with core contributors
already. If work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end user facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places (None)
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed
or any additional comments/features here -->
This PR is currently a draft, I still need to know if adding
language-related keyboard management is a good idea or specifying the
use of a gobal key to make it easier to manage all the keyboards in one.
Some languages can use different keyboards, I think this would become
problematic if the keyboard does not match the key used by default.
However, using a universal key can also pose an issue to finding the
key. that remains to be discussed
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2025-12-05 11:57:01 +01:00
|
|
|
|
private void SetWindowsSize()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.characters.MaxWidth = _powerAccent.GetDisplayMaxWidth();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-26 18:01:50 +02:00
|
|
|
|
protected override void OnClosed(EventArgs e)
|
|
|
|
|
|
{
|
2025-08-22 08:22:15 +02:00
|
|
|
|
_powerAccent.SaveUsageInfo();
|
2022-08-26 18:01:50 +02:00
|
|
|
|
_powerAccent.Dispose();
|
|
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|