~jpastuszek/blog

471bfacc604a8b9f806a6c70ebefebc85b0558c2 — Jakub Pastuszek 9 months ago 55c55d4
dunst post
A content/2022-12-17-dunst-vertical/index.md => content/2022-12-17-dunst-vertical/index.md +99 -0
@@ 0,0 1,99 @@
+++
title = "Dunst desktop notifications: vertical layout"

[taxonomies]
tags = ["desktop", "linux", "sway"]
categories = ["desktop"]

[extra]
image = "screenshot.png"
image_alt = "Screenshot of dunst notification"
+++

Desktop notifications mechanism allows background asynchronous processed to interrupt your
work flow and take your attention away to some event that just has happened.
<!-- more -->

You would want notifications is some environments where you are expected to be available
to interruptions and handle some external events in timely fashion.

I don't use notifications in my personal computing environments.
On the other hand in professional setting handling random events thrown at me
is part of my job description.

# Background

I like building things from first principles. My Linux desktop is built with
[Void Linux](https://voidlinux.org/).
It allows me to build my own desktop experience and tailor it to particular use case.

My desktop is based on [sway](https://swaywm.org/). Sway is a Wayland compositor and does not
offer desktop notifications functionality alone. It needs additional software
to implement that functionality.

# Dunst

From [Dunst home page](https://dunst-project.org/):

> Dunst is a lightweight replacement for the notification daemons provided by most desktop environments.

After installation it can be configured globally with `/etc/dunst/dunstrc` or
you can use per-user configuration `~/.config/dunst/dunstrc`.

It produces minimalistic notification pop-ups that are rectangular
with solid color fill and optional border.
The text can be formatted using [Pango markup](https://docs.gtk.org/Pango/pango_markup.html).

It runs as a UNIX daemon, listening on a socket. It comes with `notify-send` command that is
standardised and can be used to produce notifications from scripts. Major browsers and
most desktop software should just work with it correctly.

There is also more specialized command that unlocks some dunst specific notification features
called `dunstify`.

If you run one of them for the first time an ad-hock dunst daemon will be spawned by them for you.

I have set up dunst as per-user runit service.

Dunst has many advanced features, see:

* [ArchLinux Wiki article](https://wiki.archlinux.org/title/Dunst)

# Customization

In default configuration sway show a bar at the top of the screen.
It shows buttons to navigate active desktops and some real-time system information.

By default dunst will produce a rectangular box in the right-top corner of the screen.
It will overlay on top of desktop content, including full-screen applications (e.g. video).

I have decided that I would like it to only obscure the bar part of the screen, so I can continue
working uninterrupted and wrap up my work to a consistent state before changing focus.

To achieve this I have tweaked the following default settings:

* `width = 960` - makes the notification rectangle about half of the screen in width,
* `height = 23` - makes it exactly the height of the sway bar,
* `offset = 0x-23` - move the notifications to cover the bar,
* `notification_limit = 1` - only show one notification rectangle; otherwise multiple notifications would cover my work; you can still click through all of the notifications,
* `progress_bar = false` - progress bars won't be visible in such small space; we will configure message format to include numerical value for progress,
* `separator_height = 0` and `frame_width = 0` - don't show frames,
* `padding = 4` and `font = Monospace 10` and `vertical_alignment = top` - vertically align the text,
* `alignment = right` - horizontally align the text to right side of the screen,
* `format = "%b %p<b>%s</b> <i>%a</i>"` - show message body, progress bar value, subject and application name,
* `ignore_newline = true` - collect multi-line messages in one line,
* `icon_position = right` - show icon on the right,
* `min_icon_size = 16` and `max_icon_size = 16` - reduce icon size to fit.

Additionally I set up dunst daemon to show notification on startup with `--startup_notification ture` flag
so that I know it is working.

Also I have tweaked timeout options:

* for `urgency_normal` I set `timeout = 0` - this will make the notifications to queue up until dismissed,
* for `urgency_low` I set `timeout = 4` - only show dunst startup message briefly.

I have also configured sway to allow me to interact with notification using keyboard shortcuts:

* `bindsym $mod+period exec dunstctl history-pop` - _penguing + dot_ will pop up notification from history,
* `bindsym $mod+BackSpace exec dunstctl close` - _panguin + backspace_ will dismiss last notification.

A content/2022-12-17-dunst-vertical/screenshot.png => content/2022-12-17-dunst-vertical/screenshot.png +0 -0