hyprshell_windows_lib/switch/
close.rs1use crate::global::WindowsSwitchData;
2use adw::gtk::glib;
3use adw::gtk::prelude::*;
4use core_lib::{FindByFirst, WarnWithDetails};
5use exec_lib::switch::{switch_client, switch_workspace};
6use exec_lib::{reset_no_follow_mouse, to_client_address};
7use tracing::{debug, debug_span, trace};
8
9#[must_use]
10pub fn switch_already_hidden(data: &WindowsSwitchData) -> bool {
11 !data.window.is_visible()
12}
13
14pub fn close_switch(data: &mut WindowsSwitchData, switch: bool) {
15 let _span = debug_span!("close_switch").entered();
16
17 reset_no_follow_mouse().warn_details("Failed to reset follow mouse");
18 while let Some(child) = data.main_flow.first_child() {
19 data.main_flow.remove(&child);
20 }
21 trace!("Hiding window (windows) {:?}", data.window.id());
22 data.window.set_visible(false);
23
24 if switch {
25 if let Some(id) = data.active.client {
26 debug!(
27 "Switching to client {}",
28 data.hypr_data
29 .clients
30 .find_by_first(&id)
31 .map_or_else(|| "<Unknown>".to_string(), |c| c.title.clone())
32 );
33 glib::idle_add_local(move || {
35 switch_client(to_client_address(id))
36 .warn_details(&format!("Failed to execute with id {id:?}"));
37 glib::ControlFlow::Break
38 });
39 } else {
40 let id = data.active.workspace;
41 debug!(
42 "Switching to workspace {}",
43 data.hypr_data
44 .workspaces
45 .find_by_first(&id)
46 .map_or_else(|| "<Unknown>".to_string(), |c| c.name.clone())
47 );
48 glib::idle_add_local(move || {
49 switch_workspace(id).warn_details(&format!(
50 "Failed to execute switch workspace with id {id:?}"
51 ));
52 glib::ControlFlow::Break
53 });
54 }
55 }
56}