Improving on my gaming config that I posted months ago here: https://www.reddit.com/r/hyprland/comments/1uxwh5a/lets_discuss_our_hyprland_specific_gaming_tweaks/
Would love to see what everyone else has going on
Gaming.lua
Summary: Tag most common game windows from common game classes. Apply window rules to them via tags i.e. game or tearing & has hooks like the tearing hook that sets specific config options when the game window opens & then resets them on close. A hook that sets do not disturb & sets CPU power profile to performance when the game window opens & reverts them back on close. Applies rules for overrides from overrides menu listed below.
-- Tagging game windows
hl.window_rule({
name = "proton-game-tag",
match = {
xdg_tag = "proton-game",
},
tag = "+game",
})
hl.window_rule({
name = "steam-apps-tag",
match = {
initial_class = "steam_app_.*",
},
tag = "+game",
})
hl.window_rule({
name = "gamescope-tag",
match = {
class = "gamescope",
},
tag = "+game",
})
hl.window_rule({
name = "minecraft-tag",
match = {
class = "Minecraft.*",
},
tag = "+game",
})
-- Shared rules for game-tagged windows
local gameRules = {
border_size = 0,
rounding = 0,
decorate = false,
force_rgbx = true,
sync_fullscreen = true,
no_anim = true,
no_blur = true,
no_dim = true,
no_max_size = true,
no_shadow = true,
no_glow = true,
no_wobble = true,
persistent_size = true,
opaque = true,
fullscreen_state = "2 2",
}
-- Tearing = everything above + extras
local tearingExtras = {
immediate = true,
}
local function applyGameRules(tag, extras)
local rule = {
name = tag .. "-games",
match = { tag = tag, fullscreen = true },
}
for key, value in pairs(gameRules) do
rule[key] = value
end
for key, value in pairs(extras or {}) do
rule[key] = value
end
hl.window_rule(rule)
hl.window_rule({
name = tag .. "-game-popups",
match = { tag = tag },
content = "game",
workspace = 3,
center = true,
idle_inhibit = "always",
})
end
applyGameRules("game")
applyGameRules("tearing", tearingExtras)
------------------------------
---- GAME OVERRIDES MENU -----
------------------------------
local overridesFile = os.getenv("HOME") .. "/.config/hypr/game-overrides.tsv"
local function escapeRegex(s)
return (s:gsub("[%^%$%(%)%.%[%]%*%+%?%-{}|\\]", "\\%0"))
end
local function loadOverrides()
local f = io.open(overridesFile, "r")
if not f then return end
for line in f:lines() do
local class, flags = line:match("^(.-)\t(.*)$")
if class and class ~= "" then
local match = { class = "^" .. escapeRegex(class) .. "$" }
for flag in flags:gmatch("[^,]+") do
if flag == "game" or flag == "tearing" then
hl.window_rule({
name = class .. "-override-" .. flag,
match = match,
tag = "+" .. flag,
})
elseif flag == "no_vrr" then
hl.window_rule({
name = class .. "-override-no_vrr",
match = match,
no_vrr = true,
})
end
end
end
end
f:close()
end
loadOverrides()
-- Override menu bind
hl.bind(mainMod .. " + SHIFT + G", hl.dsp.exec_cmd("~/.local/bin/game-override-menu"))
------------------------------
---- GAME TAG / TRACKING -----
------------------------------
local GAME_TAGS = { "game", "tearing" }
local TEARING_TAGS = { "tearing" }
local function hasAnyTag(win, wanted)
if not win or not win.tags then return false end
for _, tag in ipairs(win.tags) do
for _, name in ipairs(wanted) do
if tag == name or tag == name .. "*" then return true end
end
end
return false
end
-- Calls setActive(true) when the first matching window appears and
-- setActive(false) when the last one closes. Also rebuilds after a reload.
local function trackTaggedWindows(tags, setActive)
local tracked, active = {}, false
local function update()
local now = next(tracked) ~= nil
if now ~= active then
active = now
setActive(now)
end
end
hl.on("window.open", function(win)
if hasAnyTag(win, tags) then
tracked[win.address] = true
update()
end
end)
hl.on("window.close", function(win)
if tracked[win.address] then
tracked[win.address] = nil
update()
end
end)
for _, win in ipairs(hl.get_windows()) do
if hasAnyTag(win, tags) then tracked[win.address] = true end
end
update()
end
----------------------------
---- GAME TEARING HOOK -----
----------------------------
local tearingEnabled = false
local stateFile = "/tmp/hypr-tearing-state"
local function stateFileExists()
local file = io.open(stateFile, "r")
if file then
file:close()
return true
end
return false
end
local function enableTearing()
if tearingEnabled then return end
local wasAlreadyEnabled = stateFileExists()
-- Reflect your config values to change here
hl.config({
general = { allow_tearing = true },
misc = { vrr = 0 },
render = { direct_scanout = 0 },
})
local f = io.open(stateFile, "w")
if f then f:close() end
if not wasAlreadyEnabled then
hl.exec_cmd([[notify-send "Gaming Mode" "Tearing Enabled // VRR Disabled"]])
end
tearingEnabled = true
end
local function disableTearing()
if not tearingEnabled then return end
-- Reflect your default config values to change here
hl.config({
general = { allow_tearing = false },
misc = { vrr = 3 },
render = { direct_scanout = 2 },
})
os.remove(stateFile)
hl.exec_cmd([[notify-send "Gaming Mode" "Tearing Disabled // VRR Enabled"]])
tearingEnabled = false
end
trackTaggedWindows(TEARING_TAGS, function(on)
if on then enableTearing() else disableTearing() end
end)
-------------------------------------
---- GAME PERFORMANCE & DND HOOK ----
-------------------------------------
local gamePerfEnabled = false
local function setGamePerf(enabled)
if enabled == gamePerfEnabled then return end
gamePerfEnabled = enabled
if enabled then
hl.exec_cmd("powerprofilesctl set performance")
hl.exec_cmd("noctalia msg notification-dnd-set on")
else
hl.exec_cmd("powerprofilesctl set balanced")
hl.exec_cmd("noctalia msg notification-dnd-set off")
end
end
trackTaggedWindows(GAME_TAGS, setGamePerf)
--------------------------------------
---- FLOATING FULLSCREEN CASE FIX ----
--------------------------------------
hl.on("window.fullscreen", function(w)
if w == nil or not w.floating or w.fullscreen == 0 then return end
if not hasAnyTag(w, GAME_TAGS) then return end
hl.dispatch(hl.dsp.window.float({ window = w, action = "disable" }))
end)
Game Overrides Zenity Menu
TLDR: Grabs the focused window class & opens a zenity menu that can manually apply the tag tearing or game if it hasn't been from prior rules like in the case of native linux games which can't be automagically tagged by a common steam class & can apply override rules like no_vrr for example.
#!/usr/bin/env bash
class="$1"
if [ -z "$class" ]; then
class=$(hyprctl activewindow | sed -n 's/^[[:space:]]*class: //p' | head -n1)
fi
if [ -z "$class" ]; then
notify-send "Overrides" "No focused window class found"
exit 1
fi
safe_class=$(printf '%s' "$class" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
file="$HOME/.config/hypr/game-overrides.tsv"
touch "$file"
flags=$(CLASS="$class" awk -F'\t' '$1==ENVIRON["CLASS"]{print $2}' "$file")
has() { [[ ",$flags," == *",$1,"* ]] && echo TRUE || echo FALSE; }
write_flags() {
local tmp; tmp=$(mktemp "$file.XXXXXX")
CLASS="$class" awk -F'\t' '$1!=ENVIRON["CLASS"]' "$file" > "$tmp"
[ -n "$1" ] && printf '%s\t%s\n' "$class" "$1" >> "$tmp"
mv "$tmp" "$file"
}
while true; do
selected=$(zenity --list --checklist \
--title="Overrides: $class" \
--text="Tick what applies to: <b>$safe_class</b>\n\n<i>Changes won't apply until the game is restarted.</i>\n\n<i>Note: no_vrr is dropped automatically when tearing is selected, since tearing already disables VRR.</i>" \
--column="" --column="key" --column="Option" \
--hide-column=2 --print-column=2 --separator=',' \
--width=360 --height=320 \
"$(has game)" game "Manually tag: game" \
"$(has tearing)" tearing "Manually tag: tearing" \
"$(has no_vrr)" no_vrr "Window rule: no_vrr" \
FALSE clear "Remove all overrides") || exit 0
if [[ ",$selected," == *",game,"* && ",$selected," == *",tearing,"* && ",$selected," != *",clear,"* ]]; then
zenity --error --width=320 \
--text="Pick either game or tearing, not both. Tearing already includes the game behavior."
flags="$selected"
continue
fi
break
done
if [[ ",$selected," == *",tearing,"* ]]; then
selected=$(printf ',%s,' "$selected" | sed 's/,no_vrr,/,/g; s/^,//; s/,$//')
fi
if [[ ",$selected," == *",clear,"* ]]; then
write_flags ""
else
write_flags "$selected"
fi
hyprctl reload