Skip to content

Instantly share code, notes, and snippets.

@johansson
Forked from benley/xrandr-scale.hs
Created April 11, 2018 19:42
Show Gist options
  • Save johansson/1b041ec87e793340b6b8d36b7c3af4c0 to your computer and use it in GitHub Desktop.
Save johansson/1b041ec87e793340b6b8d36b7c3af4c0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env runhaskell
import System.Process (callCommand)
runcmd args =
putStrLn ("+ " ++ cmd) >> callCommand cmd
where cmd = unwords args
-- (Name of your laptop's internal display, x res, y res)
(internalOutput, intX, intY) = ("eDP1", 3840, 2160)
-- (Name of your external display, x res, y res)
(externalOutput, extX, extY) = ("DP2", 3840, 2160)
-- Coefficient to use when computing resolution for the virtual screen
-- to scale down for your external display:
scaleFactor = 1.75
(scaledExtX, scaledExtY) = (extX * scaleFactor, extY * scaleFactor)
extScaleFrom = show (round scaledExtX) ++ "x" ++ show (round scaledExtY)
internalPos = show (round scaledExtX) ++ "x" ++ show (round (scaledExtY - intY))
-- If your laptop has a touchscreen, put its xinput name here (from `xinput list`)
touchXinputId = "ELAN\\ Touchscreen"
main = do
runcmd [ "xrandr", "--auto" ]
runcmd [ "xrandr"
, "--output", externalOutput
, "--scale-from", extScaleFrom
, "--pos", "0x0"
, "--primary"
, "--output", internalOutput
, "--pos", internalPos
]
runcmd [ "xinput", "map-to-output", touchXinputId, internalOutput ]
-- Any other extra commands to run can go here, e.g.
-- runcmd [ "feh", "~/.background-image", "--bg-scale" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment