{-# LANGUAGE DeriveDataTypeable #-}------------------------------------------------------------------------------ |-- Module : XMonad.Util.PositionStore-- Copyright : (c) Jan Vornberger 2009-- License : BSD3-style (see LICENSE)---- Maintainer : jan.vornberger@informatik.uni-oldenburg.de-- Stability : unstable-- Portability : not portable---- A utility module to store information about position and size of a window.-- See "XMonad.Layout.PositionStoreFloat" for a layout that makes use of this.-------------------------------------------------------------------------------moduleXMonad.Util.PositionStore(getPosStore,modifyPosStore,posStoreInsert,posStoreMove,posStoreQuery,posStoreRemove,PositionStore,)whereimportXMonadimportqualifiedXMonad.Util.ExtensibleStateasXSimportqualifiedData.MapasM-- Store window positions relative to the upper left screen edge-- and windows sizes as well as positions as fractions of the screen size.-- This way windows can be easily relocated and scaled when switching screens.dataPositionStore=PS(M.MapWindowPosStoreRectangle)deriving(Read,Show,Typeable)dataPosStoreRectangle=PSRectangleDoubleDoubleDoubleDoublederiving(Read,Show,Typeable)instanceExtensionClassPositionStorewhereinitialValue=PSM.emptyextensionType=PersistentExtensiongetPosStore::X(PositionStore)getPosStore=XS.getmodifyPosStore::(PositionStore->PositionStore)->X()modifyPosStore=XS.modifyposStoreInsert::PositionStore->Window->Rectangle->Rectangle->PositionStoreposStoreInsert(PSposStoreMap)w(Rectanglexywhht)(RectanglesrXsrYsrWhsrHt)=letoffsetX=x-srXoffsetY=y-srYinPS$M.insertw(PSRectangle(fromIntegraloffsetX/fromIntegralsrWh)(fromIntegraloffsetY/fromIntegralsrHt)(fromIntegralwh/fromIntegralsrWh)(fromIntegralht/fromIntegralsrHt))posStoreMapposStoreRemove::PositionStore->Window->PositionStoreposStoreRemove(PSposStoreMap)w=PS$M.deletewposStoreMapposStoreQuery::PositionStore->Window->Rectangle->MaybeRectangleposStoreQuery(PSposStoreMap)w(RectanglesrXsrYsrWhsrHt)=do(PSRectanglexywhht)<-M.lookupwposStoreMapletrealWh=fromIntegralsrWh*whrealHt=fromIntegralsrHt*htrealOffsetX=fromIntegralsrWh*xrealOffsetY=fromIntegralsrHt*yreturn(Rectangle(srX+roundrealOffsetX)(srY+roundrealOffsetY)(roundrealWh)(roundrealHt))posStoreMove::PositionStore->Window->Position->Position->Rectangle->Rectangle->PositionStoreposStoreMoveposStorewxyoldSrnewSr=case(posStoreQueryposStorewoldSr)ofNothing->posStore-- not in store, can't move -> do nothingJust(Rectangle__whht)->posStoreInsertposStorew(Rectanglexywhht)newSr