scratchpad.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. coded_by='
  3. In the name of Allah, the most Gracious, the most Merciful.
  4. ▓▓▓▓▓▓▓▓▓▓
  5. ░▓ Author ▓ Abdullah <https://abdullah.today>
  6. ░▓▓▓▓▓▓▓▓▓▓
  7. ░░░░░░░░░░
  8. ░█▀▀░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█░█░█▀█░█▀█░█▀▄
  9. ░▀▀█░█░░░█▀▄░█▀█░░█░░█░░░█▀█░█▀▀░█▀█░█░█
  10. ░▀▀▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀░▀░▀░░░▀░▀░▀▀░
  11. '
  12. toggle_flag() {
  13. id=$(bspc query -N -n "focused")
  14. if [ -n "$id" ]; then
  15. if [ $(xprop -id "$id" | grep "_SCRATCH_ORDER" | wc -l) -gt 0 ]; then
  16. xprop -id $id -remove _SCRATCH_ORDER
  17. xprop -id $id -remove _SCRATCH_VISIBILITY
  18. else
  19. xprop -id $id -f _SCRATCH_ORDER 32ii -set _SCRATCH_ORDER $(date +%s,%N)
  20. xprop -id $id -f _SCRATCH_VISIBILITY 8i -set _SCRATCH_VISIBILITY 0
  21. xdotool windowunmap $id
  22. fi
  23. fi
  24. }
  25. switch_app() {
  26. id=$(bspc query -N -n "focused")
  27. if [ $(xprop -id "$id" | grep "_SCRATCH_VISIBILITY(INTEGER) = 1" | wc -l) -gt 0 ]; then
  28. xprop -id $id -f _SCRATCH_VISIBILITY 8i -set _SCRATCH_VISIBILITY 0
  29. xdotool windowunmap $id
  30. fi
  31. sid=$(
  32. id=$(bspc query -N -n "focused");
  33. for w in $(xwininfo -root -children | grep -e "^\s*0x[0-9a-f]\+" -o); do
  34. if [ "$w" != "$id" ]; then
  35. t=$(xprop -id $w _SCRATCH_ORDER | grep ' = \(.*\)')
  36. if [ -n "$t" ]; then
  37. echo $t $w
  38. fi
  39. fi
  40. done | sort -n | head -n1 | cut -d" " -f 5
  41. );
  42. if [ -n "$sid" ] && [ "$(printf "%04d" $sid)" != "$(printf "%04d" $id)" ]; then
  43. echo "$sid" != "$id"
  44. xprop -id $sid -f _SCRATCH_ORDER 32ii -set _SCRATCH_ORDER $(date +%s,%N)
  45. xprop -id $sid -f _SCRATCH_VISIBILITY 8i -set _SCRATCH_VISIBILITY 1
  46. xdotool windowmap $sid
  47. bspc node -f $sid
  48. fi
  49. }
  50. op="$1"
  51. if [ "$op" = "toggle-flag" ]; then
  52. toggle_flag
  53. elif [ "$op" = "switch-app" ]; then
  54. switch_app
  55. fi