A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
fix: improve dock functionality with elevated processes; update styles and add elevation reporting tool
CristianOlivera1d1887673c677
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 789cc09..b1ef193 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,9 @@ copia la sección de la versión que se publica a la release de GitHub.- Fixed: the Dock section of Settings could not scroll to its last options.- Fixed: opening Settings twice opened two windows; it now brings the open oneto the front.+- Fixed: with an app running as administrator in front (Task Manager, an admin+ terminal, an installer), the dock's Start button and the menu bar buttons did+ nothing, because Windows drops simulated keys aimed at such apps.### Español@@ -28,6 +31,10 @@ copia la sección de la versión que se publica a la release de GitHub.a la frecuencia del monitor y ya no se salta sus primeros fotogramas.- Corregido: la sección Dock de Ajustes no dejaba bajar hasta las últimas opciones.- Corregido: abrir Ajustes dos veces abría dos ventanas; ahora trae al frente la abierta.+- Corregido: con una app de administrador delante (Administrador de tareas, una+ terminal de administrador, un instalador), el botón Inicio del dock y los botones+ de la barra superior no hacían nada, porque Windows descarta las teclas simuladas+ dirigidas a esas apps.## [0.1.1]diff --git a/crates/muelle-shell/Cargo.toml b/crates/muelle-shell/Cargo.tomlindex dc6c2b8..0b3473e 100644--- a/crates/muelle-shell/Cargo.toml+++ b/crates/muelle-shell/Cargo.toml@@ -28,6 +28,7 @@ windows = { workspace = true, features = ["Win32_System_Power","Win32_System_ProcessStatus","Win32_System_Registry",+ "Win32_Security","Win32_System_Threading","Win32_System_Variant","Win32_UI_HiDpi",diff --git a/crates/muelle-shell/src/launcher.rs b/crates/muelle-shell/src/launcher.rsindex 094abc6..8ddc787 100644--- a/crates/muelle-shell/src/launcher.rs+++ b/crates/muelle-shell/src/launcher.rs@@ -1,7 +1,9 @@use thiserror::Error;use windows::{Win32::{- Foundation::{HWND, LPARAM, WPARAM},+ Foundation::{CloseHandle, HANDLE, HWND, LPARAM, WPARAM},+ Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},+ System::Threading::{OpenProcess, OpenProcessToken, PROCESS_QUERY_LIMITED_INFORMATION},UI::{Input::KeyboardAndMouse::{INPUT, INPUT_0, INPUT_KEYBOARD, INPUT_MOUSE, KEYBD_EVENT_FLAGS, KEYBDINPUT,@@ -10,10 +12,11 @@ use windows::{},Shell::ShellExecuteW,WindowsAndMessaging::{- ASFW_ANY, AllowSetForegroundWindow, GetForegroundWindow, HWND_TOP, IsIconic,- IsWindowVisible, PostMessageW, SW_MINIMIZE, SW_RESTORE, SW_SHOWNORMAL,- SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE, SetForegroundWindow, SetWindowPos,- ShowWindow, ShowWindowAsync, SwitchToThisWindow, WM_CLOSE,+ ASFW_ANY, AllowSetForegroundWindow, FindWindowW, GetForegroundWindow,+ GetWindowThreadProcessId, HWND_TOP, IsIconic, IsWindowVisible, PostMessageW,+ SW_MINIMIZE, SW_RESTORE, SW_SHOWNORMAL, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE,+ SetForegroundWindow, SetWindowPos, ShowWindow, ShowWindowAsync, SwitchToThisWindow,+ WM_CLOSE,},},},@@ -88,8 +91,67 @@ pub fn open_with(app: &str, files: &[String]) -> Result<(), LaunchError> {}}+/// `true` if the window in front belongs to a program running as+/// administrator (Task Manager, an admin terminal, an installer), or to one+/// the dock cannot even inspect, which is never less privileged.+fn foreground_is_elevated() -> bool {+ // SAFETY: Read-only queries on the foreground window.+ let pid = unsafe {+ let window = GetForegroundWindow();+ if window.is_invalid() {+ return false;+ }+ let mut pid = 0u32;+ GetWindowThreadProcessId(window, Some(&mut pid));+ pid+ };+ process_is_elevated(pid)+}++/// See [`foreground_is_elevated`].+#[must_use]+pub fn process_is_elevated(pid: u32) -> bool {+ // SAFETY: Read-only queries; both handles are closed before returning.+ unsafe {+ let Ok(process) = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, pid) else {+ return true;+ };+ let mut token = HANDLE::default();+ let opened = OpenProcessToken(process, TOKEN_QUERY, &mut token).is_ok();+ let _ = CloseHandle(process);+ if !opened {+ return true;+ }+ let mut elevation = TOKEN_ELEVATION::default();+ let mut size = 0u32;+ let read = GetTokenInformation(+ token,+ TokenElevation,+ Some((&raw mut elevation).cast()),+ size_of::<TOKEN_ELEVATION>() as u32,+ &mut size,+ )+ .is_ok();+ let _ = CloseHandle(token);+ !read || elevation.TokenIsElevated != 0+ }+}+/// Presses the given keys together and releases them.+///+/// Windows drops simulated input aimed at a program running as administrator+/// (UIPI), so with one in front the Windows key did nothing. In that case the+/// dock first takes the focus itself, which it may because the user just+/// clicked it, and the keys then go to an ordinary process.fn tap(keys: &[VIRTUAL_KEY]) {+ if foreground_is_elevated() {+ // SAFETY: Looks up the dock's own window and focuses it.+ unsafe {+ if let Ok(dock) = FindWindowW(crate::dock_link::DOCK_WINDOW_CLASS, None) {+ bring_to_front(dock);+ }+ }+ }let key = |vk: VIRTUAL_KEY, flags: KEYBD_EVENT_FLAGS| INPUT {r#type: INPUT_KEYBOARD,Anonymous: INPUT_0 {diff --git a/muelle/src/styles/dock.css b/muelle/src/styles/dock.cssindex e7a8fb5..b1840cb 100644--- a/muelle/src/styles/dock.css+++ b/muelle/src/styles/dock.css@@ -141,7 +141,7 @@height: 78px;list-style: none;border: 1px solid rgb(255 255 255 / 0.12);- border-radius: 22px;+ border-radius: 40px;corner-shape: squircle;background: rgb(255 255 255 / 0.14);box-shadow:diff --git a/spikes/src/bin/spike_elevated.rs b/spikes/src/bin/spike_elevated.rsnew file mode 100644index 0000000..e87e964--- /dev/null+++ b/spikes/src/bin/spike_elevated.rs@@ -0,0 +1,13 @@+//! Reports whether processes run elevated, as the dock decides it.+//! Usage: spike_elevated <pid> [pid...]++use muelle_shell::launcher::process_is_elevated;++fn main() {+ for pid in std::env::args()+ .skip(1)+ .filter_map(|arg| arg.parse::<u32>().ok())+ {+ println!("{pid}: elevated={}", process_is_elevated(pid));+ }+}