From 8867b7568e4ee2e4b960b089a74c3dd4344491a4 Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Mon, 21 May 2007 18:48:08 +0200 Subject: Rescreen: collects new screen information darcs-hash:20070521164808-a5988-939df7eb10a12f12529b517158c7fda2d9249178.gz --- Rescreen.hs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Rescreen.hs diff --git a/Rescreen.hs b/Rescreen.hs new file mode 100644 index 0000000..90e6ab9 --- /dev/null +++ b/Rescreen.hs @@ -0,0 +1,41 @@ +-- Grabs new screen information. Useful for randr setups. +-- To use rescreen, add a keybinding in Config.hs. For example: +-- , ((modMask .|. shiftMask, xK_F12 ), rescreen) + +-- TODO Get this code into xmonad when it is ready for randr support. +-- Make it happen automatically on randr events. It's currently 20 loc, but I +-- believe it can be shrunk a bit. + +module XMonadContrib.Rescreen (rescreen) where + +import qualified StackSet as W +import XMonad +import Operations + +import Graphics.X11.Xlib +import Graphics.X11.Xinerama + +import Control.Monad.State +import Control.Monad.Reader +import Data.List (partition) + +rescreen :: X () +rescreen = do + dpy <- asks display + xinesc <- io $ getScreenInfo dpy + -- TODO: This stuff is necessary because Xlib apparently caches screen + -- width/height. Find a better solution later. I hate Xlib. + let sx = maximum $ map (\r -> rect_x r + fromIntegral (rect_width r)) xinesc + sy = maximum $ map (\r -> rect_y r + fromIntegral (rect_height r)) xinesc + modify (\s -> s { xineScreens = xinesc, dimensions = (sx, sy) }) + ws <- gets windowset + let s = W.current ws : W.visible ws + t = zipWith const [0 :: ScreenId ..] xinesc + (stay, hide) = partition (\x -> fromIntegral (W.screen x) < length t) s + newsids = filter (\x -> fromIntegral x >= length s) t + (newvis, newinvis) = splitAt (length newsids) (map W.workspace hide ++ W.hidden ws) + (newcurr : xs) = stay ++ zipWith W.Screen newvis newsids + windows $ const $ ws { W.current = newcurr + , W.visible = xs + , W.hidden = newinvis + } -- cgit v1.2.3