From 2575ca2da41a0ecfaaa1af0f4a67f7198b0e10fe Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 26 Oct 2022 16:00:02 -0700 Subject: [PATCH] feat(wm): add monitor index preference cmd This commit adds a new komorebic command, monitor-index-preference, which allows the user to set the index preference within the VecDeque of monitors based on the "size" of a display. This works as the size Rect identifies a unique display on the greater virtual screen and persists across display connections and disconnections unless the user deliberately changes the positioning of the display monitor on the virtual screen. When a new monitor is added to the state, the monitor preferences will be checked, and if a preference exists, the new monitor will be inserted at that index, otherwise, it will be pushed to the back of the VecDeque. resolve #275 --- komorebi-core/src/lib.rs | 1 + komorebi.generated.ahk | 41 +++++++++++++++++++++++++++++-- komorebi/src/main.rs | 2 ++ komorebi/src/process_command.rs | 13 ++++++++++ komorebi/src/windows_callbacks.rs | 20 ++++++++++++++- komorebic.lib.ahk | 4 +++ komorebic/src/main.rs | 29 ++++++++++++++++++++++ 7 files changed, 107 insertions(+), 3 deletions(-) diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 6ada3bc0..ea0b0d75 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -72,6 +72,7 @@ pub enum SocketMessage { ChangeLayoutCustom(PathBuf), FlipLayout(Axis), // Monitor and Workspace Commands + MonitorIndexPreference(usize, i32, i32, i32, i32), EnsureWorkspaces(usize, usize), NewWorkspace, ToggleTiling, diff --git a/komorebi.generated.ahk b/komorebi.generated.ahk index fbe9b714..b59dd358 100644 --- a/komorebi.generated.ahk +++ b/komorebi.generated.ahk @@ -9,6 +9,11 @@ Run, komorebic.exe float-rule exe "1Password.exe", , Hide ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line Run, komorebic.exe identify-tray-application class "CreativeCloudDesktopWindowClass", , Hide +; ArmCord +Run, komorebic.exe identify-border-overflow-application exe "ArmCord.exe", , Hide +; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +Run, komorebic.exe identify-tray-application exe "ArmCord.exe", , Hide + ; AutoHotkey ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line Run, komorebic.exe identify-tray-application exe "AutoHotkeyU64.exe", , Hide @@ -46,9 +51,9 @@ Run, komorebic.exe identify-border-overflow-application exe "DiscordCanary.exe", Run, komorebic.exe identify-tray-application exe "DiscordCanary.exe", , Hide ; DiscordDevelopment -Run, komorebic.exe identify-border-overflow-application exe "DiscordDeveloper.exe", , Hide +Run, komorebic.exe identify-border-overflow-application exe "DiscordDevelopment.exe", , Hide ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line -Run, komorebic.exe identify-tray-application exe "DiscordDeveloper.exe", , Hide +Run, komorebic.exe identify-tray-application exe "DiscordDevelopment.exe", , Hide ; DiscordPTB Run, komorebic.exe identify-border-overflow-application exe "DiscordPTB.exe", , Hide @@ -95,6 +100,9 @@ Run, komorebic.exe identify-tray-application exe "chrome.exe", , Hide ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line Run, komorebic.exe identify-tray-application exe "GoogleDriveFS.exe", , Hide +; Houdoku +Run, komorebic.exe identify-border-overflow-application exe "Houdoku.exe", , Hide + ; Inno Setup ; Target hidden window spawned by Inno Setup applications Run, komorebic.exe float-rule class "TApplication", , Hide @@ -283,6 +291,10 @@ Run, komorebic.exe manage-rule exe "slack.exe", , Hide ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line Run, komorebic.exe identify-tray-application exe "slack.exe", , Hide +; SoulseekQt +; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +Run, komorebic.exe identify-tray-application exe "SoulseekQt.exe", , Hide + ; Spotify Run, komorebic.exe identify-border-overflow-application exe "Spotify.exe", , Hide ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line @@ -291,6 +303,9 @@ Run, komorebic.exe identify-tray-application exe "Spotify.exe", , Hide ; Steam Run, komorebic.exe identify-border-overflow-application class "vguiPopupWindow", , Hide +; SystemSettings +Run, komorebic.exe float-rule class "Shell_Dialog", , Hide + ; Task Manager Run, komorebic.exe float-rule class "TaskManagerWindow", , Hide @@ -319,6 +334,10 @@ Run, komorebic.exe identify-tray-application exe "UnrealEditor.exe", , Hide ; Visual Studio Code Run, komorebic.exe identify-border-overflow-application exe "Code.exe", , Hide +; WebTorrent Desktop +; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +Run, komorebic.exe identify-tray-application exe "WebTorrent.exe", , Hide + ; Windows Console (conhost.exe) Run, komorebic.exe manage-rule class "ConsoleWindowClass", , Hide @@ -331,6 +350,14 @@ Run, komorebic.exe float-rule title "Control Panel", , Hide ; Targets MSI Installers Run, komorebic.exe float-rule class "MsiDialogCloseClass", , Hide +; WingetUI +; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +Run, komorebic.exe identify-tray-application exe "WingetUI.exe", , Hide + +; WingetUI +; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +Run, komorebic.exe identify-tray-application exe "wingetui.exe", , Hide + ; Wox ; Targets a hidden window spawned by Wox Run, komorebic.exe float-rule title "Hotkey sink", , Hide @@ -338,6 +365,16 @@ Run, komorebic.exe float-rule title "Hotkey sink", , Hide ; Zoom Run, komorebic.exe float-rule exe "Zoom.exe", , Hide +; mpv +; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +Run, komorebic.exe identify-tray-application class "mpv", , Hide + +; mpv.net +Run, komorebic.exe identify-object-name-change-application exe "mpvnet.exe", , Hide + +; paint.net +Run, komorebic.exe float-rule exe "paintdotnet.exe", , Hide + ; qBittorrent ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line Run, komorebic.exe identify-tray-application exe "qbittorrent.exe", , Hide diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 085a575d..d8b2ace4 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -90,6 +90,8 @@ lazy_static! { "firefox.exe".to_string(), "idea64.exe".to_string(), ])); + static ref MONITOR_INDEX_PREFERENCES: Arc>> = + Arc::new(Mutex::new(HashMap::new())); static ref WORKSPACE_RULES: Arc>> = Arc::new(Mutex::new(HashMap::new())); static ref MANAGE_IDENTIFIERS: Arc>> = Arc::new(Mutex::new(vec![])); diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index bd0678ea..0888ed40 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -55,6 +55,7 @@ use crate::HIDING_BEHAVIOUR; use crate::INITIAL_CONFIGURATION_LOADED; use crate::LAYERED_WHITELIST; use crate::MANAGE_IDENTIFIERS; +use crate::MONITOR_INDEX_PREFERENCES; use crate::OBJECT_NAME_CHANGE_ON_LAUNCH; use crate::SUBSCRIPTION_PIPES; use crate::TCP_CONNECTIONS; @@ -402,6 +403,18 @@ impl WindowManager { std::process::exit(0) } + SocketMessage::MonitorIndexPreference(index_preference, left, top, right, bottom) => { + let mut monitor_index_preferences = MONITOR_INDEX_PREFERENCES.lock(); + monitor_index_preferences.insert( + index_preference, + Rect { + left, + top, + right, + bottom, + }, + ); + } SocketMessage::EnsureWorkspaces(monitor_idx, workspace_count) => { self.ensure_workspaces_for_monitor(monitor_idx, workspace_count)?; } diff --git a/komorebi/src/windows_callbacks.rs b/komorebi/src/windows_callbacks.rs index 596d266c..cd1d0515 100644 --- a/komorebi/src/windows_callbacks.rs +++ b/komorebi/src/windows_callbacks.rs @@ -39,6 +39,7 @@ use crate::windows_api::WindowsApi; use crate::winevent_listener::WINEVENT_CALLBACK_CHANNEL; use crate::BORDER_COLOUR_CURRENT; use crate::BORDER_RECT; +use crate::MONITOR_INDEX_PREFERENCES; use crate::TRANSPARENCY_COLOUR; pub extern "system" fn valid_display_monitors( @@ -71,7 +72,24 @@ pub extern "system" fn enum_display_monitor( } if let Ok(m) = WindowsApi::monitor(hmonitor.0) { - monitors.elements_mut().push_back(m); + let monitor_index_preferences = MONITOR_INDEX_PREFERENCES.lock(); + let mut index_preference = None; + for (index, monitor_size) in &*monitor_index_preferences { + if m.size() == monitor_size { + index_preference = Option::from(index); + } + } + + if let Some(preference) = index_preference { + let current_len = monitors.elements().len(); + if *preference > current_len { + monitors.elements_mut().reserve(1); + } + + monitors.elements_mut().insert(*preference, m); + } else { + monitors.elements_mut().push_back(m); + } } true.into() diff --git a/komorebic.lib.ahk b/komorebic.lib.ahk index d70e475d..a3b21027 100644 --- a/komorebic.lib.ahk +++ b/komorebic.lib.ahk @@ -180,6 +180,10 @@ Retile() { RunWait, komorebic.exe retile, , Hide } +MonitorIndexPreference(index_preference, left, top, right, bottom) { + RunWait, komorebic.exe monitor-index-preference %index_preference% %left% %top% %right% %bottom%, , Hide +} + EnsureWorkspaces(monitor, workspace_count) { RunWait, komorebic.exe ensure-workspaces %monitor% %workspace_count%, , Hide } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index acf3c81e..07155462 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -279,6 +279,20 @@ struct WorkAreaOffset { bottom: i32, } +#[derive(Parser, AhkFunction)] +struct MonitorIndexPreference { + /// Preferred monitor index (zero-indexed) + index_preference: usize, + /// Left value of the monitor's size Rect + left: i32, + /// Top value of the monitor's size Rect + top: i32, + /// Right value of the monitor's size Rect + right: i32, + /// Bottom value of the monitor's size Rect + bottom: i32, +} + #[derive(Parser, AhkFunction)] struct EnsureWorkspaces { /// Monitor index (zero-indexed) @@ -606,6 +620,9 @@ enum SubCommand { PromoteFocus, /// Force the retiling of all managed windows Retile, + /// Set the monitor index preference for a monitor identified using its size + #[clap(arg_required_else_help = true)] + MonitorIndexPreference(MonitorIndexPreference), /// Create at least this many workspaces for the specified monitor #[clap(arg_required_else_help = true)] EnsureWorkspaces(EnsureWorkspaces), @@ -1108,6 +1125,18 @@ fn main() -> Result<()> { .as_bytes()?, )?; } + SubCommand::MonitorIndexPreference(arg) => { + send_message( + &SocketMessage::MonitorIndexPreference( + arg.index_preference, + arg.left, + arg.top, + arg.right, + arg.bottom, + ) + .as_bytes()?, + )?; + } SubCommand::EnsureWorkspaces(workspaces) => { send_message( &SocketMessage::EnsureWorkspaces(workspaces.monitor, workspaces.workspace_count)