On X11, use events modifiers to detect state

While there's a separate event to deliver modifiers for keyboard,
unfortunately, it's not even remotely reflects the modifiers state.

Thus use events along side regular modifier updates to correctly
detect the state. Also, apply the modifiers from the regular
key event by converting their state to xkb modifiers state.

Links: https://github.com/alacritty/alacritty/issues/7549
Closes: #3388
This commit is contained in:
Kirill Chibisov 2024-02-18 01:39:42 +04:00 committed by GitHub
parent db41938deb
commit e61a7320a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 1166 additions and 775 deletions

View file

@ -28,12 +28,13 @@ use x11rb::protocol::xproto::{self, ConnectionExt as _};
use x11rb::x11_utils::X11Error as LogicalError;
use x11rb::xcb_ffi::ReplyOrIdError;
use super::{common::xkb_state::KbdState, ControlFlow, OsError};
use super::{ControlFlow, OsError};
use crate::{
error::{EventLoopError, OsError as RootOsError},
event::{Event, StartCause, WindowEvent},
event_loop::{DeviceEvents, EventLoopClosed, EventLoopWindowTarget as RootELW},
platform::pump_events::PumpStatus,
platform_impl::common::xkb::Context,
platform_impl::platform::{min_timeout, WindowId},
window::WindowAttributes,
};
@ -281,8 +282,8 @@ impl<T: 'static> EventLoop<T> {
// Create a channel for sending user events.
let (user_sender, user_channel) = mpsc::channel();
let kb_state =
KbdState::from_x11_xkb(xconn.xcb_connection().get_raw_xcb_connection()).unwrap();
let xkb_context =
Context::from_x11_xkb(xconn.xcb_connection().get_raw_xcb_connection()).unwrap();
let window_target = EventLoopWindowTarget {
ime,
@ -322,7 +323,7 @@ impl<T: 'static> EventLoop<T> {
ime_event_receiver,
xi2ext,
xkbext,
kb_state,
xkb_context,
num_touch: 0,
held_key_press: None,
first_touch: None,