window: x11: remove a little redundant code from key processing
This commit is contained in:
1 parent
ba9bc30b79
commit
d6a9ed5ae7
2 files changed
+14
-28
No files matched your search
@@ -1,5 +1,5 @@
|
||||
use crate::os::xkeysyms::keysym_to_keycode;
|
||||
use crate::{KeyCode, Modifiers};
|
||||
use crate::{KeyEvent, Modifiers};
|
||||
use anyhow::{anyhow, ensure};
|
||||
use libc;
|
||||
use std::cell::RefCell;
|
||||
@@ -102,7 +102,7 @@ impl Keyboard {
|
||||
Ok((kbd, first_ev))
|
||||
}
|
||||
|
||||
pub fn process_key_event(&self, xcb_ev: &xcb::KeyPressEvent) -> Option<(KeyCode, Modifiers)> {
|
||||
pub fn process_key_event(&self, xcb_ev: &xcb::KeyPressEvent) -> Option<KeyEvent> {
|
||||
let pressed = (xcb_ev.response_type() & !0x80) == xcb::KEY_PRESS;
|
||||
|
||||
let xcode = xkb::Keycode::from(xcb_ev.detail());
|
||||
@@ -132,22 +132,16 @@ impl Keyboard {
|
||||
xsym
|
||||
};
|
||||
|
||||
// could be from_u32_unchecked
|
||||
let ks_char = std::char::from_u32(xkb::keysym_to_utf32(ksym));
|
||||
let kc = keysym_to_keycode(ksym).or_else(|| keysym_to_keycode(xsym))?;
|
||||
|
||||
let kc = match ks_char {
|
||||
Some(c) if (c as u32) >= 0x20 => KeyCode::Char(c),
|
||||
_ => {
|
||||
if let Some(key) = keysym_to_keycode(xsym) {
|
||||
key
|
||||
} else {
|
||||
log::debug!("xkbc:Missing xcb keysym 0x{:x} definition", xsym);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Some((kc, self.get_key_modifiers()))
|
||||
Some(KeyEvent {
|
||||
key: kc,
|
||||
modifiers: self.get_key_modifiers(),
|
||||
raw_key: None,
|
||||
raw_modifiers: Default::default(),
|
||||
repeat_count: 1,
|
||||
key_is_down: pressed,
|
||||
})
|
||||
}
|
||||
|
||||
fn mod_is_active(&self, modifier: &str) -> bool {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::connection::ConnectionOps;
|
||||
use crate::os::xkeysyms;
|
||||
use crate::os::{Connection, Window};
|
||||
use crate::{
|
||||
Clipboard, Color, Dimensions, KeyEvent, MouseButtons, MouseCursor, MouseEvent, MouseEventKind,
|
||||
Clipboard, Color, Dimensions, MouseButtons, MouseCursor, MouseEvent, MouseEventKind,
|
||||
MousePress, Operator, PaintContext, Point, Rect, ScreenPoint, Size, WindowCallbacks, WindowOps,
|
||||
WindowOpsMut,
|
||||
};
|
||||
@@ -352,16 +352,8 @@ impl XWindowInner {
|
||||
xcb::KEY_PRESS | xcb::KEY_RELEASE => {
|
||||
let key_press: &xcb::KeyPressEvent = unsafe { xcb::cast_event(event) };
|
||||
self.copy_and_paste.time = key_press.time();
|
||||
if let Some((code, mods)) = conn.keyboard.process_key_event(key_press) {
|
||||
let key = KeyEvent {
|
||||
key: code,
|
||||
raw_key: None,
|
||||
raw_modifiers: Default::default(),
|
||||
modifiers: mods,
|
||||
repeat_count: 1,
|
||||
key_is_down: r == xcb::KEY_PRESS,
|
||||
}
|
||||
.normalize_shift();
|
||||
if let Some(key) = conn.keyboard.process_key_event(key_press) {
|
||||
let key = key.normalize_shift();
|
||||
self.callbacks
|
||||
.key_event(&key, &XWindow::from_id(self.window_id));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user