Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add ability to put certain parts of notification on a specific side of that notification. #744

Closed
apoorv569 opened this issue Aug 2, 2020 · 33 comments
Labels

Comments

@apoorv569
Copy link

apoorv569 commented Aug 2, 2020

I am trying to use dunst as a volume and brightness notification, It would nice to see a feature that adds the ability to have certain parts of the notification output to a specified side of that notification, for example, I'm using a script for displaying a notification for when I try to adjust my volume or brightness,

#!/usr/bin/env bash

# You can call this script like this:
# $ ./volumeControl.sh up
# $ ./volumeControl.sh down
# $ ./volumeControl.sh mute

# Script modified from these wonderful people:
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a

function get_volume {
 # amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
 pactl list sinks | grep "Volume:" | awk 'NR==3 {print $5}' | sed 's/[^0-9]*//g'
}

function is_mute {
 # amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
 pactl list sinks | grep "Mute:" | awk '{print $2}' | grep yes > /dev/null
}

# For showing the volume outpute after the progress bar.
# ALSA
#vol_get=$(amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1)

# Pulseaudio
vol_get=$(pactl list sinks | grep "Volume:" | awk 'NR==3 {print $5}' | sed 's/[^0-9]*//g')
 
if [[ "$(pactl list sinks | grep "Mute:" | awk '{print $2}' | grep yes > /dev/null)" != "" ]]; then
     icon="~/.local/bin/vol-mute.png" 
elif [ "$vol_get" -lt "26" ]; then
	icon="~/.local/bin/vol-off.png"
elif [ "$vol_get" -lt "51" ] && [ "$vol_get" -gt "24" ]; then
	icon="~/.local/bin/vol-low.png"
elif [ "$vol_get" -lt "76" ] && [ "$vol_get" -gt "49" ]; then
	icon="~/.local/bin/vol-med.png"
else
	icon="~/.local/bin/vol-high.png"
fi

function send_notification {
 
  if is_mute ; then
    dunstify -i $iconMuted -r 2593 -u normal "mute"
  else
    volume=$(get_volume)
   
    # Make the bar with the special character ─ (it's not dash -)
    # https://en.wikipedia.org/wiki/Box-drawing_character
    bar=$(seq --separator="─" 0 "$((volume / 5))" | sed 's/[0-9]//g')
    
    # Spaces is used for keeping the output volume to the right side of the notification.
    spaces=$(seq --separator="+" 0 "$(( 30 - (volume / 5) ))" | sed 's/[0-9]//g')

    # Send the notification
    dunstify -i $icon -r 2593 -u normal "  ${bar}${spaces} $vol_get %"

  fi
}

case $1 in
  up)
   # set the volume on (if it was muted)
   # ALSA 
  # amixer -D pulse set Master on > /dev/null
   
   # Pulseaudio
   pactl set-sink-mute @DEFAULT_SINK@ false > /dev/null
    
   # up the volume (+ 5%)
   # ALSA
  # amixer -D pulse sset Master 5%+ > /dev/null
   
   # Pulseaudio
   pactl set-sink-volume @DEFAULT_SINK@ +2%
    
   send_notification
   ;;
  
  down)
   # ALSA 
  # amixer -D pulse set Master on > /dev/null
   
   # Pulseaudio
   pactl set-sink-mute @DEFAULT_SINK@ false > /dev/null
   
   # ALSA
   # amixer -D pulse sset Master 5%- > /dev/null
   
   # Pulseaudio
   pactl set-sink-volume @DEFAULT_SINK@ -2%
    
   send_notification
   ;;
  
  mute)
   # toggle mute
   
   # ALSA 
  # amixer -D pulse set Master 1+ toggle > /dev/null
   
   # Pulseaudio
   pactl set-sink-mute @DEFAULT_SINK@ toggle > /dev/null
   
   send_notification
   ;;
esac

It would be nice if I could do something like this for example

dunstify -i $icon -r 2593 -u normal "  -sl x=50,y-50 ${bar}${spaces} -sr x=50,y=50 $vol_get %"

Where -sl is show on left side and -sr is show on right side, and x and y are of course for positioning, can also add -sm for show in the middle, or something like this.

For now I'm using

spaces=$(seq --separator="+" 0 "$(( 30 - (volume / 5) ))" | sed 's/[0-9]//g')

this for defining spaces so my volume% shows on the right side, something like this
Peek 2020-07-30 23-51

Now I just need to replace + with empty blank/space character, and I have it how I want it.

Label - Feature.

@tsipinakis
Copy link
Member

It seems like a good idea on the surface, but sadly I don't think this will ever be implemented without rewriting the drawing code entirely as that is just now how dunst is designed. The entire notification is a big text area whose contents is dictated by format and the notification window is shaped/formatted around it. So adding something like extra text on specific coordinates is going to be difficult and in my opinion not worth the effort.

From this it looks like the padding workaround works, are there any edge cases that still break and something like this would be needed?

@apoorv569
Copy link
Author

apoorv569 commented Aug 5, 2020

