Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wayland + GNOME: WindowConfig::size() sets size incorrectly #265

Open
190n opened this issue May 4, 2023 · 12 comments
Open

Wayland + GNOME: WindowConfig::size() sets size incorrectly #265

190n opened this issue May 4, 2023 · 12 comments
Labels
blocked This feature cannot be done yet bug Something isn't working stale Abandoned issue by inactivity

Comments

@190n
Copy link

190n commented May 4, 2023

With the following app:

use notan::{draw::*, prelude::*};

#[notan_main]
fn main() -> Result<(), String> {
	notan::init()
		.add_config(DrawConfig)
		.add_config(notan::app::WindowConfig::new().size(400, 400))
		.draw(draw)
		.build()
}

fn draw(app: &mut App, gfx: &mut Graphics) {
	println!("{} x {}", gfx.size().0, gfx.size().1);
	let mut draw = gfx.create_draw();
	draw.clear(Color::BLACK);
	draw.rect((0.0, 0.0), (400.0, 400.0));
	gfx.render(&draw);
}

I get the following result showing the window is larger than 400x400. In the console it prints 420 x 455. Trying other resolutions, it seems like the width is always increased by 20 and the height by 55.

I'm using Arch Linux with GNOME on Wayland, and 125% display scaling.

image

It works properly if I use app.window().set_size(400, 400).

I'm not sure if this is related to #219 so I opened a separate issue.

@Nazariglez Nazariglez changed the title WindowConfig::size() sets size incorrectly Wayland + GNMOE: WindowConfig::size() sets size incorrectly May 5, 2023
@Nazariglez Nazariglez added bug Something isn't working help wanted Extra attention is needed labels May 5, 2023
@Nazariglez
Copy link
Owner

Hey! Unfortunately I don't have access to wayland, and this seems not be an issue using Xorg. My guess is that something can be wrong with winit and wayland. Both ways to set the size use the same way to do it, the difference is that WindowConfig is doing it before the creation of the window and set_size is doing it after. Can you share what graphics card are you using? just to know if it's nvidia. And what screen dpi?

Let's see if we figure it a solution. Meanwhile I am marking this as need help for now to see if somebody with wayland can help us.

@Nazariglez Nazariglez changed the title Wayland + GNMOE: WindowConfig::size() sets size incorrectly Wayland + GNOME: WindowConfig::size() sets size incorrectly May 5, 2023
@Nazariglez
Copy link
Owner

I am thinking another thing, can you set .resizable(true) on WindowConfig and see after you resize the window manually the surface get right the size?

@Nazariglez
Copy link
Owner

Can you try with this branch? https://github.com/Nazariglez/notan/tree/log/size and paste here all the logs? Thanks

@190n
Copy link
Author

190n commented May 6, 2023

Thank you for the quick replies!

  1. I'm using Intel Alder Lake integrated graphics (i5-1240P). Linux 6.2.12, mesa 23.0.3-1. Screen scaling is 125%, but GNOME is weird about that so I think it actually reports 200% scale and the wrong screen resolution to applications and then scales them down to look right. I also tried changing the scale factor to 100%, and all symptoms are the same.

  2. With .resizeable(true), the initial size is 420x420 instead of 420x455. gfx.size() does seem to accurately report the size -- when I shrink the window until it prints 400x400 in the terminal, the white rectangle covers the whole area.

  3. Here's the output from the version including resizeable:

    1: config: WindowConfig { title: "Notan App", width: 400, height: 400, fullscreen: false, min_size: None, max_size: None, maximized: false, resizable: true, vsync: false, multisampling: 0, high_dpi: false, lazy_loop: false, transparent: false, always_on_top: false, decorations: true, visible: true, mouse_passthrough: false, canvas_id: "notan_canvas", window_icon_path: None, window_icon_data: None, taskbar_icon_path: None, taskbar_icon_data: None }
    2023-05-06 00:21:37 [crossfont::ft] DEBUG: Loaded Face Face { ft_face: Font Face: Regular, load_flags: TARGET_LIGHT, render_mode: "Lcd", lcd_filter: 1 }
    2: backend::size: (400, 400)
    2023-05-06 00:21:37 [notan_glow] INFO: Using opengl graphics api
    3: app::size: (400, 400)
    4: graphics::size: (400, 400) - graphics::dpi: 1.0
    5: app::size: (400, 400) - graphics::size: (400, 400) - graphics::dpi: 1.0
    420 x 420
    420 x 420
    420 x 420
    

    At this point my code starts printing 420x420 a lot. Here is the output from the non-resizeable version:

    1: config: WindowConfig { title: "Notan App", width: 400, height: 400, fullscreen: false, min_size: None, max_size: None, maximized: false, resizable: false, vsync: false, multisampling: 0, high_dpi: false, lazy_loop: false, transparent: false, always_on_top: false, decorations: true, visible: true, mouse_passthrough: false, canvas_id: "notan_canvas", window_icon_path: None, window_icon_data: None, taskbar_icon_path: None, taskbar_icon_data: None }
    2023-05-06 00:22:32 [crossfont::ft] DEBUG: Loaded Face Face { ft_face: Font Face: Regular, load_flags: TARGET_LIGHT, render_mode: "Lcd", lcd_filter: 1 }
    2: backend::size: (400, 400)
    2023-05-06 00:22:32 [notan_glow] INFO: Using opengl graphics api
    3: app::size: (400, 400)
    4: graphics::size: (400, 400) - graphics::dpi: 1.0
    5: app::size: (400, 400) - graphics::size: (400, 400) - graphics::dpi: 1.0
    420 x 455
    420 x 455
    420 x 455
    

@Nazariglez
Copy link
Owner

I added some more logs to the branch, it's weird that at first everything is set right and then the draw method fails to get right the size. Can you test it again please? You can use cargo run --example window_open. I put your code there with an app.exit() on the end of the draw method.

@190n
Copy link
Author

190n commented May 7, 2023

Here's the output from that example. The size appears to actually be correct at first:

1: config: WindowConfig { title: "Notan App", width: 400, height: 400, fullscreen: false, min_size: None, max_size: None, maximized: false, resizable: false, vsync: false, multisampling: 0, high_dpi: false, lazy_loop: false, transparent: false, always_on_top: false, decorations: true, visible: true, mouse_passthrough: false, canvas_id: "notan_canvas", window_icon_path: None, window_icon_data: None, taskbar_icon_path: None, taskbar_icon_data: None }
2023-05-07 19:02:56 [crossfont::ft] DEBUG: Loaded Face Face { ft_face: Font Face: Regular, load_flags: TARGET_LIGHT, render_mode: "Lcd", lcd_filter: 1 }
2: backend::size: (400, 400)
2023-05-07 19:02:56 [notan_glow] INFO: Using opengl graphics api
3: app::size: (400, 400)
4: graphics::size: (400, 400) - graphics::dpi: 1.0
5: app::size: (400, 400) - graphics::size: (400, 400) - graphics::dpi: 1.0
2023-05-07 19:02:56 [notan_winit::backend] INFO: Winit Event: Focused(false)
7: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
8: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
400 x 400

If I remove app.exit() it seems that the size is actually messed up only after the first few frames:

1: config: WindowConfig { title: "Notan App", width: 400, height: 400, fullscreen: false, min_size: None, max_size: None, maximized: false, resizable: false, vsync: false, multisampling: 0, high_dpi: false, lazy_loop: false, transparent: false, always_on_top: false, decorations: true, visible: true, mouse_passthrough: false, canvas_id: "notan_canvas", window_icon_path: None, window_icon_data: None, taskbar_icon_path: None, taskbar_icon_data: None }
2023-05-07 19:03:09 [crossfont::ft] DEBUG: Loaded Face Face { ft_face: Font Face: Regular, load_flags: TARGET_LIGHT, render_mode: "Lcd", lcd_filter: 1 }
2: backend::size: (400, 400)
2023-05-07 19:03:09 [notan_glow] INFO: Using opengl graphics api
3: app::size: (400, 400)
4: graphics::size: (400, 400) - graphics::dpi: 1.0
5: app::size: (400, 400) - graphics::size: (400, 400) - graphics::dpi: 1.0
2023-05-07 19:03:09 [notan_winit::backend] INFO: Winit Event: Focused(false)
7: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
8: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
400 x 400
7: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
8: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
400 x 400
7: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
8: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
400 x 400
2023-05-07 19:03:09 [notan_winit::backend] INFO: Winit Event: Resized(PhysicalSize { width: 420, height: 455 })
6: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
7: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
8: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
420 x 455
7: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
8: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
420 x 455
2023-05-07 19:03:09 [notan_winit::backend] INFO: Winit Event: ScaleFactorChanged { scale_factor: 2.0, new_inner_size: PhysicalSize { width: 840, height: 910 } }
2023-05-07 19:03:09 [notan_winit::backend] INFO: Winit Event: Resized(PhysicalSize { width: 840, height: 910 })
2023-05-07 19:03:09 [notan_winit::backend] INFO: Winit Event: Focused(true)
2023-05-07 19:03:09 [notan_winit::backend] INFO: Winit Event: ModifiersChanged((empty))
7: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
8: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
420 x 455
7: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
8: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
420 x 455

And then the last three lines are repeated.

@Nazariglez
Copy link
Owner

Hey @190n thanks for the logs, I was able to found (what I think is) the same issue rust-windowing/winit#1446. I'll try to see if there is anything that we can do from notan in the next few days/weeks.

@Nazariglez
Copy link
Owner

As far I can see on the issue in winit, they tell that the size set is a "suggestion" for the OS, and that it's possible that it doesn't respect it, like wayland and swap or similar can do their own thing, so I am not sure if we can do anything more than intestead of hardcode the size to draw the quad get it from app. To be sure, can I ask you for one more test? Just git pull and win. window_open until the size changes again please. I would like to see the size reported vs inner vs out and the size that is on gfx vs app.

@190n
Copy link
Author

190n commented May 9, 2023

1: config: WindowConfig { title: "Notan App", width: 400, height: 400, fullscreen: false, min_size: None, max_size: None, maximized: false, resizable: false, vsync: false, multisampling: 0, high_dpi: false, lazy_loop: false, transparent: false, always_on_top: false, decorations: true, visible: true, mouse_passthrough: false, canvas_id: "notan_canvas", window_icon_path: None, window_icon_data: None, taskbar_icon_path: None, taskbar_icon_data: None }
2023-05-09 18:13:25 [crossfont::ft] DEBUG: Loaded Face Face { ft_face: Font Face: Regular, load_flags: TARGET_LIGHT, render_mode: "Lcd", lcd_filter: 1 }
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
2: backend::size: (400, 400)
2023-05-09 18:13:25 [notan_glow] INFO: Using opengl graphics api
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
3: app::size: (400, 400)
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
4: graphics::size: (400, 400) - graphics::dpi: 1.0
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
5: app::size: (400, 400) - graphics::size: (400, 400) - graphics::dpi: 1.0
2023-05-09 18:13:25 [notan_winit::backend] INFO: Winit Event: Focused(false)
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
7: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
8: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
gfx: (400, 400), app: (400, 400)
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
7: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
8: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
gfx: (400, 400), app: (400, 400)
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
7: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
8: app::size: (400, 400) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
Winit inner_size PhysicalSize { width: 400, height: 400 }, scale: 1, logical LogicalSize { width: 400.0, height: 400.0 } inner_scale 1.0
gfx: (400, 400), app: (400, 400)
2023-05-09 18:13:25 [notan_winit::backend] INFO: Winit Event: Resized(PhysicalSize { width: 420, height: 455 })
> Resized: evt:PhysicalSize { width: 420, height: 455 } in:PhysicalSize { width: 420, height: 455 } out:PhysicalSize { width: 420, height: 455 }, dpi:1
Winit inner_size PhysicalSize { width: 420, height: 455 }, scale: 1, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 1.0
6: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (400, 400) - graphics::dpi: 1.0
7: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
8: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
Winit inner_size PhysicalSize { width: 420, height: 455 }, scale: 1, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 1.0
gfx: (420, 455), app: (420, 455)
Winit inner_size PhysicalSize { width: 420, height: 455 }, scale: 1, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 1.0
7: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
8: app::size: (420, 455) app:dpi: 1.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
Winit inner_size PhysicalSize { width: 420, height: 455 }, scale: 1, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 1.0
gfx: (420, 455), app: (420, 455)
2023-05-09 18:13:25 [notan_winit::backend] INFO: Winit Event: ScaleFactorChanged { scale_factor: 2.0, new_inner_size: PhysicalSize { width: 840, height: 910 } }
2023-05-09 18:13:25 [notan_winit::backend] INFO: Winit Event: Resized(PhysicalSize { width: 840, height: 910 })
> Resized: evt:PhysicalSize { width: 840, height: 910 } in:PhysicalSize { width: 840, height: 910 } out:PhysicalSize { width: 840, height: 910 }, dpi:2
2023-05-09 18:13:25 [notan_winit::backend] INFO: Winit Event: Focused(true)
2023-05-09 18:13:25 [notan_winit::backend] INFO: Winit Event: ModifiersChanged((empty))
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
7: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 1.0
8: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
gfx: (420, 455), app: (420, 455)
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
7: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
8: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
gfx: (420, 455), app: (420, 455)
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
7: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
8: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
gfx: (420, 455), app: (420, 455)
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
7: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
8: app::size: (420, 455) app:dpi: 2.0 - graphics::size: (420, 455) - graphics::dpi: 2.0
Winit inner_size PhysicalSize { width: 840, height: 910 }, scale: 2, logical LogicalSize { width: 420.0, height: 455.0 } inner_scale 2.0
gfx: (420, 455), app: (420, 455)

All the same after this.

@Nazariglez
Copy link
Owner

The 3 sizes reported by winit are the same, I am not sure right now if this is intended or it's a bug, I am opening an issue on winit rust-windowing/winit#2799

@Nazariglez Nazariglez added blocked This feature cannot be done yet and removed help wanted Extra attention is needed labels May 11, 2023
@Nazariglez
Copy link
Owner

Hey @190n, good news! I was able to get a Fedora+Wayland working on my machine and did some test (this is good because I can test anything there from now on). And the issue is fixed using the latest changes in winit. The bad news is that winit's version isn't published yet. Once published we need to wait (or help) with glutin getting updated too.

So this will be a fix for notan 0.10.0 which is almost done, however, blocked now for this. Once a new version of winit and glutin gets published I'll update notan and probably release 0.10.

Thanks for reporting this, all the testing, and your patience.

Copy link

This issue is stale because it has been open for 1 year with no activity.

@github-actions github-actions bot added the stale Abandoned issue by inactivity label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This feature cannot be done yet bug Something isn't working stale Abandoned issue by inactivity
Projects
None yet
Development

No branches or pull requests

2 participants