From 02bee5aea7d4e95abad5c6792f6caab1190a1e68 Mon Sep 17 00:00:00 2001 From: Shawn Wallace Date: Fri, 24 May 2024 00:09:28 -0400 Subject: [PATCH] Support WM_CLASS missing instance and null Done by AvaloniaILSpy, for some reason --- src/xstate.rs | 18 +++++++++++++----- tests/integration.rs | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/xstate.rs b/src/xstate.rs index 7eeceab..6b68fff 100644 --- a/src/xstate.rs +++ b/src/xstate.rs @@ -449,11 +449,19 @@ impl XState { let cookie = self.get_property_cookie(window, x::ATOM_WM_CLASS, x::ATOM_STRING, 256); let resolver = move |reply: x::GetPropertyReply| { let data: &[u8] = reply.value(); - // wm class is instance + class - ignore instance - let class_start = data.iter().copied().position(|b| b == 0u8).unwrap() + 1; - let data = data[class_start..].to_vec(); + trace!("wm class data: {data:?}"); + // wm class (normally) is instance + class - ignore instance + let class_start = if let Some(p) = data.iter().copied().position(|b| b == 0u8) { + p + 1 + } else { + 0 + }; + let mut data = data[class_start..].to_vec(); + if data.last().copied().unwrap() != 0 { + data.push(0); + } let class = CString::from_vec_with_nul(data).unwrap(); - debug!("{:?} class: {class:?}", window); + trace!("{:?} class: {class:?}", window); class.to_string_lossy().to_string() }; PropertyCookieWrapper { @@ -506,7 +514,7 @@ impl XState { let resolver = |reply: x::GetPropertyReply| { let data: &[u32] = reply.value(); let hints = WmHints::from(data); - debug!("wm hints: {hints:?}"); + trace!("wm hints: {hints:?}"); hints }; PropertyCookieWrapper { diff --git a/tests/integration.rs b/tests/integration.rs index 71780d6..8d30cf8 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -403,7 +403,7 @@ fn toplevel_flow() { window, x::ATOM_STRING, x::ATOM_WM_CLASS, - &[c"f".to_bytes_with_nul(), c"ssalc".to_bytes_with_nul()].concat(), + &[c"boink".to_bytes()].concat(), ); connection.set_property( window, @@ -415,7 +415,7 @@ fn toplevel_flow() { let data = f.testwl.get_surface_data(surface).unwrap(); let toplevel = data.toplevel().toplevel.clone(); assert_eq!(data.toplevel().title, Some("bindow".into())); - assert_eq!(data.toplevel().app_id, Some("ssalc".into())); + assert_eq!(data.toplevel().app_id, Some("boink".into())); assert_eq!( data.toplevel().min_size, Some(testwl::Vec2 { x: 25, y: 50 })