Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 27, 2025

This PR implements a comprehensive WindowListener API for the WindowManager class, enabling applications to listen for various window lifecycle events. The implementation follows the existing event dispatcher pattern used throughout the library and provides full functionality on macOS with stub implementations for Windows and Linux platforms.

New Features

Window Event Types

The implementation introduces 9 new event types covering the complete window lifecycle:

  • WindowCreatedEvent - Fired when a new window is created
  • WindowClosedEvent - Fired when a window is closed/destroyed
  • WindowFocusedEvent - Fired when a window gains focus
  • WindowBlurredEvent - Fired when a window loses focus
  • WindowMinimizedEvent - Fired when a window is minimized
  • WindowMaximizedEvent - Fired when a window is maximized
  • WindowRestoredEvent - Fired when a window is restored from minimized/maximized state
  • WindowMovedEvent - Fired when a window is moved (includes new position data)
  • WindowResizedEvent - Fired when a window is resized (includes new size data)

WindowManager API Extensions

The WindowManager class now includes event dispatcher capabilities:

WindowManager window_manager;

// Add callback-based listeners (recommended approach)
auto listener_id = window_manager.AddListener<WindowCreatedEvent>(
    [](const WindowCreatedEvent& event) {
        std::cout << "Window created: " << event.GetWindowId() << std::endl;
    }
);

// Add object-based listeners  
auto focus_id = window_manager.AddListener<WindowFocusedEvent>(&my_listener);

// Remove listeners
window_manager.RemoveListener(listener_id);

// Access underlying event dispatcher for advanced usage
EventDispatcher& dispatcher = window_manager.GetEventDispatcher();

Platform Implementation

macOS (Complete Implementation)

The macOS implementation uses NSNotificationCenter to monitor NSWindow events:

  • Sets up observers for all relevant NSWindow notifications (focus, minimize, resize, move, close)
  • Uses a dedicated WindowManagerImpl class with proper Objective-C delegate to handle platform-specific details
  • Ensures proper memory management and cleanup of notification observers
  • Dispatches events synchronously for immediate notification of window state changes

Windows & Linux (Stub Implementation)

Provides stub implementations that maintain API compatibility while allowing for future platform-specific development. The stub implementations include:

  • Complete WindowManagerImpl structure ready for implementation
  • Proper event dispatcher integration
  • All required WindowManager methods (Create, Destroy, etc.)

Implementation Details

The implementation carefully follows existing library patterns:

  1. Consistent with DisplayManager: Uses the same event dispatcher pattern as the existing DisplayManager class
  2. Thread-safe: Leverages the existing thread-safe EventDispatcher infrastructure
  3. Type-safe: Uses strongly-typed events with compile-time type checking
  4. Memory-safe: Proper RAII patterns and automatic cleanup of platform resources

Missing Destroy Method

As part of this implementation, the missing Destroy method was added to all platform implementations of WindowManager, providing complete API coverage.

Documentation & Examples

  • Complete API documentation in docs/WindowListener.md
  • Working test example in examples/window_listener_test/ demonstrating both callback and object-based listeners
  • Integration with existing CMake build system

This implementation provides a solid foundation for window event handling across platforms while maintaining the library's existing architectural patterns and coding standards.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits August 27, 2025 12:46
Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [macOS] Implement WindowListener on WindowManager class [macOS] Implement WindowListener on WindowManager class Aug 27, 2025
@Copilot Copilot AI requested a review from lijy91 August 27, 2025 12:53
Copilot finished work on behalf of lijy91 August 27, 2025 12:53
@lijy91 lijy91 marked this pull request as ready for review August 27, 2025 13:18
@lijy91 lijy91 merged commit 70e4187 into main Aug 27, 2025
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants