From f246c317941baf5299c5795fe4bcf717d9b5432e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Thu, 19 Sep 2024 11:09:23 -0300 Subject: [PATCH] Revert "sway: disable vrr" This reverts commit 752f029bce075d605d22e1a0b40c016801467e13. --- scripts/default.nix | 1 + scripts/vrr-fullscreen | 28 ++++++++++++++++++++++++++++ user/sway/default.nix | 17 ++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 scripts/vrr-fullscreen diff --git a/scripts/default.nix b/scripts/default.nix index 0e88436..1e3290e 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -129,6 +129,7 @@ libinput libratbag ]; + vrr-fullscreen = [ ]; } // lib.mapAttrs importScript { wdmenu = ./wdmenu.nix; diff --git a/scripts/vrr-fullscreen b/scripts/vrr-fullscreen new file mode 100755 index 0000000..8413923 --- /dev/null +++ b/scripts/vrr-fullscreen @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# List of supported outputs for VRR +output_vrr_whitelist=( + "DP-1" + "DP-2" +) + +# Toggle VRR for fullscreened apps in prespecified displays to avoid stutters while in desktop +swaymsg -t subscribe -m '[ "window" ]' | while read window_json; do + window_event=$(echo ${window_json} | jq -r '.change') + + # Process only focus change and fullscreen toggle + 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') + + # Use only VRR in whitelisted outputs + 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') + + # Only update output if nesseccary to avoid flickering + [[ $output_vrr_status = "disabled" && $window_fullscreen_status = "1" ]] && swaymsg output "${output_name}" adaptive_sync 1 + [[ $output_vrr_status = "enabled" && $window_fullscreen_status = "0" ]] && swaymsg output "${output_name}" adaptive_sync 0 + fi + fi +done diff --git a/user/sway/default.nix b/user/sway/default.nix index 42e26af..2a6dc70 100644 --- a/user/sway/default.nix +++ b/user/sway/default.nix @@ -69,9 +69,9 @@ in }; output = { "*" = { + adaptive_sync = "off"; bg = "${theme.background} fill"; mode = "1920x1080@144.000Hz"; - adaptive_sync = "on"; }; }; fonts = { @@ -122,6 +122,21 @@ in indicator = true; }; + systemd.user.services.vrr-fullscreen = { + Unit = { + Description = "Enable VRR for fullscreen windows"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session.target" ]; + }; + Service = { + ExecStart = "${lib.getExe pkgs.vrr-fullscreen}"; + Restart = "on-failure"; + }; + Install = { + WantedBy = [ "sway-session.target" ]; + }; + }; + services.gpg-agent.pinentryPackage = pkgs.pinentry-all; xdg.configFile."OpenTabletDriver/settings.json".source = ./open-tablet-driver.json;