Commit Graph

22 Commits

Author SHA1 Message Date
Yu Leng
ae9dd9970c Add EnableRotation to SignalSettingsUpdated trigger list
The `EnableRotation` property was added to the list of feature
visibility properties that trigger the `SignalSettingsUpdated()`
method when their values change. This ensures that the `PowerDisplay`
UI refreshes appropriately when the `EnableRotation` property is
updated. The change aligns with the existing behavior for other
properties like `EnableContrast`, `EnableVolume`, `EnableInputSource`,
and `IsHidden`. This update addresses the lack of UI refresh for
`EnableRotation` due to `set_config()` not signaling the
`SettingsUpdatedEvent`.
2025-11-28 16:17:39 +08:00
Yu Leng
1f425f9540 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.
2025-11-28 00:05:48 +08:00
Yu Leng
7c69874689 Add system tray icon support for PowerDisplay
Introduced a `TrayIconService` to manage the system tray icon, enabling quick access to settings and exit options. Added a new `ShowSystemTrayIcon` setting to control tray icon visibility, with UI integration in the settings page.

Implemented `SettingsDeepLink` to open PowerDisplay settings directly in the PowerToys Settings UI. Updated `App.xaml.cs` to integrate tray icon lifecycle management and refresh behavior.

Replaced `ManagedCsWin32` with `CsWin32` for Windows API interop. Added localized strings for tray menu options and updated default settings to enable the tray icon by default. Improved resilience by handling `WM_TASKBAR_RESTART` for tray icon recreation.
2025-11-27 20:57:54 +08:00
Yu Leng
3598c2c126 Refactor and enhance monitor matching logic
- Renamed project entries in `PowerToys.sln` for consistency.
- Added new projects: "runner," "NewShellExtensionContextMenu," and "BgcodePreviewHandlerCpp."
- Introduced `MonitorMatchingHelper` to centralize monitor identification logic.
- Added unit tests for `MonitorMatchingHelper` to validate parsing and matching.
- Updated `MonitorInfo` with `MonitorNumber`, `TotalMonitorCount`, and `DisplayName` for dynamic formatting.
- Enhanced WMI monitor matching with pre-fetched display devices.
- Updated UI components to use dynamic `DisplayName` for monitors.
- Added `PowerDisplay.Lib.UnitTests` project for testing.
- Improved serialization, logging, and null handling in `PowerDisplayViewModel`.
- Removed redundant parsing logic from `MonitorDiscoveryHelper`.
2025-11-26 19:08:01 +08:00
Yu Leng
f5a2235f53 Improve logging, synchronization, and process handling
Enhanced logging for event handling, settings updates, and process management to improve traceability and debugging.

- Added detailed logging and exception handling in `NativeEventWaiter.cs` for event listener setup and execution.
- Updated `MainViewModel.Settings.cs` to synchronize monitor settings and save changes after applying color temperature.
- Improved process management in `dllmain.cpp` to ensure `PowerDisplay` is running before signaling events, with added race condition prevention.
- Removed redundant settings update signaling in `dllmain.cpp` to avoid excessive UI refreshes and dropdown closures.
- Enhanced monitor synchronization in `PowerDisplayViewModel.cs` to handle pending operations and prevent stale data overwrites.
- General improvements in error handling and logging across all changes.
2025-11-25 16:45:06 +08:00
Yu Leng
471cad659f Refactor and optimize profile and monitor handling
Refactored profile name generation by centralizing logic in `ProfileHelper` with overloads for flexibility. Simplified folder creation logic in `PathConstants` using a reusable helper method.

Improved profile loading and saving in `ProfileService` with internal helper methods for better error handling and reduced duplication. Optimized monitor key generation and lookup with concise expressions and dictionary-based retrieval for O(1) performance.

Introduced caching for color presets in `MonitorInfo` to avoid redundant computations and added a helper for range validation in `MainViewModel.Settings`. Centralized percentage formatting and property change handling to reduce duplication.

Removed redundant methods in `PowerDisplayViewModel` and streamlined event unsubscription in `MainWindow`. Enhanced logging, readability, and maintainability across the codebase.
2025-11-24 23:36:25 +08:00
Yu Leng
15746e8f45 Refactor and enhance monitor management system
Refactored namespaces to improve modularity, including moving `PowerDisplay.Native` to `PowerDisplay.Common.Drivers`. Introduced the `IMonitorData` interface for better abstraction of monitor hardware data. Replaced `ColorTemperature` with `ColorTemperatureVcp` for precise VCP-based color temperature control, adding utilities for Kelvin conversion.

Enhanced monitor state management with a new `MonitorStateFile` for JSON persistence and updated `MonitorStateManager` for debounced saves. Added `MonitorMatchingHelper` for consistent monitor identification and `ProfileHelper` for profile management operations.

Refactored P/Invoke declarations into helper classes, updated UI bindings for `ColorTemperatureVcp`, and improved logging for better runtime visibility. Removed redundant code, added new utility classes (`MonitorValueConverter`, `MonitorMatchingHelper`), and ensured backward compatibility.

