Skip to content

Instantly share code, notes, and snippets.

@advilm
Last active September 27, 2024 07:56
Show Gist options
  • Select an option

  • Save advilm/f8d4ba12e34fae9090f3b47e8b0836a3 to your computer and use it in GitHub Desktop.

Select an option

Save advilm/f8d4ba12e34fae9090f3b47e8b0836a3 to your computer and use it in GitHub Desktop.

Revisions

  1. advilm revised this gist Feb 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lock_script.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ else
    fi

    # Set settings back to what they were before
    test -z "$old_mute" || amixer set Master unmute > /dev/null
    test -z "$old_mute" || amixer set Master unmute > /dev/null
    test "$old_dnd" = false && xfconf-query -c xfce4-notifyd -p /do-not-disturb -s false
    ```
    Note: The xfconf-query do not disturb stuff is only for xfce-notifyd.
  2. advilm renamed this gist Feb 22, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. advilm revised this gist Feb 22, 2022. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions lock_stuff.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    scripts/lock.sh
    ### scripts/lock.sh
    ```sh
    #!/bin/sh

    @@ -50,8 +50,7 @@ test "$old_dnd" = false && xfconf-query -c xfce4-notifyd -p /do-not-disturb -s f
    ```
    Note: The xfconf-query do not disturb stuff is only for xfce-notifyd.


    xss-lock command
    ### xss-lock command
    ```
    xss-lock --transfer-sleep-lock -- ~/scripts/lock.sh
    ```
  4. advilm revised this gist Feb 22, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions lock_stuff.md
    Original file line number Diff line number Diff line change
    @@ -48,6 +48,8 @@ fi
    test -z "$old_mute" || amixer set Master unmute > /dev/null
    test "$old_dnd" = false && xfconf-query -c xfce4-notifyd -p /do-not-disturb -s false
    ```
    Note: The xfconf-query do not disturb stuff is only for xfce-notifyd.


    xss-lock command
    ```
  5. advilm revised this gist Feb 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lock_stuff.md
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ fi

    # Set settings back to what they were before
    test -z "$old_mute" || amixer set Master unmute > /dev/null
    test $old_dnd = false && xfconf-query -c xfce4-notifyd -p /do-not-disturb -s false
    test "$old_dnd" = false && xfconf-query -c xfce4-notifyd -p /do-not-disturb -s false
    ```

    xss-lock command
  6. advilm renamed this gist Feb 22, 2022. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions lock_stuff → lock_stuff.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    # scripts/lock.sh
    scripts/lock.sh
    ```sh
    #!/bin/sh

    scrot -o /tmp/screenshot.png
    @@ -46,6 +47,9 @@ fi
    # Set settings back to what they were before
    test -z "$old_mute" || amixer set Master unmute > /dev/null
    test $old_dnd = false && xfconf-query -c xfce4-notifyd -p /do-not-disturb -s false
    ```

    # xss-lock command
    xss-lock --transfer-sleep-lock -- ~/scripts/lock.sh
    xss-lock command
    ```
    xss-lock --transfer-sleep-lock -- ~/scripts/lock.sh
    ```
  7. advilm revised this gist Feb 22, 2022. 1 changed file with 38 additions and 32 deletions.
    70 changes: 38 additions & 32 deletions lock_stuff
    Original file line number Diff line number Diff line change
    @@ -1,45 +1,51 @@
    # /etc/systemd/system/suspend.service
    [Unit]
    Description=Delay suspend until i3lock starts
    Before=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
    # scripts/lock.sh
    #!/bin/sh

    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c 'while ! pidof i3lock; do sleep 1; done'
    scrot -o /tmp/screenshot.png
    convert /tmp/screenshot.png -blur 0x5 /tmp/screenshot.png

    [Install]
    WantedBy=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
    # Turn on DND
    old_dnd="$(xfconf-query -c xfce4-notifyd -p /do-not-disturb)"
    xfconf-query -c xfce4-notifyd -p /do-not-disturb -s true

    # scripts/lock.sh
    #!/bin/sh
    # Pause stuff and mute audio
    playerctl -a pause > /dev/null
    old_mute="$(amixer get Master | tail -2 | grep '\[on\]')"
    amixer set Master mute > /dev/null

    if ! pidof i3lock; then
    scrot -o /tmp/screenshot.png
    convert /tmp/screenshot.png -blur 0x5 /tmp/screenshot.png

    # Turn on DND
    old="$(xfconf-query -c xfce4-notifyd -p /do-not-disturb)"
    xfconf-query -c xfce4-notifyd -p /do-not-disturb -s true

    # Pause stuff and mute audio
    playerctl -a pause > /dev/null
    aold="$(amixer get Master | tail -2 | grep '\[on\]')"
    amixer set Master mute > /dev/null

    i3lock -ui /tmp/screenshot.png

    # Waits for i3lock to die or valid fingerprint to kill i3lock
    wait_fingerprint() {
    while pidof i3lock > /dev/null; do
    if (timeout 5 fprintd-verify | grep -q verify-match); then
    pkill i3lock
    fi
    done
    }

    # Code taken from xss-lock transfer sleep lock example
    if [[ -e /dev/fd/${XSS_SLEEP_LOCK_FD:--1} ]]; then
    kill_i3lock() {
    pkill -xu $EUID "$@" i3lock
    }

    trap kill_i3lock TERM INT

    # Set settings back to what they were before
    if ! [ -z "$aold" ]; then
    amixer set Master unmute > /dev/null
    fi
    xfconf-query -c xfce4-notifyd -p /do-not-disturb -s $old
    # we have to make sure the locker does not inherit a copy of the lock fd
    i3lock -ui /tmp/screenshot.png {XSS_SLEEP_LOCK_FD}<&-

    # now close our fd (only remaining copy) to indicate we're ready to sleep
    exec {XSS_SLEEP_LOCK_FD}<&-

    wait_fingerprint
    else
    trap 'kill %%' TERM INT
    i3lock -nui /tmp/screenshot.png &
    wait_fingerprint
    fi

    # Set settings back to what they were before
    test -z "$old_mute" || amixer set Master unmute > /dev/null
    test $old_dnd = false && xfconf-query -c xfce4-notifyd -p /do-not-disturb -s false

    # xss-lock command
    xss-lock -- ~/scripts/lock.sh
    xss-lock --transfer-sleep-lock -- ~/scripts/lock.sh
  8. advilm revised this gist Feb 22, 2022. 1 changed file with 36 additions and 13 deletions.
    49 changes: 36 additions & 13 deletions lock_stuff
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,45 @@
    # /etc/systemd/system/suspend@.service
    # /etc/systemd/system/suspend.service
    [Unit]
    Description=Lock screen when waking up
    Description=Delay suspend until i3lock starts
    Before=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

    [Service]
    User=%I
    Type=forking
    Environment=DISPLAY=:0
    ExecStart=i3lock
    ExecStartPost=/usr/bin/sleep 1
    Type=oneshot
    ExecStart=/bin/bash -c 'while ! pidof i3lock; do sleep 1; done'

    [Install]
    WantedBy=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

    # /etc/pam.d/i3lock
    auth sufficient pam_unix.so try_first_pass likeauth nullok
    auth sufficient pam_fprintd.so
    auth include system-auth
    # scripts/lock.sh
    #!/bin/sh

    # Note: even without the nullok it still requires you to press enter to use fingerprint
    # Not sure why
    if ! pidof i3lock; then
    scrot -o /tmp/screenshot.png
    convert /tmp/screenshot.png -blur 0x5 /tmp/screenshot.png

    # Turn on DND
    old="$(xfconf-query -c xfce4-notifyd -p /do-not-disturb)"
    xfconf-query -c xfce4-notifyd -p /do-not-disturb -s true

    # Pause stuff and mute audio
    playerctl -a pause > /dev/null
    aold="$(amixer get Master | tail -2 | grep '\[on\]')"
    amixer set Master mute > /dev/null

    i3lock -ui /tmp/screenshot.png

    while pidof i3lock > /dev/null; do
    if (timeout 5 fprintd-verify | grep -q verify-match); then
    pkill i3lock
    fi
    done

    # Set settings back to what they were before
    if ! [ -z "$aold" ]; then
    amixer set Master unmute > /dev/null
    fi
    xfconf-query -c xfce4-notifyd -p /do-not-disturb -s $old
    fi

    # xss-lock command
    xss-lock -- ~/scripts/lock.sh
  9. advilm revised this gist Feb 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion lock_stuff
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # /etc/systemd/system/suspend@username.service
    # /etc/systemd/system/[email protected]
    [Unit]
    Description=Lock screen when waking up
    Before=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
  10. advilm revised this gist Feb 8, 2022. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion lock_stuff
    Original file line number Diff line number Diff line change
    @@ -14,5 +14,9 @@ ExecStartPost=/usr/bin/sleep 1
    WantedBy=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

    # /etc/pam.d/i3lock
    auth sufficient pam_unix.so try_first_pass likeauth nullok
    auth sufficient pam_fprintd.so
    auth include system-auth
    auth include system-auth

    # Note: even without the nullok it still requires you to press enter to use fingerprint
    # Not sure why
  11. advilm created this gist Feb 8, 2022.
    18 changes: 18 additions & 0 deletions lock_stuff
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # /etc/systemd/system/[email protected]
    [Unit]
    Description=Lock screen when waking up
    Before=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

    [Service]
    User=%I
    Type=forking
    Environment=DISPLAY=:0
    ExecStart=i3lock
    ExecStartPost=/usr/bin/sleep 1

    [Install]
    WantedBy=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

    # /etc/pam.d/i3lock
    auth sufficient pam_fprintd.so
    auth include system-auth