Use entry api for `DeviceAddedEvent`s seat creation/update
This commit is contained in:
parent
10857d108e
commit
ab35f140a0
|
@ -6,7 +6,7 @@ use input::{Libinput, Device, Seat as LibinputSeat, DeviceCapability};
|
||||||
use input::event::*;
|
use input::event::*;
|
||||||
|
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
use std::collections::hash_map::{DefaultHasher, HashMap};
|
use std::collections::hash_map::{DefaultHasher, Entry, HashMap};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
pub struct LibinputInputBackend {
|
pub struct LibinputInputBackend {
|
||||||
|
@ -73,9 +73,9 @@ impl InputBackend for LibinputInputBackend {
|
||||||
let device_seat = added.seat();
|
let device_seat = added.seat();
|
||||||
self.devices.push(added);
|
self.devices.push(added);
|
||||||
|
|
||||||
let contains = self.seats.contains_key(&device_seat);
|
match self.seats.entry(device_seat) {
|
||||||
if contains {
|
Entry::Occupied(mut seat_entry) => {
|
||||||
let old_seat = self.seats.get_mut(&device_seat).unwrap();
|
let old_seat = seat_entry.get_mut();
|
||||||
{
|
{
|
||||||
let caps = old_seat.capabilities_mut();
|
let caps = old_seat.capabilities_mut();
|
||||||
caps.pointer = new_caps.pointer || caps.pointer;
|
caps.pointer = new_caps.pointer || caps.pointer;
|
||||||
|
@ -85,12 +85,14 @@ impl InputBackend for LibinputInputBackend {
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
handler.on_seat_changed(old_seat);
|
handler.on_seat_changed(old_seat);
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
|
Entry::Vacant(seat_entry) => {
|
||||||
let mut hasher = DefaultHasher::default();
|
let mut hasher = DefaultHasher::default();
|
||||||
device_seat.hash(&mut hasher);
|
seat_entry.key().hash(&mut hasher);
|
||||||
self.seats.insert(device_seat.clone(), Seat::new(hasher.finish(), new_caps));
|
let seat = seat_entry.insert(Seat::new(hasher.finish(), new_caps));
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
handler.on_seat_created(self.seats.get(&device_seat).unwrap());
|
handler.on_seat_created(seat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue