Add input source control support to monitor settings

Introduced support for input source control across the app.

- Added `SupportsInputSource` and `EnableInputSource` properties to data models (`FeatureSupportResult`, `MonitorInfo`, etc.).
- Updated `MainViewModel` and `MonitorViewModel` to handle input source visibility (`ShowInputSource`) and initialization.
- Modified XAML bindings to reflect the new `ShowInputSource` property.
- Enhanced `PowerDisplayPage.xaml` with a checkbox for enabling/disabling input source control.
- Added localization for the input source control checkbox.
- Implemented signaling (`SignalSettingsUpdated`) to notify `PowerDisplay` of feature visibility changes.
- Improved logging to include input source feature status.
- Performed general code cleanup and added clarifying comments.

These changes ensure the input source control feature is configurable, persists user preferences, and integrates seamlessly with the existing application.
This commit is contained in:
Yu Leng
2025-11-28 00:05:48 +08:00
parent 12916deca0
commit 1f425f9540
9 changed files with 106 additions and 7 deletions

View File

@@ -248,6 +248,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// Preserve user settings from existing monitor
newMonitor.EnableContrast = existingMonitor.EnableContrast;
newMonitor.EnableVolume = existingMonitor.EnableVolume;
newMonitor.EnableInputSource = existingMonitor.EnableInputSource;
newMonitor.IsHidden = existingMonitor.IsHidden;
}
@@ -290,6 +291,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
monitor.SupportsContrast = result.SupportsContrast;
monitor.SupportsColorTemperature = result.SupportsColorTemperature;
monitor.SupportsVolume = result.SupportsVolume;
monitor.SupportsInputSource = result.SupportsInputSource;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA1816:Dispose methods should call SuppressFinalize", Justification = "Base class PageViewModelBase.Dispose() handles GC.SuppressFinalize")]
@@ -352,6 +354,36 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// Save settings when any monitor property changes
NotifySettingsChanged();
// For feature visibility properties, explicitly signal PowerDisplay to refresh
// This is needed because set_config() doesn't signal SettingsUpdatedEvent to avoid UI refresh issues
if (e.PropertyName == nameof(MonitorInfo.EnableContrast) ||
e.PropertyName == nameof(MonitorInfo.EnableVolume) ||
e.PropertyName == nameof(MonitorInfo.EnableInputSource) ||
e.PropertyName == nameof(MonitorInfo.IsHidden))
{
SignalSettingsUpdated();
}
}
/// <summary>
/// Signal PowerDisplay.exe that settings have been updated and need to be applied
/// </summary>
private void SignalSettingsUpdated()
{
try
{
using var eventHandle = new System.Threading.EventWaitHandle(
false,
System.Threading.EventResetMode.AutoReset,
Constants.SettingsUpdatedPowerDisplayEvent());
eventHandle.Set();
Logger.LogInfo("Signaled SettingsUpdatedPowerDisplayEvent for feature visibility change");
}
catch (Exception ex)
{
Logger.LogError($"Failed to signal SettingsUpdatedPowerDisplayEvent: {ex.Message}");
}
}
public void Launch()