actions: Fix focus on Output-actions

This commit is contained in:
Victoria Brekenfeld 2024-09-09 17:50:19 +02:00
parent 932c204de4
commit 5006eae60b
3 changed files with 186 additions and 154 deletions

View file

@ -3,8 +3,8 @@
use crate::{ use crate::{
config::{Action, PrivateAction}, config::{Action, PrivateAction},
shell::{ shell::{
layout::tiling::SwapWindowGrab, FocusResult, InvalidWorkspaceIndex, MoveResult, SeatExt, focus::target::KeyboardFocusTarget, layout::tiling::SwapWindowGrab, FocusResult,
Trigger, WorkspaceDelta, InvalidWorkspaceIndex, MoveResult, SeatExt, Trigger, WorkspaceDelta,
}, },
utils::prelude::*, utils::prelude::*,
wayland::{ wayland::{
@ -402,11 +402,30 @@ impl State {
WorkspaceDelta::new_shortcut(), WorkspaceDelta::new_shortcut(),
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
); );
match res {
Ok(Some(new_pos)) => {
std::mem::drop(shell);
seat.set_active_output(&next_output); seat.set_active_output(&next_output);
if let Ok(Some(new_pos)) = res {
let new_target = shell
.workspaces
.active(&next_output)
.1
.focus_stack
.get(&seat)
.last()
.cloned()
.map(KeyboardFocusTarget::from);
std::mem::drop(shell);
let move_cursor = if let Some(under) = new_target {
let update_cursor = self.common.config.cosmic_conf.focus_follows_cursor;
Shell::set_focus(self, Some(&under), seat, None, update_cursor);
!update_cursor
} else {
true
};
if let Some(ptr) = seat.get_pointer() { if let Some(ptr) = seat.get_pointer() {
if move_cursor {
ptr.motion( ptr.motion(
self, self,
None, None,
@ -416,14 +435,10 @@ impl State {
time, time,
}, },
); );
}
ptr.frame(self); ptr.frame(self);
} }
} }
Ok(None) => {
seat.set_active_output(&next_output);
}
_ => {}
}
} else if propagate { } else if propagate {
std::mem::drop(shell); std::mem::drop(shell);
@ -474,11 +489,30 @@ impl State {
WorkspaceDelta::new_shortcut(), WorkspaceDelta::new_shortcut(),
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
); );
match res {
Ok(Some(new_pos)) => {
std::mem::drop(shell);
seat.set_active_output(&next_output); seat.set_active_output(&next_output);
if let Ok(Some(new_pos)) = res {
let new_target = shell
.workspaces
.active(&next_output)
.1
.focus_stack
.get(&seat)
.last()
.cloned()
.map(KeyboardFocusTarget::from);
std::mem::drop(shell);
let move_cursor = if let Some(under) = new_target {
let update_cursor = self.common.config.cosmic_conf.focus_follows_cursor;
Shell::set_focus(self, Some(&under), seat, None, update_cursor);
!update_cursor
} else {
true
};
if let Some(ptr) = seat.get_pointer() { if let Some(ptr) = seat.get_pointer() {
if move_cursor {
ptr.motion( ptr.motion(
self, self,
None, None,
@ -488,14 +522,10 @@ impl State {
time, time,
}, },
); );
}
ptr.frame(self); ptr.frame(self);
} }
} }
Ok(None) => {
seat.set_active_output(&next_output);
}
_ => {}
}
} }
} }
@ -518,11 +548,30 @@ impl State {
WorkspaceDelta::new_shortcut(), WorkspaceDelta::new_shortcut(),
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
); );
match res {
Ok(Some(new_pos)) => {
std::mem::drop(shell);
seat.set_active_output(&prev_output); seat.set_active_output(&prev_output);
if let Ok(Some(new_pos)) = res {
let new_target = shell
.workspaces
.active(&prev_output)
.1
.focus_stack
.get(&seat)
.last()
.cloned()
.map(KeyboardFocusTarget::from);
std::mem::drop(shell);
let move_cursor = if let Some(under) = new_target {
let update_cursor = self.common.config.cosmic_conf.focus_follows_cursor;
Shell::set_focus(self, Some(&under), seat, None, update_cursor);
!update_cursor
} else {
true
};
if let Some(ptr) = seat.get_pointer() { if let Some(ptr) = seat.get_pointer() {
if move_cursor {
ptr.motion( ptr.motion(
self, self,
None, None,
@ -532,14 +581,10 @@ impl State {
time, time,
}, },
); );
}
ptr.frame(self); ptr.frame(self);
} }
} }
Ok(None) => {
seat.set_active_output(&prev_output);
}
_ => {}
}
} }
} }

View file

@ -603,9 +603,9 @@ impl State {
//If the pointer isn't grabbed, we should check if the focused element should be updated //If the pointer isn't grabbed, we should check if the focused element should be updated
} else if self.common.config.cosmic_conf.focus_follows_cursor { } else if self.common.config.cosmic_conf.focus_follows_cursor {
let shell = self.common.shell.read().unwrap(); let shell = self.common.shell.read().unwrap();
let (old_keyboard_target, _) = let old_keyboard_target =
shell.keyboard_target_from_position(original_position, &seat); shell.keyboard_target_from_position(original_position, &seat);
let (new_keyboard_target, _) = let new_keyboard_target =
shell.keyboard_target_from_position(position, &seat); shell.keyboard_target_from_position(position, &seat);
if old_keyboard_target != new_keyboard_target if old_keyboard_target != new_keyboard_target
@ -904,9 +904,7 @@ impl State {
let global_position = let global_position =
seat.get_pointer().unwrap().current_location().as_global(); seat.get_pointer().unwrap().current_location().as_global();
let shell = self.common.shell.write().unwrap(); let shell = self.common.shell.write().unwrap();
let (under, trigger_move) = let under = shell.keyboard_target_from_position(global_position, &seat);
shell.keyboard_target_from_position(global_position, &seat);
if trigger_move {
// Don't check override redirect windows, because we don't set keyboard focus to them explicitly. // Don't check override redirect windows, because we don't set keyboard focus to them explicitly.
// These cases are handled by the XwaylandKeyboardGrab. // These cases are handled by the XwaylandKeyboardGrab.
if let Some(target) = shell.element_under(global_position, &output) { if let Some(target) = shell.element_under(global_position, &output) {
@ -975,11 +973,10 @@ impl State {
else { else {
return; return;
}; };
let Some(geom) = shell let Some(geom) =
.space_for(target_elem) shell.space_for(target_elem).and_then(
.and_then(|f| { |f| f.element_geometry(target_elem),
f.element_geometry(target_elem) )
})
else { else {
return; return;
}; };
@ -992,12 +989,8 @@ impl State {
offset.x > 0.0, offset.x > 0.0,
offset.y > 0.0, offset.y > 0.0,
) { ) {
(true, true) => { (true, true) => ResizeEdge::TOP_LEFT,
ResizeEdge::TOP_LEFT (false, true) => ResizeEdge::TOP_RIGHT,
}
(false, true) => {
ResizeEdge::TOP_RIGHT
}
(true, false) => { (true, false) => {
ResizeEdge::BOTTOM_LEFT ResizeEdge::BOTTOM_LEFT
} }
@ -1025,7 +1018,6 @@ impl State {
} }
} }
} }
}
std::mem::drop(shell); std::mem::drop(shell);
Shell::set_focus(self, under.as_ref(), &seat, Some(serial), false); Shell::set_focus(self, under.as_ref(), &seat, Some(serial), false);

View file

@ -1424,10 +1424,8 @@ impl Shell {
&self, &self,
global_position: Point<f64, Global>, global_position: Point<f64, Global>,
seat: &Seat<State>, seat: &Seat<State>,
) -> (Option<KeyboardFocusTarget>, bool) { ) -> Option<KeyboardFocusTarget> {
let output = seat.active_output(); let output = seat.active_output();
// if not done and super key pressed
let mut grab_conditions_met = false;
let relative_pos = global_position.to_local(&output); let relative_pos = global_position.to_local(&output);
let mut under: Option<KeyboardFocusTarget> = None; let mut under: Option<KeyboardFocusTarget> = None;
@ -1484,11 +1482,7 @@ impl Shell {
// Don't check override redirect windows, because we don't set keyboard focus to them explicitly. // Don't check override redirect windows, because we don't set keyboard focus to them explicitly.
// These cases are handled by the XwaylandKeyboardGrab. // These cases are handled by the XwaylandKeyboardGrab.
if let Some(target) = self.element_under(global_position, &output) { if let Some(target) = self.element_under(global_position, &output) {
if !seat.get_keyboard().unwrap().modifier_state().logo {
under = Some(target); under = Some(target);
} else {
grab_conditions_met = true;
}
} else { } else {
let layers = layer_map_for_output(&output); let layers = layer_map_for_output(&output);
if let Some(layer) = layers if let Some(layer) = layers
@ -1512,7 +1506,8 @@ impl Shell {
} }
} }
} }
(under, grab_conditions_met)
under
} }
/// Coerce a keyboard focus target into a CosmicMapped element. This is useful when performing window specific /// Coerce a keyboard focus target into a CosmicMapped element. This is useful when performing window specific