Skip to content

Instantly share code, notes, and snippets.

@vderyagin
Created January 16, 2014 09:22
Show Gist options
  • Save vderyagin/8452060 to your computer and use it in GitHub Desktop.
Save vderyagin/8452060 to your computer and use it in GitHub Desktop.
get screen resolution in X (shells out to xrandr(1))
import Data.List
import Data.Maybe
import System.Process
import Text.Regex.Posix
main :: IO ()
main = do
(w, h) <- getScreenResolution
putStrLn $ show w ++ "×" ++ show h
getScreenResolution :: IO (Int, Int)
getScreenResolution = do
rawOutput <- readProcess "xrandr" [] []
let currentMode = fromJust . find (elem '*') $ lines rawOutput
[[_, w, h]] = currentMode =~ "([0-9]+)x([0-9]+)"
return (read w, read h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment