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)]
struct OutputGeometry {
x: i32,
y: i32,
width: i32,
height: i32,
scale: i32,
@ -52,7 +50,7 @@ struct OutputGeometry {
#[derive(Clone, Default, serde::Serialize)]
struct Output {
#[serde(skip_serializing)]
name: String,
name: Option<String>,
title: String,
geometry: OutputGeometry,
focused_tags: Tags,
@ -101,13 +99,6 @@ impl Env {
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 {
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 gdk_id = 0;
for (output_id, output) in &self.outputs {
let mut new = output.clone();
new.focused = if let Some(focused_id) = self.focused_output {
*output_id == focused_id
} else {
false
};
new.gdk_id = gdk_id;
outputs.insert(new.name.clone(), new);
if let Some(name) = output.name.clone() {
let mut new = output.clone();
new.focused = if let Some(focused_id) = self.focused_output {
*output_id == focused_id
} else {
false
};
new.gdk_id = gdk_id;
outputs.insert(name, new);
}
gdk_id += 1;
}
state.serialize_field("outputs", &outputs)?;
@ -162,7 +155,9 @@ fn handle_river_seat_status(
},
zriver_seat_status_v1::Event::FocusedView { title } => {
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 } => {
@ -204,24 +199,36 @@ fn handle_river_output_status(
match event {
zriver_output_status_v1::Event::FocusedTags {
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 {
tags,
} => env.get_output(output_id).populated_tags = tags[0..]
.chunks(4)
.map(|s| {
let buf = [s[0], s[1], s[2], s[3]];
let tagmask = u32::from_le_bytes(buf);
for i in 0..32 {
if 1 << i == tagmask {
return 1 + i;
}
}
0
}).collect(),
} => {
if let Some(output) = env.outputs.get_mut(&output_id) {
output.populated_tags = tags[0..]
.chunks(4)
.map(|s| {
let buf = [s[0], s[1], s[2], s[3]];
let tagmask = u32::from_le_bytes(buf);
for i in 0..32 {
if 1 << i == tagmask {
return 1 + i;
}
}
0
}).collect();
}
},
zriver_output_status_v1::Event::UrgentTags {
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 {
name,
} => env.layout = Some(name),
@ -239,8 +246,8 @@ fn handle_output_event(
env.read_status.wl_output = true;
match event {
wl_output::Event::Geometry {
x,
y,
x: _,
y: _,
physical_width: _,
physical_height: _,
subpixel: _,
@ -255,22 +262,29 @@ fn handle_output_event(
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 } => {
let entry = env.get_output(output_id);
entry.geometry.width = width;
entry.geometry.height = height;
entry.geometry.refresh = refresh as f32 / 1000.0f32;
if let Some(output) = env.outputs.get_mut(&output_id) {
output.geometry.width = width;
output.geometry.height = height;
output.geometry.refresh = refresh as f32 / 1000.0f32;
}
},
wl_output::Event::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 {
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 => {
let output: Main<WlOutput> = registry.bind(version, id);
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);
}
},