From de8450ebb2ce6ad6eefa6df5b49080dcbe836d7f Mon Sep 17 00:00:00 2001 From: lars-berger Date: Mon, 12 Aug 2024 14:28:27 +0800 Subject: [PATCH 1/2] feat: set foreground window without simulating keypress (#672) --- .../wm/src/common/platform/native_window.rs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm/src/common/platform/native_window.rs index 906d4c227..22b8898c0 100644 --- a/packages/wm/src/common/platform/native_window.rs +++ b/packages/wm/src/common/platform/native_window.rs @@ -280,21 +280,24 @@ impl NativeWindow { } pub fn set_foreground(&self) -> anyhow::Result<()> { - // Simulate a key press event to activate the window. - let input = INPUT { - r#type: INPUT_KEYBOARD, - Anonymous: INPUT_0 { - ki: KEYBDINPUT { - wVk: VIRTUAL_KEY(0), - wScan: 0, - dwFlags: KEYBD_EVENT_FLAGS(0), - time: 0, - dwExtraInfo: 0, + // UIAccess allows for setting the foreground window without needing to + // send a key press event. + #[cfg(not(feature = "ui_access"))] + unsafe { + let input = INPUT { + r#type: INPUT_KEYBOARD, + Anonymous: INPUT_0 { + ki: KEYBDINPUT { + wVk: VIRTUAL_KEY(1), + wScan: 0, + dwFlags: KEYBD_EVENT_FLAGS(0), + time: 0, + dwExtraInfo: 0, + }, }, - }, - }; + }; - unsafe { + // Simulate a key press event to activate the window. SendInput(&[input], std::mem::size_of::() as i32); } From f87c2b3d0e3ab82a21a95eceeac49189a95f2198 Mon Sep 17 00:00:00 2001 From: Amine Djeghri <32715913+AmineDjeghri@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:59:12 +0200 Subject: [PATCH 2/2] docs: update readme to include windows rules (#654) --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 7a6bfadf0..5dd01cce3 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,30 @@ workspaces: keep_alive: false ``` +### Config: Window rules + +Commands can be run when a window is first launched. This is useful for adding window-specific behaviors like always starting a window as fullscreen, or assigning to a specific workspace. + +Windows can be targeted by their process, class, and title. Multiple matching criteria can be used together to target a window more precisely. + +```yaml +window_rules: + - commands: ["move --workspace 1"] + match: + # Move browsers to workspace 1. + - window_process: { regex: "msedge|brave|chrome" } + + - commands: ["ignore"] + match: + # Ignores any Zebar windows. + - window_process: { equals: "zebar" } + + # Ignores picture-in-picture windows for browsers. + # Note that *both* the title and class must match for the rule to run. + - window_title: { regex: "[Pp]icture.in.[Pp]icture" } + window_class: { regex: "Chrome_WidgetWin_1|MozillaDialogClass" } +``` + ### Config: Window effects Visual effects can be applied to windows via the `window_effects` option. Currently, colored borders are the only effect available with more to come in the future.