{-# LANGUAGE MultiParamTypeClasses, DeriveDataTypeable, TypeSynonymInstances, FlexibleContexts, PatternGuards #-}------------------------------------------------------------------------------ |-- Module : XMonad.Layout.Minimize-- Copyright : (c) Jan Vornberger 2009, Alejandro Serrano 2010-- License : BSD3-style (see LICENSE)---- Maintainer : jan.vornberger@informatik.uni-oldenburg.de-- Stability : unstable-- Portability : not portable---- Makes it possible to minimize windows, temporarily removing them-- from the layout until they are restored.-------------------------------------------------------------------------------moduleXMonad.Layout.Minimize(-- * Usage-- $usageminimize,minimizeWindow,MinimizeMsg(RestoreMinimizedWin,RestoreNextMinimizedWin),Minimize,)whereimportXMonadimportqualifiedXMonad.StackSetasWimportXMonad.Layout.LayoutModifierimportXMonad.Layout.BoringWindowsasBWimportXMonad.Util.WindowProperties(getProp32)importData.ListimportqualifiedData.MapasMimportData.MaybeimportForeign.C.Types(CLong)-- $usage-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:---- > import XMonad.Layout.Minimize---- Then edit your @layoutHook@ by adding the Minimize layout modifier:---- > myLayout = minimize (Tall 1 (3/100) (1/2)) ||| Full ||| etc..-- > main = xmonad defaultConfig { layoutHook = myLayout }---- For more detailed instructions on editing the layoutHook see:---- "XMonad.Doc.Extending#Editing_the_layout_hook"---- In the key-bindings, do something like:---- > , ((modm, xK_m ), withFocused minimizeWindow)-- > , ((modm .|. shiftMask, xK_m ), sendMessage RestoreNextMinimizedWin)---- The first action will minimize the focused window, while the second one will restore-- the next minimized window.---- For detailed instruction on editing the key binding see:---- "XMonad.Doc.Extending#Editing_key_bindings".---- The module is designed to work together with "XMonad.Layout.BoringWindows" so-- that minimized windows will be skipped over when switching the focused window with-- the keyboard. Include 'BW.boringWindows' in your layout hook and see the-- documentation of "XMonad.Layout.BoringWindows" on how to modify your keybindings.---- Also see "XMonad.Hooks.Minimize" if you want to be able to minimize-- and restore windows from your taskbar.dataMinimizea=Minimize[Window](M.MapWindowW.RationalRect)deriving(Read,Show)minimize::LayoutClasslWindow=>lWindow->ModifiedLayoutMinimizelWindowminimize=ModifiedLayout$Minimize[]M.emptydataMinimizeMsg=MinimizeWinWindow|RestoreMinimizedWinWindow|RestoreNextMinimizedWinderiving(Typeable,Eq)instanceMessageMinimizeMsgminimizeWindow::Window->X()minimizeWindoww=sendMessage(MinimizeWinw)>>BW.focusDownsetMinimizedState::Window->Int->(CLong->[CLong]->[CLong])->X()setMinimizedStatewinstf=dosetWMStatewinstwithDisplay$\dpy->dowm_state<-getAtom"_NET_WM_STATE"mini<-getAtom"_NET_WM_STATE_HIDDEN"wstate<-fromMaybe[]`fmap`getProp32wm_statewinletptype=4-- The atom property type for changePropertyfi_mini=fromIntegralminiio$changeProperty32dpywinwm_stateptypepropModeReplace(ffi_miniwstate)setMinimized::Window->X()setMinimizedwin=setMinimizedStatewiniconicState(:)setNotMinimized::Window->X()setNotMinimizedwin=setMinimizedStatewinnormalStatedeleteinstanceLayoutModifierMinimizeWindowwheremodifierDescription_="Minimize"modifyLayout(Minimizeminimized_)wksprect=doletstack=W.stackwkspfiltStack=stack>>=W.filter(\w->not(w`elem`minimized))runLayout(wksp{W.stack=filtStack})recthandleMess(Minimizeminimizedunfloated)m|Just(MinimizeWinw)<-fromMessagem,not(w`elem`minimized)=dosetMinimizedwws<-getswindowsetcaseM.lookupw(W.floatingws)ofNothing->return$Just$Minimize(w:minimized)unfloatedJustr->domodify(\s->s{windowset=W.sinkwws})return$Just$Minimize(w:minimized)(M.insertwrunfloated)|Just(RestoreMinimizedWinw)<-fromMessagem=dosetNotMinimizedwcaseM.lookupwunfloatedofNothing->return$Just$Minimize(minimized\\[w])unfloatedJustr->dows<-getswindowsetmodify(\s->s{windowset=W.floatwrws})return$Just$Minimize(minimized\\[w])(M.deletewunfloated)|JustRestoreNextMinimizedWin<-fromMessagem=dows<-getswindowsetifnot(nullminimized)thencaseM.lookup(headminimized)unfloatedofNothing->doletw=headminimizedsetNotMinimizedwmodify(\s->s{windowset=W.focusWindowwws})return$Just$Minimize(tailminimized)unfloatedJustr->doletw=headminimizedsetNotMinimizedwmodify(\s->s{windowset=(W.focusWindoww.W.floatwr)ws})return$Just$Minimize(tailminimized)(M.deletewunfloated)elsereturnNothing|JustBW.UpdateBoring<-fromMessagem=dows<-gets(W.workspace.W.current.windowset)flipsendMessageWithNoRefreshws$BW.Replace"Minimize"minimizedreturnNothing|otherwise=returnNothing