Repository: j0ru/kickoff (language: rust)

Issue:
Panic on Result::unwrap() at src/main.rs:320
```console
$ RUST_BACKTRACE=full kickoff
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }', src/main.rs:320:46
stack backtrace:
   0:     0x561fd25bfc10 - <unknown>
   1:     0x561fd2429d8e - <unknown>
   2:     0x561fd259b9f4 - <unknown>
   3:     0x561fd25c0b83 - <unknown>
   4:     0x561fd25c1abd - <unknown>
   5:     0x561fd25c1682 - <unknown>
   6:     0x561fd25c15ec - <unknown>
   7:     0x561fd25c15c1 - <unknown>
   8:     0x561fd2380362 - <unknown>
   9:     0x561fd23805e2 - <unknown>
  10:     0x561fd23bd23a - <unknown>
  11:     0x561fd239f7e4 - <unknown>
  12:     0x561fd2486014 - <unknown>
  13:     0x561fd2495741 - <unknown>
  14:     0x561fd2457d83 - <unknown>
  15:     0x561fd24940e7 - <unknown>
  16:     0x7f2b90029290 - <unknown>
  17:     0x7f2b9002934a - __libc_start_main
  18:     0x561fd23939e5 - <unknown>
  19:                0x0 - <unknown>
EXIT 101
```
```console
$ kickoff --version
kickoff 0.5.1
EXIT 0
```
Running Plasma Wayland
```console
$ pacman -Ss plasma wayland | grep installed
extra/kwayland-integration 5.25.5-1 (plasma) [installed]
extra/layer-shell-qt 5.25.5-1 (plasma) [installed]
extra/plasma-wayland-protocols 1.8.0-1 [installed]
extra/plasma-wayland-session 5.25.5-2 [installed]
EXIT 0
```


Discussion / hints:
Sorry for the late answer.
Is this problem a regression or has it never worked?
I recently had to create a hotpatch to stay compatible with sway, maybe there is a protocol difference between sway and kde in the layershell implementation.
First time trying it, and this is the error I got, so it never worked for me.

I installed it with the package manager. [This is the PKGBUILD](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=kickoff).

I will try to build it from source and will try multiple versions and will report on what I discover.
v0.5.0 is the latest version before the patch, if that doesn't work, none will, so that's the only one that needs to be tested.
I just updated all dependencies, try building it from main, maybe the problem has gone away by itself.
* `cargo install kickoff` - Still panics. The stack trace is more readable, although doesn't look that helpful.
* Built from main - panics
* Built from v0.5.1 - panics
* Built from v0.5.0 or v0.4.5:
```
$ ./target/debug/kickoff
[wayland-client error] Attempted to dispatch unknown opcode 0 for wl_shm, aborting.
[1]    26304 IOT instruction (core dumped)  ./target/debug/kickoff
EXIT 134
```
Building with `cargo build`.
```
$ cargo --version
cargo 1.66.0-nightly (73ba3f35e 2022-09-18)
EXIT 0
```
It's not out of the question that there might be something wrong with my setup. I've just switched to wayland. Still learning the ropes.
It's not just you, I spend some time this afternoon to test some things for myself and I couldn't get it to work. The current incompatibility is a problem of kickoff, I'll look into it tomorrow 
I found the issue, if my next train has power sockets I might even be able to fix it today

Fix patch:
diff --git a/src/gui.rs b/src/gui.rs
index 38ee38b..f952ffc 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -28,7 +28,7 @@ use std::cell::Cell;
 use std::io::{BufWriter, ErrorKind, Seek, SeekFrom, Write};
 use std::rc::Rc;
 
-use image::RgbaImage;
+use image::{Pixel, Rgba, RgbaImage};
 
 use crate::keybinds::Keybindings;
 
@@ -108,7 +108,7 @@ impl Surface {
         }
     }
 
-    pub fn draw(&mut self, image: &RgbaImage) -> Result<(), std::io::Error> {
+    pub fn draw(&mut self, mut image: RgbaImage) -> Result<(), std::io::Error> {
         if let Some(pool) = self.pools.pool() {
             let stride = 4 * self.dimensions.0 as i32;
             let width = self.dimensions.0 as i32;
@@ -118,7 +118,11 @@ impl Surface {
             pool.resize((stride * height) as usize)?;
 
             // Create a new buffer from the pool
-            let buffer = pool.buffer(0, width, height, stride, wl_shm::Format::Abgr8888);
+            let buffer = pool.buffer(0, width, height, stride, wl_shm::Format::Argb8888);
+            image.pixels_mut().for_each(|pixel| {
+                let channels = pixel.channels_mut();
+                *pixel = *Rgba::from_slice(&[channels[2], channels[1], channels[0], channels[3]]);
+            });
 
             // Write the color to all bytes of the pool
             pool.seek(SeekFrom::Start(0))?;
diff --git a/src/main.rs b/src/main.rs
index d855cfa..d1f2122 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -297,7 +297,7 @@ async fn run() -> Result<Option<JoinHandle<()>>, Box<dyn Error>> {
                 );
             }
 
-            match surface.draw(&img) {
+            match surface.draw(img) {
                 Ok(_) => {}
                 Err(e) => {
                     error!("{}", e);


Test patch: