mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +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;
|
||||
_keyboardListener.UpdateActivationKey((int)ActivationKey);
|
||||
|
||||
DoNotActivateOnGameMode = settings.Properties.DoNotActivateOnGameMode;
|
||||
_keyboardListener.UpdateDoNotActivateOnGameMode(DoNotActivateOnGameMode);
|
||||
|
||||
InputTime = settings.Properties.InputTime.Value;
|
||||
_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;
|
||||
|
||||
public Position Position
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <common/utils/string_utils.h>
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/excluded_apps.h>
|
||||
#include <common/utils/game_mode.h>
|
||||
|
||||
namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
{
|
||||
@@ -85,6 +86,11 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
m_settings.activationKey = static_cast<PowerAccentActivationKey>(activationKey);
|
||||
}
|
||||
|
||||
void KeyboardListener::UpdateDoNotActivateOnGameMode(bool doNotActivateOnGameMode)
|
||||
{
|
||||
m_settings.doNotActivateOnGameMode = doNotActivateOnGameMode;
|
||||
}
|
||||
|
||||
void KeyboardListener::UpdateInputTime(int32_t 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()
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
struct PowerAccentSettings
|
||||
{
|
||||
PowerAccentActivationKey activationKey{ PowerAccentActivationKey::Both };
|
||||
bool doNotActivateOnGameMode{ true };
|
||||
std::chrono::milliseconds inputTime{ 300 }; // Should match with UI.Library.PowerAccentSettings.DefaultInputTimeMs
|
||||
std::vector<std::wstring> excludedApps;
|
||||
};
|
||||
@@ -36,6 +37,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
void SetIsLanguageLetterDelegate(IsLanguageLetter IsLanguageLetterDelegate);
|
||||
|
||||
void UpdateActivationKey(int32_t activationKey);
|
||||
void UpdateDoNotActivateOnGameMode(bool doNotActivateOnGameMode);
|
||||
void UpdateInputTime(int32_t inputTime);
|
||||
void UpdateExcludedApps(std::wstring_view excludedApps);
|
||||
|
||||
@@ -44,6 +46,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
|
||||
private:
|
||||
bool OnKeyDown(KBDLLHOOKSTRUCT info) noexcept;
|
||||
bool OnKeyUp(KBDLLHOOKSTRUCT info) noexcept;
|
||||
bool IsSuppressedByGameMode();
|
||||
bool IsForegroundAppExcluded();
|
||||
|
||||
static inline KeyboardListener* s_instance;
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace PowerToys
|
||||
void SetNextCharEvent(event NextChar nextCharEvent);
|
||||
void SetIsLanguageLetterDelegate(IsLanguageLetter isLanguageLetterDelegate);
|
||||
void UpdateActivationKey(Int32 activationKey);
|
||||
void UpdateDoNotActivateOnGameMode(Boolean doNotActivateOnGameMode);
|
||||
void UpdateInputTime(Int32 inputTime);
|
||||
void UpdateExcludedApps(String excludedApps);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user