Skip to content

Conversation

GoldsteinE
Copy link
Contributor

Using physical window sizes leads to all kinds of fun stuff: winit always uses scale factor 1.0 on start to convert it back to logical pixels and uses these logical pixels to set min/max size for non-resizeable windows. You're supposed to adjust size after getting a scale change event if you're using physical sizes, but adjusting min/max sizes doesn't seem to work on sway, so the window is stuck with an incorrect size.

The scale factor we guessed might also be wrong even if there's only a single display since it doesn't take fractional scale into account.

TL;DR: winit actually wants logical sizes in these methods (since Wayland in general operates mostly on logical sizes) and converting them back and forth is lossy.

@GoldsteinE GoldsteinE force-pushed the window-logical-size branch from 24e322e to 52bc8a7 Compare May 30, 2025 09:34
@GoldsteinE GoldsteinE changed the title Draft: Use logical sizes when creating a window Use logical sizes when creating a window May 30, 2025
@GoldsteinE
Copy link
Contributor Author

Okay, I think this is ready. I wasn’t able to run all the tests locally (because some tests failed even on main branch for some reason), but it shouldn’t break anything.

@GoldsteinE GoldsteinE changed the title Use logical sizes when creating a window Fix incorrect window sizes for non-resizeable windows on Wayland May 30, 2025
@GoldsteinE GoldsteinE changed the title Fix incorrect window sizes for non-resizeable windows on Wayland Fix incorrect window sizes for non-resizable windows on Wayland May 30, 2025
@bircni
Copy link
Contributor

bircni commented May 30, 2025

Currently checking on my device....

@bircni
Copy link
Contributor

bircni commented May 30, 2025

all good here just some pixels in some images - i dont think thats because of you

));
}

#[expect(clippy::disallowed_types)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd like to see also a reason here this would be cool

Suggested change
#[expect(clippy::disallowed_types)]
#[expect(clippy::disallowed_types, reason = "aaaa")]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added lint reasons to all the expects.

window_attributes = window_attributes.with_max_inner_size(PhysicalSize::new(
pixels_per_point * size.x,
pixels_per_point * size.y,
window_attributes = window_attributes.with_max_inner_size(dpi::LogicalSize::new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a direct import would be better i think as we imported all the other dpi:: also

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I didn't do a direct import is to avoid allowing the lint there too. I can do it though if you prefer it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okay :-)
maybe we should then think about removing the lint or that disallowed type?
but @emilk should decide

@GoldsteinE
Copy link
Contributor Author

@bircni Hi! Could you please direct me to my next steps here? This is my first time contributing to egui and I’m a bit confused.

I’m happy to add lint reasons and do a direct import if you prefer it, but I’m not sure if this PR is waiting on me doing that or on emilk making a decision about this lint in general.

Thanks for review either way

@bircni
Copy link
Contributor

bircni commented Jun 12, 2025

@GoldsteinE we are still waiting on comments from @emilk - but adding a reason would always be great!

If emilk decides to reallow the types we can do that afterwards :-)

Using physical window sizes leads to all kinds of fun stuff:
winit always uses scale factor 1.0 on start to convert it back
to logical pixels and uses these logical pixels to set min/max size
for non-resizeable windows. You're supposed to adjust size after
getting a scale change event if you're using physical sizes,
but adjusting min/max sizes doesn't seem to work on sway, so the
window is stuck with an incorrect size.

The scale factor we guessed might also be wrong even if there's only a
single display since it doesn't take fractional scale into account.

TL;DR: winit actually wants logical sizes in these methods
(since Wayland in general operates mostly on logical sizes)
and converting them back and forth is lossy.
@GoldsteinE GoldsteinE force-pushed the window-logical-size branch from 52bc8a7 to 3ddf288 Compare June 12, 2025 21:12
@GoldsteinE
Copy link
Contributor Author

Sure, I’ve done that.

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code makes sense to me - I'll give it a test on my Mac in a minute

@emilk emilk added bug Something is broken eframe Relates to epi and eframe egui-winit porblems related to winit labels Jun 24, 2025
@emilk
Copy link
Owner

emilk commented Jun 24, 2025

This works beautifully on my mac ❤️

Copy link

Preview available at https://egui-pr-preview.github.io/pr/7103-window-logical-size
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

));
}

#[expect(clippy::disallowed_types, reason = "zoom factor is manually accounted for")]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@emilk
Copy link
Owner

emilk commented Jun 24, 2025

Thanks for fixing this!

@emilk emilk merged commit 853feea into emilk:main Jun 24, 2025
26 checks passed
@GoldsteinE
Copy link
Contributor Author

Thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is broken eframe Relates to epi and eframe egui-winit porblems related to winit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-resizable window jumps to incorrect size on trying to resize

3 participants