Gamescope/Gamemode for desktop?

Not sure if anyone else has the same weird needs that I do, but I move my PC around to different displays a bit and I have to update my launch options every time, which is very annoying. The three different contexts I use my PC with are:

  • at my desk (3440x1440@175hz w/ HDR and VRR)
  • on my living room TV (4k@120hz w/ HDR and VRR)
  • streaming, using my HDMI dummy plug with sunshine (1920x1200@60hz, no HDR or VRR)

I ended up writing a little bash script that constructs launch options based on what kscreen-doctor detects about your current display mode.

Note that this only works on KDE desktop, not Gnome or gamemode

#!/bin/bash

# Function to get the current active mode id for the enabled output
get_current_mode_id() {
  get_screen_info | jq -r '.outputs[] | select(.enabled == true) | .currentModeId'
}

# Function to get the active mode information (width, height, refresh rate) based on the mode id for the enabled output
get_mode_info() {
  local mode_id="$1"
  get_screen_info | jq -r --arg mode_id "$mode_id" '.outputs[] | select(.enabled == true) | .modes[] | select(.id == $mode_id) | {width: .size.width, height: .size.height, refresh: .refreshRate}'
}

# Function to get the HDR state of the enabled display
get_hdr_state() {
  get_screen_info | jq -r '.outputs[] | select(.enabled == true) | .hdr'
}

# Function to get the VRR (adaptive sync) state of the enabled display
get_vrr_state() {
  get_screen_info | jq -r '.outputs[] | select(.enabled == true) | .vrrPolicy'
}

# Function to get current screen information in JSON format
get_screen_info() {
  kscreen-doctor -j
}

# Extract width, height, and refresh rate from mode info for the enabled output
get_width() {
  echo "$1" | jq -r '.width'
}

get_height() {
  echo "$1" | jq -r '.height'
}

get_refresh_rate() {
  echo "$1" | jq -r '.refresh'
}

# Main script logic

# Get the current mode ID and mode info for the enabled display
mode_id=$(get_current_mode_id)
mode_info=$(get_mode_info "$mode_id")

# Extract width, height, and refresh rate from the mode info
KDE_WIDTH=$(get_width "$mode_info")
KDE_HEIGHT=$(get_height "$mode_info")
KDE_REFRESH=$(get_refresh_rate "$mode_info")

# Get HDR and VRR (adaptive sync) states for the enabled display
HDR_STATE=$(get_hdr_state)
VRR_STATE=$(get_vrr_state)

# Build the gamescope command with dynamic flags based on HDR and VRR support
gamescope_cmd="gamescope -W $KDE_WIDTH -H $KDE_HEIGHT -r $KDE_REFRESH --framerate-limit 175 --fullscreen --force-grab-cursor --mangoapp"

# Append HDR flag if HDR is supported and enabled
if [[ "$HDR_STATE" == "true" ]]; then
  gamescope_cmd="$gamescope_cmd --hdr-enabled"
fi

# Append VRR (adaptive sync) flag if supported
if [[ "$VRR_STATE" == 1 || "$VRR_STATE" == 2 ]]; then
  gamescope_cmd="$gamescope_cmd --adaptive-sync"
fi

# Output the environment variables and the gamescope command
echo "Screen Width: $KDE_WIDTH"
echo "Screen Height: $KDE_HEIGHT"
echo "Screen Refresh Rate: $KDE_REFRESH"
echo "HDR State: $HDR_STATE"
echo "VRR State: $VRR_STATE"
echo "Running: $gamescope_cmd"

# Run the constructed gamescope command
$gamescope_cmd -- "$@"

Then you can just set you launch options to gamescope-kde-dynamic-res %command%, assuming you name the bash script gamescope-kde-dynamic-res and have it in a location that’s in your PATH.

The script doesn’t rely on any extra utilities, so it should work on a vanilla bazzite KDE desktop installation.

5 Likes