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

[bug] always_on_bottom fails to set window to bottom when created on Windows #9597

Closed
Charlie-XIAO opened this issue Apr 29, 2024 · 5 comments
Labels
platform: Windows status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@Charlie-XIAO
Copy link

Charlie-XIAO commented Apr 29, 2024

Describe the bug

Transferred from Discord.

On Windows, always on bottom fails to set the window to bottom when it is initially created. Afterwards it works fine. Alternatively if one further sets .visible(false) then show it later, it will be automatically on the bottom but there is sometimes a flickering.

Reproduction

Create an app with create-tauri-app and change src-tauri/src/main.rs to:

use tauri::{Builder, WebviewUrl, WebviewWindowBuilder};

fn main() {
    Builder::default()
        .setup(|app| {
            WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))
                .always_on_bottom(true)
                .build()?;
            Ok(())
        })
        .run(tauri::generate_context!())
        .unwrap();
}

With the above the window is not initially on bottom. Then try

use tauri::{Builder, WebviewUrl, WebviewWindowBuilder};

fn main() {
    Builder::default()
        .setup(|app| {
            let webview = WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))
                .always_on_bottom(true)
                .visible(false)
                .build()?;
            webview.show()?;
            Ok(())
        })
        .run(tauri::generate_context!())
        .unwrap();
}

This will set the window initially to the bottom, but sometimes there is a flickering.

Expected behavior

.always_on_bottom(true) should initially set the window to bottom, without using the trick.

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 123.0.2420.97
    ✔ MSVC: Visual Studio 生成工具 2022
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.10.0
    - npm: 10.2.3

[-] Packages
    - tauri [RUST]: 2.0.0-beta.16
    - tauri-build [RUST]: 2.0.0-beta.13
    - wry [RUST]: 0.39.3
    - tao [RUST]: 0.27.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.9
    - @tauri-apps/cli [NPM]: 2.0.0-beta.13

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite
@Charlie-XIAO Charlie-XIAO added status: needs triage This issue needs to triage, applied to new issues type: bug labels Apr 29, 2024
@Charlie-XIAO Charlie-XIAO changed the title [bug] [bug] always_on_bottom fails to set window to bottom when created on Windows Apr 29, 2024
@amrbashir
Copy link
Member

amrbashir commented Apr 29, 2024

you need to pair it with .focused(false) otherwise the window will be created with focus and will be placed on top until it loses focus

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
@Charlie-XIAO
Copy link
Author

Charlie-XIAO commented Apr 29, 2024

Thanks! That indeed works, but the window still flickers upon creation. Does that have a solution?

@amrbashir
Copy link
Member

Not sure what flicker you mean, can you show a video?

@Charlie-XIAO
Copy link
Author

Sorry my screen recording software can only capture one app so I have to use my phone:

screen-recording.mp4

@Charlie-XIAO
Copy link
Author

Charlie-XIAO commented Apr 29, 2024

Sorry @amrbashir, .focused(false) does solve the issue in the snippet above. I've just narrowed down my app and found that to reproduce the "flickering" problem we further need to set .maximized(true). Note that .focused(false) further causes problems when we call .set_ignore_cursor_events(true/false). Please try the following:

fn main() {
    tauri::Builder::default()
        .setup(|app| {
            let main = WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))
                .maximized(true) // causes the flickering
                .always_on_bottom(true)
                .focused(false)
                .build()?;
            sleep(Duration::from_secs(2));
            main.set_ignore_cursor_events(true)?; // some unexpected motions
            sleep(Duration::from_secs(2));
            main.set_ignore_cursor_events(false)?; // same as above
            Ok(())
        })
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Please let me know if you cannot reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Windows status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

3 participants