mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[QuickAccent]Add option to not activate when in game mode (#30983)
* [Quick Accent] Do not activate on game mode * Fix XAML styling * Fix idl syntax error * [Quick Accent] Fix game mode options not working
This commit is contained in:
@@ -56,6 +56,9 @@ public class SettingsService
|
|||||||
ActivationKey = settings.Properties.ActivationKey;
|
ActivationKey = settings.Properties.ActivationKey;
|
||||||
_keyboardListener.UpdateActivationKey((int)ActivationKey);
|
_keyboardListener.UpdateActivationKey((int)ActivationKey);
|
||||||
|
|
||||||
|
DoNotActivateOnGameMode = settings.Properties.DoNotActivateOnGameMode;
|
||||||
|
_keyboardListener.UpdateDoNotActivateOnGameMode(DoNotActivateOnGameMode);
|
||||||
|
|
||||||
InputTime = settings.Properties.InputTime.Value;
|
InputTime = settings.Properties.InputTime.Value;
|
||||||
_keyboardListener.UpdateInputTime(InputTime);
|
_keyboardListener.UpdateInputTime(InputTime);
|
||||||
|
|
||||||
@@ -123,6 +126,21 @@ public class SettingsService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _doNotActivateOnGameMode = true;
|
||||||
|
|
||||||
|
public bool DoNotActivateOnGameMode
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _doNotActivateOnGameMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_doNotActivateOnGameMode = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Position _position = Position.Top;
|
private Position _position = Position.Top;
|
||||||
|
|
||||||
public Position Position
|
public Position Position
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <common/utils/string_utils.h>
|
#include <common/utils/string_utils.h>
|
||||||
#include <common/utils/process_path.h>
|
#include <common/utils/process_path.h>
|
||||||
#include <common/utils/excluded_apps.h>
|
#include <common/utils/excluded_apps.h>
|
||||||
|
#include <common/utils/game_mode.h>
|
||||||
|
|
||||||
namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||||
{
|
{
|
||||||
@@ -85,6 +86,11 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
|||||||
m_settings.activationKey = static_cast<PowerAccentActivationKey>(activationKey);
|
m_settings.activationKey = static_cast<PowerAccentActivationKey>(activationKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeyboardListener::UpdateDoNotActivateOnGameMode(bool doNotActivateOnGameMode)
|
||||||
|
{
|
||||||
|
m_settings.doNotActivateOnGameMode = doNotActivateOnGameMode;
|
||||||
|
}
|
||||||
|
|
||||||
void KeyboardListener::UpdateInputTime(int32_t inputTime)
|
void KeyboardListener::UpdateInputTime(int32_t inputTime)
|
||||||
{
|
{
|
||||||
m_settings.inputTime = std::chrono::milliseconds(inputTime);
|
m_settings.inputTime = std::chrono::milliseconds(inputTime);
|
||||||
@@ -112,6 +118,11 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KeyboardListener::IsSuppressedByGameMode()
|
||||||
|
{
|
||||||
|
return m_settings.doNotActivateOnGameMode && detect_game_mode();
|
||||||
|
}
|
||||||
|
|
||||||
bool KeyboardListener::IsForegroundAppExcluded()
|
bool KeyboardListener::IsForegroundAppExcluded()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_mutex_excluded_apps);
|
std::lock_guard<std::mutex> lock(m_mutex_excluded_apps);
|
||||||
@@ -180,7 +191,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_toolbarVisible && letterPressed != LetterKey::None && triggerPressed && !IsForegroundAppExcluded())
|
if (!m_toolbarVisible && letterPressed != LetterKey::None && triggerPressed && !IsSuppressedByGameMode() && !IsForegroundAppExcluded())
|
||||||
{
|
{
|
||||||
Logger::debug(L"Show toolbar. Letter: {}, Trigger: {}", letterPressed, triggerPressed);
|
Logger::debug(L"Show toolbar. Letter: {}, Trigger: {}", letterPressed, triggerPressed);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
|||||||
struct PowerAccentSettings
|
struct PowerAccentSettings
|
||||||
{
|
{
|
||||||
PowerAccentActivationKey activationKey{ PowerAccentActivationKey::Both };
|
PowerAccentActivationKey activationKey{ PowerAccentActivationKey::Both };
|
||||||
|
bool doNotActivateOnGameMode{ true };
|
||||||
std::chrono::milliseconds inputTime{ 300 }; // Should match with UI.Library.PowerAccentSettings.DefaultInputTimeMs
|
std::chrono::milliseconds inputTime{ 300 }; // Should match with UI.Library.PowerAccentSettings.DefaultInputTimeMs
|
||||||
std::vector<std::wstring> excludedApps;
|
std::vector<std::wstring> excludedApps;
|
||||||
};
|
};
|
||||||
@@ -36,6 +37,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
|||||||
void SetIsLanguageLetterDelegate(IsLanguageLetter IsLanguageLetterDelegate);
|
void SetIsLanguageLetterDelegate(IsLanguageLetter IsLanguageLetterDelegate);
|
||||||
|
|
||||||
void UpdateActivationKey(int32_t activationKey);
|
void UpdateActivationKey(int32_t activationKey);
|
||||||
|
void UpdateDoNotActivateOnGameMode(bool doNotActivateOnGameMode);
|
||||||
void UpdateInputTime(int32_t inputTime);
|
void UpdateInputTime(int32_t inputTime);
|
||||||
void UpdateExcludedApps(std::wstring_view excludedApps);
|
void UpdateExcludedApps(std::wstring_view excludedApps);
|
||||||
|
|
||||||
@@ -44,6 +46,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
|||||||
private:
|
private:
|
||||||
bool OnKeyDown(KBDLLHOOKSTRUCT info) noexcept;
|
bool OnKeyDown(KBDLLHOOKSTRUCT info) noexcept;
|
||||||
bool OnKeyUp(KBDLLHOOKSTRUCT info) noexcept;
|
bool OnKeyUp(KBDLLHOOKSTRUCT info) noexcept;
|
||||||
|
bool IsSuppressedByGameMode();
|
||||||
bool IsForegroundAppExcluded();
|
bool IsForegroundAppExcluded();
|
||||||
|
|
||||||
static inline KeyboardListener* s_instance;
|
static inline KeyboardListener* s_instance;
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ namespace PowerToys
|
|||||||
void SetNextCharEvent(event NextChar nextCharEvent);
|
void SetNextCharEvent(event NextChar nextCharEvent);
|
||||||
void SetIsLanguageLetterDelegate(IsLanguageLetter isLanguageLetterDelegate);
|
void SetIsLanguageLetterDelegate(IsLanguageLetter isLanguageLetterDelegate);
|
||||||
void UpdateActivationKey(Int32 activationKey);
|
void UpdateActivationKey(Int32 activationKey);
|
||||||
|
void UpdateDoNotActivateOnGameMode(Boolean doNotActivateOnGameMode);
|
||||||
void UpdateInputTime(Int32 inputTime);
|
void UpdateInputTime(Int32 inputTime);
|
||||||
void UpdateExcludedApps(String excludedApps);
|
void UpdateExcludedApps(String excludedApps);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
[JsonPropertyName("activation_key")]
|
[JsonPropertyName("activation_key")]
|
||||||
public PowerAccentActivationKey ActivationKey { get; set; }
|
public PowerAccentActivationKey ActivationKey { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("do_not_activate_on_game_mode")]
|
||||||
|
public bool DoNotActivateOnGameMode { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("toolbar_position")]
|
[JsonPropertyName("toolbar_position")]
|
||||||
public StringProperty ToolbarPosition { get; set; }
|
public StringProperty ToolbarPosition { get; set; }
|
||||||
|
|
||||||
@@ -36,6 +39,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
public PowerAccentProperties()
|
public PowerAccentProperties()
|
||||||
{
|
{
|
||||||
ActivationKey = PowerAccentActivationKey.Both;
|
ActivationKey = PowerAccentActivationKey.Both;
|
||||||
|
DoNotActivateOnGameMode = true;
|
||||||
ToolbarPosition = "Top center";
|
ToolbarPosition = "Top center";
|
||||||
InputTime = new IntProperty(PowerAccentSettings.DefaultInputTimeMs);
|
InputTime = new IntProperty(PowerAccentSettings.DefaultInputTimeMs);
|
||||||
SelectedLang = "ALL";
|
SelectedLang = "ALL";
|
||||||
|
|||||||
@@ -31,13 +31,21 @@
|
|||||||
Severity="Informational" />
|
Severity="Informational" />
|
||||||
|
|
||||||
<controls:SettingsGroup x:Uid="QuickAccent_Activation_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
<controls:SettingsGroup x:Uid="QuickAccent_Activation_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
||||||
<tkcontrols:SettingsCard x:Uid="QuickAccent_Activation_Shortcut" HeaderIcon="{ui:FontIcon Glyph=}">
|
<tkcontrols:SettingsExpander
|
||||||
|
x:Uid="QuickAccent_Activation_Shortcut"
|
||||||
|
HeaderIcon="{ui:FontIcon Glyph=}"
|
||||||
|
IsExpanded="True">
|
||||||
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.ActivationKey, Mode=TwoWay}">
|
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.ActivationKey, Mode=TwoWay}">
|
||||||
<ComboBoxItem x:Uid="QuickAccent_Activation_Key_Arrows" />
|
<ComboBoxItem x:Uid="QuickAccent_Activation_Key_Arrows" />
|
||||||
<ComboBoxItem x:Uid="QuickAccent_Activation_Key_Space" />
|
<ComboBoxItem x:Uid="QuickAccent_Activation_Key_Space" />
|
||||||
<ComboBoxItem x:Uid="QuickAccent_Activation_Key_Either" />
|
<ComboBoxItem x:Uid="QuickAccent_Activation_Key_Either" />
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
</tkcontrols:SettingsCard>
|
<tkcontrols:SettingsExpander.Items>
|
||||||
|
<tkcontrols:SettingsCard ContentAlignment="Left">
|
||||||
|
<CheckBox x:Uid="QuickAccent_Prevent_Activation_On_Game_Mode" IsChecked="{x:Bind ViewModel.DoNotActivateOnGameMode, Mode=TwoWay}" />
|
||||||
|
</tkcontrols:SettingsCard>
|
||||||
|
</tkcontrols:SettingsExpander.Items>
|
||||||
|
</tkcontrols:SettingsExpander>
|
||||||
</controls:SettingsGroup>
|
</controls:SettingsGroup>
|
||||||
|
|
||||||
<controls:SettingsGroup x:Uid="QuickAccent_Language" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
<controls:SettingsGroup x:Uid="QuickAccent_Language" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
||||||
|
|||||||
@@ -4017,6 +4017,10 @@ Activate by holding the key for the character you want to add an accent to, then
|
|||||||
<data name="CmdNotFound_Arm64ArchBar.Title" xml:space="preserve">
|
<data name="CmdNotFound_Arm64ArchBar.Title" xml:space="preserve">
|
||||||
<value>Command Not Found is not supported on the ARM64 architecture currently. We are actively working on a solution.</value>
|
<value>Command Not Found is not supported on the ARM64 architecture currently. We are actively working on a solution.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="QuickAccent_Prevent_Activation_On_Game_Mode.Content" xml:space="preserve">
|
||||||
|
<value>Do not activate when Game Mode is on</value>
|
||||||
|
<comment>"Game mode" is the Windows feature to prevent notification when playing a game.</comment>
|
||||||
|
</data>
|
||||||
<data name="GeneralPage_ToggleSwitch_ShowNewUpdatesToast.Description" xml:space="preserve">
|
<data name="GeneralPage_ToggleSwitch_ShowNewUpdatesToast.Description" xml:space="preserve">
|
||||||
<value>Notifications in the settings and the tray flyout are always shown</value>
|
<value>Notifications in the settings and the tray flyout are always shown</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -165,6 +165,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DoNotActivateOnGameMode
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _powerAccentSettings.Properties.DoNotActivateOnGameMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _powerAccentSettings.Properties.DoNotActivateOnGameMode)
|
||||||
|
{
|
||||||
|
_powerAccentSettings.Properties.DoNotActivateOnGameMode = value;
|
||||||
|
OnPropertyChanged(nameof(DoNotActivateOnGameMode));
|
||||||
|
RaisePropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int _inputTimeMs = PowerAccentSettings.DefaultInputTimeMs;
|
private int _inputTimeMs = PowerAccentSettings.DefaultInputTimeMs;
|
||||||
|
|
||||||
public int InputTimeMs
|
public int InputTimeMs
|
||||||
|
|||||||
Reference in New Issue
Block a user