Skip to content

Read and set a window's position and size - #38

Merged
O6lvl4 merged 1 commit into
mainfrom
window-position
Oct 1, 2026
Merged

O6lvl4 merged 1 commit into
mainfrom
window-position

Conversation

@O6lvl4

@O6lvl4 O6lvl4 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

For a program that reopens its windows where they were:

  • x() / y() give the top left of the current window's frame, in logical pixels from the top left of the main display.
  • set_position(x, y) moves the frame there, unless nothing of it would show on a display (a display that was unplugged since). On macOS the displays come from NSScreen.screens: winit's available_monitors() came back empty here, because CGGetActiveDisplayList failed. Elsewhere they come from winit.
  • set_size(w, h) sizes the drawable. On macOS the size changes at once with no Resized event, so the new size is recorded, the surface reconfigured, and resized() reports it.

Checked on macOS with two displays: a window moved to (120, 140) and sized to 500x260 reads back as 120,140 at 1000x520 physical. Moving it to (-99999, 140) leaves it in place. Moving it to (-100, -1000) puts it on the display above.

@O6lvl4
O6lvl4 merged commit c4782c3 into main Oct 1, 2026
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.

1 participant