Refactor DisplayManager to use generic event system while maintaining backward compatibility #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR refactors the DisplayManager's custom event listener system to use the existing generic event handling system (
Event
,EventDispatcher
,TypedEvent
) while maintaining 100% backward compatibility with existing code.Problem
The DisplayManager was using its own custom listener pattern with
DisplayListener
interface and direct listener management, which was inconsistent with the library's generic event system. This created:Solution
Core Changes
New Event Types:
DisplayAddedEvent
- Fired when a display is connectedDisplayRemovedEvent
- Fired when a display is disconnectedBoth extend
TypedEvent<T>
and provide access to theDisplay
object viaGetDisplay()
.Enhanced DisplayManager API:
Dual Event Dispatch:
The refactored system dispatches events to both the new EventDispatcher and legacy listeners simultaneously:
Platform Integration
Updated macOS implementation (
display_manager_macos.mm
) to use the new event dispatch methods:Backward Compatibility
All existing APIs remain functional:
DisplayListener
interface unchangedDisplayEventHandler
callback functionality preservedAddListener()
/RemoveListener()
methods still workBenefits
Usage Examples
New Event API (Recommended):
Legacy API (Still Supported):
Testing
Files Changed
src/display_manager.h
- Added event types and EventDispatcher integrationsrc/display_manager.cpp
- Implemented dual event dispatch systemsrc/platform/macos/display_manager_macos.mm
- Updated to use new event methodsdocs/DISPLAY_EVENT_USAGE.md
- Comprehensive usage documentation and migration guideThis refactoring modernizes the DisplayManager event handling while ensuring zero disruption to existing codebases, providing a smooth migration path to the more powerful generic event system.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.