mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 13:14:04 +02:00
monitor center
This commit is contained in:
parent
aa283284fe
commit
1b6e700c7b
1 changed files with 22 additions and 0 deletions
|
@ -9,9 +9,25 @@ mod hotkeys;
|
|||
mod tray;
|
||||
|
||||
use tauri::Manager;
|
||||
use tauri::PhysicalPosition;
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
|
||||
|
||||
fn center_window_on_current_monitor(window: &tauri::Window) {
|
||||
if let Some(monitor) = window.current_monitor().unwrap() {
|
||||
let monitor_size = monitor.size();
|
||||
let window_size = window.outer_size().unwrap();
|
||||
|
||||
let x = (monitor_size.width as i32 - window_size.width as i32) / 2;
|
||||
let y = (monitor_size.height as i32 - window_size.height as i32) / 2;
|
||||
|
||||
window.set_position(PhysicalPosition::new(
|
||||
monitor.position().x + x,
|
||||
monitor.position().y + y,
|
||||
)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
|
@ -33,6 +49,7 @@ fn main() {
|
|||
|
||||
if let Some(window) = app.get_window("main") {
|
||||
let _ = window.restore_state(StateFlags::POSITION);
|
||||
center_window_on_current_monitor(&window);
|
||||
window.show().unwrap();
|
||||
}
|
||||
|
||||
|
@ -51,6 +68,11 @@ fn main() {
|
|||
| tauri::WindowEvent::Focused(false) => {
|
||||
let _ = AppHandleExt::save_window_state(app.app_handle(), StateFlags::POSITION);
|
||||
}
|
||||
tauri::WindowEvent::Focused(true) => {
|
||||
if let Some(window) = app.get_window("main") {
|
||||
center_window_on_current_monitor(&window);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![clipboard::simulate_paste])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue