xmonad / X11

A Haskell binding to the X11 graphics library.

Home Page:http://hackage.haskell.org/package/X11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Misreporting physical heights?

fmap opened this issue · comments

commented

I imagine this is a bug in the C library, if anything, but just in case:

% ghci -v0
λ: import Graphics.X11.Xlib
λ: import Control.Arrow
λ: (flip displayWidthMM 0 &&& flip displayHeightMM 0) <$> openDisplay []
(940,420)
it :: (Foreign.C.Types.CInt, Foreign.C.Types.CInt)
λ: 
% xrandr | grep mm
eDP1 connected 2560x1600+0+0 (normal left inverted right x axis y axis) 286mm x 179mm
DP1 disconnected 1024x768+2560+0 (normal left inverted right x axis y axis) 0mm x 0mm
% 
commented
% ghc-pkg describe X11
name: X11
version: 1.6.1.1
id: X11-1.6.1.1-fbec979d1d48ed93a7f4090c1fc46e9c
license: BSD3
copyright: Alastair Reid, 1999-2003, libraries@haskell.org 2003-2007, Don Stewart 2007-2009, Spencer Janssen 2007-2009, Daniel Wagner 2009-2011.
maintainer: Daniel Wagner <daniel@wagner-home.com>
stability:
homepage: https://github.com/haskell-pkg-janitors/X11
package-url:
synopsis: A binding to the X11 graphics library
description: A Haskell binding to the X11 graphics library.
             The binding is a direct translation of the C binding; for
             documentation of these calls, refer to "The Xlib Programming
             Manual", available online at <http://tronche.com/gui/x/xlib/>.
category: Graphics
author:
exposed: True
exposed-modules: Graphics.X11 Graphics.X11.Types Graphics.X11.Xlib
                 Graphics.X11.Xlib.Atom Graphics.X11.Xlib.Color
                 Graphics.X11.Xlib.Context Graphics.X11.Xlib.Cursor
                 Graphics.X11.Xlib.Display Graphics.X11.Xlib.Event
                 Graphics.X11.Xlib.Font Graphics.X11.Xlib.Misc
                 Graphics.X11.Xlib.Region Graphics.X11.Xlib.Screen
                 Graphics.X11.Xlib.Types Graphics.X11.Xlib.Window
                 Graphics.X11.Xlib.Image Graphics.X11.Xlib.Extras
                 Graphics.X11.Xinerama Graphics.X11.Xrandr Graphics.X11.XScreenSaver
                 Graphics.X11.ExtraTypes Graphics.X11.ExtraTypes.AP
                 Graphics.X11.ExtraTypes.DEC Graphics.X11.ExtraTypes.HP
                 Graphics.X11.ExtraTypes.Sun Graphics.X11.ExtraTypes.XF86
                 Graphics.X11.ExtraTypes.XorgDefault
hidden-modules: Graphics.X11.Xlib.Internal
trusted: False
import-dirs: /nix/store/ln6152i7m5jgfbyg28zwxylw6s15q5yn-haskell-X11-ghc7.6.3-1.6.1.1/lib/ghc-7.6.3/X11-1.6.1.1
library-dirs: /nix/store/ln6152i7m5jgfbyg28zwxylw6s15q5yn-haskell-X11-ghc7.6.3-1.6.1.1/lib/ghc-7.6.3/X11-1.6.1.1
              /nix/store/0sh2jja121096l63nvhryy2yj4apgp2b-libX11-1.6.2/lib
              /nix/store/cfdzbci9pc3kzn7v4qh8dllvh2bqmlfk-libXext-1.3.2/lib
              /nix/store/liy7pyxz3chfp2bff9nk0ck4m45v2dfy-libXinerama-1.1.3/lib
              /nix/store/j28hs13ms7241pliaz8plj24wfdsgspx-libXrandr-1.4.2/lib
              /nix/store/bdb55pcvzbn8gkzzq1h0d3li0cl1nj2y-libXrender-0.9.8/lib
hs-libraries: HSX11-1.6.1.1
extra-libraries: Xinerama Xext X11 Xrandr Xext
extra-ghci-libraries:
include-dirs: /nix/store/0sh2jja121096l63nvhryy2yj4apgp2b-libX11-1.6.2/include
              /nix/store/cfdzbci9pc3kzn7v4qh8dllvh2bqmlfk-libXext-1.3.2/include
              /nix/store/liy7pyxz3chfp2bff9nk0ck4m45v2dfy-libXinerama-1.1.3/include
              /nix/store/j28hs13ms7241pliaz8plj24wfdsgspx-libXrandr-1.4.2/include
              /nix/store/bdb55pcvzbn8gkzzq1h0d3li0cl1nj2y-libXrender-0.9.8/include
              /nix/store/ln6152i7m5jgfbyg28zwxylw6s15q5yn-haskell-X11-ghc7.6.3-1.6.1.1/lib/ghc-7.6.3/X11-1.6.1.1/include
includes: HsXlib.h HsAllKeysyms.h
depends: base-4.6.0.1-02ac91ff7de681afee6a8fa62f0c87f3
         data-default-0.5.3-690cbd65b712475fa704cfcf6dff3163
hugs-options:
cc-options:
ld-options:
framework-dirs:
frameworks:
haddock-interfaces: /nix/store/ln6152i7m5jgfbyg28zwxylw6s15q5yn-haskell-X11-ghc7.6.3-1.6.1.1/share/doc/X11-1.6.1.1/html/X11.haddock
haddock-html: /nix/store/ln6152i7m5jgfbyg28zwxylw6s15q5yn-haskell-X11-ghc7.6.3-1.6.1.1/share/doc/X11-1.6.1.1/html
pkgroot: "/nix/store/n1drkghiakkwv23vz2qfbddbgyr1hh0r-haskell-env-ghc-7.6.3/lib/ghc-7.6.3"
commented

It seems Xlib Screen and Display sizes treat all outputs as one monitor, but the below RandR code does what I want:

{-# LANGUAGE LambdaCase #-}

import Control.Arrow ((&&&))
import Data.Maybe (catMaybes)
import Control.Monad (liftM2)
import Control.Applicative ((<$>))
import Foreign.C.Types (CULong)
import Graphics.X11.Xlib (Display, Window, openDisplay, defaultScreen, rootWindow, createSimpleWindow, blackPixel)
import Graphics.X11.Xrandr (XRROutputInfo(..), XRRScreenResources(..), xrrGetOutputInfo, xrrGetScreenResources)

getPhysicalSize :: XRROutputInfo -> (CULong, CULong)
getPhysicalSize = xrr_oi_mm_width &&& xrr_oi_mm_height

getScreenResources :: Display -> IO (Maybe XRRScreenResources)
getScreenResources = liftM2 (>>=) emptyWindow xrrGetScreenResources

displays :: IO [(CULong, CULong)]
displays = openDisplay []  >>= \display -> getScreenResources display >>= \case
  Just resources -> fmap getPhysicalSize . catMaybes <$> xrrGetOutputInfo display resources `mapM` xrr_sr_outputs resources
  Nothing -> return []

emptyWindow :: Display -> IO Window
emptyWindow display = do
  let screen = defaultScreen display
      pixel  = blackPixel display screen
  root <- rootWindow display screen
  createSimpleWindow display root 0 0 1 1 0 pixel pixel