Skip to content

Conversation

pks-t
Copy link

@pks-t pks-t commented Jul 12, 2025

Description

With swayidle one can configure two different kinds of hooks:

  • Idle timeouts are executed after the session has been idle for a specific amount of time.

  • Events are executed when systemd notifies us that for example the user session is locked or that the device is about to suspend.

While not obvious, there is a significant difference between how these two kinds are configured: there can be several timeouts with separate commands to be executed, but each event can only be specified once. If an event is specified multiple times, then the last command wins.

This can be very easy to miss in swayidle's documentation. Furthermore, because the config is a list of { event = "..."; command = "..."; } attrset, we double down on this confusion and make it seem like having multiple handlers for an event was actually supported.

Fix this by converting from a list of "event" submodules to an attrset where the key is the event name and the value is the command to be executed. This makes it impossible to specify multiple commands for a single event by accident.

If a user does want to have multiple commands executed on any event they can for example use pkgs.writeShellScript and manually chain the commands in that script.

Checklist

  • Change is backwards compatible.

  • Code formatted with nix fmt or
    nix-shell -p treefmt nixfmt-rfc-style deadnix keep-sorted --run treefmt.

  • Code tested through nix-shell --pure tests -A run.all
    or nix build --reference-lock-file flake.lock ./tests#test-all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

@c0deaddict

With swayidle one can configure two different kinds of hooks:

  - Idle timeouts are executed after the session has been idle for a
    specific amount of time.

  - Events are executed when systemd notifies us that for example the
    user session is locked or that the device is about to suspend.

While not obvious, there is a significant difference between how these
two kinds are configured: there can be several timeouts with separate
commands to be executed, but each event can only be specified once. If
an event is specified multiple times, then the last command wins.

This can be very easy to miss in swayidle's documentation. Furthermore,
because the config is a list of `{ event = "..."; command = "..."; }`
attrset, we double down on this confusion and make it seem like having
multiple handlers for an event was actually supported.

Fix this by converting from a list of "event" submodules to an attrset
where the key is the event name and the value is the command to be
executed. This makes it impossible to specify multiple commands for a
single event by accident.

If a user _does_ want to have multiple commands executed on any event
they can for example use `pkgs.writeShellScript` and manually chain the
commands in that script.
@teto teto self-assigned this Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants