Last active
April 5, 2021 02:14
-
-
Save varenc/f723f1cb205198e98a698d96efd26535 to your computer and use it in GitHub Desktop.
Displayplacer workaround: switch to unscaled modes by looking up mode number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a workaround for https://github.com/jakehilborn/displayplacer/issues/35 and https://github.com/jakehilborn/displayplacer/issues/31 | |
# Displayplacer ignores "scaling:off" and always enabling scaling unless you switch via mode number instead. | |
# It even turns scaling on for non-sense situations like when you're setting the resolution to your | |
# display's physical resolution resulting in a subtle but serious performance hit. | |
function resolutionSwitch() { | |
# check the output of `displayplacer list` and pass in everything after the "mode xx: " of the desired settings shown | |
# if you want "scaling:off", just don't include scaling and pass in '$' at the end to match against the end | |
# examples: | |
# $ resolutionSwitch "res:2304x1296 hz:60 color_depth:8$" | |
# $ resolutionSwitch "res:3008x1692 hz:60 color_depth:8 scaling:on" | |
SID="2648EE53-5F1E-37A6-99FA-30FB0B2E49A9"; # replace with your monitor ID. (or make it an argument) | |
## Alternatively, get the screen id based on the monitor's description | |
## SID=$(displayplacer list | grep -B2 "27 inch external screen" | grep Persistent | awk '{print $4}') | |
# extract the displayplacer mode number for the desired settings | |
DESIRED="$1" | |
MODE_NUM=$(displayplacer list | sed -E "s/[[:blank:]]+(<-- current mode)?$//g" | sed -n -e "/$SID/,/Persistent screen/ p" | grep -E "^ mode" | grep "$DESIRED" | cut -d ":" -f 1 | sed -E 's/^[[:blank:]]+mode[[:blank:]]//g') # UGGLLLYYYYYY | |
# check that a single mode was found | |
if [ $(echo $MODE_NUM | wc -w) -ne 1 ]; then | |
echo "Did not find a unique mode number: '$MODE_NUM'...giving up"; | |
return; | |
fi | |
echo "Switching monitor '$SID' to mode '$MODE_NUM' which represents the settings '$DESIRED'"; | |
displayplacer "id:$SID mode:$MODE_NUM" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment