Close the display correctly after counting the number of screens

This patch adds support for calling countScreens in arbitrary places. Prior to
this patch one would end up with an open display for each call of the
countScreens function with would eventually mess up X. This patch ensures that
the display that is no longer needed is closed after the operation and thus
using the function without side effects.
This commit is contained in:
quesel
2010-11-16 08:14:49 +00:00
parent 67db59bf73
commit 3813d625b6

View File

@@ -28,6 +28,7 @@ module XMonad.Layout.IndependentScreens (
) where
-- for the screen stuff
import Control.Applicative((<*), liftA2)
import Control.Arrow hiding ((|||))
import Control.Monad
import Data.List
@@ -112,7 +113,7 @@ onCurrentScreen f vws = screen . current >>= f . flip marshall vws
-- > }
--
countScreens :: (MonadIO m, Integral i) => m i
countScreens = liftM genericLength . liftIO $ openDisplay "" >>= getScreenInfo
countScreens = liftM genericLength . liftIO $ openDisplay "" >>= liftA2 (<*) getScreenInfo closeDisplay
-- | This turns a naive pretty-printer into one that is aware of the
-- independent screens. That is, you can write your pretty printer to behave