Sweets / tiramisu

Desktop notifications, the UNIX way
MIT License
747 stars 19 forks source link

[QUESTION] But to have desktop notifications #29

Closed Veraellyunjie closed 3 years ago

Veraellyunjie commented 3 years ago

Is there a way to intercept notifications with tiramisu, process them and make (some of) them appear as desktop notifications?

E.g.:

  1. Have desktop notifications in leetspeak/Morse/X-SAMPA etc.
  2. Notifications to be both showed on the desktop and e-mailed.
  3. Depending on notification in question, either show it as a desktop notification or e-mail it.
Sweets commented 3 years ago

Yes. That's kind of the purpose of tiramisu, to provide a means to do whatever you want with a notification.

You'll pipe the output from STDOUT into a program of your choice. Since you want to do multiple things based on notification data, you'll have to write your own script to read the input data and determine what to do with it.

Veraellyunjie commented 3 years ago

So how do I still have the desktop notifications with tiramisu? Those that are usually rectangles that pop-up for several seconds in a screen's corner. Currently, I use lxqt-notificationd which draws that rectangles. In order to use tiramisu I need to kill lxqt-notificationd; tiramisu doesn't draw that rectangles, so I am left without the conventional on-screen desktop notifications. Yes, I get notification messages in STDOUT, but how do I turn them into conventional on-screen desktop notifications if tiramisu doesn't draw those rectangles and only one org.freedesktop.Notifications daemon can be active? In other words, how to have notifications both in STDOUT and on the screen?

dther commented 3 years ago

You'll want to use something like herbe. Herbe is a notification system that doesn't use D-Bus, but acts like dunst and lxqtnotificationd - it draws a visual box on your desktop that you can dismiss in your own time, and gets its information from stdin. It isn't dissimilar to using dmenu, or a less-intrusive pop up window alert script.

The caveat to this is that, well, it looks like dunst, and you might not like how it looks different from lxqt's notifications. There's not much you can do about this aside from editing the source code to look like lxqt, or finding/making an alternative D-Bus-less notification program that looks more like it.

Sweets commented 3 years ago

So how do I still have the desktop notifications with tiramisu? Those that are usually rectangles that pop-up for several seconds in a screen's corner. Currently, I use lxqt-notificationd which draws that rectangles. In order to use tiramisu I need to kill lxqt-notificationd; tiramisu doesn't draw that rectangles, so I am left without the conventional on-screen desktop notifications. Yes, I get notification messages in STDOUT, but how do I turn them into conventional on-screen desktop notifications if tiramisu doesn't draw those rectangles and only one org.freedesktop.Notifications daemon can be active? In other words, how to have notifications both in STDOUT and on the screen?

You'll need to use some application that draws the notifications on the screen. There can only be one daemon active; so the drawing on the screen is up to the user.

Veraellyunjie commented 3 years ago

@dther You got the point what I want, thanks for reply.

The problem with herbe is not only its look, but also:

Thus, herbe is not a viable alternative for a modern desktop (for now).

the drawing on the screen is up to the user

Well, I would have thought that when a user comes for a desktop notifications utility, (s)he expects the desktop notifications already present in it :) Drawing on the screen the notifications-way is not something that a user just does him/her-self.
The unix way is about design and not about missing parts. It is not that I demand it from @Sweets, but this part of the desktop notifications functionality is lacking in tiramisu and needs to be filled somehow.

finding/making an alternative D-Bus-less notification program

This is the question of the topic.
herbe is overly minimal;
any viable options available?

Sweets commented 3 years ago

The underlying issue here is that tiramisu isn't functionally lacking in this regard. It does what it's supposed to, and nothing more. The bigger issue here is that there's few utilities that allow you to freely display whatever you would like as a desktop notification.

This issue is very niche though, given that most if not all desktop notification daemons are built to display the notifications themselves. None of them defer to another application to.

That being said though, you could easily create a program that achieves this. Even with simply using GTK, if you would rather not opt for lower level calls to X using xlib/xcb or Wayland even.

The life cycle of such a program would be as follows:

Some additional functionality could be done for notifications that expect input of some kind. Say processing user input to the window. Again though, this is all beyond the scope of what tiramisu is trying to accomplish. It's not lacking in functionality on an individual level, moreso it's lacking supporting elements.

dther commented 3 years ago

when a user comes for a desktop notifications utility, (s)he expects the desktop notifications already present in it herbe is overly minimal; any viable options available?

Unfortunately not, and I don't forsee there being an "easy" solution to these problems. As @Sweets explains, these are meant to be solved by the user. To start you off, here's one possible solution for your "no buttons" problem:

herbe is designed to use exit codes to convey how the notification was dismissed. Clicking with ACTION_BUTTON (by default right click) will always result in EXIT_SUCCESS, anything else is a failure. The implication of this is you can bind an action to an arbitrary shell script. Like so...

#Have a tiramisu wrapper script extract this info:
# $TIRAMISU_MESSAGE - variable containing the text of the notification
# $TIRAMISU_COMMAND - a command to switch to a window, take a screenshot, 
# whatever you want to do when you click on the notification. 
# It can vary based on what $TIRAMISU_MESSAGE is. 
# maybe you don't want browser notifications to be clickable, 
# or maybe you want to launch a terminal app instead of the desktop app.

herbe $TIRAMISU_MESSAGE && sh -c $TIRAMISU_COMMAND
# Right clicking will cause $TIRAMISU_COMMAND to run,
# left clicking ignores the notification
# $TIRAMISU_MESSAGE is unaffected by this, and you can easily push this to your email script still.

"no progress bar" and "no log" could similarly be solved with little shell scripts like these. I'll leave that as an exercise to you. "no icons" and "no changing notification text" will, unfortunately, require a bit more adventurous C hacking to get working. I'd do it myself, but I haven't found the time. :(

In short, the price of tiramisu's great customisability means that it leaves these features to be designed by the users who want them. It's powerful and useful, but as you've seen, sometimes inconvenient- I'd like many of the features you'd outlined too, but it falls on us to implement them... and I still use dunst, because I haven't had time to customise my own herbe + tiramisu system :(

Veraellyunjie commented 2 years ago

JFYI, there also is https://github.com/phillbush/xnotify

~/.xinitrc:

XNOTIFY_FIFO="$HOME/.cache/xnotify$DISPLAY.fifo"
export XNOTIFY_FIFO
rm -f $XNOTIFY_FIFO
mkfifo $XNOTIFY_FIFO
xnotify 0<>$XNOTIFY_FIFO
tiramisu -o "$(printf '#summary\t#body\n')" > $XNOTIFY_FIFO &
unrealapex commented 9 months ago

herbe is designed to use exit codes to convey how the notification was dismissed. Clicking with ACTION_BUTTON (by default right click) will always result in EXIT_SUCCESS, anything else is a failure. The implication of this is you can bind an action to an arbitrary shell script. Like so...

#Have a tiramisu wrapper script extract this info:
# $TIRAMISU_MESSAGE - variable containing the text of the notification
# $TIRAMISU_COMMAND - a command to switch to a window, take a screenshot, 
# whatever you want to do when you click on the notification. 
# It can vary based on what $TIRAMISU_MESSAGE is. 
# maybe you don't want browser notifications to be clickable, 
# or maybe you want to launch a terminal app instead of the desktop app.

herbe $TIRAMISU_MESSAGE && sh -c $TIRAMISU_COMMAND
# Right clicking will cause $TIRAMISU_COMMAND to run,
# left clicking ignores the notification
# $TIRAMISU_MESSAGE is unaffected by this, and you can easily push this to your email script still.

How would I go about getting $TIRAMISU_COMMAND? I tried using the #actions key, however, its output cannot be ran:

tiramisu -o "#actions" | 
  while read -r line; do
    actions=$(cut -d ';' -f 1 <<< "$line")
    # TODO: execute notification action
    herbe "foo" && sh -c "$actions"
done