From 20a128596bd4f3cce5263a7b1ed7104542eec3de Mon Sep 17 00:00:00 2001 From: FTCHD <144691102+FTCHD@users.noreply.github.com> Date: Tue, 12 May 2026 19:31:34 +0300 Subject: [PATCH] focus on linux mint --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/common/shortcut.rs | 6 ++++++ src-tauri/common/window.rs | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 815c29c..adcf94c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -250,6 +250,7 @@ dependencies = [ "cocoa", "fix-path-env", "flate2", + "gtk", "log", "machine-uid", "objc", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1a64b08..29ad215 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -58,6 +58,7 @@ objc = "0.2" [target.'cfg(target_os = "linux")'.dependencies] zbus = { version = "5" } x11rb = "0.13" +gtk = "0.18" [patch.crates-io] tao = { git = "https://github.com/tauri-apps/tao", branch = "fix-windows-white-flash" } diff --git a/src-tauri/common/shortcut.rs b/src-tauri/common/shortcut.rs index f7042a1..265a961 100644 --- a/src-tauri/common/shortcut.rs +++ b/src-tauri/common/shortcut.rs @@ -2,6 +2,8 @@ use tauri::{AppHandle, Manager, WebviewWindow, WebviewWindowBuilder}; use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState}; use super::window::make_transparent; +#[cfg(target_os = "linux")] +use super::window::focus_window_linux; pub const DEFAULT_TOOLBAR_SHORTCUT: &str = "CmdOrCtrl+Shift+/"; const TOOLBAR_WINDOW_LABEL: &str = "Toolbar"; @@ -118,6 +120,8 @@ pub fn show_toolbar_window(app_handle: &AppHandle) -> Result<(), tauri::Error> { window.show()?; window.unminimize()?; window.set_focus()?; + #[cfg(target_os = "linux")] + focus_window_linux(&window); } Ok(()) @@ -133,6 +137,8 @@ fn open_toolbar(app_handle: &AppHandle) -> Result<(), tauri::Error> { window.show()?; window.unminimize()?; window.set_focus()?; + #[cfg(target_os = "linux")] + focus_window_linux(&window); } } diff --git a/src-tauri/common/window.rs b/src-tauri/common/window.rs index 0358de7..73bedb9 100644 --- a/src-tauri/common/window.rs +++ b/src-tauri/common/window.rs @@ -48,6 +48,14 @@ fn centered_logical_position( Some((x, y)) } +#[cfg(target_os = "linux")] +pub(crate) fn focus_window_linux(window: &WebviewWindow) { + use gtk::prelude::*; + if let Ok(gtk_win) = window.gtk_window() { + gtk_win.present_with_time(gtk::current_event_time()); + } +} + #[tauri::command] #[allow(unused_variables)] pub async fn open_full_window( @@ -58,6 +66,8 @@ pub async fn open_full_window( ) -> Result<(), String> { if let Some(existing) = app_handle.get_webview_window(&name) { existing.set_focus().map_err(|e| e.to_string())?; + #[cfg(target_os = "linux")] + focus_window_linux(&existing); return Ok(()); } @@ -108,6 +118,8 @@ pub async fn open_full_window( window.set_zoom(1.0).map_err(|e| e.to_string())?; window.show().map_err(|e| e.to_string())?; window.set_focus().map_err(|e| e.to_string())?; + #[cfg(target_os = "linux")] + focus_window_linux(&window); #[cfg(target_os = "linux")] if let Some((x, y)) = centered_logical_position(&app_handle, width, height) { @@ -133,6 +145,8 @@ pub async fn open_window( ) -> Result<(), String> { if let Some(existing) = app_handle.get_webview_window(&name) { existing.set_focus().map_err(|e| e.to_string())?; + #[cfg(target_os = "linux")] + focus_window_linux(&existing); return Ok(()); } @@ -205,6 +219,8 @@ pub async fn open_window( ) -> Result<(), String> { if let Some(existing) = app_handle.get_webview_window(&name) { existing.set_focus().map_err(|e| e.to_string())?; + #[cfg(target_os = "linux")] + focus_window_linux(&existing); return Ok(()); } @@ -231,6 +247,7 @@ pub async fn open_window( window.set_zoom(1.0).map_err(|e| e.to_string())?; window.show().map_err(|e| e.to_string())?; window.set_focus().map_err(|e| e.to_string())?; + focus_window_linux(&window); if let Some((x, y)) = centered_logical_position(&app_handle, width, height) { let _ = window.set_position(tauri::Position::Logical(tauri::LogicalPosition::new(x, y))); @@ -250,6 +267,8 @@ pub async fn open_small_window( ) -> Result<(), String> { if let Some(existing) = app_handle.get_webview_window(&name) { existing.set_focus().map_err(|e| e.to_string())?; + #[cfg(target_os = "linux")] + focus_window_linux(&existing); return Ok(()); } @@ -292,6 +311,8 @@ pub async fn open_small_window( window.set_decorations(false).map_err(|e| e.to_string())?; window.show().map_err(|e| e.to_string())?; window.set_focus().map_err(|e| e.to_string())?; + #[cfg(target_os = "linux")] + focus_window_linux(&window); window.set_always_on_top(true).map_err(|e| e.to_string())?; #[cfg(target_os = "linux")]