plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

[positioner] Adjust Window Position Offsets

Open 0Ky opened this issue 2 years ago • 10 comments

When using the Position::TrayCenter enum, I've noticed that the window opens extremely close to the system tray — there's practically no gap at all. For aesthetic and usability purposes, this is less than ideal.

I believe there isn't a way to adjust the position offsets, which would allow for a more customizable experience based on user or application needs. Thus, I would like to request the feature of adjustable window position offsets for the tauri-plugin-positioner. This could potentially be a configuration option that allows us to define additional pixel offsets (x and y) from the position provided by the Position:: enum.

0Ky avatar Jun 13 '23 14:06 0Ky

@0Ky What operating system are you on? I'm not able to call any of the tray variants from rust on windows at all. Am able to call the non tray variants like Center just fine.

rp1231 avatar Nov 12 '23 12:11 rp1231

@rp1231 Did you enable the system-tray feature in Cargo.toml?

FabianLars avatar Nov 12 '23 13:11 FabianLars

@FabianLars Yes it's enabled

tauri = { version = "1.5.2", features = ["api-all", "system-tray"] }

rp1231 avatar Nov 12 '23 13:11 rp1231

I meant on the positioner plugin. If you also did that, please open a new issue, preferibly with a reproduction example but at least the output of the tauri info command, the dependency section from Cargo.toml, and some code of what you've tried.

FabianLars avatar Nov 12 '23 13:11 FabianLars

@FabianLars enabled that on the plugin and got an error saying "Tray position not set". How do I set the tray position in the plugin. Couldn't find any documentation regarding that. Thanks

rp1231 avatar Nov 12 '23 14:11 rp1231

@0Ky What operating system are you on?

Windows 11.

I'm not able to call any of the tray variants from rust on windows at all. Am able to call the non tray variants like Center just fine.

Are you following the correct usage guide?

Cargo.toml:

tauri = { version = "1.5.2", features = ["api-all", "system-tray"] }
tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] }

main.rs:

Initialize the plugin:

use tauri_plugin_positioner::{WindowExt, Position};

fn main() {
    tauri::Builder::default()
        // include these
        .plugin(tauri_plugin_positioner::init()) 
        .on_system_tray_event(|app, event| {
           tauri_plugin_positioner::on_tray_event(app, &event);
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Change position with adjustable offset values:

let window = app.get_window("main").unwrap();
let _ = window.move_window(Position::TrayCenter);
let current_position = window.outer_position().unwrap();
let offset_position = PhysicalPosition {
    x: current_position.x - 18,
    y: current_position.y - 12,
};
let _ = window.set_position(tauri::Position::Physical(offset_position));

0Ky avatar Nov 12 '23 18:11 0Ky

Thanks for chiming in! Just wanted to add that the important thing here is the on_system_tray_event thing. There has to be one tray event before the first move_window call so that the plugin knows where the tray is. (In other words, if you call move_window before the first tray event you will get an error)

FabianLars avatar Nov 12 '23 21:11 FabianLars

@0Ky Thanks for the explanation and example code, especially for the offset. @FabianLars Thanks I think I might be encountering the error due to that, I'll see what I can do to fix my code.

rp1231 avatar Nov 13 '23 06:11 rp1231

Thanks for chiming in! Just wanted to add that the important thing here is the on_system_tray_event thing. There has to be one tray event before the first move_window call so that the plugin knows where the tray is. (In other words, if you call move_window before the first tray event you will get an error)

Does not actually errors but panics. There should be a way to gracefully handle that and fallback to another position.

truchi avatar Nov 13 '23 17:11 truchi

@truchi Feel free to open a new issue about this :)

FabianLars avatar Nov 13 '23 18:11 FabianLars