dotfiles.git

commit 3432443defb6f440df76f60d16cbda2db202fe7f

Author: Adam Evyčędo <git@apiote.xyz>

guak position on every screen resolution

 .config/sh/functions | 20 +++++++++++++++++---


diff --git a/.config/sh/functions b/.config/sh/functions
index 2638522096bad06de4b11506c247c2a1e4b6f206..d564344eb921f63c875ecea7fd2a0bfb807ec989 100644
--- a/.config/sh/functions
+++ b/.config/sh/functions
@@ -94,6 +94,16 @@ alarm() {
 	echo "notify-send -u critical -i appointment-soon 'Alarm' '$2'; ffplay ~adam/Music/mps/cloister.ogg" | at "$1"
 }
 
+guakPosition() {
+	width=$(swaymsg -t get_outputs | jq '.. | objects | select(.focused == true).current_mode.width')
+	height=$(swaymsg -t get_outputs | jq '.. | objects | select(.focused == true).current_mode.height')
+	scale=$(swaymsg -t get_outputs | jq '.. | objects | select(.focused == true).scale')
+	w=$(echo "$width $scale / p" | dc)
+	h=$(echo "$height $scale / 2.5 / p" | dc)
+	move=$(echo "$height $scale / $h - 2 / p" | dc)
+	swaymsg "[pid=${pid}] floating enable, resize set $w $h, move position center, move up $move px"
+}
+
 guakStart() {
 	wezterm start --always-new-process >/dev/null 2>&1 &
 	pid=$(jobs -p)
@@ -108,8 +118,7 @@     i=$((i+=1))
     nanosleep 100000000
 	done
 	nanosleep 125
-	swaymsg "[pid=${pid}] floating enable, resize set 1504 400, move position center, move up 300 px"
-	# TODO size and move is `swaymgs -t get_outputs * / scale_factor
+	guakPosition
 }
 
 guakIsVisible() {
@@ -121,6 +130,7 @@ 	if guakIsVisible; then
 		swaymsg "[pid=${pid}] move scratchpad"
 	else
 		swaymsg "[pid=${pid}] scratchpad show"
+		guakPosition
 	fi
 }
 
@@ -1377,4 +1387,8 @@ 				swaymsg bar mode overlay
 			fi
 		fi
 	done
-}
\ No newline at end of file
+}
+
+bc() {
+	/usr/local/bin/bc -c -l /usr/lib/plan9/lib/bclib | dc | tail -n1
+}