Skip to content

Instantly share code, notes, and snippets.

@JohnRTitor
Last active December 20, 2023 16:42
Show Gist options
  • Save JohnRTitor/0b7be14ee45042e3430a05a80f00ad68 to your computer and use it in GitHub Desktop.
Save JohnRTitor/0b7be14ee45042e3430a05a80f00ad68 to your computer and use it in GitHub Desktop.
Overclock Display on Linux

For Wayland, you need to add a kernel parameter:

  1. Edit /etc/default/grub

  2. Add the following kernel parameter: video=HDMI-A-1:1920x1080@75

where HDMI-A-1 is the port of display output, 1920x1080 is the resolution, 75 is the refresh rate

  1. Run sudo update-grub
  2. Reboot (init 6)
  3. Then select the custom refresh rate from the settings

If you are using X11, save the script below as my-custom-resolution.sh, after testing, make it autostart on boot. How to make it autostart is out of scope for this gist.

@JohnRTitor
Copy link
Author

JohnRTitor commented Dec 20, 2023

#!/usr/bin/env bash

# SCRIPT ONLY WORKS ON X11

# Set the values below as desired after testing
# After the desired values are chosen
# Set this script to autostart using KDE/GNOME GUI
# Else lookup guides online to execute scripts on boot
x_res=1920
y_res=1080
refresh_rate=75

echo "Detected environment type: $XDG_SESSION_TYPE"

# Check if the session is running on X11
# Either "x11" or "wayland"
if [ "$XDG_SESSION_TYPE" == "wayland" ]; then
    echo "Wayland environment detected. Custom resolution not applied."
    exit 0
fi

# Get the connected display output port name
# Output similar to: HDMI-A-0
display_output=$(xrandr | awk '/ connected/ {print $1}')

# Check if a display is connected
if [ -z "$display_output" ]; then
    echo "No connected display found. Custom resolution not applied."
    exit 1
fi

# Use cvt to generate the mode line for the custom resolution
# Output similar to: "1920x1080_75.05"  221.00  1920 2064 2264 2608  1080 1083 1088 1130 -hsync +vsync
custom_mode_line=$(cvt $x_res $y_res $refresh_rate | grep "Modeline" | cut -d' ' -f2-)

# Extract mode name from the custom_mode_line
# Output similar to: "1920x1080_75.05"
custom_mode_name=$(echo "$custom_mode_line" | awk '{print $1}')

# Add the new mode using xrandr
xrandr --newmode $custom_mode_line
xrandr --addmode "$display_output" "$custom_mode_name"
xrandr --output "$display_output" --mode "$custom_mode_name"

echo "Custom resolution applied to display: $display_output"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment