Add new EditorHandle::default_scale function #18
Conversation
- forward `os_screen_scale` as `default_scale` in EditorHandle - comment why `os_scale` on Windows and Linux is 1.0 and why `default_scale` on macOS is 1.0
|
I like this idea in principle but there are a couple of problems:
I have some more specific comments as well but I wanted to resolve these issues first. Also note that there will be some conflicts with the mouse event pre-scaling code as well. |
There is no scaling applied on the OS window level on Windows and Linux:
It's confusing, yes, but it's two different values for different purposes - so it also should be two different functions. But yes, this whole topic is confusing, especially because it works different on macOS, but that's ugly either way. My old approach to apply the OS scaling on all platforms caused confusion on other sides. But you do have a better overview here, so there indeed might be a better approach to deal with the platform differences here. |
Ah yeah scratch that, looks like drag and drop coordinates are already broken at the head of main, will have to fix that separately |
|
Exactly. #17 was my attempt to fix that, but now is obsolete. Still think os_scale (usage) should be removed on Windows and Linux because it's always 1.0 by design now. |
|
Figured out that an earlier change where |
|
I'm confused now. Why is there a OS scale on Windows now? Drag and drop worked just fine here, after applying the slint canvas scaling. Which was expected and exactly what my fix was about. In DPI aware apps on Windows, all positions, sizes, mouse positions, and drag & drop coordinates are pixels. There's no need to apply Windows' DPI scaling. The scaling that gets applied by the host is applied as slint canvas scaling. So it should also be applied on the slint level IMHO. Where it gets extra confusing on Windows is when an app is marked as DPI unaware. The all those positions and sizes will get magically upscaled by Windows. But this is consistent too, as the host would then also apply no extra scaling. There still is no need to apply some DPI scaling then. Anyway. Let me know if you are interested in the default scale thing, then I'll create a new patch. As mentioned before I also have no problem keeping this in my fork. |
|
If it helps, I'm confused too. I'm aware of how it should work but ScreenToClient was returning incorrect coordinates before the change and the change grew bigger as the window was moved away from the top left window, indicating that it's an issue with the screen coordinates being incorrectly scaled. Since Slint doesn't officially support drag & drop yet, I'm also sending a mouse move event whenever there's a drag move event. If you try before and after the change on Windows and make an element follow the mouse cursor in Slint, you can see before the manual DPI scaling there was a difference between regular mouse events and drag events. Anyway I've now implemented the default scale thing, although I made it a global function called |
Maybe that happens on multi monitor setups with different scalings only? I can't replicate that here on single monitor setups with whatever scaling.
Thanks! This should be 1.0 on macOS. Adding a impl EditorHandle {
pub fn default_scale() -> f64 {
// On macOS the system's window backend scaling gets automatically applied.
#[cfg(target_os="macos")]
{
1.0
}
// On Windows and Linux the window backends do not use the system's DPI settings, but rely on the host to provide scaling values. Use the default screens scaling by default.
#[cfg(any(target_os="windows", target_os="linux"))]
{
screen_scale()
}
}
}I promise I won't nag you about scaling anytime soon :) Works great now. |
I have just one monitor, no idea what's going wrong. Anyway I added |
Follow up of #10.
This adds:
Window::os_screen_scale()to query the main screen's default scaling, using the backing factor on macOS, LOGPIXELSX info on Windows, and screen height_in_pixels/millimeters ratio on Linux.EditorHandle::default_scale(), which plugin editors can use to initialize default canvas scaling.So, this only provides a default value for editor scalings. Hosts will override this in most cases.
But when hosts don't set scaling, this sets a somewhat sensible default. And when hosts do set a scaling, this avoids that the plugin window gets resized and rebuilt in case the host's scaling matches the default screen's scaling - which is very likely.
I've also added a few more comments for the Windows platform info, trying to make clear why no DPI scaling is used there.
We already discussed this topic. Totally fine with me in case you don't want such a default scaling and rely on scaling info from hosts only. I'll keep that in my fork then. But I think it doesn't hurt, but just helps in edge cases.