Fix libinput panic on tty switch

This commit is contained in:
Drakulix 2018-01-27 13:04:42 +01:00
parent 495c492e50
commit 5411209bb5
1 changed files with 104 additions and 92 deletions

View File

@ -381,7 +381,8 @@ impl backend::InputBackend for LibinputInputBackend {
.filter(|x| x.seat() == device_seat) .filter(|x| x.seat() == device_seat)
.any(|x| x.has_capability(libinput::DeviceCapability::Touch)); .any(|x| x.has_capability(libinput::DeviceCapability::Touch));
} else { } else {
panic!("Seat changed that was never created") warn!(self.logger, "Seat changed that was never created");
continue;
} }
// check if the seat has any other devices // check if the seat has any other devices
@ -393,13 +394,18 @@ impl backend::InputBackend for LibinputInputBackend {
handler.on_seat_destroyed(evlh, &seat); handler.on_seat_destroyed(evlh, &seat);
} }
} else { } else {
panic!("Seat destroyed that was never created"); warn!(self.logger, "Seat destroyed that was never created");
continue;
} }
// it has, notify about updates // it has, notify about updates
} else if let Some(ref mut handler) = self.handler { } else if let Some(ref mut handler) = self.handler {
let seat = &self.seats[&device_seat]; if let Some(seat) = self.seats.get(&device_seat) {
trace!(self.logger, "Calling on_seat_changed with {:?}", seat); trace!(self.logger, "Calling on_seat_changed with {:?}", seat);
handler.on_seat_changed(evlh, seat); handler.on_seat_changed(evlh, &seat);
} else {
warn!(self.logger, "Seat changed that was never created");
continue;
}
} }
} }
} }
@ -411,9 +417,7 @@ impl backend::InputBackend for LibinputInputBackend {
use input::event::touch::*; use input::event::touch::*;
if let Some(ref mut handler) = self.handler { if let Some(ref mut handler) = self.handler {
let device_seat = touch_event.device().seat(); let device_seat = touch_event.device().seat();
let seat = &self.seats if let &Some(ref seat) = &self.seats.get(&device_seat) {
.get(&device_seat)
.expect("Recieved touch event of non existing Seat");
match touch_event { match touch_event {
TouchEvent::Down(down_event) => { TouchEvent::Down(down_event) => {
trace!(self.logger, "Calling on_touch_down with {:?}", down_event); trace!(self.logger, "Calling on_touch_down with {:?}", down_event);
@ -444,6 +448,10 @@ impl backend::InputBackend for LibinputInputBackend {
handler.on_touch_frame(evlh, seat, frame_event) handler.on_touch_frame(evlh, seat, frame_event)
} }
} }
} else {
warn!(self.logger, "Recieved touch event of non existing Seat");
continue;
}
} }
} }
libinput::Event::Keyboard(keyboard_event) => { libinput::Event::Keyboard(keyboard_event) => {
@ -451,11 +459,13 @@ impl backend::InputBackend for LibinputInputBackend {
match keyboard_event { match keyboard_event {
KeyboardEvent::Key(key_event) => if let Some(ref mut handler) = self.handler { KeyboardEvent::Key(key_event) => if let Some(ref mut handler) = self.handler {
let device_seat = key_event.device().seat(); let device_seat = key_event.device().seat();
let seat = &self.seats if let &Some(ref seat) = &self.seats.get(&device_seat) {
.get(&device_seat)
.expect("Recieved key event of non existing Seat");
trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event); trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event);
handler.on_keyboard_key(evlh, seat, key_event); handler.on_keyboard_key(evlh, seat, key_event);
} else {
warn!(self.logger, "Recieved key event of non existing Seat");
continue;
}
}, },
} }
} }
@ -463,9 +473,7 @@ impl backend::InputBackend for LibinputInputBackend {
use input::event::pointer::*; use input::event::pointer::*;
if let Some(ref mut handler) = self.handler { if let Some(ref mut handler) = self.handler {
let device_seat = pointer_event.device().seat(); let device_seat = pointer_event.device().seat();
let seat = &self.seats if let &Some(ref seat) = &self.seats.get(&device_seat) {
.get(&device_seat)
.expect("Recieved pointer event of non existing Seat");
match pointer_event { match pointer_event {
PointerEvent::Motion(motion_event) => { PointerEvent::Motion(motion_event) => {
trace!( trace!(
@ -525,6 +533,10 @@ impl backend::InputBackend for LibinputInputBackend {
handler.on_pointer_button(evlh, seat, button_event); handler.on_pointer_button(evlh, seat, button_event);
} }
} }
} else {
warn!(self.logger, "Recieved pointer event of non existing Seat");
continue;
}
} }
} }
_ => {} //FIXME: What to do with the rest. _ => {} //FIXME: What to do with the rest.