It seems like a good idea on the surface, but sadly I don't think this will ever be implemented without rewriting the drawing code entirely as that is just now how dunst is designed. The entire notification is a big text area whose contents is dictated by format and the notification window is shaped/formatted around it. So adding something like extra text on specific coordinates is going to be difficult and in my opinion not worth the effort.

From this it looks like the padding workaround works, are there any edge cases that still break and something like this would be needed?

Yes, this workaround is not perfect, I had to tweak the spacing according to my icon and the size of notification I wanted, I have dunst geometry set to 300x5-5+40, to adjust according to my panel on the top and from the right side of the screen. Also this workaround could break if I increase/decrease the font size, or maybe try to use volume more than 100%, like on my laptop it sometimes wraps to the next line, and because it updates when I press the key that I have set as the keybinding for increasing/decreasing/muting volume, it some crashes the notification if I press the keybinding too fast or hold the key, and the notification won't show, also the in the notification it shows the volume 2% less than the current volume for some reason.
Peek 2020-08-02 19-29

If possible this can be implemented as a separate thing rather than changing the existing code, like adding this volume and brightness notifications inbuilt to dunst so user doesn't have to rely on scripts, perhaps have some formatting options for this special type of notification. Just thinking out loud here.

@progandy
Copy link
Contributor

progandy commented Aug 5, 2020

dunst understands the "value" hint and uses it to display a progress value from 0-100% in textual form. The rendering code could be changed to show that as a good looking progress bar.

Instead of using dunst, maybe a standalone overlay bar may interest you:
https://github.com/florentc/xob
https://github.com/francma/wob

@tsipinakis
Copy link
Member

Using the progress hint is a much better idea (and IIRC there have been some previous attempts to add a progress bar this way, that went unfinished).

@apoorv569
Copy link
Author

dunst understands the "value" hint and uses it to display a progress value from 0-100% in textual form. The rendering code could be changed to show that as a good looking progress bar.

Instead of using dunst, maybe a standalone overlay bar may interest you:
https://github.com/florentc/xob
https://github.com/francma/wob

The overlay bar is a neat idea, though I wanted to use dunst, as I don't want separate program for just showing volume or brightness, if dunst can work for my notifications and volume and brightness then I'm fine with it. And what's the the progress hint, how do I use it?

@progandy
Copy link
Contributor

progandy commented Aug 5, 2020

The hint works this way:

notify-send --icon=notification-audio-volume-medium --hint=int:value:66 Volume
dunstify --hints=int:value:66 Brightness 

There is no progressbar yet, only these dunst notification formats:

       %p  progress value ([  0%] to [100%])
       %n  progress value without any extra characters

@fwsmit
Copy link
Member

fwsmit commented Dec 5, 2020

Dunst now draws a progress bar when passed a progress value, see #775.

I'm not sure how useful the double alignment feature is, but an easy way to implement it, is to allow multiple strings to be passed to the notification, each with seperate alignment. These could be rendered independently with their own alignment. This doesn't need a whole rewrite of the drawing code, but it does require tweaking of the interface.

@tsipinakis
Copy link
Member

tsipinakis commented Dec 5, 2020

Given that the original purpose of this PR was progress bar, I'd argue this can be closed. What do you think @apoorv569 ?

PS: I haven't forgotten about your PR @fwsmit, it's pretty big so I'll need some time to review it :)

@fwsmit
Copy link
Member

fwsmit commented Dec 5, 2020

Yeah I know, no problem. Take your time

@apoorv569
Copy link
Author

Given that the original purpose of this PR was progress bar, I'd argue this can be closed. What do you think @apoorv569 ?

PS: I haven't forgotten about your PR @fwsmit, it's pretty big so I'll need some time to review it :)

Interesting. I tried running the example given in #775 notify-send -h int:value:10 "Brightness" , it doesn't show any progress bar, just shows the text.

@tsipinakis
Copy link
Member

Make sure you are using the latest master. dunstctl debug should output dunst version: v1.5.0-32-g732227e.

If that's correct try with the default dunstrc, perhaps something in your config is messing it up.

@apoorv569
Copy link
Author

Make sure you are using the latest master. dunstctl debug should output dunst version: v1.5.0-32-g732227e.

If that's correct try with the default dunstrc, perhaps something in your config is messing it up.

dunstctl debug outputs dunst version: 1.5.0, also I tried with and without the my personal config.

Peek 2020-12-09 21-55

@tsipinakis
Copy link
Member

This feature is not in 1.5, it was only recently merged. You'll have to built from source to try it.

@apoorv569
Copy link
Author

apoorv569 commented Dec 11, 2020

This feature is not in 1.5, it was only recently merged. You'll have to built from source to try it.

Yes I built it from source today, it works nicely. Any way to change color of that blue bar?

Any idea how long before this merge hits the official repo of Arch?

@fwsmit
Copy link
Member

fwsmit commented Dec 11, 2020

Yes I built it from source today, it works nicely. Any way to change color of that blue bar?

You can change it by changing the hightlight color in the urgency low, normal and high sections. We should probably add an example to the dunstrc in this repo.

@apoorv569
Copy link
Author

Yes I built it from source today, it works nicely. Any way to change color of that blue bar?

You can change it by changing the hightlight color in the urgency low, normal and high sections. We should probably add an example to the dunstrc in this repo.

Yes an example would be nice, the screenshots in #775, are really nice, I would really like to make mine look like that. :D

@fwsmit
Copy link
Member

fwsmit commented Dec 12, 2020

Yes an example would be nice, the screenshots in #775, are really nice, I would really like to make mine look like that. :D

Go ahead and take a look at the manjaro dunst config. It's available here. That's where my configuration is from

@tsipinakis
Copy link
Member

Yes I built it from source today, it works nicely

Great, I'll close this then

Any idea how long before this merge hits the official repo of Arch?

After #781 is merged I'll wait a few weeks for any issues to be reported by git users then I'll make a new release unless something else comes up.

@apoorv569
Copy link
Author

Yes an example would be nice, the screenshots in #775, are really nice, I would really like to make mine look like that. :D

Go ahead and take a look at the manjaro dunst config. It's available here. That's where my configuration is from

Nice, thanks 👍

@apoorv569
Copy link
Author

Yes I built it from source today, it works nicely

Great, I'll close this then

Any idea how long before this merge hits the official repo of Arch?

After #781 is merged I'll wait a few weeks for any issues to be reported by git users then I'll make a new release unless something else comes up.

The only issue, well not really an issue but, sometimes when raising volume or brightness, a new notification pops up instead of the bar raising in the already popped notification. But this is a minor thing.

@tsipinakis
Copy link
Member

That's probably an issue with the script sending the notification. You are using a stack tag, aren't you? :)

@apoorv569
Copy link
Author

That's probably an issue with the script sending the notification. You are using a stack tag, aren't you? :)

Yes in my dunstrc I have

    # Stack together notifications with the same content
    stack_duplicates = true

    # Hide the count of stacked notifications with the same content
    hide_duplicate_count = false

@tsipinakis
Copy link
Member

tsipinakis commented Dec 13, 2020

That's not what I meant, see an example here (the x-canonical-private-synchronous part). Notifications with the same tag are stacked together regardless of any other settings.

Edit: Documentation is indeed light on this feature, another point for improvement.

@apoorv569
Copy link
Author

That's not what I meant, see an example here (the x-canonical-private-synchronous part). Notifications with the same tag are stacked together regardless of any other settings.

Edit: Documentation is indeed light on this feature, another point for improvement.

No I don't have anything like that in the script. I simply have notify-send -i $icon -h int:value:$volume "Volume".

@fwsmit
Copy link
Member

fwsmit commented Dec 13, 2020

The stack feature works only if the notifications have exactly the same content. If you have two notifications with a different volume, they will not stack. If you want to stack different notifications you can use -h string:x-canonical-private-synchronous:some_name (using the same name for every notification you want to stack).

@apoorv569
Copy link
Author

The stack feature works only if the notifications have exactly the same content. If you have two notifications with a different volume, they will not stack. If you want to stack different notifications you can use -h string:x-canonical-private-synchronous:some_name (using the same name for every notification you want to stack).

Does this has to do anything with the company Canonical ?

@tsipinakis
Copy link
Member

It was initially used by notify-osd from ubuntu/canonical, so, yes? You can also use -h string:x-dunst-stack-tag:some_name for the dunst-only version.

@apoorv569
Copy link
Author

It was initially used by notify-osd from ubuntu/canonical, so, yes? You can also use -h string:x-dunst-stack-tag:some_name for the dunst-only version.

Ah! Nice. I'll use this one x-dunst-stack-tag. Some documentation explaining the difference between these tags would be nice too. :D

@apoorv569
Copy link
Author

@tsipinakis Hi, its been a couple of months, I don't see a update with the patch that got added for #775. Is it not out yet?

Also I wanted to ask sometimes when a notification comes, and is very big, like a message on telegram or something, it shows a huge notification covering up almost my entire right side of the screen, is there a way to limit the number of lines to show?

@fwsmit
Copy link
Member

fwsmit commented Mar 14, 2021

@tsipinakis Hi, its been a couple of months, I don't see a update with the patch that got added for #775. Is it not out yet?

What distro are you on? You should be on 1.6.1 now.

Also I wanted to ask sometimes when a notification comes, and is very big, like a message on telegram or something, it shows a huge notification covering up almost my entire right side of the screen, is there a way to limit the number of lines to show?

Not yet, see #625

@apoorv569
Copy link
Author

apoorv569 commented Mar 14, 2021

What distro are you on? You should be on 1.6.1 now.

I'm on Arch Linux, dunst --version shows

❯ dunst --version
Dunst - A customizable and lightweight notification-daemon 1.5.0 (2020-07-23)

I'm surprised Arch does not include the latest update yet.

Not yet, see #625

Oh that is cool.

@fwsmit
Copy link
Member

fwsmit commented Mar 14, 2021

Yeah the arch package is already marked as out-of-date for a while, still not updated.

@apoorv569
Copy link
Author

Yeah the arch package is already marked as out-of-date for a while, still not updated.

I installed dunst-git from the AUR for the meantime.. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants