feat: working osk

This commit is contained in:
eneller
2026-01-24 18:11:33 +01:00
parent cade0046bf
commit 3b5d304845
4 changed files with 107 additions and 22 deletions

78
src-tauri/Cargo.lock generated
View File

@@ -840,7 +840,7 @@ dependencies = [
"objc2 0.6.3", "objc2 0.6.3",
"objc2-app-kit", "objc2-app-kit",
"objc2-foundation 0.3.2", "objc2-foundation 0.3.2",
"windows", "windows 0.61.3",
"x11rb", "x11rb",
"xkbcommon", "xkbcommon",
"xkeysym", "xkeysym",
@@ -1844,6 +1844,7 @@ dependencies = [
"tauri", "tauri",
"tauri-build", "tauri-build",
"tauri-plugin-opener", "tauri-plugin-opener",
"windows 0.62.2",
"x11", "x11",
] ]
@@ -3598,7 +3599,7 @@ dependencies = [
"tao-macros", "tao-macros",
"unicode-segmentation", "unicode-segmentation",
"url", "url",
"windows", "windows 0.61.3",
"windows-core 0.61.2", "windows-core 0.61.2",
"windows-version", "windows-version",
"x11-dl", "x11-dl",
@@ -3670,7 +3671,7 @@ dependencies = [
"webkit2gtk", "webkit2gtk",
"webview2-com", "webview2-com",
"window-vibrancy", "window-vibrancy",
"windows", "windows 0.61.3",
] ]
[[package]] [[package]]
@@ -3771,7 +3772,7 @@ dependencies = [
"tauri-plugin", "tauri-plugin",
"thiserror 2.0.17", "thiserror 2.0.17",
"url", "url",
"windows", "windows 0.61.3",
"zbus", "zbus",
] ]
@@ -3797,7 +3798,7 @@ dependencies = [
"url", "url",
"webkit2gtk", "webkit2gtk",
"webview2-com", "webview2-com",
"windows", "windows 0.61.3",
] ]
[[package]] [[package]]
@@ -3823,7 +3824,7 @@ dependencies = [
"url", "url",
"webkit2gtk", "webkit2gtk",
"webview2-com", "webview2-com",
"windows", "windows 0.61.3",
"wry", "wry",
] ]
@@ -4550,7 +4551,7 @@ checksum = "d4ba622a989277ef3886dd5afb3e280e3dd6d974b766118950a08f8f678ad6a4"
dependencies = [ dependencies = [
"webview2-com-macros", "webview2-com-macros",
"webview2-com-sys", "webview2-com-sys",
"windows", "windows 0.61.3",
"windows-core 0.61.2", "windows-core 0.61.2",
"windows-implement", "windows-implement",
"windows-interface", "windows-interface",
@@ -4574,7 +4575,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36695906a1b53a3bf5c4289621efedac12b73eeb0b89e7e1a89b517302d5d75c" checksum = "36695906a1b53a3bf5c4289621efedac12b73eeb0b89e7e1a89b517302d5d75c"
dependencies = [ dependencies = [
"thiserror 2.0.17", "thiserror 2.0.17",
"windows", "windows 0.61.3",
"windows-core 0.61.2", "windows-core 0.61.2",
] ]
@@ -4630,11 +4631,23 @@ version = "0.61.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
dependencies = [ dependencies = [
"windows-collections", "windows-collections 0.2.0",
"windows-core 0.61.2", "windows-core 0.61.2",
"windows-future", "windows-future 0.2.1",
"windows-link 0.1.3", "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]] [[package]]
@@ -4646,6 +4659,15 @@ dependencies = [
"windows-core 0.61.2", "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]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.61.2" version = "0.61.2"
@@ -4680,7 +4702,18 @@ checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
dependencies = [ dependencies = [
"windows-core 0.61.2", "windows-core 0.61.2",
"windows-link 0.1.3", "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]] [[package]]
@@ -4727,6 +4760,16 @@ dependencies = [
"windows-link 0.1.3", "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]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.3.4" version = "0.3.4"
@@ -4856,6 +4899,15 @@ dependencies = [
"windows-link 0.1.3", "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]] [[package]]
name = "windows-version" name = "windows-version"
version = "0.1.7" version = "0.1.7"
@@ -5082,7 +5134,7 @@ dependencies = [
"webkit2gtk", "webkit2gtk",
"webkit2gtk-sys", "webkit2gtk-sys",
"webview2-com", "webview2-com",
"windows", "windows 0.61.3",
"windows-core 0.61.2", "windows-core 0.61.2",
"windows-version", "windows-version",
"x11-dl", "x11-dl",

View File

@@ -23,9 +23,16 @@ tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
enigo = "0.6.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] [target.'cfg(target_os = "linux")'.dependencies]
x11 = { version = "2.21.0", features = ["xlib"] } x11 = { version = "2.21.0", features = ["xlib"] }
raw-window-handle = "0.6.2"
[profile.dev] [profile.dev]
incremental = true # Compile your binary in smaller steps. incremental = true # Compile your binary in smaller steps.

View File

@@ -6,8 +6,6 @@ use tauri::Manager;
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command] #[tauri::command]
fn greet(name: &str) -> String { 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) format!("Hello, {}! You've been greeted from Rust!", name)
} }
@@ -51,16 +49,42 @@ fn send_key(key: String) -> Result<(), String> {
pub fn run() { pub fn run() {
tauri::Builder::default() tauri::Builder::default()
.setup(|app| { .setup(|app| {
#[cfg_attr(not(target_os = "linux"), allow(unused_variables))]
let window = app.get_webview_window("main").unwrap(); let window = app.get_webview_window("main").unwrap();
#[cfg(target_os = "windows")] #[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")] #[cfg(target_os = "linux")]
{ {
use x11::xlib; use x11::xlib;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, WindowHandle}; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
// raw X11 pointers here
unsafe { unsafe {
let handle = window.raw_window_handle(); let handle = window.raw_window_handle();
if let Ok(RawWindowHandle::Xlib(h)) = handle { if let Ok(RawWindowHandle::Xlib(h)) = handle {
@@ -69,7 +93,7 @@ pub fn run() {
let hints = xlib::XAllocWMHints(); let hints = xlib::XAllocWMHints();
if !hints.is_null() { if !hints.is_null() {
(*hints).flags = xlib::InputHint; (*hints).flags = xlib::InputHint;
(*hints).input = 0; // Set input hint to False (*hints).input = 0;
xlib::XSetWMHints(display, h.window, hints); xlib::XSetWMHints(display, h.window, hints);
xlib::XFree(hints as *mut _); xlib::XFree(hints as *mut _);
} }
@@ -78,10 +102,11 @@ pub fn run() {
} }
} }
} }
Ok(()) Ok(())
}) })
.plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![greet, send_key]) .invoke_handler(tauri::generate_handler![greet, send_key])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

View File

@@ -18,7 +18,8 @@
"minWidth": 800, "minWidth": 800,
"minHeight": 700, "minHeight": 700,
"resizable": true, "resizable": true,
"center": true "center": true,
"alwaysOnTop": true
} }
], ],
"security": { "security": {