Add Caps Lock support (#30470)
Closes #21700 Release Notes: - Added caps lock support and show a warning if the user is entering an SSH password with Caps Lock enabled --------- Co-authored-by: Mikayla Maki <mikayla@zed.dev> Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com> Co-authored-by: 张小白 <364772080@qq.com>
This commit is contained in:
parent
e47c48fd3b
commit
90aa99bb14
16 changed files with 146 additions and 31 deletions
|
@ -1,3 +1,4 @@
|
|||
use crate::Capslock;
|
||||
use core::str;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
|
@ -203,8 +204,11 @@ pub struct X11ClientState {
|
|||
pub(crate) ximc: Option<X11rbClient<Rc<XCBConnection>>>,
|
||||
pub(crate) xim_handler: Option<XimHandler>,
|
||||
pub modifiers: Modifiers,
|
||||
pub capslock: Capslock,
|
||||
// TODO: Can the other updates to `modifiers` be removed so that this is unnecessary?
|
||||
// capslock logic was done analog to modifiers
|
||||
pub last_modifiers_changed_event: Modifiers,
|
||||
pub last_capslock_changed_event: Capslock,
|
||||
|
||||
pub(crate) compose_state: Option<xkbc::compose::State>,
|
||||
pub(crate) pre_edit_text: Option<String>,
|
||||
|
@ -473,7 +477,9 @@ impl X11Client {
|
|||
|
||||
X11Client(Rc::new(RefCell::new(X11ClientState {
|
||||
modifiers: Modifiers::default(),
|
||||
capslock: Capslock::default(),
|
||||
last_modifiers_changed_event: Modifiers::default(),
|
||||
last_capslock_changed_event: Capslock::default(),
|
||||
event_loop: Some(event_loop),
|
||||
loop_handle: handle,
|
||||
common,
|
||||
|
@ -961,17 +967,25 @@ impl X11Client {
|
|||
};
|
||||
|
||||
let modifiers = Modifiers::from_xkb(&state.xkb);
|
||||
if state.last_modifiers_changed_event == modifiers {
|
||||
let capslock = Capslock::from_xkb(&state.xkb);
|
||||
if state.last_modifiers_changed_event == modifiers
|
||||
&& state.last_capslock_changed_event == capslock
|
||||
{
|
||||
drop(state);
|
||||
} else {
|
||||
let focused_window_id = state.keyboard_focused_window?;
|
||||
state.modifiers = modifiers;
|
||||
state.last_modifiers_changed_event = modifiers;
|
||||
state.capslock = capslock;
|
||||
state.last_capslock_changed_event = capslock;
|
||||
drop(state);
|
||||
|
||||
let focused_window = self.get_window(focused_window_id)?;
|
||||
focused_window.handle_input(PlatformInput::ModifiersChanged(
|
||||
ModifiersChangedEvent { modifiers },
|
||||
ModifiersChangedEvent {
|
||||
modifiers,
|
||||
capslock,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue