feat: Add initial dock scripts

This commit is contained in:
Fabio Lenherr 2023-03-15 23:43:03 +01:00
parent 477afdf6f4
commit 642aacd358
13 changed files with 145 additions and 35 deletions

46
eww_laptop/scripts/auto_dock.sh Executable file
View file

@ -0,0 +1,46 @@
#!/bin/bash
bat=/sys/class/power_supply/BAT0/
char="$(cat "$bat/status")"
monitor_count=$(hyprctl monitors | rg "ID 1")
internal_active=$(hyprctl monitors | rg "eDP-1")
close() {
if [ "$char" == "Discharging" ]; then
# dunstify 'discharging and locking'
playerctl --all-players -a pause
swaylock -c 000000 & systemctl suspend
else
if [ "$monitor_count" == "" ]; then
# dunstify 'charging but no second monitor, locking'
playerctl --all-players -a pause
swaylock -c 000000 & systemctl suspend
else
dunstify 'charging and second monitor, switching to external mode'
./monitor.sh onlysecond
fi
fi
}
open() {
if [ "$internal_active" == "" ]; then
if [ "$monitor_count" == "" ]; then
dunstify 'external monitor connected, extending'
./monitor.sh extend
else
dunstify 'only internal'
./monitor.sh onlyfirst
fi
fi
}
if [ "$1" == "open" ]; then
open
else
close
fi

36
eww_laptop/scripts/monitor.sh Executable file
View file

@ -0,0 +1,36 @@
#!/bin/bash
onlysecond() {
dunstify "Switching to external monitor only"
hyprctl keyword monitor ,highrr,0x0,1
hyprctl keyword monitor eDP-1,disabled
}
onlyfirst() {
dunstify "Switching to internal monitor only"
hyprctl keyword monitor ,disabled
hyprctl keyword monitor eDP-1,1920x1080@144,0x0,1
}
extend() {
dunstify "Switching to extend mode"
hyprctl keyword monitor ,highrr,1920x0,1
hyprctl keyword monitor eDP-1,1920x1080@144,0x0,1
}
mirror() {
dunstify "Switching to mirror mode"
hyprctl keyword monitor ,highrr,0x0,1
hyprctl keyword monitor eDP-1,1920x1080@144,0x0,1
}
if [ "$1" == "onlysecond" ]; then
onlysecond
elif [ "$1" == "onlyfirst" ]; then
onlyfirst
elif [ "$1" == "extend" ]; then
extend
elif [ "$1" == "mirror" ]; then
mirror
fi

View file

@ -0,0 +1,23 @@
#!/usr/bin/env python3
import os
import socket
# Replace "your_user" with the actual username of the logged-in user.
USER = "dashie"
def execute_script(event):
# This function executes the script file as the specified user.
os.system(f"/home/dashie/.config/eww/scripts/auto_dock.sh {event}")
# Create a socket object and connect to the acpid socket.
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect("/var/run/acpid.socket")
# Listen for events and execute the script file.
while True:
data = sock.recv(1024).decode()
if "button/lid" in data:
event = data.split()[-1]
execute_script(event)