From b704c731073ddcd7ddb9ae75bba4175b59ec2ac6 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 7 Oct 2023 12:24:28 -0400 Subject: [PATCH] sway project script --- home-config/home-configuration.scm | 1 + home-config/nix-home-manager/home.nix | 1 + home-config/sway/config.d/keybinds | 4 + home-config/sway/config.d/project | 6 ++ home-config/sway/scripts.d/project.sh | 119 ++++++++++++++++++++++++++ modules/home-config/base-system.scm | 5 +- 6 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 home-config/sway/config.d/project create mode 100755 home-config/sway/scripts.d/project.sh diff --git a/home-config/home-configuration.scm b/home-config/home-configuration.scm index 701e377..3b9edaa 100644 --- a/home-config/home-configuration.scm +++ b/home-config/home-configuration.scm @@ -31,6 +31,7 @@ (packages (append (specifications->packages (list "xdg-utils" "mako" "vscodium" + "libnotify" "i3-autotiling" "wofi" "qrencode" diff --git a/home-config/nix-home-manager/home.nix b/home-config/nix-home-manager/home.nix index f39d488..289be29 100644 --- a/home-config/nix-home-manager/home.nix +++ b/home-config/nix-home-manager/home.nix @@ -24,6 +24,7 @@ slack cryptomator pcem + cider #steam # Rust diff --git a/home-config/sway/config.d/keybinds b/home-config/sway/config.d/keybinds index 7278d49..bfc6f56 100644 --- a/home-config/sway/config.d/keybinds +++ b/home-config/sway/config.d/keybinds @@ -36,6 +36,10 @@ bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5% bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5% bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle +bindsym F3 exec pactl set-sink-volume @DEFAULT_SINK@ +5% +bindsym F2 exec pactl set-sink-volume @DEFAULT_SINK@ -5% +bindsym F1 exec pactl set-sink-mute @DEFAULT_SINK@ toggle +bindsym F4 exec pactl set-source-mute @DEFAULT_SOURCE@ toggle # Brightness keybinds bindsym XF86MonBrightnessDown exec brightnessctl set 5%- diff --git a/home-config/sway/config.d/project b/home-config/sway/config.d/project new file mode 100644 index 0000000..3cb1049 --- /dev/null +++ b/home-config/sway/config.d/project @@ -0,0 +1,6 @@ +### Project + +bindsym $mod+Alt+Left exec ~/.config/sway/scripts.d/project.sh LEFT +bindsym $mod+Alt+Right exec ~/.config/sway/scripts.d/project.sh RIGHT +bindsym $mod+Alt+Up exec ~/.config/sway/scripts.d/project.sh EXTERNAL_ONLY +bindsym $mod+Alt+Down exec ~/.config/sway/scripts.d/project.sh PRIMARY_ONLY diff --git a/home-config/sway/scripts.d/project.sh b/home-config/sway/scripts.d/project.sh new file mode 100755 index 0000000..afb8507 --- /dev/null +++ b/home-config/sway/scripts.d/project.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash + +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 [ "$NAME" == "$1" ]; then + echo "$i" + exit 0 + elif [ "$NAME" == "null" ]; then + exit 1 + fi + ((i=i+1)) + done +} + +die() { + notify-send -u critical -t 3000 "Sway" "Failed to get display" +} + +PRIMARY=$(get_id "eDP-1") +EXTERNAL=$(get_id "DP-1" || get_id "HDMI-1") + +PRIMARY_SCALE=1.5 +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/modules/home-config/base-system.scm b/modules/home-config/base-system.scm index 842c28a..e35e0fa 100644 --- a/modules/home-config/base-system.scm +++ b/modules/home-config/base-system.scm @@ -156,7 +156,10 @@ (unix-sock-group "libvirt") (tls-port "16555"))) (service virtlog-service-type) - (service bluetooth-service-type) + (service bluetooth-service-type + (bluetooth-configuration + (experimental #t) + (fast-connectable? #t))) (service pam-limits-service-type) (service fprintd-service-type) (udev-rules-service 'fido2 libfido2 #:groups '("plugdev")))