Skip to content
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

Make numlock state on boot configurable #1107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Nashenas88
Copy link
Contributor

This will expose 3 settings for numlock behavior:

  1. Numlock is off on boot (this is the current default behavior)
  2. Numlock is on on boot
  3. Numlock will restore the state from the last boot

Fixes #369

@git-f0x
Copy link
Contributor

git-f0x commented Jan 3, 2025

Would it maybe be better to always just use the state from last boot, rather than needing additional settings?
Though I might not be aware of cases where restoring the previous state would be undesirable.

@wiiznokes
Copy link

Would it maybe be better to always just use the state from last boot, rather than needing additional settings? Though I might not be aware of cases where restoring the previous state would be undesirable.

Maybe to have the same (clean) state when booting. I don't think having an option for this is a bad thing as long as it configurable via config files

@zanaviska
Copy link

Could this PR possible fix the bug when num-lock resets to default(or it just turns off?) when switching keyboard languages?

@Nashenas88
Copy link
Contributor Author

@git-f0x I just based it off my own preference and by what's available in other systems.
@wiiznokes it's been designed to be configured through config files. This PR does not touch cosmic settings, but there's no reason GUI controls couldn't be added as well.
@zanaviska I didn't specifically build for that so I'm not sure.

Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. :)

@@ -172,7 +172,7 @@ pub fn create_seat(
output: &Output,
config: &Config,
name: String,
) -> Seat<State> {
) -> (Seat<State>, KeyboardHandle<State>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not change this api. We can simply call initial_seat.get_keyboard() afterwards to get the keyboard.

src/input/mod.rs Outdated
@@ -1449,6 +1449,19 @@ impl State {
event.time() as u64 * 1000,
);

// If the numlock key is pressed ...
if event.key_code() == Keycode::new(77) && event.state() == KeyState::Pressed {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This completely ignores the fact, that we might filter out this event, which would cause the state to mismatch with the actual numlock state.

Instead we should check if the modifiers_state has changed after processing keyboard input, e.g. after line 242.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hint: We also don't want to write the file on every potential keyboard event, so we need to compare the old value with the new one, without numlock_mut().

let time = state.common.clock.now().as_millis();
let _ = keyboard.input(
state,
smithay_input::Keycode::new(77),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike magic numbers, can you please add a const KEY_NUMLOCK = 69 to the beginning of this file and do KEY_NUMLOCK + 8 here?

Copy link

@zanaviska zanaviska Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, KEY_NUMLOCK + 8 is equally magical as 77 is. But maybe in this context 8 is somewhat standart offset. That is not for me to judge

Nashenas88 and others added 2 commits January 25, 2025 22:00
This will expose 3 settings for numlock behavior:
1. Numlock is off on boot (this is the current default behavior)
2. Numlock is on on boot
3. Numlock will restore the state from the last boot

Fixes pop-os#369
Get keyboard after create_seat called rather than returning from
create_seat.
Use constants rather than magic numbers for keypress.
Only save updated modifier state after keypresses are handled/skipped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Remember Num Lock state
5 participants