------------------------------------------------------------------------------ |-- Module : XMonad.Hooks.PositionStoreHooks-- Copyright : (c) Jan Vornberger 2009-- License : BSD3-style (see LICENSE)---- Maintainer : jan.vornberger@informatik.uni-oldenburg.de-- Stability : unstable-- Portability : not portable---- This module contains two hooks for the-- PositionStore (see "XMonad.Util.PositionStore") - a ManageHook and-- an EventHook.---- The ManageHook can be used to fill the PositionStore with position and size-- information about new windows. The advantage of using this hook is, that the-- information is recorded independent of the currently active layout. So the-- floating shape of the window can later be restored even if it was opened in a-- tiled layout initially.---- For windows, that do not request a particular position, a random position will-- be assigned. This prevents windows from piling up exactly on top of each other.---- The EventHook makes sure that windows are deleted from the PositionStore-- when they are closed.-------------------------------------------------------------------------------moduleXMonad.Hooks.PositionStoreHooks(-- * Usage-- $usagepositionStoreManageHook,positionStoreEventHook)whereimportXMonadimportqualifiedXMonad.StackSetasWimportXMonad.Util.PositionStoreimportXMonad.Util.XUtils(fi)importSystem.Random(randomRIO)importControl.Applicative((<$>))importControl.Monad(when)importData.MaybeimportData.Monoid-- $usage-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:---- > import XMonad.Hooks.PositionStoreHooks---- and adding 'positionStoreManageHook' to your 'ManageHook' as well-- as 'positionStoreEventHook' to your event hooks:---- > myManageHook = positionStoreManageHook <+> manageHook defaultConfig-- > myHandleEventHook = positionStoreEventHook-- >-- > main = xmonad defaultConfig { manageHook = myManageHook-- > , handleEventHook = myHandleEventHook-- > }--positionStoreManageHook::ManageHookpositionStoreManageHook=ask>>=liftX.positionStoreInit>>idHookpositionStoreInit::Window->X()positionStoreInitw=withDisplay$\d->dowa<-io$getWindowAttributesdwws<-getswindowsetarbitraryOffsetX<-randomIntOffsetarbitraryOffsetY<-randomIntOffsetif(wa_xwa==0)&&(wa_ywa==0)thendoletsr@(RectanglesrXsrY__)=screenRect.W.screenDetail.W.current$wsmodifyPosStore(\ps->posStoreInsertpsw(Rectangle(srX+fiarbitraryOffsetX)(srY+fiarbitraryOffsetY)(fi$wa_widthwa)(fi$wa_heightwa))sr)elsedosc<-fromMaybe(W.currentws)<$>pointScreen(fi$wa_xwa)(fi$wa_ywa)letsr=screenRect.W.screenDetail$scmodifyPosStore(\ps->posStoreInsertpsw(Rectangle(fi$wa_xwa)(fi$wa_ywa)(fi$wa_widthwa)(fi$wa_heightwa))sr)whererandomIntOffset::X(Int)randomIntOffset=io$randomRIO(42,242)positionStoreEventHook::Event->XAllpositionStoreEventHook(DestroyWindowEvent{ev_window=w,ev_event_type=et})=dowhen(et==destroyNotify)$domodifyPosStore(\ps->posStoreRemovepsw)return(AllTrue)positionStoreEventHook_=return(AllTrue)