diff --git a/src/main.rs b/src/main.rs index d5cfa35..61125dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ struct Args { #[derive(Debug, Clone, Serialize, PartialEq, Eq)] struct State { - active_window: Option, + active_window: WindowInfo, workspaces: Vec, } @@ -28,8 +28,18 @@ struct Workspace { #[derive(Debug, Clone, Serialize, PartialEq, Eq)] struct WindowInfo { id: u32, - name: Option, - class: Option, + name: String, + class: String, +} + +impl WindowInfo { + fn placeholder() -> Self { + Self { + id: 0, + name: String::new(), + class: String::new(), + } + } } xcb::atoms_struct! { @@ -119,7 +129,7 @@ impl X11 { }) .collect(); - let mut active_window = None; + let mut active_window = WindowInfo::placeholder(); for id in client_ids { // Skip dock/panel windows @@ -153,16 +163,18 @@ impl X11 { // Check if this is the active window if effective_active_id == Some(id) { - active_window = Some(window.clone()); + active_window = window.clone(); } workspace.windows.push(window); } // If we still don't have an active window, try to find the focused window - if active_window.is_none() { + if active_window.id == 0 { if let Some(id) = effective_active_id { - active_window = self.window_info(id).ok(); + if let Ok(window) = self.window_info(id) { + active_window = window; + } } } @@ -242,11 +254,13 @@ impl X11 { let name = self .property_bytes_opt(window, self.atoms.net_wm_name, self.atoms.utf8_string)? - .and_then(|bytes| String::from_utf8(bytes).ok()); + .and_then(|bytes| String::from_utf8(bytes).ok()) + .unwrap_or_default(); let class = self .property_bytes_opt(window, self.atoms.wm_class, x::ATOM_STRING)? - .map(|bytes| parse_wm_class(&bytes)); + .map(|bytes| parse_wm_class(&bytes)) + .unwrap_or_default(); Ok(WindowInfo { id, name, class }) }