'Replace` mode
vredesbyyrd opened this issue · 4 comments
Hi, thanks for sharing this tool, its quite awesome!
Would it be possible to implement a mode where only one notification can be displayed at a time? In pseudo code: timeout = 5sec or new notification received
.
I'm trying to write a simple script that will display an album art notification on mpd
track change events, and xnotify
seems like the almost perfect tool for the job.
Maybe a way to flush the notification queue whenever stdin receives new data?
Thanks for your time
Done!
The last commit add an -o
command-line option (-o
for “one notification at a time”) that implements this behavior.
Can you check whether this new version works as expected for you?
Also, I recommend you to use a tab between the album name and track title for better formatting.
(The text before a tab appears in bold and the text after the tab appears in a new line).
Awesome, thanks for the quick patch and the formatting tips.
Although I cannot reproduce the expected behavior of the -o
flag. Executing this twice as a test:
printf 'IMG:/home/clu/.cache/beet_mpd/1_big.jpg\thello\n' | xnotify -o -G NE -g 300x300-5+30 -s 5 &
...still results in multiple notifications "living" at the same time.
Prior to this commit, I was doing this for "one notification at a time", hackish, but did the job.
local notification = bp.echo(img) | bp.xnotify('-G', 'NE', '-g', '300x300-5+30', '-s', '3')
local cmd = bp.pgrep('-f', 'xnotify')
if #cmd() > 0 then
os.execute('pkill xnotify')
print(notification())
else
print(notification())
end
Any thoughts on why this the -o
flag is not working as expected on my end? Thanks again.
I spotted the problem: you are spawning two xnotify instances.
You should create a pipe, spawn a single xnotify instance and make this instance read from the pipe.
Put the following at the beginning of your .xinitrc
or .xsession
file.
# create a variable pointing to the pipe
export XNOTIFY_FIFO="$HOME/.cache/xnotify$DISPLAY.fifo"
# remove the pipe, if it exists
rm -f $XNOTIFY_FIFO
# create the pipe
mkfifo $XNOTIFY_FIFO
# spawn xnotify reading from the pipe you just created
xnotify -o -G NE -g 300x300-5+30 -s 5 & <$XNOTIFY_FIFO 3<>$XNOTIFY_FIFO &
Each line is commented explaining what they do.
Then, you write the notification into the pipe file, whose name is contained in the variable $XNOTIFY_FIFO
:
printf 'IMG:/home/clu/.cache/beet_mpd/1_big.jpg\ttitle\tbody\n' >$XNOTIFY_FIFO
Anytime you want to create a notification, just write it into $XNOTIFY_FIFO
.
Got it. My bad, i suspected that we might need to write to a fifo for this to work, and thought I already tried to do so, apparently not :/ Everything works as advertised now.. Appreciate the walk through.
Congrats on this light and powerful piece of software, good stuff!