Implement support to enable numlock at startup
Browse files at this commit82dabc21f3c2379a7bed320574ff468869d59a18Parent: 39b3d62- feat
- implement support to enable numlock at startup
3 changed files +26 -11
- niri-config/src/lib.rs +4 -0
- resources/default-config.kdl +3 -0
- src/niri.rs +19 -11
niri-config/src/lib.rsmodified+4 -0
| @@ -120,6 +120,8 @@ pub struct Keyboard { | |||
| 120 | pub repeat_rate: u8, | 120 | pub repeat_rate: u8, |
| 121 | #[knuffel(child, unwrap(argument), default)] | 121 | #[knuffel(child, unwrap(argument), default)] |
| 122 | pub track_layout: TrackLayout, | 122 | pub track_layout: TrackLayout, |
| 123 | + #[knuffel(child)] | ||
| 124 | + pub numlock: bool, | ||
| 123 | } | 125 | } |
| 124 | 126 | ||
| 125 | impl Default for Keyboard { | 127 | impl Default for Keyboard { |
| @@ -129,6 +131,7 @@ impl Default for Keyboard { | |||
| 129 | repeat_delay: 600, | 131 | repeat_delay: 600, |
| 130 | repeat_rate: 25, | 132 | repeat_rate: 25, |
| 131 | track_layout: Default::default(), | 133 | track_layout: Default::default(), |
| 134 | + numlock: Default::default(), | ||
| 132 | } | 135 | } |
| 133 | } | 136 | } |
| 134 | } | 137 | } |
| @@ -4059,6 +4062,7 @@ mod tests { | |||
| 4059 | repeat_delay: 600, | 4062 | repeat_delay: 600, |
| 4060 | repeat_rate: 25, | 4063 | repeat_rate: 25, |
| 4061 | track_layout: Window, | 4064 | track_layout: Window, |
| 4065 | + numlock: false, | ||
| 4062 | }, | 4066 | }, |
| 4063 | touchpad: Touchpad { | 4067 | touchpad: Touchpad { |
| 4064 | off: false, | 4068 | off: false, |
resources/default-config.kdlmodified+3 -0
| @@ -16,6 +16,9 @@ input { | |||
| 16 | // layout "us,ru" | 16 | // layout "us,ru" |
| 17 | // options "grp:win_space_toggle,compose:ralt,ctrl:nocaps" | 17 | // options "grp:win_space_toggle,compose:ralt,ctrl:nocaps" |
| 18 | } | 18 | } |
| 19 | + | ||
| 20 | + // Enable numlock on startup, omitting this setting disables it. | ||
| 21 | + numlock | ||
| 19 | } | 22 | } |
| 20 | 23 | ||
| 21 | // Next sections include libinput settings. | 24 | // Next sections include libinput settings. |
src/niri.rsmodified+19 -11
| @@ -2248,22 +2248,30 @@ impl Niri { | |||
| 2248 | let single_pixel_buffer_state = SinglePixelBufferState::new::<State>(&display_handle); | 2248 | let single_pixel_buffer_state = SinglePixelBufferState::new::<State>(&display_handle); |
| 2249 | 2249 | ||
| 2250 | let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name()); | 2250 | let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name()); |
| 2251 | - if let Err(err) = seat.add_keyboard( | 2251 | + let keyboard = match seat.add_keyboard( |
| 2252 | config_.input.keyboard.xkb.to_xkb_config(), | 2252 | config_.input.keyboard.xkb.to_xkb_config(), |
| 2253 | config_.input.keyboard.repeat_delay.into(), | 2253 | config_.input.keyboard.repeat_delay.into(), |
| 2254 | config_.input.keyboard.repeat_rate.into(), | 2254 | config_.input.keyboard.repeat_rate.into(), |
| 2255 | ) { | 2255 | ) { |
| 2256 | - if let smithay::input::keyboard::Error::BadKeymap = err { | 2256 | + Err(err) => { |
| 2257 | - warn!("error loading the configured xkb keymap, trying default"); | 2257 | + if let smithay::input::keyboard::Error::BadKeymap = err { |
| 2258 | - } else { | 2258 | + warn!("error loading the configured xkb keymap, trying default"); |
| 2259 | - warn!("error adding keyboard: {err:?}"); | 2259 | + } else { |
| 2260 | + warn!("error adding keyboard: {err:?}"); | ||
| 2261 | + } | ||
| 2262 | + seat.add_keyboard( | ||
| 2263 | + Default::default(), | ||
| 2264 | + config_.input.keyboard.repeat_delay.into(), | ||
| 2265 | + config_.input.keyboard.repeat_rate.into(), | ||
| 2266 | + ) | ||
| 2267 | + .unwrap() | ||
| 2260 | } | 2268 | } |
| 2261 | - seat.add_keyboard( | 2269 | + Ok(keyboard) => keyboard, |
| 2262 | - Default::default(), | 2270 | + }; |
| 2263 | - config_.input.keyboard.repeat_delay.into(), | 2271 | + if config_.input.keyboard.numlock { |
| 2264 | - config_.input.keyboard.repeat_rate.into(), | 2272 | + let mut modifier_state = keyboard.modifier_state(); |
| 2265 | - ) | 2273 | + modifier_state.num_lock = true; |
| 2266 | - .unwrap(); | 2274 | + keyboard.set_modifier_state(modifier_state); |
| 2267 | } | 2275 | } |
| 2268 | seat.add_pointer(); | 2276 | seat.add_pointer(); |
| 2269 | 2277 | ||