These changes improve code organization, maintainability, and extensibility while aligning with hardware-level control standards.
2025-11-24 21:58:34 +08:00
Yu Leng
580651b47a Refactor PowerDisplay module and add shared library
Introduced `PowerDisplay.Lib` to centralize shared logic and models, improving modularity and reusability. Refactored namespaces, moving classes to `PowerDisplay.Common`. Added utilities like `ColorTemperatureHelper` and `MonitorFeatureHelper` for consistent logic.

Replaced `ProfileManager` with `ProfileService` for centralized profile management. Enhanced event handling, monitor state management, and settings synchronization. Improved color temperature handling and feature detection.

Removed redundant code and converters. Updated `Settings.UI.Library` and XAML bindings to use shared models. Enhanced logging, serialization, and disposal logic. Updated project files and added documentation for better maintainability.
2025-11-24 18:08:11 +08:00
Yu Leng
b381472bf7 Refactor LightSwitch and PowerDisplay integration
Simplify theme change notification logic in `LightSwitchService.cpp` by consolidating redundant checks and improving error handling. Remove the `applyMonitorSettings` setting and associated logic from `LightSwitchSettings`.

Introduce `PowerDisplayProfilesHelper` to centralize profile management, ensuring thread safety and simplifying file operations. Update UI in `LightSwitchPage.xaml` to replace `ApplyMonitorSettings` with separate dark and light mode profile settings, adding navigation to PowerDisplay settings.

Enhance `LightSwitchViewModel` with nullable annotations, new profile selection properties, and improved property synchronization. Refactor `PowerDisplayViewModel` to use `PowerDisplayProfilesHelper` for profile management.

Update localization strings for new UI elements. Perform general code cleanup, including null safety annotations, improved logging, and removal of legacy code.
2025-11-21 15:36:56 +08:00
Yu Leng
d64bb78727 Refactor PowerDisplay profile management
Simplified profile management by removing the concept of "Custom profiles" and "current profile" tracking. Profiles are now treated as templates for quick application of monitor settings, rather than persistent states.

Key changes include:
- Replaced `ObservableCollection<string>` with `ObservableCollection<PowerDisplayProfile>` to manage profile objects directly.
- Removed redundant properties and methods related to "selected" and "current" profiles.
- Refactored methods for creating, updating, and deleting profiles to operate on `PowerDisplayProfile` objects.
- Updated `PowerDisplayViewModel` and `ProfileManager` to streamline profile loading, saving, and application logic.
- Updated the UI to replace the profile dropdown with buttons for quick application, along with context menu options for managing profiles.
- Improved logging and error handling for profile operations.
- Updated resource strings and removed references to "Custom profiles" and "current profile."

These changes simplify the codebase, improve maintainability, and align the application with the new design philosophy of treating profiles as templates.
2025-11-20 04:40:36 +08:00
Yu Leng
b8abff02ac Add profile management system to PowerDisplay
Introduced a comprehensive profile management system for PowerDisplay, enabling users to create, edit, delete, and apply predefined monitor settings. Key changes include:

- Added `ProfileManager` for handling profile storage and retrieval.
- Introduced `PowerDisplayProfile`, `PowerDisplayProfiles`, and related data models for profile representation.
- Enhanced `MainViewModel` and `MonitorViewModel` to support profile application and parameter change detection.
- Created `ProfileEditorDialog` for editing and creating profiles via the UI.
- Updated `PowerDisplayViewModel` to manage profiles, including commands for adding, deleting, renaming, and saving profiles.
- Added new events (`ApplyProfileEvent`) and constants for profile application.
- Updated `PowerDisplayPage` UI to include a "Profiles" section for managing profiles.
- Added serialization support for profile-related classes.
- Updated `dllmain.cpp` and `App.xaml.cs` to handle profile-related events.

These changes improve user experience by allowing quick switching between tailored monitor configurations.
2025-11-19 17:18:01 +08:00
Yu Leng
fc54172e13 Refactor color temperature operation handling
Introduced `ColorTemperatureOperation` class to manage pending color temperature changes. Updated `MainViewModel` to process operations for specific monitors, improving efficiency and separation of concerns.

Added `PendingColorTemperatureOperation` property to `PowerDisplayProperties` for tracking operations. Enhanced IPC messaging with `MonitorId` and `ColorTemperature` in `PowerDisplayActionMessage`.

Refactored `PowerDisplayViewModel` and `PowerDisplayPage` to directly apply color temperature to specified monitors. Improved logging for better traceability.
2025-11-19 16:16:04 +08:00
Yu Leng
a48e999963 Improve error handling, debouncing, and code cleanup
Enhanced exception handling in RelayCommand to improve robustness.
Standardized slider debounce delays using a new constant
`SliderDebounceDelayMs`. Improved resource management in
SimpleDebouncer with proper disposal of CancellationTokenSource
and added support for synchronous actions. Refactored event
handling in App.xaml.cs for clarity and consistency. Removed
redundant logging in MonitorStateManager and MainViewModel to
reduce verbosity. Updated namespaces and dependencies for better
organization. General code cleanup to improve readability and
maintainability.
2025-11-19 15:26:35 +08:00
Yu Leng
ad83b5e67f Improve performance, thread safety, and resource handling
Enhanced monitor initialization with parallelism in `MonitorManager.cs` for better performance. Added cancellation support to `NativeEventWaiter.cs` with `CancellationToken` and timeout handling. Introduced thread safety in `PhysicalMonitorHandleManager.cs` using locks to prevent race conditions.

