From 8d43efe4ac38ddb6ce298d6fbdfc3ec610b8da56 Mon Sep 17 00:00:00 2001 From: lualeet <43719546+lualeet@users.noreply.github.com> Date: Sat, 29 Mar 2025 10:13:59 +0000 Subject: Add option 'focus-at-startup' to focus a chosen output on start (#1323) * Implement default-output * Fix incorrect wiki string * Center mouse on start * Move default-output to Output.focus-at-startup * fixes --------- Co-authored-by: lualeet Co-authored-by: Ivan Molodetskikh --- src/niri.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/niri.rs b/src/niri.rs index 35c8b2d7..14c48f17 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -630,6 +630,8 @@ impl State { state.load_xkb_file(); // Initialize some IPC server state. state.ipc_keyboard_layouts_changed(); + // Focus the default monitor if set by the user. + state.focus_default_monitor(); Ok(state) } @@ -794,6 +796,29 @@ impl State { rv } + pub fn focus_default_monitor(&mut self) { + // Our default target is the first output in sorted order. + let Some(mut target) = self.niri.sorted_outputs.first().cloned() else { + // No outputs are connected. + return; + }; + + let config = self.niri.config.borrow(); + for config in &config.outputs.0 { + if !config.focus_at_startup { + continue; + } + if let Some(output) = self.niri.output_by_name_match(&config.name) { + target = output.clone(); + break; + } + } + drop(config); + + self.niri.layout.focus_output(&target); + self.move_cursor_to_output(&target); + } + /// Focus a specific window, taking care of a potential active output change and cursor /// warp. pub fn focus_window(&mut self, window: &Window) { -- cgit