summaryrefslogtreecommitdiff
path: root/files/sway/vrr_fullscreen.sh
blob: 0db4e1016d9f8b1a02c23772c0177ffeacd725ef (plain)
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
#! /usr/bin/env bash

# https://github.com/swaywm/sway/issues/5076#issuecomment-1753499364

output_vrr_whitelist=("$(awk -F ' ' 'NR==1{print $3}' $HOME/.config/sway/monitors)")

swaymsg -t subscribe -m '[ "window" ]' | while read window_json; do
  app_id=$(echo ${window_json} | jq -r '.container.app_id')
  if [[ $app_id == "com.moonlight_stream.Moonlight" || $app_id == "Waydroid" ]]; then
    continue
  fi
  window_event=$(echo ${window_json} | jq -r '.change')
  if [[ $window_event = "focus" || $window_event = "fullscreen_mode" ]]; then
    output_json=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused == true)')
    output_name=$(echo ${output_json} | jq -r '.name')
    if [[ ${output_vrr_whitelist[*]} =~ ${output_name} ]]; then
      output_vrr_status=$(echo ${output_json} | jq -r '.adaptive_sync_status')
      window_fullscreen_status=$(echo ${window_json} | jq -r '.container.fullscreen_mode')
      if [[ $output_vrr_status = "disabled" && $window_fullscreen_status = "1" ]]; then
        swaymsg output "${output_name}" adaptive_sync 1
        swaymsg 'seat * hide_cursor 0'
      fi
      if [[ $output_vrr_status = "enabled" && $window_fullscreen_status = "0" ]]; then
        swaymsg output "${output_name}" adaptive_sync 0
        swaymsg 'seat * hide_cursor 4000'
      fi
    fi
  fi
done