summaryrefslogtreecommitdiffstatshomepage
path: root/dot_config
diff options
context:
space:
mode:
Diffstat (limited to 'dot_config')
-rw-r--r--dot_config/sway/config1
-rw-r--r--dot_config/sway/executable_display-recover.sh47
-rw-r--r--dot_config/sway/executable_display-wake.sh8
-rw-r--r--dot_config/systemd/user/swayidle.service14
4 files changed, 64 insertions, 6 deletions
diff --git a/dot_config/sway/config b/dot_config/sway/config
index bfdfed1..6490001 100644
--- a/dot_config/sway/config
+++ b/dot_config/sway/config
@@ -204,6 +204,7 @@ bindsym $mod+period exec ~/.config/sway/emoji-picker.sh
# Display mode switching
bindsym --no-repeat XF86Display exec ~/.config/sway/display-toggle.sh
+bindsym --locked --no-repeat XF86Display exec ~/.config/sway/display-recover.sh
# Multimedia hardware keys (uncommon)
bindsym XF86Tools exec $term --class=floating -e pulsemixer
diff --git a/dot_config/sway/executable_display-recover.sh b/dot_config/sway/executable_display-recover.sh
new file mode 100644
index 0000000..5ebb70a
--- /dev/null
+++ b/dot_config/sway/executable_display-recover.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env dash
+set -u
+
+log="${XDG_RUNTIME_DIR:-/tmp}/display-recover.log"
+
+outputs_json() {
+ swaymsg -t get_outputs -r 2>/dev/null || printf '[]\n'
+}
+
+first_laptop() {
+ jq -r '[.[] | select(.name | test("^eDP")) | .name] | first // empty'
+}
+
+externals() {
+ jq -r '.[] | select(.name | test("^eDP") | not) | .name'
+}
+
+laptop_width() {
+ jq -r --arg name "$1" '.[] | select(.name == $name) | .current_mode.width // .modes[0].width // 1920'
+}
+
+{
+ printf '\n[%s] display recovery\n' "$(date -Is)"
+
+ "$HOME/.config/sway/display-wake.sh" || true
+
+ outputs=$(outputs_json)
+ laptop=$(printf '%s\n' "$outputs" | first_laptop)
+ width=1920
+
+ if [ -n "$laptop" ]; then
+ width=$(printf '%s\n' "$outputs" | laptop_width "$laptop")
+ swaymsg output "$laptop" enable pos 0 0 || true
+ fi
+
+ printf '%s\n' "$outputs" | externals | while read -r output; do
+ [ -n "$output" ] || continue
+ swaymsg output "$output" power on || true
+ sleep 0.2
+ swaymsg output "$output" disable || true
+ sleep 0.5
+ swaymsg output "$output" enable pos "$width" 0 || true
+ done
+
+ swaymsg 'output * power on' || true
+ brightnessctl -r || true
+} >>"$log" 2>&1
diff --git a/dot_config/sway/executable_display-wake.sh b/dot_config/sway/executable_display-wake.sh
new file mode 100644
index 0000000..11137cb
--- /dev/null
+++ b/dot_config/sway/executable_display-wake.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env dash
+set -u
+
+brightnessctl -r >/dev/null 2>&1 || true
+swaymsg 'output * power on' >/dev/null 2>&1 || true
+sleep 0.2
+
+"$HOME/.config/sway/display-toggle.sh" apply >/dev/null 2>&1 || true
diff --git a/dot_config/systemd/user/swayidle.service b/dot_config/systemd/user/swayidle.service
index bd0dca5..2ba80e7 100644
--- a/dot_config/systemd/user/swayidle.service
+++ b/dot_config/systemd/user/swayidle.service
@@ -1,5 +1,5 @@
[Unit]
-Description=Idle manager for Wayland (lock + DPMS)
+Description=Idle manager for Wayland (dim + lock + DPMS)
PartOf=graphical-session.target
After=graphical-session.target
ConditionEnvironment=WAYLAND_DISPLAY
@@ -7,12 +7,14 @@ ConditionEnvironment=WAYLAND_DISPLAY
[Service]
Type=simple
ExecStart=%h/.nix-profile/bin/swayidle -w \
- timeout 300 'swaymsg "output * power off"' \
- resume 'swaymsg "output * power on"' \
- timeout 330 'swaylock -f -e -c 000000' \
+ timeout 300 'brightnessctl -s set 10% || true' \
+ resume 'brightnessctl -r || true' \
+ timeout 330 'pgrep -x swaylock >/dev/null || swaylock -f -e -c 000000' \
+ timeout 360 'swaymsg "output * power off"' \
+ resume '%h/.config/sway/display-wake.sh' \
timeout 1800 '%h/.local/bin/on-battery-suspend' \
- before-sleep 'playerctl -a pause; swaylock -f -e -c 000000' \
- lock 'swaylock -f -e -c 000000'
+ before-sleep 'playerctl -a pause; pgrep -x swaylock >/dev/null || swaylock -f -e -c 000000' \
+ lock 'pgrep -x swaylock >/dev/null || swaylock -f -e -c 000000'
Restart=on-failure
RestartSec=2s