Try a fix

This commit is contained in:
Alexander Rosenberg 2024-04-28 17:21:03 -07:00
parent 2f628d6a2c
commit dee8fe9ab9
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -41,8 +41,6 @@ impl Serialize for Tags {
#[derive(Clone, serde::Serialize, Default)] #[derive(Clone, serde::Serialize, Default)]
struct OutputGeometry { struct OutputGeometry {
x: i32,
y: i32,
width: i32, width: i32,
height: i32, height: i32,
scale: i32, scale: i32,
@ -52,7 +50,7 @@ struct OutputGeometry {
#[derive(Clone, Default, serde::Serialize)] #[derive(Clone, Default, serde::Serialize)]
struct Output { struct Output {
#[serde(skip_serializing)] #[serde(skip_serializing)]
name: String, name: Option<String>,
title: String, title: String,
geometry: OutputGeometry, geometry: OutputGeometry,
focused_tags: Tags, focused_tags: Tags,
@ -101,13 +99,6 @@ impl Env {
println!("{}", serde_json::to_string(self).unwrap()); println!("{}", serde_json::to_string(self).unwrap());
} }
fn get_output(&mut self, id: u32) -> &mut Output {
if !self.outputs.contains_key(&id) {
self.outputs.insert(id, Default::default());
}
self.outputs.get_mut(&id).unwrap()
}
fn is_empty(&self) -> bool { fn is_empty(&self) -> bool {
self.layout.is_none() && self.mode.is_none() && self.outputs.len() == 0 self.layout.is_none() && self.mode.is_none() && self.outputs.len() == 0
} }
@ -135,14 +126,16 @@ impl Serialize for Env {
let mut outputs: HashMap<String, Output> = HashMap::new(); let mut outputs: HashMap<String, Output> = HashMap::new();
let mut gdk_id = 0; let mut gdk_id = 0;
for (output_id, output) in &self.outputs { for (output_id, output) in &self.outputs {
let mut new = output.clone(); if let Some(name) = output.name.clone() {
new.focused = if let Some(focused_id) = self.focused_output { let mut new = output.clone();
*output_id == focused_id new.focused = if let Some(focused_id) = self.focused_output {
} else { *output_id == focused_id
false } else {
}; false
new.gdk_id = gdk_id; };
outputs.insert(new.name.clone(), new); new.gdk_id = gdk_id;
outputs.insert(name, new);
}
gdk_id += 1; gdk_id += 1;
} }
state.serialize_field("outputs", &outputs)?; state.serialize_field("outputs", &outputs)?;
@ -162,7 +155,9 @@ fn handle_river_seat_status(
}, },
zriver_seat_status_v1::Event::FocusedView { title } => { zriver_seat_status_v1::Event::FocusedView { title } => {
if let Some(focused_output) = env.focused_output { if let Some(focused_output) = env.focused_output {
env.get_output(focused_output).title = title; if let Some(output) = env.outputs.get_mut(&focused_output) {
output.title = title;
}
} }
}, },
zriver_seat_status_v1::Event::Mode { name } => { zriver_seat_status_v1::Event::Mode { name } => {
@ -204,24 +199,36 @@ fn handle_river_output_status(
match event { match event {
zriver_output_status_v1::Event::FocusedTags { zriver_output_status_v1::Event::FocusedTags {
tags: focused_tags, tags: focused_tags,
} => env.get_output(output_id).focused_tags = Tags(focused_tags), } => {
if let Some(output) = env.outputs.get_mut(&output_id) {
output.focused_tags = Tags(focused_tags);
}
},
zriver_output_status_v1::Event::ViewTags { zriver_output_status_v1::Event::ViewTags {
tags, tags,
} => env.get_output(output_id).populated_tags = tags[0..] } => {
.chunks(4) if let Some(output) = env.outputs.get_mut(&output_id) {
.map(|s| { output.populated_tags = tags[0..]
let buf = [s[0], s[1], s[2], s[3]]; .chunks(4)
let tagmask = u32::from_le_bytes(buf); .map(|s| {
for i in 0..32 { let buf = [s[0], s[1], s[2], s[3]];
if 1 << i == tagmask { let tagmask = u32::from_le_bytes(buf);
return 1 + i; for i in 0..32 {
} if 1 << i == tagmask {
} return 1 + i;
0 }
}).collect(), }
0
}).collect();
}
},
zriver_output_status_v1::Event::UrgentTags { zriver_output_status_v1::Event::UrgentTags {
tags, tags,
} => env.get_output(output_id).urgent_tags = Tags(tags), } => {
if let Some(output) = env.outputs.get_mut(&output_id) {
output.urgent_tags = Tags(tags);
}
},
zriver_output_status_v1::Event::LayoutName { zriver_output_status_v1::Event::LayoutName {
name, name,
} => env.layout = Some(name), } => env.layout = Some(name),
@ -239,8 +246,8 @@ fn handle_output_event(
env.read_status.wl_output = true; env.read_status.wl_output = true;
match event { match event {
wl_output::Event::Geometry { wl_output::Event::Geometry {
x, x: _,
y, y: _,
physical_width: _, physical_width: _,
physical_height: _, physical_height: _,
subpixel: _, subpixel: _,
@ -255,22 +262,29 @@ fn handle_output_event(
handle_river_output_status(&output, event, env); handle_river_output_status(&output, event, env);
}); });
} }
let entry = env.get_output(output_id);
entry.geometry.x = x;
entry.geometry.y = y;
}, },
wl_output::Event::Mode { flags: _, width, height, refresh } => { wl_output::Event::Mode { flags: _, width, height, refresh } => {
let entry = env.get_output(output_id); if let Some(output) = env.outputs.get_mut(&output_id) {
entry.geometry.width = width; output.geometry.width = width;
entry.geometry.height = height; output.geometry.height = height;
entry.geometry.refresh = refresh as f32 / 1000.0f32; output.geometry.refresh = refresh as f32 / 1000.0f32;
}
}, },
wl_output::Event::Name { wl_output::Event::Name {
name, name,
} => env.get_output(output_id).name = name, } => {
if let Some(output) = env.outputs.get_mut(&output_id) {
output.name = Some(name);
}
},
wl_output::Event::Scale { wl_output::Event::Scale {
factor factor
} => env.get_output(output_id).geometry.scale = factor,
} => {
if let Some(output) = env.outputs.get_mut(&output_id) {
output.geometry.scale = factor;
}
},
_ => {}, _ => {},
} }
} }
@ -285,7 +299,9 @@ fn global_manager_callback(
"wl_output" if version >= 3 => { "wl_output" if version >= 3 => {
let output: Main<WlOutput> = registry.bind(version, id); let output: Main<WlOutput> = registry.bind(version, id);
if let Some(env) = env.get::<Env>() { if let Some(env) = env.get::<Env>() {
env.output_id_map.insert(id, output.as_ref().id()); let output_id = output.as_ref().id();
env.output_id_map.insert(id, output_id);
env.outputs.insert(output_id, Default::default());
output.quick_assign(handle_output_event); output.quick_assign(handle_output_event);
} }
}, },