Skip to content

Commit

Permalink
actions: Remember previous workspace on extended action
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Feb 27, 2025
1 parent 6b6cea7 commit 80a8e95
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 21 deletions.
114 changes: 94 additions & 20 deletions src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl State {
time,
pattern,
direction,
false,
true,
)
};
} else {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl State {
time,
pattern,
direction,
false,
true,
)
};
} else {
Expand Down Expand Up @@ -401,7 +401,7 @@ impl State {
time,
pattern,
direction,
false,
true,
)
}
}
Expand Down Expand Up @@ -484,7 +484,7 @@ impl State {
time,
pattern,
direction,
false,
true,
)
}
}
Expand Down Expand Up @@ -514,14 +514,33 @@ impl State {
let next_output = shell.next_output(&current_output, direction).cloned();

if let Some(next_output) = next_output {
let idx = shell.workspaces.active_num(&next_output).1;
let res = shell.activate(
&next_output,
idx,
WorkspaceDelta::new_shortcut(),
&mut self.common.workspace_state.update(),
);
seat.set_active_output(&next_output);
let res = {
let mut workspace_guard = self.common.workspace_state.update();
if propagate {
if let Some((_, prev_output, prev_idx)) =
shell.previous_workspace_idx.take()
{
if prev_output == current_output {
let _ = shell.activate(
&current_output,
prev_idx,
WorkspaceDelta::new_shortcut(),
&mut workspace_guard,
);
}
}
}

let idx = shell.workspaces.active_num(&next_output).1;
let res = shell.activate(
&next_output,
idx,
WorkspaceDelta::new_shortcut(),
&mut workspace_guard,
);
seat.set_active_output(&next_output);
res
};

if let Ok(Some(new_pos)) = res {
let new_target = shell
Expand Down Expand Up @@ -585,14 +604,34 @@ impl State {
let next_output = shell.next_output(&focused_output, direction).cloned();

if let Some(next_output) = next_output {
let res = shell.move_current_window(
seat,
&focused_output,
(&next_output, None),
is_move_action,
Some(direction),
&mut self.common.workspace_state.update(),
);
let res = {
let mut workspace_guard = self.common.workspace_state.update();
let res = shell.move_current_window(
seat,
&focused_output,
(&next_output, None),
is_move_action,
Some(direction),
&mut workspace_guard,
);

if is_move_action && propagate {
if let Some((_, prev_output, prev_idx)) =
shell.previous_workspace_idx.take()
{
if prev_output == focused_output {
let _ = shell.activate(
&focused_output,
prev_idx,
WorkspaceDelta::new_shortcut(),
&mut workspace_guard,
);
}
}
}
res
};

if let Ok(Some((target, new_pos))) = res {
std::mem::drop(shell);
Shell::set_focus(self, Some(&target), seat, None, is_move_action);
Expand Down Expand Up @@ -659,6 +698,24 @@ impl State {
};

if let Some(direction) = dir {
if let Some(last_mod_serial) = seat.last_modifier_change() {
let mut shell = self.common.shell.write().unwrap();
if !shell
.previous_workspace_idx
.as_ref()
.is_some_and(|(serial, _, _)| *serial == last_mod_serial)
{
let current_output = seat.active_output();
let workspace_idx =
shell.workspaces.active_num(&current_output).1;
shell.previous_workspace_idx = Some((
last_mod_serial,
current_output.downgrade(),
workspace_idx,
));
}
}

let action = match (
direction,
self.common.config.cosmic_conf.workspaces.workspace_layout,
Expand Down Expand Up @@ -701,6 +758,23 @@ impl State {
.move_current_element(direction, seat);
match res {
MoveResult::MoveFurther(_move_further) => {
if let Some(last_mod_serial) = seat.last_modifier_change() {
let mut shell = self.common.shell.write().unwrap();
if !shell
.previous_workspace_idx
.as_ref()
.is_some_and(|(serial, _, _)| *serial == last_mod_serial)
{
let current_output = seat.active_output();
let workspace_idx = shell.workspaces.active_num(&current_output).1;
shell.previous_workspace_idx = Some((
last_mod_serial,
current_output.downgrade(),
workspace_idx,
));
}
}

let action = match (
direction,
self.common.config.cosmic_conf.workspaces.workspace_layout,
Expand Down
4 changes: 3 additions & 1 deletion src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use smithay::{
},
Seat,
},
output::Output,
output::{Output, WeakOutput},
reexports::{
wayland_protocols::ext::{
session_lock::v1::server::ext_session_lock_v1::ExtSessionLockV1,
Expand Down Expand Up @@ -257,6 +257,7 @@ pub struct Shell {
pub override_redirect_windows: Vec<X11Surface>,
pub session_lock: Option<SessionLock>,
pub seats: Seats,
pub previous_workspace_idx: Option<(Serial, WeakOutput, usize)>,

theme: cosmic::Theme,
pub active_hint: bool,
Expand Down Expand Up @@ -1338,6 +1339,7 @@ impl Shell {
pending_activations: HashMap::new(),
override_redirect_windows: Vec::new(),
session_lock: None,
previous_workspace_idx: None,

theme,
active_hint: config.cosmic_conf.active_hint,
Expand Down

0 comments on commit 80a8e95

Please sign in to comment.