diff options
Diffstat (limited to 'home/config/sway/scripts.d')
-rwxr-xr-x | home/config/sway/scripts.d/auto.sh | 14 | ||||
-rwxr-xr-x | home/config/sway/scripts.d/project.sh | 122 | ||||
-rwxr-xr-x | home/config/sway/scripts.d/scratchpads.sh | 4 |
3 files changed, 140 insertions, 0 deletions
diff --git a/home/config/sway/scripts.d/auto.sh b/home/config/sway/scripts.d/auto.sh new file mode 100755 index 0000000..07a61fd --- /dev/null +++ b/home/config/sway/scripts.d/auto.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +nm-applet --indicator & +autotiling-rs & + +/usr/bin/gnome-keyring-daemon --foreground & +wl-clip-persist --clipboard both & + +#gtk-launch discord & +#gtk-launch io.element.Element & +#gtk-launch org.gajim.Gajim & +#gtk-launch org.mozilla.Thunderbird & + +hypridle & diff --git a/home/config/sway/scripts.d/project.sh b/home/config/sway/scripts.d/project.sh new file mode 100755 index 0000000..84e1a8d --- /dev/null +++ b/home/config/sway/scripts.d/project.sh @@ -0,0 +1,122 @@ +#!/usr/bin/env bash + +PID=$$ + +get_mode() { + swaymsg -t get_outputs -r | jq ".[$1].modes[0]" +} + +get_name() { + swaymsg -t get_outputs -r | jq -r ".[$1].name" +} + +get_width() { + get_mode "$1" | jq ".width" +} + +get_height() { + get_mode "$1" | jq ".width" +} + +get_refresh() { + get_mode "$1" | jq ".refresh" | rev | cut -c 4- | rev +} + +get_placement() { + # $1 - monitor placement + # $2 - monitor index compared + # $3 - monitor compared scale + WIDTH="$(jq -n "$(get_width $2)/$3" | awk -F. '{print $1}')" + case $1 in + "NONE") + echo "0 0" + ;; + "RIGHT") + echo "$WIDTH 0" + ;; + *) + echo "0 0" + ;; + esac +} + +update() { + # $1 - monitor index + # $2 - monitor scale + # $3 - monitor placement + # $4 - monitor index compared + # $5 - monitor compared scale + swaymsg output "$(get_name $1)" "enable" + swaymsg output "$(get_name $1)" resolution "$(get_width $1)x$(get_height $1)@$(get_refresh $1)hz" scale $2 position "$(get_placement $3 $4 $5)" +} + +off() { + swaymsg output "$(get_name $1)" "disable" +} + +get_id() { + i=0 + while true; do + NAME="$(get_name $i)" + if [ $(echo "$NAME" | grep "^$1") ]; then + echo "$i" + return 0 + elif [ "$NAME" == "null" ]; then + return 1 + fi + ((i=i+1)) + done +} + +die() { + notify-send -u critical -t 3000 "Sway" "$1" + kill $PID +} + +PRIMARY=$(get_id "eDP-1" || die "Failed to get primary display") +EXTERNAL=$(get_id "DP" || get_id "HDMI" || die "Failed to get external display") + +PRIMARY_SCALE=$2 +EXTERNAL_SCALE=1 + +set_monitors() { + update $EXTERNAL $EXTERNAL_SCALE $1 $PRIMARY $PRIMARY_SCALE + update $PRIMARY $PRIMARY_SCALE $2 $EXTERNAL $EXTERNAL_SCALE +} + +set_left() { + set_monitors "NONE" "RIGHT" +} + +set_right() { + set_monitors "RIGHT" "NONE" +} + +set_primary_only() { + set_monitors "NONE" "NONE" + off $EXTERNAL +} + +set_external_only() { + set_monitors "NONE" "NONE" + off $PRIMARY +} + +case $1 in + "LEFT") + set_left + notify-send -t 3000 "Sway" "External display set to left aligned" + ;; + "RIGHT") + set_right + notify-send -t 3000 "Sway" "External display set to right aligned" + ;; + "PRIMARY_ONLY") + set_primary_only + notify-send -t 3000 "Sway" "Set to primary display only" + ;; + "EXTERNAL_ONLY") + set_external_only + notify-send -t 3000 "Sway" "Set to external display only" + ;; +esac diff --git a/home/config/sway/scripts.d/scratchpads.sh b/home/config/sway/scripts.d/scratchpads.sh new file mode 100755 index 0000000..bb8e361 --- /dev/null +++ b/home/config/sway/scripts.d/scratchpads.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +( swaymsg -t get_tree | /bin/grep '"app_id": "'$1'"' ) || ( ( $TERMINAL --class=$1 -e $2 & ) && sleep 0.2 ) +swaymsg "[app_id=\"$1\"]" scratchpad show |