diff options
| author | tv <tv@krebsco.de> | 2026-12-04 01:55:06 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-04 03:05:12 +0000 |
| commit | 607fb1010baae845910e75ba31687bffb259636b (patch) | |
| tree | 13feecaa2c3c2091c83ea80ebfa1cdbe4db8f361 /pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs | |
| parent | 3b8389042fde0a9dcb1eaa8d6401e8332915af88 (diff) | |
xmonad-tv: update from the dirt
Diffstat (limited to 'pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs')
| -rw-r--r-- | pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs b/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs index 74222712..2a234fe2 100644 --- a/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs +++ b/pkgs/haskell/xmonad-tv/src/XMonad/Extra.hs @@ -1,9 +1,17 @@ +{-# 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 = @@ -12,3 +20,32 @@ isFloating w = 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 [] + + + |
