Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,31 @@ impl State {
0 => 9,
x => x - 1,
};
let _ = self.common.shell.write().activate(
let res = self.common.shell.write().activate(
&current_output,
workspace as usize,
WorkspaceDelta::new_shortcut(),
&mut self.common.workspace_state.update(),
);
if res.is_ok() {
self.reconcile_focus_to_pointer(seat);
}
}

Action::LastWorkspace => {
let current_output = seat.active_output();
let mut shell = self.common.shell.write();
let workspace = shell.workspaces.len(&current_output).saturating_sub(1);
let _ = shell.activate(
let res = shell.activate(
&current_output,
workspace,
WorkspaceDelta::new_shortcut(),
&mut self.common.workspace_state.update(),
);
drop(shell);
if res.is_ok() {
self.reconcile_focus_to_pointer(seat);
}
}

Action::NextWorkspace => {
Expand Down Expand Up @@ -239,6 +246,8 @@ impl State {
direction,
true,
)
} else if next.is_ok() {
self.reconcile_focus_to_pointer(seat);
}
}

Expand Down Expand Up @@ -278,6 +287,8 @@ impl State {
direction,
true,
)
} else if previous.is_ok() {
self.reconcile_focus_to_pointer(seat);
};
}

Expand Down
50 changes: 50 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,56 @@ impl State {
}
}

/// Reconcile keyboard focus to the window under the pointer on the active workspace.
///
/// Does nothing unless focus-follows-cursor is enabled and the pointer is
/// ungrabbed, and never clears focus when the pointer is over empty space.
pub fn reconcile_focus_to_pointer(&mut self, seat: &Seat<State>) {
if !self.common.config.cosmic_conf.focus_follows_cursor {
return;
}

let Some(ptr) = seat.get_pointer() else {
return;
};
if ptr.is_grabbed() {
return;
}

let position = ptr.current_location().as_global();
let target = {
let shell = self.common.shell.read();
let Some(output) = shell
.outputs()
.find(|output| output.geometry().to_f64().contains(position))
.cloned()
else {
return;
};
shell
.active_space(&output)
.and_then(|workspace| workspace.toplevel_element_under(position, seat))
};

let Some(target) = target else {
return;
};

if let Some(pointer_focus_state) = self.common.pointer_focus_state.take() {
self.common
.event_loop_handle
.remove(pointer_focus_state.token);
}

Shell::set_focus(
self,
Some(&target),
seat,
Some(SERIAL_COUNTER.next_serial()),
false,
);
}

#[profiling::function]
pub fn element_under(
global_pos: Point<f64, Global>,
Expand Down