- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option 'focus-at-startup' to focus a chosen output on start #1323
Conversation
I can't find the issue/discussion but I remember someone was asking to have the mouse centered on startup, since |
Sure, that's a good idea. The sorting logic to pick a single output is duplicated a few times by now, but I don't think it should be an issue. |
src/niri.rs
Outdated
let config_temp = self.niri.config.clone(); | ||
let config = config_temp.borrow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let config_temp = self.niri.config.clone(); | |
let config = config_temp.borrow(); | |
let config = self.niri.config.borrow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that. Unfortunately,
let config = self.niri.config.borrow();
leads to E0502: cannot borrow `*self` as mutable because it is also borrowed as immutable
as the immutable reference to self.config
cannot be dropped before the loop is done iterating and self
must be mutably borrowed to call move_cursor_to_output
Inlining it to
let config = self.niri.config.clone().borrow();
leads to E0716: temporary value dropped while borrowed
6418f7f
to
8af70dc
Compare
Simplified it a bit, good to merge now. |
Thanks |
Adds a per-output focus-at-startup option to focus a chosen output when niri starts.
This is implemented by adding a
focus_default_monitor
method toState
and calling it inState::new
. If the option is set tonull
or no monitor is successfully matched, centers the cursor on the first monitor by name. Otherwise, it focuses the first detected and matching monitor by order of declaration.The contents of the
focus_default_monitor
aren't nice to look at, but I couldn't get it any simpler without a temp variable dropped too early or a borrow checker upset.