workspaces: Correctly parse and handle states

This commit is contained in:
Victoria Brekenfeld 2022-07-08 23:22:25 +02:00
parent 85fe582d1d
commit 30a184fe36

View file

@ -87,7 +87,7 @@ pub fn spawn_workspaces(tx: glib::Sender<State>) -> SyncSender<WorkspaceEvent> {
.find_map(|(g_i, g)| { .find_map(|(g_i, g)| {
g.workspaces g.workspaces
.iter() .iter()
.position(|w| w.state == 0) .position(|w| w.states.contains(&zcosmic_workspace_handle_v1::State::Active))
.map(|w_i| (g, w_i)) .map(|w_i| (g, w_i))
}) })
{ {
@ -152,7 +152,12 @@ impl State {
.iter() .iter()
.filter_map(|g| { .filter_map(|g| {
if g.output == self.expected_output { if g.output == self.expected_output {
Some(g.workspaces.iter().map(|w| (w.name.clone(), w.state))) Some(g.workspaces.iter().map(|w| dbg!((w.name.clone(), match &w.states {
x if x.contains(&zcosmic_workspace_handle_v1::State::Active) => 0,
x if x.contains(&zcosmic_workspace_handle_v1::State::Urgent) => 1,
x if x.contains(&zcosmic_workspace_handle_v1::State::Hidden) => 2,
_ => 3,
}))))
} else { } else {
None None
} }
@ -173,7 +178,7 @@ struct Workspace {
workspace_handle: ZcosmicWorkspaceHandleV1, workspace_handle: ZcosmicWorkspaceHandleV1,
name: String, name: String,
coordinates: Vec<u8>, coordinates: Vec<u8>,
state: u32, states: Vec<zcosmic_workspace_handle_v1::State>,
} }
impl Dispatch<wl_registry::WlRegistry, ()> for State { impl Dispatch<wl_registry::WlRegistry, ()> for State {
@ -280,7 +285,7 @@ impl Dispatch<ZcosmicWorkspaceGroupHandleV1, ()> for State {
workspace_handle: workspace, workspace_handle: workspace,
name: String::new(), name: String::new(),
coordinates: Vec::new(), coordinates: Vec::new(),
state: 4, states: Vec::new(),
}) })
} }
} }
@ -336,12 +341,8 @@ impl Dispatch<ZcosmicWorkspaceHandleV1, ()> for State {
.iter_mut() .iter_mut()
.find(|w| &w.workspace_handle == workspace) .find(|w| &w.workspace_handle == workspace)
}) { }) {
if state.len() == 4 { // wayland is host byte order
// XXX is it little endian?? w.states = state.chunks(4).map(|chunk| zcosmic_workspace_handle_v1::State::try_from(u32::from_ne_bytes(chunk.try_into().unwrap())).unwrap()).collect();
w.state = u32::from_le_bytes(state.try_into().unwrap());
} else {
w.state = 3;
}
} }
} }
zcosmic_workspace_handle_v1::Event::Remove => { zcosmic_workspace_handle_v1::Event::Remove => {