In the context of swayidle, after-resume and resume are used to specify commands to be executed when the system resumes from sleep or inactivity. Here’s the distinction between the two:

resume

  • Trigger: This command is executed when user activity resumes after a period of inactivity that previously triggered a timeout command.
  • Use Case: It is typically used to reverse the effects of the timeout commands (e.g., turning the display back on, stopping a screensaver, etc.).

after-resume

  • Trigger: This command is executed after the system resumes from a sleep state (suspend/hibernate).
  • Use Case: It is used to perform actions needed to restore the system state after it wakes up from sleep (e.g., re-enabling displays, refreshing network connections, etc.).

Example Usage

exec_always swayidle -w \
    timeout 300 'swaymsg "output * dpms off"' \
    resume 'swaymsg "output * dpms on"' \
    before-sleep 'swaylock' \
    after-resume 'swaymsg "input type:keyboard xkb_switch_layout 0"' \
    after-resume 'swaymsg "output * dpms on"'

Detailed Breakdown

  1. Timeout Command:

    timeout 300 'swaymsg "output * dpms off"'
    
    • This command turns off the display after 300 seconds (5 minutes) of inactivity.
  2. Resume Command:

    resume 'swaymsg "output * dpms on"'
    
    • This command turns the display back on when user activity resumes after the display was turned off due to inactivity.
  3. Before-Sleep Command:

    before-sleep 'swaylock'
    
    • This command locks the screen just before the system goes to sleep.
  4. After-Resume Commands:

    after-resume 'swaymsg "input type:keyboard xkb_switch_layout 0"'
    after-resume 'swaymsg "output * dpms on"'
    
    • These commands switch the keyboard layout and turn the display back on after the system resumes from sleep.

Summary

  • resume: Executes commands when user activity resumes after a period of inactivity (related to timeout).
  • after-resume: Executes commands when the system resumes from a sleep state (related to suspend/hibernate).

Using both appropriately allows you to handle both cases: resuming from inactivity and waking up from sleep, ensuring your system behaves as expected in different scenarios.