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,38 +417,40 @@ 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) match touch_event {
.expect("Recieved touch event of non existing Seat"); TouchEvent::Down(down_event) => {
match touch_event { trace!(self.logger, "Calling on_touch_down with {:?}", down_event);
TouchEvent::Down(down_event) => { handler.on_touch_down(evlh, seat, down_event)
trace!(self.logger, "Calling on_touch_down with {:?}", down_event); }
handler.on_touch_down(evlh, seat, down_event) TouchEvent::Motion(motion_event) => {
} trace!(
TouchEvent::Motion(motion_event) => { self.logger,
trace!( "Calling on_touch_motion with {:?}",
self.logger, motion_event
"Calling on_touch_motion with {:?}", );
motion_event handler.on_touch_motion(evlh, seat, motion_event)
); }
handler.on_touch_motion(evlh, seat, motion_event) TouchEvent::Up(up_event) => {
} trace!(self.logger, "Calling on_touch_up with {:?}", up_event);
TouchEvent::Up(up_event) => { handler.on_touch_up(evlh, seat, up_event)
trace!(self.logger, "Calling on_touch_up with {:?}", up_event); }
handler.on_touch_up(evlh, seat, up_event) TouchEvent::Cancel(cancel_event) => {
} trace!(
TouchEvent::Cancel(cancel_event) => { self.logger,
trace!( "Calling on_touch_cancel with {:?}",
self.logger, cancel_event
"Calling on_touch_cancel with {:?}", );
cancel_event handler.on_touch_cancel(evlh, seat, cancel_event)
); }
handler.on_touch_cancel(evlh, seat, cancel_event) TouchEvent::Frame(frame_event) => {
} trace!(self.logger, "Calling on_touch_frame with {:?}", frame_event);
TouchEvent::Frame(frame_event) => { handler.on_touch_frame(evlh, seat, frame_event)
trace!(self.logger, "Calling on_touch_frame with {:?}", frame_event); }
handler.on_touch_frame(evlh, seat, frame_event)
} }
} else {
warn!(self.logger, "Recieved touch event of non existing Seat");
continue;
} }
} }
} }
@ -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) trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event);
.expect("Recieved key event of non existing Seat"); handler.on_keyboard_key(evlh, seat, key_event);
trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event); } else {
handler.on_keyboard_key(evlh, seat, key_event); warn!(self.logger, "Recieved key event of non existing Seat");
continue;
}
}, },
} }
} }
@ -463,67 +473,69 @@ 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) match pointer_event {
.expect("Recieved pointer event of non existing Seat"); PointerEvent::Motion(motion_event) => {
match pointer_event {
PointerEvent::Motion(motion_event) => {
trace!(
self.logger,
"Calling on_pointer_move with {:?}",
motion_event
);
handler.on_pointer_move(evlh, seat, motion_event);
}
PointerEvent::MotionAbsolute(motion_abs_event) => {
trace!(
self.logger,
"Calling on_pointer_move_absolute with {:?}",
motion_abs_event
);
handler.on_pointer_move_absolute(evlh, seat, motion_abs_event);
}
PointerEvent::Axis(axis_event) => {
let rc_axis_event = Rc::new(axis_event);
if rc_axis_event.has_axis(Axis::Vertical) {
trace!( trace!(
self.logger, self.logger,
"Calling on_pointer_axis for Axis::Vertical with {:?}", "Calling on_pointer_move with {:?}",
*rc_axis_event motion_event
);
handler.on_pointer_axis(
evlh,
seat,
self::PointerAxisEvent {
axis: Axis::Vertical,
event: rc_axis_event.clone(),
},
); );
handler.on_pointer_move(evlh, seat, motion_event);
} }
if rc_axis_event.has_axis(Axis::Horizontal) { PointerEvent::MotionAbsolute(motion_abs_event) => {
trace!( trace!(
self.logger, self.logger,
"Calling on_pointer_axis for Axis::Horizontal with {:?}", "Calling on_pointer_move_absolute with {:?}",
*rc_axis_event motion_abs_event
); );
handler.on_pointer_axis( handler.on_pointer_move_absolute(evlh, seat, motion_abs_event);
evlh, }
seat, PointerEvent::Axis(axis_event) => {
self::PointerAxisEvent { let rc_axis_event = Rc::new(axis_event);
axis: Axis::Horizontal, if rc_axis_event.has_axis(Axis::Vertical) {
event: rc_axis_event.clone(), trace!(
}, self.logger,
"Calling on_pointer_axis for Axis::Vertical with {:?}",
*rc_axis_event
);
handler.on_pointer_axis(
evlh,
seat,
self::PointerAxisEvent {
axis: Axis::Vertical,
event: rc_axis_event.clone(),
},
);
}
if rc_axis_event.has_axis(Axis::Horizontal) {
trace!(
self.logger,
"Calling on_pointer_axis for Axis::Horizontal with {:?}",
*rc_axis_event
);
handler.on_pointer_axis(
evlh,
seat,
self::PointerAxisEvent {
axis: Axis::Horizontal,
event: rc_axis_event.clone(),
},
);
}
}
PointerEvent::Button(button_event) => {
trace!(
self.logger,
"Calling on_pointer_button with {:?}",
button_event
); );
handler.on_pointer_button(evlh, seat, button_event);
} }
} }
PointerEvent::Button(button_event) => { } else {
trace!( warn!(self.logger, "Recieved pointer event of non existing Seat");
self.logger, continue;
"Calling on_pointer_button with {:?}",
button_event
);
handler.on_pointer_button(evlh, seat, button_event);
}
} }
} }
} }