blob: 2a234fe21fbca7b9bbc46ded137c25ee02186a49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
{-# 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 []
|