state: Move shell behind RwLock
This commit is contained in:
parent
647deb81f1
commit
5d5a510691
45 changed files with 2657 additions and 2097 deletions
|
|
@ -107,9 +107,13 @@ impl Shell {
|
|||
) {
|
||||
let element = match target {
|
||||
Some(KeyboardFocusTarget::Element(mapped)) => Some(mapped.clone()),
|
||||
Some(KeyboardFocusTarget::Fullscreen(window)) => {
|
||||
state.common.shell.element_for_surface(window).cloned()
|
||||
}
|
||||
Some(KeyboardFocusTarget::Fullscreen(window)) => state
|
||||
.common
|
||||
.shell
|
||||
.read()
|
||||
.unwrap()
|
||||
.element_for_surface(window)
|
||||
.cloned(),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
@ -117,7 +121,12 @@ impl Shell {
|
|||
if mapped.is_minimized() {
|
||||
return;
|
||||
}
|
||||
state.common.shell.append_focus_stack(&mapped, seat);
|
||||
state
|
||||
.common
|
||||
.shell
|
||||
.write()
|
||||
.unwrap()
|
||||
.append_focus_stack(&mapped, seat);
|
||||
}
|
||||
|
||||
// update keyboard focus
|
||||
|
|
@ -130,7 +139,7 @@ impl Shell {
|
|||
);
|
||||
}
|
||||
|
||||
state.common.shell.update_active();
|
||||
state.common.shell.write().unwrap().update_active();
|
||||
}
|
||||
|
||||
pub fn append_focus_stack(&mut self, mapped: &CosmicMapped, seat: &Seat<State>) {
|
||||
|
|
@ -233,25 +242,27 @@ fn raise_with_children(floating_layer: &mut FloatingLayout, focused: &CosmicMapp
|
|||
|
||||
impl Common {
|
||||
pub fn refresh_focus(state: &mut State) {
|
||||
for seat in state
|
||||
let seats = state
|
||||
.common
|
||||
.shell
|
||||
.read()
|
||||
.unwrap()
|
||||
.seats
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
{
|
||||
.collect::<Vec<_>>();
|
||||
for seat in seats.into_iter() {
|
||||
let mut shell = state.common.shell.write().unwrap();
|
||||
let output = seat.active_output();
|
||||
if !state.common.shell.outputs().any(|o| o == &output) {
|
||||
seat.set_active_output(&state.common.shell.outputs().next().unwrap());
|
||||
if !shell.outputs().any(|o| o == &output) {
|
||||
seat.set_active_output(&shell.outputs().next().unwrap());
|
||||
continue;
|
||||
}
|
||||
let last_known_focus = ActiveFocus::get(&seat);
|
||||
|
||||
if let Some(target) = last_known_focus {
|
||||
if target.alive() {
|
||||
if focus_target_is_valid(&mut state.common.shell, &seat, &output, target) {
|
||||
if focus_target_is_valid(&mut *shell, &seat, &output, target) {
|
||||
continue; // Focus is valid
|
||||
} else {
|
||||
trace!("Wrong Window, focus fixup");
|
||||
|
|
@ -266,6 +277,8 @@ impl Common {
|
|||
if !popup_grab.has_ended() {
|
||||
if let Some(new) = popup_grab.current_grab() {
|
||||
trace!("restore focus to previous popup grab");
|
||||
std::mem::drop(shell);
|
||||
|
||||
if let Some(keyboard) = seat.get_keyboard() {
|
||||
keyboard.set_focus(
|
||||
state,
|
||||
|
|
@ -285,7 +298,7 @@ impl Common {
|
|||
trace!("Surface dead, focus fixup");
|
||||
}
|
||||
} else {
|
||||
let workspace = state.common.shell.active_space(&output);
|
||||
let workspace = shell.active_space(&output);
|
||||
let focus_stack = workspace.focus_stack.get(&seat);
|
||||
|
||||
if focus_stack.last().is_none() {
|
||||
|
|
@ -309,7 +322,9 @@ impl Common {
|
|||
}
|
||||
|
||||
// update keyboard focus
|
||||
let target = update_focus_target(&state.common.shell, &seat, &output);
|
||||
let target = update_focus_target(&*shell, &seat, &output);
|
||||
std::mem::drop(shell);
|
||||
|
||||
if let Some(keyboard) = seat.get_keyboard() {
|
||||
debug!("Restoring focus to {:?}", target.as_ref());
|
||||
keyboard.set_focus(state, target.clone(), SERIAL_COUNTER.next_serial());
|
||||
|
|
@ -318,7 +333,7 @@ impl Common {
|
|||
}
|
||||
}
|
||||
|
||||
state.common.shell.update_active()
|
||||
state.common.shell.write().unwrap().update_active()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ impl PointerFocusTarget {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn toplevel(&self, data: &mut State) -> Option<CosmicSurface> {
|
||||
pub fn toplevel(&self, shell: &Shell) -> Option<CosmicSurface> {
|
||||
match &self {
|
||||
PointerFocusTarget::WlSurface {
|
||||
toplevel: Some(PointerFocusToplevel::Surface(surface)),
|
||||
|
|
@ -142,12 +142,7 @@ impl PointerFocusTarget {
|
|||
toplevel: Some(PointerFocusToplevel::Popup(PopupKind::Xdg(popup))),
|
||||
..
|
||||
} => get_popup_toplevel(popup)
|
||||
.and_then(|s| {
|
||||
data.common
|
||||
.shell
|
||||
.element_for_surface(&s)
|
||||
.map(|mapped| (mapped, s))
|
||||
})
|
||||
.and_then(|s| shell.element_for_surface(&s).map(|mapped| (mapped, s)))
|
||||
.and_then(|(m, s)| {
|
||||
m.windows()
|
||||
.find(|(w, _)| w.wl_surface().map(|s2| s == s2).unwrap_or(false))
|
||||
|
|
@ -210,7 +205,8 @@ impl IsAlive for KeyboardFocusTarget {
|
|||
|
||||
impl PointerTarget<State> for PointerFocusTarget {
|
||||
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &PointerMotionEvent) {
|
||||
if let Some(element) = self.toplevel(data) {
|
||||
let toplevel = self.toplevel(&*data.common.shell.read().unwrap());
|
||||
if let Some(element) = toplevel {
|
||||
for session in element.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
|
|
@ -238,7 +234,8 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
}
|
||||
}
|
||||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &PointerMotionEvent) {
|
||||
if let Some(element) = self.toplevel(data) {
|
||||
let toplevel = self.toplevel(&*data.common.shell.read().unwrap());
|
||||
if let Some(element) = toplevel {
|
||||
for session in element.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
|
|
@ -308,7 +305,8 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
}
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
if let Some(element) = self.toplevel(data) {
|
||||
let toplevel = self.toplevel(&*data.common.shell.read().unwrap());
|
||||
if let Some(element) = toplevel {
|
||||
for session in element.cursor_sessions() {
|
||||
session.set_cursor_pos(None);
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue