dunst-project / dunst

Lightweight and customizable notification daemon
https://dunst-project.org
Other
4.59k stars 341 forks source link

Allow setting notification width in the rules #1049

Open DusanLesan opened 2 years ago

DusanLesan commented 2 years ago

I am unable to set some notifications to be larger than all others

Currently, I am trying to display weather reports from wttr.in. I want it to be wide more than 500 pixels but I cannot add that to the weather notification rule. If I set width = (300, 1000), I am able too see weather notification fine but then all notification try to use max width. In my case, max width is only ok for this weather notification but not for other notifications like for example messages from slack. I want most of my notifications to be displayed only in one small box instead of extending over half of my screen.

I need a way to set max width for some notifications without allowing others to be wide.

I have also experienced few other difficulties that are not critical as this one. If you think they are valid, I can remove them from here and create separate issues.

Installation info

Minimal dunstrc ```ini [global] height = 1035 width = (300, 1000) format = "%s\n%b" ```
fwsmit commented 2 years ago

I need a way to set max width for some notifications without allowing others to be wide.

I get that there is a use case. Here's the reason why I didn't implement it initially. Dunst currently uses a single window to show all the notifications. Dunst is only able to set a single width for the entire window. So if there are multiple notification with different widths set, dunst doesn't know what to do. Before allowing multiple widths, I would first like to implement multiple windows (#1018).

Event though I am able to see output from the curl request in my terminal, I cannot see it in dunst without limiting output from displaying colors that looks like this

Dunst doesn't support terminal colors. You could probably write some clever sed or other command to convert it to the pango format.

Second issue I have is that for some reason, the text in the body is getting moved like it is not monospace but the same text in summary is ok. The format is the same for %s as for %b: format = "<b>%s</b>\n<b>%b</b>". You can see that in the body, few table borders start drifting from expected position:

This could be a real issue. Although I don't think it would be on dunst's side. If you want, you can figure out some reproduction steps to work the issue out.

Third issue is nitpick about documentation. It is really easy to miss that there is markup option and because of that to miss that we need to learn pango markup. Mentioning pango link in format section could be realy helpful for someone like me.

It'd be great if you could submit a pull request to make it easier to find. We can always use help improving the documentation.

DusanLesan commented 2 years ago

I need a way to set max width for some notifications without allowing others to be wide.

I get that there is a use case. Here's the reason why I didn't implement it initially. Dunst currently uses a single window to show all the notifications. Dunst is only able to set a single width for the entire window. So if there are multiple notification with different widths set, dunst doesn't know what to do. Before allowing multiple widths, I would first like to implement multiple windows (#1018).

Ok. I now understand the issue. I will be patient. Resizing all up when wide notification is sent and then after it is hidden, returning to default would be good enough for me.

Event though I am able to see output from the curl request in my terminal, I cannot see it in dunst without limiting output from displaying colors that looks like this

Dunst doesn't support terminal colors. You could probably write some clever sed or other command to convert it to the pango format.

I am now doing that for calendar like:

 notify-send "date" "$(cal -m --color=always | sed "s/..7m/<b><span color=\"red\">/;s/..27m/<\/span><\/b>/")" 

But in this case that may be too inconvenient since weather text is having more colors

Second issue I have is that for some reason, the text in the body is getting moved like it is not monospace but the same text in summary is ok. The format is the same for %s as for %b: format = "<b>%s</b>\n<b>%b</b>". You can see that in the body, few table borders start drifting from expected position:

This could be a real issue. Although I don't think it would be on dunst's side. If you want, you can figure out some reproduction steps to work the issue out.

You can try to repro this with my minimal config and this command. It may be enough just to allow notifications this wide. notify-send "$(curl -s "wttr.in/London?0QFT")" "$(curl -s "wttr.in/London?0QFT")"

Third issue is nitpick about documentation. It is really easy to miss that there is markup option and because of that to miss that we need to learn pango markup. Mentioning pango link in format section could be realy helpful for someone like me.

It'd be great if you could submit a pull request to make it easier to find. We can always use help improving the documentation.

I do not really have the idea how to word this out. IMO just adding For a complete markup reference see <https://docs.gtk.org/Pango/pango_markup.html> Same as for markup setting would be plenty helpful

fwsmit commented 2 years ago

Ok. I now understand the issue. I will be patient. Resizing all up when wide notification is sent and then after it is hidden, returning to default would be good enough for me.

You can play around with dunstctl rule name [enable|disable|toggle] to enable/disable rules dynamically.

I do not really have the idea how to word this out. IMO just adding For a complete markup reference see <https://docs.gtk.org/Pango/pango_markup.html> Same as for markup setting would be plenty helpful

Done in 096a433f031c85ef90e707d10eab8afba4593472

You can try to repro this with my minimal config and this command. It may be enough just to allow notifications this wide. notify-send "$(curl -s "wttr.in/London?0QFT")" "$(curl -s "wttr.in/London?0QFT")"

Could not reproduce with that. It looks fine on my system: 20220316_17h36m46s_grim

You might need to add a font or some other detail to make reproducing possible. Note as well that I tried it on the latest master + latest pango.

DusanLesan commented 2 years ago

You can try to repro this with my minimal config and this command. It may be enough just to allow notifications this wide. notify-send "$(curl -s "wttr.in/London?0QFT")" "$(curl -s "wttr.in/London?0QFT")"

Could not reproduce with that. It looks fine on my system: 20220316_17h36m46s_grim

Sorry, I have provided the wrong command so the output is different than in the original message. Correct one should be:

notify-send "$(curl -s "wttr.in/London?1QFT")" "$(curl -s "wttr.in/London?1QFT")"
fwsmit commented 2 years ago

Thanks for providing me with a repro. I found the cause: The \ characters in the suns are acting as escape characters and disappear because of that. You can see it with:

dunstify "test \ " "test \ " The second backslash disappears.

Even with markup = no and markup = strip this happens. I think it's expected for the markup=yes case, and maybe for markup=strip, but I think for markup = no there should be no weird things like this going on.

edit: I've created a new issue for this #1055

DusanLesan commented 2 years ago

@fwsmit Unless you need this issue open for some tracking purposes, I am ok with closing it. Also I am ok with messed up escaping. I can just double up all backslashes I have in input.

emilBeBri commented 11 months ago

@DusanLesan did you find a good solution for this? been playing around with it and the output looks skewed even if I run it through sed to get double escape slashes. (even looked at your dotfiles but couldn't find it)

DusanLesan commented 11 months ago

@DusanLesan did you find a good solution for this? been playing around with it and the output looks skewed even if I run it through sed to get double escape slashes. (even looked at your dotfiles but couldn't find it)

Does this work for you:

notify-send "$(curl -s "wttr.in/Los_Angeles?1QFT")" "$(curl -s "wttr.in/Los_Angeles?1QFT" | sed 's/\\/\\\\/g' )"
emilBeBri commented 11 months ago

Hey that's what I did myself, although I'm not sure why you would have the whole output twice?

It is sort of readable, but also skewed, so it does not have that quality of being immediately readable that would be nice. Looks like this:

scrot_2023-11-02_18-45-37

in my dunstrc I made the width dynamic (globally)

    width = (300, 20000)
DusanLesan commented 11 months ago

Hey that's what I did myself, although I'm not sure why you would have the whole output twice?

I have it doubled only because that is how I already had it in this thread (and that is because summary behaves differently than message body for me).

With my dunstrc only modified to have dynamic size, command

notify-send " " "$(curl -s "wttr.in/${cityPath##*/}?1FTQ" | sed 's/\\/\\\\/g' )"

gives this result for me image

But I do not even use sed for myself because instead I use weather response as a summary (like I commited now)