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 option to automatically exit after X seconds of inactivity #1420

Open
3hhh opened this issue Dec 16, 2024 · 3 comments
Open
Labels

Comments

@3hhh
Copy link

3hhh commented Dec 16, 2024

It would be nice to have an option to automatically exit dunst after X (configurable) seconds of inactivity (= without active notifications).

dunst is restarted via dbus anyway, if it's needed after a longer period of inactivity.

Currently I use the below wrapper script to achieve this behaviour:

#!/bin/bash
#
# Small wrapper for dunst to kill it, if it becomes unused.
#
# Can be used as dbus execution alternative.

set -e -o pipefail

#timeout in seconds after which to kill dunst
TIMEOUT=60

#time in seconds to wait before the next check
CHECK_INTERVAL=3

#current timeout
TIMEOUT_CUR="$TIMEOUT"

#is_unmanaged [window id]
function is_unmanaged {
local win="$1"
xwininfo -id "$win" | grep 'Map State: IsUnMapped' &> /dev/null
}

#wait for dunst to become unused for more than $TIMEOUT seconds and kill it afterwards
function killUnusedDunst {
local windows=
local line=""
local win found

local re='^\s+(0x[0-9A-Fa-f]+) "Dunst".*$'
while : ; do
  sleep $CHECK_INTERVAL
  TIMEOUT_CUR=$(( $TIMEOUT_CUR - $CHECK_INTERVAL ))
  found=1

  windows="$(xwininfo -root -tree | grep '"Dunst"')"
  while IFS= read -r line || [ -n "$line" ] ; do
    [[ "$line" =~ $re ]] || continue
    win="${BASH_REMATCH[1]}"
    found=0

    #reset, if the window is managed
    is_unmanaged "$win" || TIMEOUT_CUR="$TIMEOUT"
  done <<< "$windows"

  #no windows found or timeout?
  if [ $found -ne 0 ] || [ $TIMEOUT_CUR -le 0 ] ; then
    killall "dunst"
    return
  fi
done
}

dunst "$@" &
disown
killUnusedDunst
@bynect bynect added the Feature label Dec 16, 2024
@bynect
Copy link
Member

bynect commented Dec 16, 2024

Dunst is restarted automatically by dbus. however the notification history is lost. this is why we added the dunstctl reload command to begin with.

What would your use case be for killing dunst every time you are inactive?

@3hhh
Copy link
Author

3hhh commented Dec 16, 2024

Well, ps aux | grep dunst in one of my VMs shows:

user        1687  2.5  5.5 608348 19544 ?        Sl   23:00   0:00 dunst

This looks quite a lot to me to just show a notification from time to time.
Considering that I currently run ~15 VMs, in the worst case each with 2 dunst processes (one for the regular user, one for root) that could sum up to 20*2*15 = 600 MB RSS memory. Interestingly the VSZ number is higher than even what init or Xorg request...
I run those VMs on Qubes OS, which supports memory load balancing across VMs, but of course only for unallocated memory.

Moreover my window manager is buggy and fails to properly implement override-redirect windows, which may make them appear behind windows, if they are re-mapped (which dunst happens to do). The timeout makes sure that dunst doesn't re-map old windows too often.

@bynect
Copy link
Member

bynect commented Dec 16, 2024

We depend on a lot of memory heavy and dubiously memleak-free libraries (cairo, pango, glib). Maybe the memory footprint is high due to some hidden leak? I will have to investigate

However I don't think that adding an option just to quit on idle is worth it. I would rather allow the use of a script on idle at that point

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

2 participants