Return placeholder instead of null
- Placeholder value when no windows active - Empty string window name and class - Avoid `null` for easier parsing
This commit is contained in:
parent
011b1d1aee
commit
987e07982e
32
src/main.rs
32
src/main.rs
@ -14,7 +14,7 @@ struct Args {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
||||
struct State {
|
||||
active_window: Option<WindowInfo>,
|
||||
active_window: WindowInfo,
|
||||
workspaces: Vec<Workspace>,
|
||||
}
|
||||
|
||||
@ -28,8 +28,18 @@ struct Workspace {
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
||||
struct WindowInfo {
|
||||
id: u32,
|
||||
name: Option<String>,
|
||||
class: Option<String>,
|
||||
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 })
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user