summaryrefslogtreecommitdiff
path: root/pip.fish
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-17 17:19:16 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-17 17:19:16 +1100
commit01cef7d818e2e3be30bdaf0033d50c5800e468f5 (patch)
treedf21cf1d2fc08d4d8e739f4eaf2bd0be105ffbbc /pip.fish
parentscreenshot script (diff)
downloadcaelestia-cli-01cef7d818e2e3be30bdaf0033d50c5800e468f5.tar.gz
caelestia-cli-01cef7d818e2e3be30bdaf0033d50c5800e468f5.tar.bz2
caelestia-cli-01cef7d818e2e3be30bdaf0033d50c5800e468f5.zip
picture in picture script
Diffstat (limited to 'pip.fish')
-rwxr-xr-xpip.fish60
1 files changed, 60 insertions, 0 deletions
diff --git a/pip.fish b/pip.fish
new file mode 100755
index 0000000..bbea9e7
--- /dev/null
+++ b/pip.fish
@@ -0,0 +1,60 @@
+#!/bin/fish
+
+argparse -n 'caelestia-pip' -X 0 \
+ 'h/help' \
+ 'd/daemon' \
+ -- $argv
+or exit
+
+if set -q _flag_h
+ echo 'Usage:'
+ echo ' caelestia pip ( -h | --help )'
+ echo ' caelestia pip [ -d | --daemon ]'
+ echo
+ echo 'Options:'
+ echo ' -h, --help Print this help message and exit'
+ echo ' -d, --daemon Run this script in daemon mode'
+ echo
+ echo 'Normal mode (no args):'
+ echo ' Move and resize the active window to picture in picture default geometry.'
+ echo
+ echo 'Daemon mode:'
+ echo ' Set all picture in picture window initial geometry to default.'
+
+ exit
+end
+
+. (dirname (status filename))/util.fish
+
+function handle-window -a address workspace
+ set -l monitor_id (hyprctl workspaces -j | jq '.[] | select(.name == "'$workspace'").monitorID')
+ set -l monitor_size (hyprctl monitors -j | jq -r '.[] | select(.id == '$monitor_id') | "\(.width)\n\(.height)"')
+ set -l window_size (hyprctl clients -j | jq '.[] | select(.address == "'$address'").size[]')
+ set -l scale_factor (math $monitor_size[2] / 4 / $window_size[2])
+ set -l scaled_window_size (math -s 0 $window_size[1] x $scale_factor) (math -s 0 $window_size[2] x $scale_factor)
+
+ hyprctl dispatch "resizewindowpixel exact $scaled_window_size,address:$address" > /dev/null
+ hyprctl dispatch "movewindowpixel exact $(math -s 0 $monitor_size[1] x 0.98 - $scaled_window_size[1]) $(math -s 0 $monitor_size[2] x 0.97 - $scaled_window_size[2]),address:$address" > /dev/null
+ log "Handled window at address $address"
+end
+
+if set -q _flag_d
+ socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read line
+ switch $line
+ case 'openwindow*'
+ set -l window (string sub -s 13 $line | string split ',')
+ if string match -qr '^(Picture(-| )in(-| )[Pp]icture)$' $window[4]
+ handle-window 0x$window[1] $window[2]
+ end
+ end
+ end
+
+ exit
+end
+
+set -l active_window (hyprctl activewindow -j | jq -r '"\(.address)\n\(.workspace.name)\n\(.floating)"')
+if test $active_window[3] = true
+ handle-window $active_window
+else
+ warn 'Focused window is not floating, ignoring'
+end