Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. -----------------------------------------------------------------------------
  2. -- |
  3. -- Module : XMonad.Actions.FocusNth
  4. -- Copyright : (c) Karsten Schoelzel <kuser@gmx.de>
  5. -- License : BSD
  6. --
  7. -- Maintainer : Karsten Schoelzel <kuser@gmx.de>
  8. -- Stability : stable
  9. -- Portability : unportable
  10. --
  11. -- Focus the nth window of the current workspace.
  12. -----------------------------------------------------------------------------
  13.  
  14. module XMonad.Actions.FocusNth (
  15. -- * Usage
  16. -- $usage
  17. focusNth,focusNth',
  18. swapNth,swapNth') where
  19.  
  20. import XMonad.StackSet
  21. import XMonad
  22.  
  23. -- $usage
  24. -- Add the import to your @~\/.xmonad\/xmonad.hs@:
  25. --
  26. -- > import XMonad.Actions.FocusNth
  27. --
  28. -- Then add appropriate keybindings, for example:
  29. --
  30. -- > -- mod4-[1..9] @@ Switch to window N
  31. -- > ++ [((modm, k), focusNth i)
  32. -- > | (i, k) <- zip [0 .. 8] [xK_1 ..]]
  33. --
  34. -- For detailed instructions on editing your key bindings, see
  35. -- "XMonad.Doc.Extending#Editing_key_bindings".
  36.  
  37. -- | Give focus to the nth window of the current workspace.
  38. focusNth :: Int -> X ()
  39. focusNth = windows . modify' . focusNth'
  40.  
  41. focusNth' :: Int -> Stack a -> Stack a
  42. focusNth' n s@(Stack _ ls rs) | (n < 0) || (n > length(ls) + length(rs)) = s
  43. | otherwise = listToStack n (integrate s)
  44.  
  45. swapNth :: Int -> X ()
  46. swapNth = windows . modify' . swapNth'
  47.  
  48. swapNth' :: Int -> Stack a -> Stack a
  49. swapNth' n s@(Stack c ls rs)
  50. | (n < 0) || (n > length ls + length rs) || (n == length ls) = s
  51. | n < length ls = let (nl, (nc : nr)) = splitAt (n + 1) ls in Stack nc (nl ++ c : nr) rs
  52. | otherwise = let (nl, (nc : nr)) = splitAt (n - length ls) rs in Stack nc ls (nl ++ c : nr)
  53.  
  54.  
  55. listToStack :: Int -> [a] -> Stack a
  56. listToStack n l = Stack t ls rs
  57. where
  58. (t:rs) = drop n l
  59. ls = reverse (take n l)
  60.  
  61.  
  62. pattern_match_failure = swapNth' 1 (Stack 0 [1,2] []) :: Stack Int
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement