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

Notification hints #13

Closed
jgroboredo opened this issue Jul 28, 2024 · 7 comments
Closed

Notification hints #13

jgroboredo opened this issue Jul 28, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@jgroboredo
Copy link

Is your feature request related to a problem? Please describe.
For example, my volume control script uses value hints to show a "progress" bar in the volume notification:

notify-send -e -h int:value:"$(get_volume)" -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: $(get_volume)"

This causes an avalanche of notifications and no progress bar.

Describe the solution you'd like
I would like that every call to this script (that increases or decreases the volume by a certain amount) would result in a single notification with a progress bar update (each notification should be replaced).

Describe alternatives you've considered
No other alternatives considered.

Additional context
This should be a single notification with a progress bar:

image

Thanks in advance!

@Jas-SinghFSU
Copy link
Owner

You can provide an ID in the notify-send command so that all messages originating from the same id won't spam you. To do this you can provide an -r 1234 flag where 1234 is your id.
Example:

notify-send -r 1234 -e -h int:value:"$(get_volume)" -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: $(get_volume)"

@jgroboredo
Copy link
Author

Thanks for your reply.

That does indeed work, but I'm still missing the display of the value hint. This is an example of the exact same notification using swaync:

image

And using AGS notification daemon:

image

@Jas-SinghFSU
Copy link
Owner

Jas-SinghFSU commented Jul 28, 2024

Would an on-screen-display built separately for indicating volume and brightness changes be something you would desire as an alternative for having to handle such things via notifications?

@Jas-SinghFSU
Copy link
Owner

Also could you share your script please?

@jgroboredo
Copy link
Author

jgroboredo commented Jul 28, 2024

Would an on-screen-display built separately for indicating volume and brightness changes be something you would desire as an alternative for having to handle such things via notifications?

I think it would suffice, yes!

Also could you share your script please?

Here's the script:

#!/bin/bash
# Scripts for volume controls for audio and mic

iDIR="$HOME/.config/swaync/icons"

# Get Volume
get_volume() {
    volume=$(pamixer --get-volume)
    if [[ "$volume" -eq "0" ]]; then
        echo "Muted"
    else
        echo "$volume%"
    fi
}

# Get icons
get_icon() {
    current=$(get_volume)
    if [[ "$current" == "Muted" ]]; then
        echo "$iDIR/volume-mute.png"
    elif [[ "${current%\%}" -le 30 ]]; then
        echo "$iDIR/volume-low.png"
    elif [[ "${current%\%}" -le 60 ]]; then
        echo "$iDIR/volume-mid.png"
    else
        echo "$iDIR/volume-high.png"
    fi
}

# Notify
notify_user() {
    if [[ "$(get_volume)" == "Muted" ]]; then
        notify-send -e -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: Muted"
    else
        notify-send -r 1234 -e -h int:value:"$(get_volume | sed 's/%//')" -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: $(get_volume)"
    fi
}

# Increase Volume
inc_volume() {
    if [ "$(pamixer --get-mute)" == "true" ]; then
        pamixer -u && notify_user
    fi
    pamixer -i 5 && notify_user
}

# Decrease Volume
dec_volume() {
    if [ "$(pamixer --get-mute)" == "true" ]; then
        pamixer -u && notify_user
    fi
    pamixer -d 5 && notify_user
}

# Toggle Mute
toggle_mute() {
	if [ "$(pamixer --get-mute)" == "false" ]; then
		pamixer -m && notify-send -e -u low -i "$iDIR/volume-mute.png" "Volume Switched OFF"
	elif [ "$(pamixer --get-mute)" == "true" ]; then
		pamixer -u && notify-send -e -u low -i "$(get_icon)" "Volume Switched ON"
	fi
}

# Toggle Mic
toggle_mic() {
	if [ "$(pamixer --default-source --get-mute)" == "false" ]; then
		pamixer --default-source -m && notify-send -e -u low -i "$iDIR/microphone-mute.png" "Microphone Switched OFF"
	elif [ "$(pamixer --default-source --get-mute)" == "true" ]; then
		pamixer -u --default-source u && notify-send -e -u low -i "$iDIR/microphone.png" "Microphone Switched ON"
	fi
}
# Get Mic Icon
get_mic_icon() {
    current=$(pamixer --default-source --get-volume)
    if [[ "$current" -eq "0" ]]; then
        echo "$iDIR/microphone-mute.png"
    else
        echo "$iDIR/microphone.png"
    fi
}

# Get Microphone Volume
get_mic_volume() {
    volume=$(pamixer --default-source --get-volume)
    if [[ "$volume" -eq "0" ]]; then
        echo "Muted"
    else
        echo "$volume%"
    fi
}

# Notify for Microphone
notify_mic_user() {
    volume=$(get_mic_volume)
    icon=$(get_mic_icon)
    notify-send -e -h int:value:"$volume" -h "string:x-canonical-private-synchronous:volume_notif" -u low -i "$icon" "Mic-Level: $volume"
}

# Increase MIC Volume
inc_mic_volume() {
    if [ "$(pamixer --default-source --get-mute)" == "true" ]; then
        pamixer --default-source -u && notify_mic_user
    fi
    pamixer --default-source -i 5 && notify_mic_user
}

# Decrease MIC Volume
dec_mic_volume() {
    if [ "$(pamixer --default-source --get-mute)" == "true" ]; then
        pamixer --default-source -u && notify_mic_user
    fi
    pamixer --default-source -d 5 && notify_mic_user
}

# Execute accordingly
if [[ "$1" == "--get" ]]; then
	get_volume
elif [[ "$1" == "--inc" ]]; then
	inc_volume
elif [[ "$1" == "--dec" ]]; then
	dec_volume
elif [[ "$1" == "--toggle" ]]; then
	toggle_mute
elif [[ "$1" == "--toggle-mic" ]]; then
	toggle_mic
elif [[ "$1" == "--get-icon" ]]; then
	get_icon
elif [[ "$1" == "--get-mic-icon" ]]; then
	get_mic_icon
elif [[ "$1" == "--mic-inc" ]]; then
	inc_mic_volume
elif [[ "$1" == "--mic-dec" ]]; then
	dec_mic_volume
elif [[ "$1" == "--player" ]]; then
    # Shitft arguments - expecting player name after --player flag
    shift
    target_player="$1"
    nsink=$(playerctl --list-all | grep -w "${target_player}" | cut -d ":" -f 2)
    [ -z "${nsink}" ] && echo "ERROR: Player ${target_player} not active..." && exit 0

    # Shitft arguments - expecting action after
    shift
    action=$1
    [ "${action}" == "i" ] && pvl="+" || pvl="-"

    playerctl --player="${nsink}" volume 0.0"5""${pvl}"
    vol=$(playerctl --player="${nsink}" volume | awk '{ printf "%.0f\n", $0 * 100 }')

    notify-send -e -h int:value:"$(echo "$vol" | sed 's/%//')" -h string:x-canonical-private-synchronous:volume_notif -u low -i "$(get_icon)" "Volume: ${vol}"
else
	get_volume
fi

Edit: This script is adapted from some other scripts I've found during the time - any resemblance is not coincidence, but I have lost the sources unfortunately.

Let me know if you need the icons for the notifications.

@Jas-SinghFSU Jas-SinghFSU added the enhancement New feature or request label Jul 28, 2024
@Jas-SinghFSU
Copy link
Owner

Added on-screen-displays to indicate volume and brightness changes.

The settings for this can be configured in Configuration > General and coloring in Theming > OSD.

@jgroboredo
Copy link
Author

Great, looking forward to test it out!

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

No branches or pull requests

2 participants