{-# LANGUAGE LambdaCase #-} module XMonad.Extra where import XMonad import System.IO (hPutStrLn, stderr) import qualified Data.Map as Map import qualified Data.Maybe import qualified XMonad.StackSet as W headMaybe :: [a] -> Maybe a headMaybe = \case x : _ -> Just x [] -> Nothing isFloating :: Window -> WindowSet -> Bool isFloating w = Map.member w . W.floating isFloatingX :: Window -> X Bool isFloatingX w = isFloating w <$> gets windowset withFocusedMaybe :: (Maybe Window -> X a) -> X a withFocusedMaybe f = withWindowSet $ f . W.peek -- Return list of all focused windows. -- The first element is the focused window on the focused workspace. -- If there is any error, the empty list will be returned instead. withAllFocused :: X [Window] withAllFocused = do ws <- gets $ map W.focus . Data.Maybe.catMaybes . map W.stack . W.workspaces . windowset withFocusedMaybe $ \case Just w -> if headMaybe ws == Just w then return ws else do io $ hPutStrLn stderr $ "withAllFocused: error: bad focus: " <> show (w, ws) return [] Nothing -> do io $ hPutStrLn stderr $ "withAllFocused: error: no focus" return []