From 44a0b3a81978761e04cf287801200c58af3fa86e Mon Sep 17 00:00:00 2001
From: Yaroslav de la Peña Smirnov <yps@yaroslavps.com>
Date: Thu, 30 Nov 2023 22:42:27 +0300
Subject: picinpic: fix and improve script

* Simplify a bit
* Take into current state (floating/not floating)
* Add delay before resize, because for some reason some mpv windows
  don't get resized without it.

Also update swayfx blur config.
---
 dotfiles/.local/bin/picinpic | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

(limited to 'dotfiles/.local/bin')

diff --git a/dotfiles/.local/bin/picinpic b/dotfiles/.local/bin/picinpic
index 98be777..42a27ea 100755
--- a/dotfiles/.local/bin/picinpic
+++ b/dotfiles/.local/bin/picinpic
@@ -1,18 +1,15 @@
 #!/bin/sh
 
-currentmonrect="$(swaymsg -t get_outputs | jq ".[] | select(.focused == true) | .rect")"
-resx=$(echo $currentmonrect | jq --raw-output ".width")
-resy=$(echo $currentmonrect | jq --raw-output ".height")
-
-sx=$(($resx / 4))
-sy=$(($resy / 4))
-posx=$(($resx - $sx - 15))
-posy=$(($resy - $sy - 40))
-
-swaymsg resize set "$sx" "$sy"
+swaymsg floating toggle
+sleep 0.1
+isfloat=$(swaymsg -t get_workspaces | jq ".[] | select(.focused == true).floating_nodes[] | select(.focused == true) | any")
+if [ "$isfloat" = "true" ]; then
+	swaymsg sticky enable
+	swaymsg resize set 25ppt 25ppt
+fi
 
 if [ "$1" = "left" ]; then
-  swaymsg move position -- "-15" "$posy"
+  swaymsg move position -- "0ppt" "75ppt"
   exit
 fi
-swaymsg move position -- "$posx" "$posy"
+swaymsg move position -- "75ppt" "75ppt"
-- 
cgit v1.2.3