Skip to content

Instantly share code, notes, and snippets.

@mateussouzaweb
Created July 20, 2022 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mateussouzaweb/a862f0ca314710f79849de3e3480c71c to your computer and use it in GitHub Desktop.
Save mateussouzaweb/a862f0ca314710f79849de3e3480c71c to your computer and use it in GitHub Desktop.
XRand Optimal Size Calculator
// Notes about how scalling works:
// - values greater than one lead to a compressed screen
// - values less than 1 leads to zoom the screen
// Notes about screen flickering:
// - If you detect issues with screen flickering
// - Update the scaling to a number like from 1x1 to 0.9999x0.9999
// - This may force your screen to respond correctly
const global = {
scale: 175
}
const monitors = [{
id: 'HDMI-A-0',
refreshRate: 60,
scale: 175,
x: 3840,
y: 2160
},{
id: 'eDP',
refreshRate: 60,
scale: 125,
x: 1920,
y: 1080
}].map((monitor, index) => {
// Just specify the desired resolution
const mode = monitor.x + 'x' + monitor.y
// Scale consider the global scale
const ratio = global.scale / monitor.scale
const scale = ratio + 'x' + ratio
return {
...monitor,
mode,
ratio,
scale,
}
}).map((monitor, index, list) => {
// Direction is left of X, centered in Y
const none = {x: 0, y: 0, ratio: 1}
const last = index == 0 ? none : list[index - 1]
const lastX = last.x ? last.x * last.ratio : 0
const lastY = last.y ? last.y * last.ratio : 0
const monitorX = monitor.x * monitor.ratio
const monitorY = monitor.y * monitor.ratio
const posX = lastX == 0 ? lastX : lastX
const posY = lastY == 0 ? lastY : (lastY - monitorY) / 2
const pos = posX + 'x' + posY
return {
...monitor,
pos
}
})
const output = 'xrandr ' + monitors.map((monitor, index) => {
return [
'--output', monitor.id,
'--rate', monitor.refreshRate,
'--mode', monitor.mode,
'--scale', monitor.scale,
'--pos', monitor.pos,
(index == 0 ? '--primary' : '')
].join(' ')
}).join(' ')
console.log(output)
#!/bin/bash
if [[ $(xrandr | grep "HDMI-A-0 connected") ]]; then
xrandr --output eDP --rate 60 --mode 1920x1080 --scale 1.4x1.4 --pos 3840x340 --primary --output HDMI-A-0 --rate 60 --mode 3840x2160 --scale 0.9999x0.9999 --pos 0x0
else
xrandr --output eDP --rate 60 --mode 1920x1080 --scale 1.4x1.4 --pos 0x0 --primary
fi
# Restart KDE plasma
# killall plasmashell
# sleep 1
# plasmashell --replace &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment