Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl WaylandPayload {
for _ in 0..count[0] {
self.keyboard_context.generate_key_repeat_events(
&mut self.xkb,
self.keymap.xkb_keymap,
&self.keymap,
self.xkb_state,
&mut self.events,
);
Expand All @@ -127,7 +127,7 @@ impl WaylandPayload {
// the message string is not accessible to us.
match errno {
0 => (),
EPROTO => {
libc::EPROTO => {
let mut interface: *const wl_interface = std::ptr::null();
let mut id = 0;
let code = (self.client.wl_display_get_protocol_error)(
Expand Down Expand Up @@ -225,7 +225,6 @@ struct KeyboardContext {
/// This is the actual key being sent by Wayland, not `keysym` or Miniquad `Keycode`
repeated_key: Option<core::ffi::c_uint>,
timerfd: core::ffi::c_int,
keymods: KeyMods,
}

fn new_itimerspec() -> libc::itimerspec {
Expand All @@ -248,7 +247,6 @@ impl KeyboardContext {
repeat_info: Default::default(),
repeated_key: None,
timerfd: unsafe { libc::timerfd_create(libc::CLOCK_MONOTONIC, libc::TFD_CLOEXEC) },
keymods: Default::default(),
}
}
fn track_key_down(&mut self, key: core::ffi::c_uint) {
Expand Down Expand Up @@ -278,34 +276,36 @@ impl KeyboardContext {
unsafe fn generate_key_repeat_events(
&self,
libxkb: &mut LibXkbCommon,
xkb_keymap: *mut xkb_keymap,
keymap: &XkbKeymap,
xkb_state: *mut xkb_state,
events: &mut Vec<WaylandEvent>,
) {
if let Some(key) = self.repeated_key {
self.generate_key_events(libxkb, xkb_keymap, xkb_state, key, true, events)
self.generate_key_events(libxkb, keymap, xkb_state, key, true, events)
}
}
unsafe fn generate_key_events(
&self,
libxkb: &mut LibXkbCommon,
xkb_keymap: *mut xkb_keymap,
keymap: &XkbKeymap,
xkb_state: *mut xkb_state,
key: core::ffi::c_uint,
repeat: bool,
events: &mut Vec<WaylandEvent>,
) {
let keymods = keymap.get_keymods(libxkb, xkb_state);

// The keycodes in Miniquad are obtained without modifiers
let keysym = libxkb.keymap_key_get_sym_without_mod(xkb_keymap, key + 8);
let keysym = libxkb.keymap_key_get_sym_without_mod(keymap.xkb_keymap, key + 8);
let keycode = keycodes::translate_keysym(keysym);
events.push(WaylandEvent::KeyDown(keycode, self.keymods, repeat));
events.push(WaylandEvent::KeyDown(keycode, keymods, repeat));

// To obtain the underlying character, we do need to provide the modifiers
let keysym = (libxkb.xkb_state_key_get_one_sym)(xkb_state, key + 8);
let chr = (libxkb.xkb_keysym_to_utf32)(keysym);
if chr > 0 {
if let Some(chr) = char::from_u32(chr) {
events.push(WaylandEvent::Char(chr, self.keymods, repeat));
events.push(WaylandEvent::Char(chr, keymods, repeat));
}
}
}
Expand Down Expand Up @@ -595,7 +595,6 @@ unsafe extern "C" fn keyboard_handle_leave(
// Clear modifiers
let display: &mut WaylandPayload = &mut *(data as *mut _);
(display.xkb.xkb_state_update_mask)(display.xkb_state, 0, 0, 0, 0, 0, 0);
display.keyboard_context.keymods = KeyMods::default();
display.keyboard_context.repeated_key = None;
display.keyboard_context.enter_serial = None;
display.events.push(WaylandEvent::WindowMinimized);
Expand All @@ -617,7 +616,6 @@ unsafe extern "C" fn keyboard_handle_key(
let keysym = libxkb.keymap_key_get_sym_without_mod(xkb_keymap, key + 8);
let keycode = keycodes::translate_keysym(keysym);
let keymods = display.keymap.get_keymods(libxkb, xkb_state);
display.keyboard_context.keymods = keymods;
match state {
0 => {
display.keyboard_context.track_key_up(key);
Expand All @@ -631,7 +629,7 @@ unsafe extern "C" fn keyboard_handle_key(
}
display.keyboard_context.generate_key_events(
libxkb,
xkb_keymap,
&display.keymap,
xkb_state,
key,
repeat,
Expand Down
5 changes: 0 additions & 5 deletions src/native/linux_wayland/libwayland_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ pub const WL_SUBSURFACE_PLACE_BELOW_SINCE_VERSION: u32 = 1;
pub const WL_SUBSURFACE_SET_SYNC_SINCE_VERSION: u32 = 1;
pub const WL_SUBSURFACE_SET_DESYNC_SINCE_VERSION: u32 = 1;

pub const ENOMEM: c_int = 12;
pub const EFAULT: c_int = 14;
pub const EINVAL: c_int = 22;
pub const EPROTO: c_int = 71;

pub type wl_shm_format = ::core::ffi::c_uint;

pub const wl_shm_format_WL_SHM_FORMAT_ARGB8888: wl_shm_format = 0;
Expand Down
Loading