Skip to content

Commit aa8ed24

Browse files
committed
Cleanup: fix U8x3 images + implement agent-to-render poke command to wake up render thread upon monitor reseat
1 parent 6f3f3e6 commit aa8ed24

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

src/pithos/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ pub enum RenderThreadCommand {
5151
Render(RenderCommand),
5252
Scroll(ScrollCommand),
5353
ConfigReload(DaemonConfig),
54+
Poke, // NOP to jostle out of command-blocking i/o => hand control back to the wayland control loop
5455
}

src/pithos/misc.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use fast_image_resize::{images::Image, pixels::U8x4};
1+
use fast_image_resize::{images::Image, pixels::{U8x3, U8x4}};
22
use std::{
33
fs::File,
44
io::{BufWriter, Write},
@@ -11,14 +11,18 @@ pub fn img_into_buffer(img: &Image, buf: &mut BufWriter<&File>) {
1111
let start = std::time::Instant::now();
1212
let loop_start = std::time::Instant::now();
1313

14-
match img.typed_image::<U8x4>() {
15-
Some(typed) => {
14+
if let Some(typed) = img.typed_image::<U8x4>() {
15+
for pixel in typed.pixels() {
16+
let (r, g, b, a) = (pixel.0[0], pixel.0[1], pixel.0[2], pixel.0[3]);
17+
buf.write_all(&[b, g, r, a]).unwrap();
18+
}
19+
} else {
20+
if let Some(typed) = img.typed_image::<U8x3>() {
1621
for pixel in typed.pixels() {
17-
let (r, g, b, a) = (pixel.0[0], pixel.0[1], pixel.0[2], pixel.0[3]);
22+
let (r, g, b, a) = (pixel.0[0], pixel.0[1], pixel.0[2], u8::max_value());
1823
buf.write_all(&[b, g, r, a]).unwrap();
1924
}
20-
}
21-
None => {
25+
} else {
2226
panic!("image could not be coerced to U8x4");
2327
}
2428
}

src/threads/niri.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ impl NiriProcessor {
223223
fn process(&mut self, pandora: Arc<dyn Daemon + Send + Sync>, e: niri_ipc::Event) {
224224
match e {
225225
Event::WorkspacesChanged { workspaces } => {
226+
self.poke(pandora.clone());
226227
for output in &mut self.outputs {
227228
output.1.max_workspace_idx = 0;
228229
}
@@ -233,17 +234,25 @@ impl NiriProcessor {
233234
self.gen_scroll_cmd_for_workspace_id(pandora.clone(), id)
234235
}
235236
Event::WindowFocusChanged { id: _ } => {
237+
self.poke(pandora.clone());
236238
// TODO - niri includes tile layouts in WindowLayout structs now
237239
// we should keep track of the full pixel width of each workspace,
238240
// as well as the position of the focused window within that mosaic
239241
// and compute a scroll percentage based on that
240242
// we'll want to then start using that whenever we gen_scroll_cmd,
241243
// and just trust the render thread to discard or use as needed.
242244
}
245+
Event::WindowLayoutsChanged { changes } => {
246+
self.poke(pandora.clone());
247+
}
243248
_ => (), // idc about other events rn
244249
}
245250
}
246251

252+
fn poke(&self, pandora: Arc<dyn Daemon + Send + Sync>) {
253+
pandora.handle_cmd(&CommandType::Tc(RenderThreadCommand::Poke));
254+
}
255+
247256
fn gen_scroll_cmd_for_workspace_id(&self, pandora: Arc<dyn Daemon + Send + Sync>, id: u64) {
248257
let workspace = self.workspaces.iter().find(|w| w.id == id).unwrap();
249258
let curr_idx = workspace.idx;

src/threads/render.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl WallpaperThread {
103103
// did not process any animation commands this tick; block on command queue lazy style
104104
if !state.is_animating() {
105105
// not currently animating; block on an inbound event
106+
self.verbose("parking at wait for inbound command".to_string());
106107
match self.cmd_queue.lock() {
107108
Ok(queue) => self.handle_cmd(
108109
conn,
@@ -171,6 +172,7 @@ impl WallpaperThread {
171172
RenderThreadCommand::ConfigReload(new_config) => {
172173
self.config_reload(state, new_config);
173174
}
175+
RenderThreadCommand::Poke => (),
174176
}
175177
}
176178

src/wayland/render_base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl WallpaperRenderState {
420420
output_state: &OutputState,
421421
) -> Self {
422422
// todo: file reuse from unplugged
423-
let mut new_state = WallpaperRenderState::new(
423+
let new_state = WallpaperRenderState::new(
424424
conn,
425425
render_state,
426426
&unplugged.image,
@@ -433,7 +433,6 @@ impl WallpaperRenderState {
433433
)),
434434
unplugged.slowdown,
435435
);
436-
new_state.start_scroll_anim(conn);
437436
return new_state;
438437
}
439438

0 commit comments

Comments
 (0)