-
Notifications
You must be signed in to change notification settings - Fork 171
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 API to manipulate XKB layouts #1188
Conversation
462006c
to
02005f8
Compare
While this is not ideal it does the job to implement basic layouts functionality like switching layout on compositor and propagating the change to client, resolving latin character for Keysym handles and set/restore layouts.
02005f8
to
97ff566
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1188 +/- ##
==========================================
- Coverage 22.00% 21.89% -0.11%
==========================================
Files 154 154
Lines 24094 24194 +100
==========================================
- Hits 5301 5298 -3
- Misses 18793 18896 +103
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
src/input/keyboard/mod.rs
Outdated
pub fn raw_latin_sym_or_raw_current_sym(&self) -> Option<Keysym> { | ||
let effective_layout = Layout(self.state.key_get_layout(self.keycode)); | ||
// NOTE: There's always a keysym in the current layout given that we have modified_sym. | ||
let base_sym = *self.raw_syms().first()?; | ||
|
||
// If the character is ascii or non-printable, return it. | ||
if base_sym.key_char().map(|ch| ch.is_ascii()).unwrap_or(true) { | ||
return Some(base_sym); | ||
}; | ||
|
||
// Try to look other layouts and find the one with ascii character. | ||
for layout in self.layouts() { | ||
if layout == effective_layout { | ||
continue; | ||
} | ||
|
||
for keysym in self.raw_syms_for_key_in_layout(self.keycode, layout) { | ||
// NOTE: Only check for ascii alphabetic since the rest of the punctuation should | ||
// be uniform across layouts. | ||
if keysym | ||
.key_char() | ||
.map(|key| key.is_ascii_alphabetic()) | ||
.unwrap_or(false) | ||
{ | ||
return Some(*keysym); | ||
} | ||
} | ||
} | ||
|
||
Some(base_sym) |
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 decided to go with something like that for now, it sort of works, even though not ideal, but it should be enough to not trigger bindings you don't want to trigger, like due to different Enter
locations. Not sure how it's relevant though.
There's no helper to check for latin, but key_char
logic sort of does that already.
pub fn raw_latin_sym_or_raw_current_sym(&self) -> Option<Keysym> { | ||
let effective_layout = Layout(self.state.key_get_layout(self.keycode)); | ||
// NOTE: There's always a keysym in the current layout given that we have modified_sym. | ||
let base_sym = *self.raw_syms().first()?; |
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 see xkb has key_get_one_sym
for when you only want a single keysym rather than multiple (it returns NoSymbol
in case there would be multiple), but I don't see a corresponding by_level
function. Maybe it would make sense to replicate this here by only proceeding when raw_syms()
has exactly one element. But also it's probably fine as is?
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.
it's fine as is, you need api for layout + level
, the thing I use is basically the only one available.
While this is not ideal it does the job to implement basic layouts
functionality like switching layout on compositor and propagating the
change to client, resolving latin character for Keysym handles and
set/restore layouts.
--
Showcase could be found here YaLTeR/niri#65