Skip to content

Commit

Permalink
using sticky window as temporary scratchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
Bijay Shrestha committed Sep 24, 2024
1 parent afdb656 commit e111001
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/keybindings.ron
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
(modifiers: [Super], key: "8"): Workspace(8),
(modifiers: [Super], key: "9"): Workspace(9),
(modifiers: [Super], key: "0"): LastWorkspace,
(modifiers: [Super], key: "p"): ToggleStickyVisibility,
(modifiers: [Super, Shift], key: "1"): MoveToWorkspace(1),
(modifiers: [Super, Shift], key: "2"): MoveToWorkspace(2),
(modifiers: [Super, Shift], key: "3"): MoveToWorkspace(3),
Expand Down
12 changes: 12 additions & 0 deletions src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ impl State {
);
}

Action::ToggleStickyVisibility => {
let mut shell = self.common.shell.write().unwrap();
let sticky_visible = shell.workspaces.sticky_visible;
if sticky_visible {
shell.workspaces.sticky_visible = false;
shell.minimize_sticky();
} else {
shell.workspaces.sticky_visible = true;
shell.unminimize_sticky();
}
}

Action::NextWorkspace => {
let next = to_next_workspace(
&mut *self.common.shell.write().unwrap(),
Expand Down
52 changes: 52 additions & 0 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ pub struct Workspaces {
autotile: bool,
autotile_behavior: TileBehavior,
theme: cosmic::Theme,
pub sticky_visible: bool,
}

impl Workspaces {
Expand All @@ -635,6 +636,7 @@ impl Workspaces {
autotile: config.cosmic_conf.autotile,
autotile_behavior: config.cosmic_conf.autotile_behavior,
theme,
sticky_visible: true,
}
}

Expand Down Expand Up @@ -3358,6 +3360,56 @@ impl Shell {
}
}

pub fn minimize_sticky(&mut self) {
for set in self.workspaces.sets.values_mut() {
let sticky_windows: Vec<CosmicMapped> = set
.sticky_layer
.mapped()
.map(|mapped| mapped.clone())
.collect();
for sticky_window in sticky_windows {
let to = minimize_rectangle(&set.output, &sticky_window.active_window());
let (window, position) =
set.sticky_layer.unmap_minimize(&sticky_window, to).unwrap();

set.minimized_windows.push(MinimizedWindow {
window,
previous_state: MinimizedState::Sticky { position },
output_geo: set.output.geometry(),
fullscreen: None,
});
}
}
}

pub fn unminimize_sticky(&mut self) {
for set in self.workspaces.sets.values_mut() {
// All windows in Workspaceset are minimized
let minimized_windows: Vec<MinimizedWindow> = set.minimized_windows.drain(..).collect();
for minimized_window in minimized_windows {
let from =
minimize_rectangle(&set.output, &minimized_window.window.active_window());
if let MinimizedState::Sticky { mut position } = minimized_window.previous_state {
let current_output_size = set.output.geometry().size.as_logical();
if current_output_size != minimized_window.output_geo.size.as_logical() {
position = Point::from((
(position.x as f64 / minimized_window.output_geo.size.w as f64
* current_output_size.w as f64)
.floor() as i32,
(position.y as f64 / minimized_window.output_geo.size.h as f64
* current_output_size.h as f64)
.floor() as i32,
))
};
set.sticky_layer
.remap_minimized(minimized_window.window, from, position);
} else {
unreachable!("None sticky window in WorkspaceSet minimized_windows");
}
}
}
}

pub fn maximize_request(&mut self, mapped: &CosmicMapped, seat: &Seat<State>) {
self.unminimize_request(mapped, seat);
let (original_layer, floating_layer, original_geometry) = if let Some(set) = self
Expand Down

0 comments on commit e111001

Please sign in to comment.