From 3b5d30484555f079267367de33eb75fd8763cc00 Mon Sep 17 00:00:00 2001 From: eneller Date: Sat, 24 Jan 2026 18:11:33 +0100 Subject: [PATCH] feat: working osk --- src-tauri/Cargo.lock | 78 ++++++++++++++++++++++++++++++++------- src-tauri/Cargo.toml | 9 ++++- src-tauri/src/lib.rs | 39 ++++++++++++++++---- src-tauri/tauri.conf.json | 3 +- 4 files changed, 107 insertions(+), 22 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 07adc85..f88d4f4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -840,7 +840,7 @@ dependencies = [ "objc2 0.6.3", "objc2-app-kit", "objc2-foundation 0.3.2", - "windows", + "windows 0.61.3", "x11rb", "xkbcommon", "xkeysym", @@ -1844,6 +1844,7 @@ dependencies = [ "tauri", "tauri-build", "tauri-plugin-opener", + "windows 0.62.2", "x11", ] @@ -3598,7 +3599,7 @@ dependencies = [ "tao-macros", "unicode-segmentation", "url", - "windows", + "windows 0.61.3", "windows-core 0.61.2", "windows-version", "x11-dl", @@ -3670,7 +3671,7 @@ dependencies = [ "webkit2gtk", "webview2-com", "window-vibrancy", - "windows", + "windows 0.61.3", ] [[package]] @@ -3771,7 +3772,7 @@ dependencies = [ "tauri-plugin", "thiserror 2.0.17", "url", - "windows", + "windows 0.61.3", "zbus", ] @@ -3797,7 +3798,7 @@ dependencies = [ "url", "webkit2gtk", "webview2-com", - "windows", + "windows 0.61.3", ] [[package]] @@ -3823,7 +3824,7 @@ dependencies = [ "url", "webkit2gtk", "webview2-com", - "windows", + "windows 0.61.3", "wry", ] @@ -4550,7 +4551,7 @@ checksum = "d4ba622a989277ef3886dd5afb3e280e3dd6d974b766118950a08f8f678ad6a4" dependencies = [ "webview2-com-macros", "webview2-com-sys", - "windows", + "windows 0.61.3", "windows-core 0.61.2", "windows-implement", "windows-interface", @@ -4574,7 +4575,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36695906a1b53a3bf5c4289621efedac12b73eeb0b89e7e1a89b517302d5d75c" dependencies = [ "thiserror 2.0.17", - "windows", + "windows 0.61.3", "windows-core 0.61.2", ] @@ -4630,11 +4631,23 @@ version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" dependencies = [ - "windows-collections", + "windows-collections 0.2.0", "windows-core 0.61.2", - "windows-future", + "windows-future 0.2.1", "windows-link 0.1.3", - "windows-numerics", + "windows-numerics 0.2.0", +] + +[[package]] +name = "windows" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections 0.3.2", + "windows-core 0.62.2", + "windows-future 0.3.2", + "windows-numerics 0.3.1", ] [[package]] @@ -4646,6 +4659,15 @@ dependencies = [ "windows-core 0.61.2", ] +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" +dependencies = [ + "windows-core 0.62.2", +] + [[package]] name = "windows-core" version = "0.61.2" @@ -4680,7 +4702,18 @@ checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" dependencies = [ "windows-core 0.61.2", "windows-link 0.1.3", - "windows-threading", + "windows-threading 0.1.0", +] + +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core 0.62.2", + "windows-link 0.2.1", + "windows-threading 0.2.1", ] [[package]] @@ -4727,6 +4760,16 @@ dependencies = [ "windows-link 0.1.3", ] +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core 0.62.2", + "windows-link 0.2.1", +] + [[package]] name = "windows-result" version = "0.3.4" @@ -4856,6 +4899,15 @@ dependencies = [ "windows-link 0.1.3", ] +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link 0.2.1", +] + [[package]] name = "windows-version" version = "0.1.7" @@ -5082,7 +5134,7 @@ dependencies = [ "webkit2gtk", "webkit2gtk-sys", "webview2-com", - "windows", + "windows 0.61.3", "windows-core 0.61.2", "windows-version", "x11-dl", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 378c587..ad71753 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -23,9 +23,16 @@ tauri-plugin-opener = "2" serde = { version = "1", features = ["derive"] } serde_json = "1" enigo = "0.6.1" +raw-window-handle = "0.6.2" + +[target.'cfg(target_os = "windows")'.dependencies] +windows = { version = "0.62.2", features = [ + "Win32_UI_WindowsAndMessaging", + "Win32_Foundation" +] } + [target.'cfg(target_os = "linux")'.dependencies] x11 = { version = "2.21.0", features = ["xlib"] } -raw-window-handle = "0.6.2" [profile.dev] incremental = true # Compile your binary in smaller steps. diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f55d203..1bf73c3 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -6,8 +6,6 @@ use tauri::Manager; // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ #[tauri::command] fn greet(name: &str) -> String { - // let mut enigo = Enigo::new(&Settings::default()).unwrap(); - // enigo.key(Key::Unicode('a'), Click); format!("Hello, {}! You've been greeted from Rust!", name) } @@ -51,16 +49,42 @@ fn send_key(key: String) -> Result<(), String> { pub fn run() { tauri::Builder::default() .setup(|app| { - #[cfg_attr(not(target_os = "linux"), allow(unused_variables))] let window = app.get_webview_window("main").unwrap(); + #[cfg(target_os = "windows")] { + use windows::Win32::UI::WindowsAndMessaging::{SetWindowPos, HWND_TOPMOST, SWP_NOACTIVATE, GetWindowLongPtrW, SetWindowLongPtrW, GWL_EXSTYLE, WS_EX_NOACTIVATE}; + use windows::Win32::Foundation::HWND; + use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; + + unsafe { + if let Ok(RawWindowHandle::Win32(handle)) = window.raw_window_handle() { + let hwnd = HWND(handle.hwnd.get() as *mut core::ffi::c_void); + + // Get current extended window style + let ex_style = GetWindowLongPtrW(hwnd, GWL_EXSTYLE) as u32; + + // Add WS_EX_NOACTIVATE flag + let new_style = ex_style | WS_EX_NOACTIVATE.0; + SetWindowLongPtrW(hwnd, GWL_EXSTYLE, new_style as isize); + + // Position window as topmost without activating + /* + SetWindowPos( + hwnd, + Some(HWND_TOPMOST), + 0, 0, 0, 0, + SWP_NOACTIVATE + ); */ + } + } } + #[cfg(target_os = "linux")] { use x11::xlib; - use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, WindowHandle}; - // raw X11 pointers here + use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; + unsafe { let handle = window.raw_window_handle(); if let Ok(RawWindowHandle::Xlib(h)) = handle { @@ -69,7 +93,7 @@ pub fn run() { let hints = xlib::XAllocWMHints(); if !hints.is_null() { (*hints).flags = xlib::InputHint; - (*hints).input = 0; // Set input hint to False + (*hints).input = 0; xlib::XSetWMHints(display, h.window, hints); xlib::XFree(hints as *mut _); } @@ -78,10 +102,11 @@ pub fn run() { } } } + Ok(()) }) .plugin(tauri_plugin_opener::init()) .invoke_handler(tauri::generate_handler![greet, send_key]) .run(tauri::generate_context!()) .expect("error while running tauri application"); -} +} \ No newline at end of file diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 051b909..64c770c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -18,7 +18,8 @@ "minWidth": 800, "minHeight": 700, "resizable": true, - "center": true + "center": true, + "alwaysOnTop": true } ], "security": {