mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
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 <lualeet@null.null> Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
This commit is contained in:
@@ -440,6 +440,8 @@ pub struct Output {
|
||||
pub mode: Option<ConfiguredMode>,
|
||||
#[knuffel(child)]
|
||||
pub variable_refresh_rate: Option<Vrr>,
|
||||
#[knuffel(child)]
|
||||
pub focus_at_startup: bool,
|
||||
#[knuffel(child, default = DEFAULT_BACKGROUND_COLOR)]
|
||||
pub background_color: Color,
|
||||
}
|
||||
@@ -462,6 +464,7 @@ impl Default for Output {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
off: false,
|
||||
focus_at_startup: false,
|
||||
name: String::new(),
|
||||
scale: None,
|
||||
transform: Transform::Normal,
|
||||
@@ -3746,6 +3749,7 @@ mod tests {
|
||||
}
|
||||
|
||||
output "eDP-1" {
|
||||
focus-at-startup
|
||||
scale 2
|
||||
transform "flipped-90"
|
||||
position x=10 y=20
|
||||
@@ -4105,6 +4109,7 @@ mod tests {
|
||||
on_demand: true,
|
||||
},
|
||||
),
|
||||
focus_at_startup: true,
|
||||
background_color: Color {
|
||||
r: 0.09803922,
|
||||
g: 0.09803922,
|
||||
|
||||
+25
@@ -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) {
|
||||
|
||||
@@ -13,6 +13,7 @@ output "eDP-1" {
|
||||
transform "90"
|
||||
position x=1280 y=0
|
||||
variable-refresh-rate // on-demand=true
|
||||
focus-at-startup
|
||||
background-color "#003300"
|
||||
}
|
||||
|
||||
@@ -164,6 +165,28 @@ output "HDMI-A-1" {
|
||||
}
|
||||
```
|
||||
|
||||
### `focus-at-startup`
|
||||
|
||||
<sup>Since: next release</sup>
|
||||
|
||||
Focus this output by default when niri starts.
|
||||
|
||||
If multiple outputs with `focus-at-startup` are connected, they are prioritized in the order that they appear in the config.
|
||||
|
||||
When none of the connected outputs are explicitly `focus-at-startup`, niri will focus the first one sorted by name (same output sorting as used elsewhere in niri).
|
||||
|
||||
```kdl
|
||||
// Focus HDMI-A-1 by default.
|
||||
output "HDMI-A-1" {
|
||||
focus-at-startup
|
||||
}
|
||||
|
||||
// ...if HDMI-A-1 wasn't connected, focus DP-2 instead.
|
||||
output "DP-2" {
|
||||
focus-at-startup
|
||||
}
|
||||
```
|
||||
|
||||
### `background-color`
|
||||
|
||||
<sup>Since: 0.1.8</sup>
|
||||
|
||||
Reference in New Issue
Block a user