Updated `PowerDisplayViewModel.cs` to include proper resource cleanup with `CancellationTokenSource` and improved memory management. Added necessary namespaces for threading and asynchronous operations. General code improvements for readability, maintainability, and reliability.
2025-11-19 15:08:00 +08:00
Yu Leng
f10c9f49e9 Add color temperature support to PowerDisplay
Enhanced PowerDisplay with support for applying color temperature settings.

- Added `APPLY_COLOR_TEMPERATURE_POWER_DISPLAY_EVENT` and event handling logic.
- Introduced `ApplyColorTemperatureFromSettings` in `MainViewModel` for explicit hardware updates.
- Refactored `MonitorInfo` to dynamically compute and cache color temperature presets.
- Updated `ReloadMonitorsFromSettings` to preserve object references and improve UI responsiveness.
- Simplified UI bindings and removed redundant properties like `MonitorType`.
- Improved event handling in `dllmain.cpp` for the new color temperature action.
- Enhanced logging for better debugging and traceability.
- Updated JSON serialization context to include new types for color temperature.
- Removed unused code and improved documentation for maintainability.
2025-11-18 20:03:36 +08:00
Yu Leng
55cd6c95b8 Fix settings issue 2025-11-17 18:21:46 +08:00
Yu Leng
15e6a762d3 fix settings ui issue 2025-11-17 16:13:52 +08:00
Yu Leng
f05740b0cb Fix color temperature doesn't work issue 2025-11-17 15:39:36 +08:00
Yu Leng
94bc13e703 Refactor PowerDisplay for dynamic monitor capabilities
Removed reliance on static `MonitorType` enumeration, replacing it with dynamic `CommunicationMethod` for better flexibility. Updated `IMonitorController` and `MonitorManager` to dynamically determine monitor control capabilities.

Refactored `Monitor` model to streamline properties and improve color temperature handling. Enhanced `MonitorViewModel` with unified methods for brightness, contrast, volume, and color temperature updates, improving UI responsiveness and hardware synchronization.

Improved settings handling by adding support for hidden monitors, preserving user preferences, and separating UI configuration from hardware parameter updates. Updated the PowerDisplay Settings UI with warnings, confirmation dialogs, and better VCP capabilities formatting.

Removed legacy IPC code in favor of event-driven settings updates. Conducted general code cleanup, improving logging, error handling, and documentation for maintainability.
2025-11-14 16:45:22 +08:00
Yu Leng
e645a19629 Refactor color temperature handling to use VCP presets
Transitioned color temperature handling from Kelvin-based values to VCP code `0x14` (Select Color Preset). Removed legacy Kelvin-to-VCP conversion logic and deprecated unused VCP codes. Updated `Monitor` and `MonitorViewModel` to reflect this change, making `ColorTemperature` read-only in the flyout UI and configurable via the Settings UI.

Enhanced monitor capabilities detection by relying on reported VCP codes instead of trial-and-error probing. Introduced `CapabilitiesStatus` to indicate feature availability and dynamically populated color temperature presets from VCP code `0x14`.

Streamlined the UI by replacing the color temperature slider with a ComboBox in the Settings UI. Added tooltips, warnings for unavailable capabilities, and improved logging for brightness and color temperature operations.

Removed obsolete code, simplified feature detection logic, and improved code documentation. Fixed issues with unsupported VCP values and ensured consistent ordering of color presets.
2025-11-14 13:17:55 +08:00
Yu Leng
5d63ca7a9c Refactor IPC and enhance PowerDisplay functionality
Refactored IPC communication by introducing a `NamedPipeProcessor` utility for unidirectional named pipe handling, replacing the old bidirectional implementation. Simplified application lifecycle management by removing mutex usage and relying on `AppInstance` for single-instance enforcement.

Replaced IPC-based monitor updates with file-based updates, saving monitor data to `settings.json` for the Settings UI. Added an `ActivationShortcut` property to PowerDisplay settings and updated the settings page UI to support shortcut configuration.

Simplified named pipe creation in `PowerDisplayProcessManager` by removing bidirectional pipe logic and focusing on unidirectional communication. Improved `MainWindow` initialization with an `EnsureInitializedAsync` method.

Updated localization resources and integrated PowerDisplay into the launcher menu. Removed redundant code, improved logging, and streamlined resource cleanup for better maintainability.
2025-11-12 16:36:43 +08:00
Yu Leng
e2774eff2d Introduce PowerDisplay 2025-10-20 16:22:47 +08:00