Add ViewportBuilder::with_monitor for targeting specific monitors#8117
Open
Le-Syl21 wants to merge 1 commit into
Open
Add ViewportBuilder::with_monitor for targeting specific monitors#8117Le-Syl21 wants to merge 1 commit into
Le-Syl21 wants to merge 1 commit into
Conversation
ViewportBuilder::with_monitor(index) and ViewportCommand::SetMonitor(index) route through winit's Fullscreen::Borderless(Some(MonitorHandle)), which is the only portable way to target a specific output on Wayland and avoids the Mutter race where OuterPosition is dropped before the window is mapped. Cross-platform: Windows, macOS, Linux X11, Linux Wayland.
|
Preview is being built... Preview will be available at https://egui-pr-preview.github.io/pr/8117-viewport-target-monitor View snapshot changes at kitdiff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
ViewportBuilder::with_monitor(index)andViewportCommand::SetMonitor(index)for targeting a specific monitor at viewport creation or at runtime.This is useful whenever an app needs to open borderless fullscreen on a specific output — kiosks, pinball cabinets, digital signage, multi-monitor dashboards. It's also the only portable way to target a specific output under Wayland, since Wayland doesn't expose absolute window positions to clients;
with_positionis silently ignored there.Implementation
egui/src/viewport.rs: addsmonitor: Option<usize>toViewportBuilder,with_monitor(index)setter,ViewportCommand::SetMonitor(index)variant, and diff detection inpatch().egui-winit/src/lib.rs:create_window(after buildingWindowAttributesbut beforeevent_loop.create_window(...)): resolvesevent_loop.available_monitors().nth(index)and callswith_fullscreen(Some(Fullscreen::Borderless(Some(monitor.clone()))))on the attributes.process_viewport_command: handlesSetMonitor(idx)by resolving viawindow.available_monitors().nth(idx)+window.set_fullscreen(Some(Fullscreen::Borderless(Some(monitor)))).Usage
Why not just
with_position(monitor.position)?with_positionis effectively a no-op.OuterPositionis dropped if set before the window is mapped. Even with repeat-send loops, the window sometimes lands on the monitor the cursor is on rather than the requested one.Fullscreen::Borderless(Some(handle))is the OS-native API for borderless fullscreen on a specific screen.Using winit's
MonitorHandleexplicitly sidesteps all of these — same API path as when users press F11 in apps.Relationship to viewport rotation (PR #8113)
Completely orthogonal —
with_monitordoesn't depend on rotation and vice versa. They're submitted separately because they're independent features. In practice they combine well for cabinet/kiosk apps (rotate the root on a specific playfield output, non-rotated secondary viewports on other screens).Test plan
cargo check --workspaceclean on Linux (X11 + Wayland)OuterPosition.with_monitor(idx)places each viewport on the correct screen deterministically.with_monitorvs e.g.with_monitor_index) before final polish.🤖 Contributions from Claude Code