shell: Focus window after unfullscreening

This commit is contained in:
Victoria Brekenfeld 2025-07-03 17:20:43 +02:00 committed by Victoria Brekenfeld
parent 261134d827
commit 9d91014b8d
6 changed files with 55 additions and 25 deletions

View file

@ -889,7 +889,12 @@ impl State {
}
}
Some(FocusTarget::Fullscreen(surface)) => {
shell.unfullscreen_request(&surface, &self.common.event_loop_handle);
if let Some(target) =
shell.unfullscreen_request(&surface, &self.common.event_loop_handle)
{
std::mem::drop(shell);
Shell::set_focus(self, Some(&target), seat, Some(serial), true);
}
}
_ => {}
}

View file

@ -589,10 +589,16 @@ pub fn fullscreen_items(window: &CosmicSurface, config: &Config) -> impl Iterato
let window = fullscreen_clone.clone();
let _ = handle.insert_idle(move |state| {
let mut shell = state.common.shell.write();
shell.unfullscreen_request(&window, &state.common.event_loop_handle);
if let Some(target) =
shell.unfullscreen_request(&window, &state.common.event_loop_handle)
{
let seat = shell.seats.last_active().clone();
std::mem::drop(shell);
Shell::set_focus(state, Some(&target), &seat, None, true);
}
});
})
//.shortcut(config.shortcut_for_action(&Action::Fullscreen))
.shortcut(config.shortcut_for_action(&Action::Fullscreen))
.toggled(true),
),
Some(Item::Separator),

View file

@ -2420,7 +2420,7 @@ impl Shell {
surface: CosmicSurface,
state: Option<FullscreenRestoreState>,
loop_handle: &LoopHandle<'static, State>,
) {
) -> CosmicMapped {
let window = CosmicMapped::from(CosmicWindow::new(
surface,
loop_handle.clone(),
@ -2439,12 +2439,12 @@ impl Shell {
.or_else(|| self.workspaces.backup_set.as_mut())
.unwrap();
set.sticky_layer.map_internal(
window,
window.clone(),
Some(state.geometry.loc),
Some(state.geometry.size.as_logical()),
Some(set.output.geometry().to_local(&set.output)),
);
return;
return window;
}
let seat = self.seats.last_active();
@ -2473,14 +2473,14 @@ impl Shell {
if workspace.tiling_enabled {
workspace.tiling_layer.remap(
window,
window.clone(),
Some(fullscreen_geometry),
None,
Some(workspace.focus_stack.get(seat).iter()),
);
} else {
workspace.floating_layer.map_internal(
window,
window.clone(),
None,
None,
Some(fullscreen_geometry),
@ -2509,9 +2509,11 @@ impl Shell {
original_layer: ManagedLayer::Floating,
});
std::mem::drop(state);
workspace
.floating_layer
.map_maximized(window, fullscreen_geometry, true);
workspace.floating_layer.map_maximized(
window.clone(),
fullscreen_geometry,
true,
);
}
}
Some(FullscreenRestoreState::Tiling {
@ -2539,9 +2541,11 @@ impl Shell {
original_layer: ManagedLayer::Tiling,
});
std::mem::drop(state);
workspace
.floating_layer
.map_maximized(window, fullscreen_geometry, true);
workspace.floating_layer.map_maximized(
window.clone(),
fullscreen_geometry,
true,
);
}
} else {
workspace.floating_layer.map_internal(
@ -2559,14 +2563,18 @@ impl Shell {
original_layer: ManagedLayer::Floating,
});
std::mem::drop(state);
workspace
.floating_layer
.map_maximized(window, fullscreen_geometry, true);
workspace.floating_layer.map_maximized(
window.clone(),
fullscreen_geometry,
true,
);
}
}
}
Some(FullscreenRestoreState::Sticky { .. }) => unreachable!(),
}
window
}
#[must_use]
@ -4596,7 +4604,7 @@ impl Shell {
&mut self,
surface: &S,
loop_handle: &LoopHandle<'static, State>,
) -> bool
) -> Option<KeyboardFocusTarget>
where
CosmicSurface: PartialEq<S>,
{
@ -4611,11 +4619,10 @@ impl Shell {
toplevel_leave_output(&old_fullscreen, &workspace.output);
toplevel_leave_workspace(&old_fullscreen, &workspace.handle);
self.remap_unfullscreened_window(old_fullscreen, restore, loop_handle);
true
let window = self.remap_unfullscreened_window(old_fullscreen, restore, loop_handle);
Some(KeyboardFocusTarget::Element(window))
} else {
false
None
}
}

View file

@ -184,7 +184,11 @@ impl ToplevelManagementHandler for State {
window: &<Self as ToplevelInfoHandler>::Window,
) {
let mut shell = self.common.shell.write();
shell.unfullscreen_request(window, &self.common.event_loop_handle);
if let Some(target) = shell.unfullscreen_request(window, &self.common.event_loop_handle) {
let seat = shell.seats.last_active().clone();
std::mem::drop(shell);
Shell::set_focus(self, Some(&target), &seat, None, true);
}
}
fn maximize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {

View file

@ -261,7 +261,11 @@ impl XdgShellHandler for State {
fn unfullscreen_request(&mut self, surface: ToplevelSurface) {
let mut shell = self.common.shell.write();
if !shell.unfullscreen_request(&surface, &self.common.event_loop_handle) {
if let Some(target) = shell.unfullscreen_request(&surface, &self.common.event_loop_handle) {
let seat = shell.seats.last_active().clone();
std::mem::drop(shell);
Shell::set_focus(self, Some(&target), &seat, None, true);
} else {
if let Some(pending) = shell.pending_windows.iter_mut().find(|pending| {
pending.surface.wl_surface().as_deref() == Some(surface.wl_surface())
}) {

View file

@ -1082,7 +1082,11 @@ impl XwmHandler for State {
fn unfullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) {
let mut shell = self.common.shell.write();
if !shell.unfullscreen_request(&window, &self.common.event_loop_handle) {
if let Some(target) = shell.unfullscreen_request(&window, &self.common.event_loop_handle) {
let seat = shell.seats.last_active().clone();
std::mem::drop(shell);
Shell::set_focus(self, Some(&target), &seat, None, true);
} else {
if let Some(pending) = shell
.pending_windows
.iter_mut()