-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Focus command to focus on specific monitor by index
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::{ | ||
containers::traits::CommonGetters, | ||
user_config::UserConfig, | ||
wm_state::WmState, | ||
workspaces::{commands::focus_workspace, WorkspaceTarget}, | ||
}; | ||
|
||
/// Focuses a monitor by a given monitor index. | ||
pub fn focus_monitor( | ||
target: &usize, | ||
state: &mut WmState, | ||
config: &UserConfig, | ||
) -> anyhow::Result<()> { | ||
let monitors = state.monitors(); | ||
|
||
let target_monitor = monitors.get(target.clone()); | ||
|
||
// if there are fewer monitors than the index provided error out and bail | ||
// early from function | ||
if target_monitor.is_none() { | ||
anyhow::bail!("target index greater than number of monitors"); | ||
} | ||
|
||
let target_monitor = target_monitor.unwrap(); | ||
|
||
if target_monitor.has_focus(None) { | ||
return Ok(()); | ||
} | ||
|
||
let displayed_workspace = target_monitor.displayed_workspace().unwrap(); | ||
|
||
focus_workspace( | ||
WorkspaceTarget::Name(displayed_workspace.config().name), | ||
state, | ||
config, | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters