focus on linux mint
This commit is contained in:
Generated
+1
@@ -250,6 +250,7 @@ dependencies = [
|
||||
"cocoa",
|
||||
"fix-path-env",
|
||||
"flate2",
|
||||
"gtk",
|
||||
"log",
|
||||
"machine-uid",
|
||||
"objc",
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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")]
|
||||
|
||||
Reference in New Issue
Block a user