seat: Make render-related state thread-safe
This commit is contained in:
parent
bd58481d19
commit
c7d50e7c5b
11 changed files with 137 additions and 112 deletions
|
|
@ -1197,13 +1197,15 @@ impl PointerTarget<State> for CosmicStack {
|
|||
};
|
||||
let _old_focus = p.swap_focus(Some(next));
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat
|
||||
let mut cursor_state = seat
|
||||
.user_data()
|
||||
.get::<RefCell<CursorImageStatus>>()
|
||||
.get::<CursorState>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
*cursor_status.borrow_mut() = CursorImageStatus::default_named();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
});
|
||||
|
||||
event.location -= self.0.with_program(|p| {
|
||||
|
|
@ -1225,13 +1227,15 @@ impl PointerTarget<State> for CosmicStack {
|
|||
};
|
||||
let _previous = p.swap_focus(Some(next));
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat
|
||||
let mut cursor_state = seat
|
||||
.user_data()
|
||||
.get::<RefCell<CursorImageStatus>>()
|
||||
.get::<CursorState>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
*cursor_status.borrow_mut() = CursorImageStatus::default_named();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
});
|
||||
|
||||
let active_window_geo = self.0.with_program(|p| {
|
||||
|
|
@ -1322,7 +1326,12 @@ impl PointerTarget<State> for CosmicStack {
|
|||
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
self.0.with_program(|p| {
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
let mut cursor_state = seat
|
||||
.user_data()
|
||||
.get::<CursorState>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
cursor_state.set_shape(CursorShape::Default);
|
||||
let _previous = p.swap_focus(None);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ use smithay::{
|
|||
};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
cell::RefCell,
|
||||
fmt,
|
||||
hash::Hash,
|
||||
sync::{
|
||||
|
|
@ -686,12 +685,9 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
assert_eq!(old_focus, None);
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat
|
||||
.user_data()
|
||||
.get::<RefCell<CursorImageStatus>>()
|
||||
.unwrap();
|
||||
*cursor_status.borrow_mut() = CursorImageStatus::default_named();
|
||||
cursor_state.lock().unwrap().set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -709,12 +705,9 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
let _previous = p.swap_focus(Some(next));
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(next.cursor_shape());
|
||||
let cursor_status = seat
|
||||
.user_data()
|
||||
.get::<RefCell<CursorImageStatus>>()
|
||||
.unwrap();
|
||||
*cursor_status.borrow_mut() = CursorImageStatus::default_named();
|
||||
cursor_state.lock().unwrap().set_shape(next.cursor_shape());
|
||||
let cursor_status = seat.user_data().get::<Mutex<CursorImageStatus>>().unwrap();
|
||||
*cursor_status.lock().unwrap() = CursorImageStatus::default_named();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -794,7 +787,7 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
self.0.with_program(|p| {
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(CursorShape::Default);
|
||||
cursor_state.lock().unwrap().set_shape(CursorShape::Default);
|
||||
let _previous = p.swap_focus(None);
|
||||
});
|
||||
PointerTarget::leave(&self.0, seat, data, serial, time)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use smithay::{
|
|||
shell::wlr_layer::{KeyboardInteractivity, Layer},
|
||||
},
|
||||
};
|
||||
use std::{borrow::Cow, cell::RefCell};
|
||||
use std::{borrow::Cow, sync::Mutex};
|
||||
use tracing::{debug, trace};
|
||||
|
||||
use self::target::{KeyboardFocusTarget, WindowGroup};
|
||||
|
|
@ -77,27 +77,28 @@ impl<'a> FocusStackMut<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ActiveFocus(RefCell<Option<KeyboardFocusTarget>>);
|
||||
pub struct ActiveFocus(Mutex<Option<KeyboardFocusTarget>>);
|
||||
|
||||
impl ActiveFocus {
|
||||
fn set(seat: &Seat<State>, target: Option<KeyboardFocusTarget>) {
|
||||
if !seat
|
||||
.user_data()
|
||||
.insert_if_missing(|| ActiveFocus(RefCell::new(target.clone())))
|
||||
.insert_if_missing_threadsafe(|| ActiveFocus(Mutex::new(target.clone())))
|
||||
{
|
||||
*seat
|
||||
.user_data()
|
||||
.get::<ActiveFocus>()
|
||||
.unwrap()
|
||||
.0
|
||||
.borrow_mut() = target;
|
||||
.lock()
|
||||
.unwrap() = target;
|
||||
}
|
||||
}
|
||||
|
||||
fn get(seat: &Seat<State>) -> Option<KeyboardFocusTarget> {
|
||||
seat.user_data()
|
||||
.get::<ActiveFocus>()
|
||||
.and_then(|a| a.0.borrow().clone())
|
||||
.and_then(|a| a.0.lock().unwrap().clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
use std::{
|
||||
cell::RefCell,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc, Mutex,
|
||||
};
|
||||
|
||||
use calloop::LoopHandle;
|
||||
|
|
@ -57,7 +54,7 @@ pub use self::default::*;
|
|||
pub struct MenuGrabState {
|
||||
elements: Arc<Mutex<Vec<Element>>>,
|
||||
}
|
||||
pub type SeatMenuGrabState = RefCell<Option<MenuGrabState>>;
|
||||
pub type SeatMenuGrabState = Mutex<Option<MenuGrabState>>;
|
||||
|
||||
impl MenuGrabState {
|
||||
pub fn render<I, R>(&self, renderer: &mut R, output: &Output) -> Vec<I>
|
||||
|
|
@ -228,7 +225,8 @@ impl Program for ContextMenu {
|
|||
.user_data()
|
||||
.get::<SeatMenuGrabState>()
|
||||
.unwrap()
|
||||
.borrow_mut();
|
||||
.lock()
|
||||
.unwrap();
|
||||
|
||||
if let Some(grab_state) = &*grab_state {
|
||||
let mut elements = grab_state.elements.lock().unwrap();
|
||||
|
|
@ -320,7 +318,8 @@ impl Program for ContextMenu {
|
|||
.user_data()
|
||||
.get::<SeatMenuGrabState>()
|
||||
.unwrap()
|
||||
.borrow_mut();
|
||||
.lock()
|
||||
.unwrap();
|
||||
|
||||
if let Some(grab_state) = &*grab_state {
|
||||
let mut elements = grab_state.elements.lock().unwrap();
|
||||
|
|
@ -713,7 +712,8 @@ impl MenuGrab {
|
|||
.user_data()
|
||||
.get::<SeatMenuGrabState>()
|
||||
.unwrap()
|
||||
.borrow_mut() = Some(grab_state);
|
||||
.lock()
|
||||
.unwrap() = Some(grab_state);
|
||||
|
||||
MenuGrab {
|
||||
elements,
|
||||
|
|
@ -729,7 +729,8 @@ impl Drop for MenuGrab {
|
|||
.user_data()
|
||||
.get::<SeatMenuGrabState>()
|
||||
.unwrap()
|
||||
.borrow_mut()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.take();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,11 +44,15 @@ use smithay::{
|
|||
output::Output,
|
||||
utils::{IsAlive, Logical, Point, Rectangle, Scale, Serial, SERIAL_COUNTER},
|
||||
};
|
||||
use std::{cell::RefCell, collections::HashSet, sync::atomic::Ordering, time::Instant};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
sync::{atomic::Ordering, Mutex},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use super::{GrabStartData, ReleaseMode};
|
||||
|
||||
pub type SeatMoveGrabState = RefCell<Option<MoveGrabState>>;
|
||||
pub type SeatMoveGrabState = Mutex<Option<MoveGrabState>>;
|
||||
|
||||
const RESCALE_ANIMATION_DURATION: f64 = 150.0;
|
||||
|
||||
|
|
@ -363,7 +367,7 @@ impl MoveGrab {
|
|||
.seat
|
||||
.user_data()
|
||||
.get::<SeatMoveGrabState>()
|
||||
.map(|s| s.borrow_mut());
|
||||
.map(|s| s.lock().unwrap());
|
||||
if let Some(grab_state) = borrow.as_mut().and_then(|s| s.as_mut()) {
|
||||
grab_state.location = location;
|
||||
grab_state.cursor_output = self.cursor_output.clone();
|
||||
|
|
@ -698,11 +702,12 @@ impl MoveGrab {
|
|||
.user_data()
|
||||
.get::<SeatMoveGrabState>()
|
||||
.unwrap()
|
||||
.borrow_mut() = Some(grab_state);
|
||||
.lock()
|
||||
.unwrap() = Some(grab_state);
|
||||
|
||||
{
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(CursorShape::Grab);
|
||||
cursor_state.lock().unwrap().set_shape(CursorShape::Grab);
|
||||
}
|
||||
|
||||
MoveGrab {
|
||||
|
|
@ -743,7 +748,7 @@ impl Drop for MoveGrab {
|
|||
let position: Option<(CosmicMapped, Point<i32, Global>)> = if let Some(grab_state) =
|
||||
seat.user_data()
|
||||
.get::<SeatMoveGrabState>()
|
||||
.and_then(|s| s.borrow_mut().take())
|
||||
.and_then(|s| s.lock().unwrap().take())
|
||||
{
|
||||
if grab_state.window.alive() {
|
||||
let window_location =
|
||||
|
|
@ -842,7 +847,7 @@ impl Drop for MoveGrab {
|
|||
|
||||
{
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(CursorShape::Default);
|
||||
cursor_state.lock().unwrap().set_shape(CursorShape::Default);
|
||||
}
|
||||
|
||||
if let Some((mapped, position)) = position {
|
||||
|
|
|
|||
|
|
@ -50,10 +50,13 @@ impl PointerTarget<State> for ResizeForkTarget {
|
|||
fn enter(&self, seat: &Seat<State>, _data: &mut State, _event: &MotionEvent) {
|
||||
let user_data = seat.user_data();
|
||||
let cursor_state = user_data.get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(match self.orientation {
|
||||
Orientation::Horizontal => CursorShape::RowResize,
|
||||
Orientation::Vertical => CursorShape::ColResize,
|
||||
});
|
||||
cursor_state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_shape(match self.orientation {
|
||||
Orientation::Horizontal => CursorShape::RowResize,
|
||||
Orientation::Vertical => CursorShape::ColResize,
|
||||
});
|
||||
}
|
||||
|
||||
fn leave(
|
||||
|
|
@ -65,7 +68,7 @@ impl PointerTarget<State> for ResizeForkTarget {
|
|||
) {
|
||||
let user_data = seat.user_data();
|
||||
let cursor_state = user_data.get::<CursorState>().unwrap();
|
||||
cursor_state.set_shape(CursorShape::Default)
|
||||
cursor_state.lock().unwrap().set_shape(CursorShape::Default)
|
||||
}
|
||||
|
||||
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ impl Drop for SeatId {
|
|||
|
||||
#[repr(transparent)]
|
||||
struct SeatId(pub usize);
|
||||
struct ActiveOutput(pub RefCell<Output>);
|
||||
struct ActiveOutput(pub Mutex<Output>);
|
||||
|
||||
pub fn create_seat(
|
||||
dh: &DisplayHandle,
|
||||
|
|
@ -166,15 +166,15 @@ pub fn create_seat(
|
|||
) -> Seat<State> {
|
||||
let mut seat = seat_state.new_wl_seat(dh, name);
|
||||
let userdata = seat.user_data();
|
||||
userdata.insert_if_missing(SeatId::default);
|
||||
userdata.insert_if_missing_threadsafe(SeatId::default);
|
||||
userdata.insert_if_missing(Devices::default);
|
||||
userdata.insert_if_missing(SupressedKeys::default);
|
||||
userdata.insert_if_missing(ModifiersShortcutQueue::default);
|
||||
userdata.insert_if_missing(SeatMoveGrabState::default);
|
||||
userdata.insert_if_missing(SeatMenuGrabState::default);
|
||||
userdata.insert_if_missing(CursorState::default);
|
||||
userdata.insert_if_missing(|| ActiveOutput(RefCell::new(output.clone())));
|
||||
userdata.insert_if_missing(|| RefCell::new(CursorImageStatus::default_named()));
|
||||
userdata.insert_if_missing_threadsafe(SeatMoveGrabState::default);
|
||||
userdata.insert_if_missing_threadsafe(SeatMenuGrabState::default);
|
||||
userdata.insert_if_missing_threadsafe(CursorState::default);
|
||||
userdata.insert_if_missing_threadsafe(|| ActiveOutput(Mutex::new(output.clone())));
|
||||
userdata.insert_if_missing_threadsafe(|| Mutex::new(CursorImageStatus::default_named()));
|
||||
|
||||
// A lot of clients bind keyboard and pointer unconditionally once on launch..
|
||||
// Initial clients might race the compositor on adding periheral and
|
||||
|
|
@ -232,7 +232,7 @@ impl SeatExt for Seat<State> {
|
|||
fn active_output(&self) -> Output {
|
||||
self.user_data()
|
||||
.get::<ActiveOutput>()
|
||||
.map(|x| x.0.borrow().clone())
|
||||
.map(|x| x.0.lock().unwrap().clone())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,8 @@ impl SeatExt for Seat<State> {
|
|||
.get::<ActiveOutput>()
|
||||
.unwrap()
|
||||
.0
|
||||
.borrow_mut() = output.clone();
|
||||
.lock()
|
||||
.unwrap() = output.clone();
|
||||
}
|
||||
|
||||
fn devices(&self) -> &Devices {
|
||||
|
|
@ -266,9 +267,9 @@ impl SeatExt for Seat<State> {
|
|||
|
||||
let cursor_status = self
|
||||
.user_data()
|
||||
.get::<RefCell<CursorImageStatus>>()
|
||||
.map(|cell| {
|
||||
let mut cursor_status = cell.borrow_mut();
|
||||
.get::<Mutex<CursorImageStatus>>()
|
||||
.map(|lock| {
|
||||
let mut cursor_status = lock.lock().unwrap();
|
||||
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
|
||||
if !surface.alive() {
|
||||
*cursor_status = CursorImageStatus::default_named();
|
||||
|
|
@ -298,9 +299,11 @@ impl SeatExt for Seat<State> {
|
|||
}
|
||||
CursorImageStatus::Named(CursorIcon::Default) => {
|
||||
let seat_userdata = self.user_data();
|
||||
seat_userdata.insert_if_missing(CursorState::default);
|
||||
seat_userdata.insert_if_missing_threadsafe(CursorState::default);
|
||||
let state = seat_userdata.get::<CursorState>().unwrap();
|
||||
let frame = state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.cursors
|
||||
.get(&CursorShape::Default)
|
||||
.unwrap()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue