~aodag/dotfiles

ref: 3555eaa7f0d4cd5fbf2ee89bc2cd44973f659e64 dotfiles/config/i3blocks/sway-focusedwindow -rwxr-xr-x 913 bytes
3555eaa7Atsushi Odagiri kitty transparent background 1 year, 13 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash

maxlen=0
if [[ $1 ]]; then
  maxlen=$1
fi

align="center"
if [[ $2 ]]; then
  align=$2
fi

format() {
  if [[ $maxlen == 0 ]]; then
    echo "$1"
    return 0
  fi
  len=${#1}
  if [[ $len -ge $maxlen ]]; then
    echo "${1:0:${maxlen}}"
  else
    pad=$(( maxlen - len ))
    case "$align" in
      "center" )
        pad=$(( pad / 2 ))
        printf "%*s%s%*s\n" $pad "" "$1" $pad ""
        ;;
      "left" )
        printf "%s%*s\n" "$1" $pad "" 
        ;;
      "right" )
        printf "%*s%s\n" $pad "" "$1"
        ;;
    esac
  fi
}

process() {
  while read -r LINE; do
    format "$LINE"
  done
}

swaymsg -t get_tree | jq --unbuffered -r '.. | select(.focused?) | .name' | process

subscribe_query='select(.container.focused and (.change == "focus" or .change == "title")) | .container.name'
swaymsg -m -t SUBSCRIBE "['window']" | jq --unbuffered -r "$subscribe_query" | process