Created
January 16, 2014 09:22
-
-
Save vderyagin/8452060 to your computer and use it in GitHub Desktop.
get screen resolution in X (shells out to xrandr(1))
This file contains 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
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