hyprshell_windows_lib/switch/
update.rs

1use crate::global::WindowsSwitchData;
2use crate::next::{find_next_client, find_next_workspace};
3use adw::prelude::WidgetExt;
4use core_lib::transfer::SwitchSwitchConfig;
5use tracing::debug_span;
6
7pub fn update_switch(data: &mut WindowsSwitchData, config: &SwitchSwitchConfig) {
8    let _span = debug_span!("update_switch").entered();
9
10    let active = if data.config.switch_workspaces {
11        find_next_workspace(
12            &config.direction,
13            true,
14            &data.hypr_data,
15            data.active,
16            data.config.items_per_row,
17        )
18    } else {
19        find_next_client(
20            &config.direction,
21            true,
22            &data.hypr_data,
23            data.active,
24            data.config.items_per_row,
25        )
26    };
27    data.active = active;
28
29    if data.config.switch_workspaces {
30        for button in data.clients.values() {
31            button.remove_css_class("active");
32        }
33        for (id, button) in &data.workspaces {
34            button.remove_css_class("active");
35            if active.workspace == *id {
36                button.add_css_class("active");
37            }
38        }
39    } else {
40        for button in data.workspaces.values() {
41            button.remove_css_class("active");
42        }
43        for (id, button) in &data.clients {
44            button.remove_css_class("active");
45            if active.client == Some(*id) {
46                button.add_css_class("active");
47            }
48        }
49    }
50}