seat: Add unique id
This commit is contained in:
parent
b884b91068
commit
b64071b068
2 changed files with 28 additions and 1 deletions
|
|
@ -20,10 +20,26 @@ use smithay::{
|
||||||
use std::{cell::RefCell, collections::HashMap};
|
use std::{cell::RefCell, collections::HashMap};
|
||||||
use xkbcommon::xkb::KEY_XF86Switch_VT_12;
|
use xkbcommon::xkb::KEY_XF86Switch_VT_12;
|
||||||
|
|
||||||
|
crate::utils::id_gen!(next_seat_id, SEAT_ID, SEAT_IDS);
|
||||||
|
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct SeatId(pub usize);
|
||||||
pub struct ActiveOutput(pub RefCell<Output>);
|
pub struct ActiveOutput(pub RefCell<Output>);
|
||||||
pub struct SupressedKeys(RefCell<Vec<u32>>);
|
pub struct SupressedKeys(RefCell<Vec<u32>>);
|
||||||
pub struct Devices(RefCell<HashMap<String, Vec<DeviceCapability>>>);
|
pub struct Devices(RefCell<HashMap<String, Vec<DeviceCapability>>>);
|
||||||
|
|
||||||
|
impl Default for SeatId {
|
||||||
|
fn default() -> SeatId {
|
||||||
|
SeatId(next_seat_id())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for SeatId {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
SEAT_IDS.lock().unwrap().remove(&self.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SupressedKeys {
|
impl SupressedKeys {
|
||||||
fn new() -> SupressedKeys {
|
fn new() -> SupressedKeys {
|
||||||
SupressedKeys(RefCell::new(Vec::new()))
|
SupressedKeys(RefCell::new(Vec::new()))
|
||||||
|
|
@ -84,6 +100,7 @@ impl Devices {
|
||||||
pub fn add_seat(dh: &DisplayHandle, name: String) -> Seat<State> {
|
pub fn add_seat(dh: &DisplayHandle, name: String) -> Seat<State> {
|
||||||
let seat = Seat::<State>::new(dh, name, None);
|
let seat = Seat::<State>::new(dh, name, None);
|
||||||
let userdata = seat.user_data();
|
let userdata = seat.user_data();
|
||||||
|
userdata.insert_if_missing(SeatId::default);
|
||||||
userdata.insert_if_missing(|| Devices::new());
|
userdata.insert_if_missing(|| Devices::new());
|
||||||
userdata.insert_if_missing(|| SupressedKeys::new());
|
userdata.insert_if_missing(|| SupressedKeys::new());
|
||||||
userdata.insert_if_missing(|| RefCell::new(CursorImageStatus::Default));
|
userdata.insert_if_missing(|| RefCell::new(CursorImageStatus::Default));
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{input::ActiveOutput, state::Common};
|
use crate::{input::{ActiveOutput, SeatId}, state::Common};
|
||||||
use smithay::{
|
use smithay::{
|
||||||
utils::{Logical, Rectangle, Transform},
|
utils::{Logical, Rectangle, Transform},
|
||||||
wayland::{output::Output, seat::Seat},
|
wayland::{output::Output, seat::Seat},
|
||||||
|
|
@ -28,6 +28,16 @@ impl OutputExt for Output {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait SeatExt {
|
||||||
|
fn id(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SeatExt for Seat<State> {
|
||||||
|
fn id(&self) -> usize {
|
||||||
|
self.user_data().get::<SeatId>().unwrap().0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn active_output(seat: &Seat<State>, state: &Common) -> Output {
|
pub fn active_output(seat: &Seat<State>, state: &Common) -> Output {
|
||||||
seat.user_data()
|
seat.user_data()
|
||||||
.get::<ActiveOutput>()
|
.get::<ActiveOutput>()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue