Reactivated num/caps-lock upon keyboard layour change
This commit is contained in:
parent
2728a9ee71
commit
2678cf41b2
2 changed files with 38 additions and 19 deletions
|
|
@ -94,23 +94,7 @@ pub fn init_backend_auto(
|
||||||
if toggle_numlock {
|
if toggle_numlock {
|
||||||
/// Linux scancode for numlock key.
|
/// Linux scancode for numlock key.
|
||||||
const NUMLOCK_SCANCODE: u32 = 69;
|
const NUMLOCK_SCANCODE: u32 = 69;
|
||||||
/// Offset used to convert Linux scancode to X11 keycode.
|
crate::config::change_modifier_state(&keyboard, NUMLOCK_SCANCODE, state);
|
||||||
const X11_KEYCODE_OFFSET: u32 = 8;
|
|
||||||
|
|
||||||
let mut input = |key_state| {
|
|
||||||
let time = state.common.clock.now().as_millis();
|
|
||||||
let _ = keyboard.input(
|
|
||||||
state,
|
|
||||||
smithay_input::Keycode::new(NUMLOCK_SCANCODE + X11_KEYCODE_OFFSET),
|
|
||||||
key_state,
|
|
||||||
SERIAL_COUNTER.next_serial(),
|
|
||||||
time,
|
|
||||||
|_, _, _| smithay::input::keyboard::FilterResult::<()>::Forward,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
// Press and release the numlock key to update modifiers.
|
|
||||||
input(smithay_input::KeyState::Pressed);
|
|
||||||
input(smithay_input::KeyState::Released);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use smithay::utils::{Clock, Monotonic};
|
use smithay::utils::{Clock, Monotonic};
|
||||||
use smithay::wayland::xdg_activation::XdgActivationState;
|
use smithay::wayland::xdg_activation::XdgActivationState;
|
||||||
pub use smithay::{
|
pub use smithay::{
|
||||||
backend::input::KeyState,
|
backend::input::{self as smithay_input, KeyState},
|
||||||
input::keyboard::{keysyms as KeySyms, Keysym, ModifiersState},
|
input::keyboard::{keysyms as KeySyms, Keysym, ModifiersState},
|
||||||
output::{Mode, Output},
|
output::{Mode, Output},
|
||||||
reexports::{
|
reexports::{
|
||||||
|
|
@ -25,7 +25,7 @@ pub use smithay::{
|
||||||
TapButtonMap,
|
TapButtonMap,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
utils::{Logical, Physical, Point, Size, Transform},
|
utils::{Logical, Physical, Point, Size, Transform, SERIAL_COUNTER},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
|
@ -694,6 +694,30 @@ fn update_input(state: &mut State) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn change_modifier_state(
|
||||||
|
keyboard: &smithay::input::keyboard::KeyboardHandle<State>,
|
||||||
|
scan_code: u32,
|
||||||
|
state: &mut State,
|
||||||
|
) {
|
||||||
|
/// Offset used to convert Linux scancode to X11 keycode.
|
||||||
|
const X11_KEYCODE_OFFSET: u32 = 8;
|
||||||
|
|
||||||
|
let mut input = |key_state, scan_code| {
|
||||||
|
let time = state.common.clock.now().as_millis();
|
||||||
|
let _ = keyboard.input(
|
||||||
|
state,
|
||||||
|
smithay_input::Keycode::new(scan_code + X11_KEYCODE_OFFSET),
|
||||||
|
key_state,
|
||||||
|
SERIAL_COUNTER.next_serial(),
|
||||||
|
time,
|
||||||
|
|_, _, _| smithay::input::keyboard::FilterResult::<()>::Forward,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
input(smithay_input::KeyState::Pressed, scan_code);
|
||||||
|
input(smithay_input::KeyState::Released, scan_code);
|
||||||
|
}
|
||||||
|
|
||||||
fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut State) {
|
fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut State) {
|
||||||
for key in &keys {
|
for key in &keys {
|
||||||
match key.as_str() {
|
match key.as_str() {
|
||||||
|
|
@ -710,6 +734,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
for seat in seats.into_iter() {
|
for seat in seats.into_iter() {
|
||||||
if let Some(keyboard) = seat.get_keyboard() {
|
if let Some(keyboard) = seat.get_keyboard() {
|
||||||
|
let old_modifier_state = keyboard.modifier_state();
|
||||||
keyboard.change_repeat_info(
|
keyboard.change_repeat_info(
|
||||||
(value.repeat_rate as i32).abs(), // Negative values are illegal
|
(value.repeat_rate as i32).abs(), // Negative values are illegal
|
||||||
(value.repeat_delay as i32).abs(),
|
(value.repeat_delay as i32).abs(),
|
||||||
|
|
@ -718,6 +743,16 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
|
||||||
error!(?err, "Failed to load provided xkb config");
|
error!(?err, "Failed to load provided xkb config");
|
||||||
// TODO Revert to default?
|
// TODO Revert to default?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Press and release the numlock key to update modifiers.
|
||||||
|
if old_modifier_state.num_lock != keyboard.modifier_state().num_lock {
|
||||||
|
const NUMLOCK_SCANCODE: u32 = 69;
|
||||||
|
change_modifier_state(&keyboard, NUMLOCK_SCANCODE, state);
|
||||||
|
}
|
||||||
|
if old_modifier_state.caps_lock != keyboard.modifier_state().caps_lock {
|
||||||
|
const CAPSLOCK_SCANCODE: u32 = 58;
|
||||||
|
change_modifier_state(&keyboard, CAPSLOCK_SCANCODE, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.common.atspi_ei.update_keymap(value.clone());
|
state.common.atspi_ei.update_keymap(value.clone());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue