From 3fec545841a02548a5df31654ad7eec99c4133aa Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Thu, 14 Jan 2021 13:05:06 +0100 Subject: [PATCH] bin: add sway_output, bind to mod+p, menu to mod+t --- bin/sway_output | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ config | 8 +++- 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100755 bin/sway_output diff --git a/bin/sway_output b/bin/sway_output new file mode 100755 index 0000000..3f19300 --- /dev/null +++ b/bin/sway_output @@ -0,0 +1,117 @@ +#!/bin/zsh +source $HOME/.config/sway/bin/sway_helpers +CMD=$HOME/.config/sway/bin/sway_output +# BAT_PATH=/sys/class/power_supply +# BAT=BAT0 +# MODE=suspend-then-hibernate + +## helpers +function _get() { + _check_app jq + data=() + swaymsg -t get_outputs | jq -r ".[] | .$1" | while read line; do + line=${line:gs/ /_} + data+=($line) + done + echo $data +} + +function _outputs() { + make=( $(_get make) ) + model=( $(_get model) ) + serial=( $(_get serial) ) + name=( $(_get name) ) + active=( $(_get active) ) + for i in $(seq ${#make[@]}); do + ac=${active[$i]/true/active} + ac=${ac/false/inactive} + printf " - %2d %6s %10s %20s %15s %10s\n" $i ${name[$i]} "($ac)" ${make[$i]} ${model[$i]} ${serial[$i]} + done +} + +function _enable() { + n=( $(_get name) ) + swaymsg output ${n[$1]} enable +} + +function _disable() { + n=( $(_get name) ) + swaymsg output ${n[$1]} disable +} + +function _interactive() { + echo "outputs (any key to abort)" + _outputs + num=$(_outputs | wc -l) + + read -k 1 "o?select output: " + if [ $o -le $num ]; then + echo "" + echo "" + else + echo "error: invalid output selected: $o" + return 1 + fi + + echo "actions (any key to abort)" + printf " - %2s %6s\n" "1" "enable" + printf " - %2s %6s\n" "2" "disable" + read -k 1 "a?select action: " + if [ $a -le 2 ]; then + echo "" + echo "" + case $a in + 1) + echo "enabling $o" + _enable $o + ;; + 2) + echo "disabling $o" + _disable $o + ;; + esac + else + echo "error: invalid action selected $a" + return 1 + fi +} + +# generate enab +function _nag() { + _check_app swaynag + name=( $(_get name) ) + z=() + # for n in $name; do + # z+=" -z \"enable $n\" \"$CMD enable $n\"" + # z+=" -z \"disable $n\" \"$CMD disable $n\"" + # done + + # swaynag -m "control outputs" $(echo ${z[@]}) + # swaynag -m "control outputs" $(echo ${z}) +} + +## main +# _log OUTPUTS INFO args: $* + +case $1 in + o*) + echo "outputs: " + _outputs + ;; + e*) + _enable $2 + ;; + d*) + _disable $2 + ;; + n*) + _nag + ;; + -h|--help|help) + echo "invalid argument: \"$1\"" + echo "arguments: [outputs|enable #|disable #]" + ;; + *) + _interactive + ;; +esac diff --git a/config b/config index 0c9e52d..3e38737 100644 --- a/config +++ b/config @@ -18,6 +18,7 @@ set $term termite set $background $HOME/Cloud/xkonni/Pictures/wallpaper/5k_bavarian_forest_bw.jpg set $lock_cmd $HOME/.config/sway/bin/sway_lock set $brightness_cmd "$HOME/.config/sway/bin/sway_brightness +set $output_cmd "$HOME/.config/sway/bin/sway_output set $suspend_cmd "$HOME/.config/sway/bin/sway_suspend set $volume_cmd "$HOME/.config/sway/bin/sway_volume set $font Cascadia Code PL Regular 10 @@ -79,7 +80,7 @@ bindsym $mod+Shift+q kill bindsym --release button3 kill # Start your launcher -bindsym $mod+p exec $menu +bindsym $mod+t exec $menu # Drag floating windows by holding down $mod and left mouse button. # Resize them with right mouse button + $mod. @@ -187,6 +188,10 @@ bindsym Print exec grim -g "$(slurp)" - | wl-copy # save selection bindsym $mod+Print exec grim -g "$(slurp)" \ $(xdg-user-dir PICTURES)/screenshot_$(date +'%Y%m%d_%H%M%S').png +# +## Output +# +bindsym $mod+p exec "$term -t float -e $output_cmd" # # Gaps @@ -248,6 +253,7 @@ bindsym $mod+m mode "move" # Window Rules: # for_window [title="nmtui"] floating enable +for_window [title="float*"] floating enable for_window [app_id="pavucontrol"] floating enable for_window [app_id="com.nextcloud.desktopclient.nextcloud"] floating enable for_window [app_id=".*"] title_format '%title (%app_id)'