Skip to content

Commit

Permalink
feat(wm): add monitor index preference cmd
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LGUG2Z committed Oct 31, 2022
1 parent 37f1a16 commit 2575ca2
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 3 deletions.
1 change: 1 addition & 0 deletions komorebi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 39 additions & 2 deletions komorebi.generated.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -331,13 +350,31 @@ 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

; 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
Expand Down
2 changes: 2 additions & 0 deletions komorebi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ lazy_static! {
"firefox.exe".to_string(),
"idea64.exe".to_string(),
]));
static ref MONITOR_INDEX_PREFERENCES: Arc<Mutex<HashMap<usize, Rect>>> =
Arc::new(Mutex::new(HashMap::new()));
static ref WORKSPACE_RULES: Arc<Mutex<HashMap<String, (usize, usize)>>> =
Arc::new(Mutex::new(HashMap::new()));
static ref MANAGE_IDENTIFIERS: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(vec![]));
Expand Down
13 changes: 13 additions & 0 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
}
Expand Down
20 changes: 19 additions & 1 deletion komorebi/src/windows_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions komorebic.lib.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
29 changes: 29 additions & 0 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2575ca2

Please sign in to comment.