Skip to content

refactor(linux): Extract GTK3 display monitor backend in preparation for GTK4 - #195324

Draft
richyo-codes wants to merge 2 commits into
flutter:masterfrom
richyo-codes:pr/linux-gtk3-display-monitor
Draft

richyo-codes wants to merge 2 commits into
flutter:masterfrom
richyo-codes:pr/linux-gtk3-display-monitor

Conversation

@richyo-codes

Copy link
Copy Markdown
Contributor

Summary

Part of #194698, which tracks incremental refactors of the GTK3 Linux embedder to enable GTK4 support cleanly.

This PR focuses on display monitoring. It moves GTK3-specific monitor discovery, scale-factor lookup, and hotplug signal subscriptions behind a private backend, while keeping display ID management and engine notifications in the shared FlDisplayMonitor implementation.

This separation provides a clear integration point for a future GTK4 backend and helps keep toolkit-specific conditionals out of the shared display-management code. It is one independently reviewable piece of the preparatory work supporting #94804.

It also fixes duplicate signal subscriptions when fl_display_monitor_start() is called more than once. Each call still publishes the current display snapshot, while subsequent monitor additions and removals produce a single update.

Changes

  • Introduce a private FlDisplayMonitorBackend interface, with the GTK3 implementation in fl_display_monitor_gtk3.cc.
  • Move monitor enumeration, scale-factor lookup, and monitor-added / monitor-removed subscriptions into the backend.
  • Return owned snapshots containing referenced monitor objects, and disconnect signal handlers when the backend is freed.
  • Keep display ID assignment, display metadata construction, and engine notifications in FlDisplayMonitor.
  • Preserve existing logical dimensions, scale factors, refresh-rate conversion, and display ID behavior: surviving monitors retain their IDs, and removed monitors receive new IDs if added again.
  • Ensure repeated startup subscribes to monitor signals only once while continuing to refresh the display snapshot.

Testing

Extend the GTK mocks to support configurable monitor lists, geometry, scale factors, and refresh rates. Add seven regression tests covering:

  • Multiple monitors and the display metadata reported to the engine.
  • Monitor removal and readdition, including preservation of surviving display IDs.
  • Empty monitor lists and removal of the final monitor.
  • Stable display IDs when monitor enumeration order changes.
  • Repeated startup refreshing the snapshot without duplicating hotplug notifications.
  • Disconnection of both monitor signals on disposal.
  • Safe handling of monitor notifications after engine destruction.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Move GTK3 monitor enumeration and topology subscriptions behind a private backend while preserving display IDs, logical dimensions, and notification behavior.

Add coverage for monitor snapshots, removal and readdition, ordering, signal cleanup, and engine destruction. The seven display tests pass before and after the extraction.
Make the GTK3 monitor backend start only once while allowing repeated starts to refresh the display snapshot. Cover hotplug notification counts and signal cleanup after repeated starts.
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-linux Building on or for Linux specifically a: desktop Running on desktop team-linux Owned by the Linux platform team labels Oct 26, 2026
@richyo-codes richyo-codes changed the title [Linux] Extract GTK3 display monitor backend in preparation for GTK4 refactor(linux): Extract GTK3 display monitor backend in preparation for GTK4 Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop engine flutter/engine related. See also e: labels. platform-linux Building on or for Linux specifically team-linux Owned by the Linux platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant