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

Wrong window size on linux mint #219

Open
LedinecMing opened this issue Jan 30, 2023 · 9 comments
Open

Wrong window size on linux mint #219

LedinecMing opened this issue Jan 30, 2023 · 9 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@LedinecMing
Copy link

gfx.device.size() gives different results when on linux or on windows(using wine) in setup function
attached first is linux, second is windows
linux
windows

@Nazariglez Nazariglez added bug Something isn't working question Further information is requested labels Jan 31, 2023
@Nazariglez
Copy link
Owner

Hello, which one is the right one? Linux or Wine? Should the white line be there as in the first image, or not?

I tried to replicate this behavior but the setup method returns the same size that I pass in the config, no matter that I use app.window().size() o gfx.size().

@LedinecMing
Copy link
Author

Hello, which one is the right one? Linux or Wine? Should the white line be there as in the first image, or not?

I tried to replicate this behavior but the setup method returns the same size that I pass in the config, no matter that I use app.window().size() o gfx.size().

White line means background is not same size as window size, it happens on linux.

@LedinecMing
Copy link
Author

@Nazariglez So gfx.size() returns wrong size in a setup function, but later in draw it returns correct window size.

@Nazariglez Nazariglez added help wanted Extra attention is needed and removed question Further information is requested labels May 5, 2023
@Nazariglez
Copy link
Owner

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

@Nazariglez
Copy link
Owner

@LedinecMing are you using mint with wayland? We think that this issue could be related to #265 and rust-windowing/winit#1446, I'll try to find a solution in the next few days/weeks if it's related.

@LedinecMing
Copy link
Author

I will try soon, still X.

@LedinecMing
Copy link
Author

LedinecMing commented May 16, 2023

@Nazariglez https://pastebin.com/t4pWVHj4 here is log and a minimal reproduction code

resize seems to be a key of an issue, everything works fine if I remove it.
image

@Nazariglez
Copy link
Owner

This is weird, I do think that the changes made in the next version of winit will help, let's keep this on hold until then.

Thanks!

@joseluis
Copy link
Contributor

joseluis commented Nov 5, 2023

Hi there. I don't know if I'm experiencing similar issues. I come here from a discord thread.

I made a simple example to showcase the problem:

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

#[notan_main]
fn main() -> Result<(), String> {
    let win_config = WindowConfig::default()
        // .set_size(300, 300) // window pixel size would be auto-scaled by dpi==1.66
        .set_high_dpi(true) // doesn't seem to change anything
        .set_resizable(true);
    init_with(setup).add_config(win_config).add_config(DrawConfig).draw(draw).build()
}

fn setup(app: &mut App) {
    let window = app.window();
    let dpi = window.dpi();
    // here we scale back the window size to a REAL pixel size of 300x300x
    window.set_size(unscale(300, dpi), unscale(300, dpi));

    println!("dpi: {dpi}");
}

fn draw(app: &mut App, gfx: &mut Graphics) {
    let _dpi = app.window().dpi(); // == 1.66

    // FIX 1: this causes the square to render at the BOTTOM left:
    // gfx.set_size(unscale(100, _dpi), unscale(100, _dpi));
    
    // FIX 2: this causes the square to render 80 pixels over the BOTTOM left:
    // gfx.set_dpi(1.0);

    let mut draw = gfx.create_draw();
    draw.clear(Color::BLUE);

    // When not changing gfx's size or dpi this renders at the TOP left:
    draw.rect((0.0, 0.0), (100.0, 100.0));

    gfx.render(&draw);
}

/// Removes a `dpi` scaling factor from a `value` in pixels.
#[inline]
fn unscale(value: u32, dpi: f64) -> u32 { (value as f64 / dpi) as u32 }

image

I'm using Linux Mint + XFCE.

Notan was detecting a dpi of 1.66..., which derived in these problems. But after updating my custom DPI settings in "Settings -> Appearance -> Fonts" from the 96 dpi by default to another value, and back, notan then reports a dpi of 1, which fixed my problems.

Additionally changing the DPI settings away from 96 dpi makes the gfx rendering on the y axis diverge by about 3.5 pixels per dpi point, so there maybe something there worth looking into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants