kolunmi / sandbar

dwm-like bar for the river wayland compositor
Other
40 stars 4 forks source link

print to the bar from script #9

Closed dkwo closed 1 year ago

dkwo commented 1 year ago

What is the recommended way to print to the bar from a script? I've seen scripts using mkfifo

mkfifo $XDG_RUNTIME_DIR/sandbar-0
sandbar < $XDG_RUNTIME_DIR/sandbar-0 &
echo "all status hello" > $XDG_RUNTIME_DIR/sandbar-0

but this does work for me: I can use the sandbar command (both in river and in the terminal (foot)), but not redirect stdin. I'm on musl, building from latest git.

Btw, I noticed the warning

cc -fstack-clash-protection -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe    -ffile-prefix-map=/builddir/sandbar-0.1=. -Wall -Wextra -Wno-unused-parameter -g -DUTF8PROC_EXPORTS -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1      -c -o sandbar.o sandbar.c
sandbar.c: In function 'draw_text':
sandbar.c:255:57: warning: 'fg_fill' may be used uninitialized [-Wmaybe-uninitialized]
  255 |                                                         pixman_image_unref(fg_fill);
      |                                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sandbar.c:220:25: note: 'fg_fill' was declared here
  220 |         pixman_image_t *fg_fill;
      |                         ^~~~~~~

Thanks for this project. It'd be great if you can tag a release, so it can be packaged.

dkwo commented 1 year ago

@dm1tz @jedugsem maybe you can help?

dkwo commented 1 year ago

let me add that this also happens on glibc, not just musl

dkwo commented 1 year ago

built with

# Template file for 'sandbar'
pkgname=sandbar
version=0.1
revision=1
hostmakedepends="pkg-config"
makedepends="wayland-protocols pixman-devel fcft-devel wayland-devel"
short_desc="Dwm-like bar for the river wayland compositor"
license="GPL-3.0-or-later"
homepage="https://github.com/kolunmi/sandbar"
_commit_hash="95258a9c074f89387505a39bff9b1f2ea03f58e3"
distfiles="https://github.com/kolunmi/sandbar/archive/${_commit_hash}.tar.gz"
checksum=96c458e79cb1d892c29815951d86a01662361c4a1d9ff19c49f2149b37db241f

do_install() {
    make install
    vbin sandbar
}
kolunmi commented 1 year ago

Hello @dkwo! I apologize for the late response. I personally use this script:

FIFO="$XDG_RUNTIME_DIR/sandbar-0"

[ -e "$FIFO" ] && rm -f "$FIFO"
mkfifo "$FIFO"

while cat "$FIFO"; do :; done | sandbar

You can then write to the fifo.

Also I'm 99% sure the warning is not an problem, but I will look into it. Thank you!

dkwo commented 1 year ago

this works, thanks a lot!

dkwo commented 1 year ago

seems almost an irrelevant issue left, thanks again for helping

dkwo commented 1 year ago

@kolunmi While this script works fine, it does hang around after river is closed, at least if I run it via riverctl spawn. Do you know a way around this? ideally, when I exit river, the script should terminate, and the sandbar-0 fifo be erased.

dkwo commented 1 year ago

This (however hacky :), seems to do the job: while [ -e "${XDG_RUNTIME_DIR}/wayland-1" ] && cat "${FIFO}"; do :; done | sandbar &

dkwo commented 1 year ago

actually, i take it back, there seems to be no reliable way to make sure there's no process hanging around. Hence it would be desirable to implement the fifo from within sandbar.