mirror of
https://github.com/xmonad/xmonad.git
synced 2025-08-04 06:01:53 -07:00
HEADS UP: change key binding for swapLeft/Right and IncMaster
The use of arrow keys for swapLeft/Right clash with firefox's back button. Use the more intuitive mod-shift-jk for this. (It's a movement operation, after all). This clashes with IncMaster, so we use mod+comma and mod+period for these (i.e. the keys mod < and mod > , to move windows to and from the master area). While we're here, replace the use of the terms 'left' and 'right' for navigation, in comments and identifiers, with 'up' and 'down' instead. Hence mod-j == focusDown. Far more intuitive for people (dons) who live in fullscreen mode and have vim movement wired into their central nervous system. Principle of least VI surprise: movement down or up means using j and k.
This commit is contained in:
29
Config.hs
29
Config.hs
@@ -148,35 +148,40 @@ defaultLayouts = [ full
|
|||||||
--
|
--
|
||||||
keys :: M.Map (KeyMask, KeySym) (X ())
|
keys :: M.Map (KeyMask, KeySym) (X ())
|
||||||
keys = M.fromList $
|
keys = M.fromList $
|
||||||
|
-- launching and killing programs
|
||||||
[ ((modMask .|. shiftMask, xK_Return), spawn "xterm")
|
[ ((modMask .|. shiftMask, xK_Return), spawn "xterm")
|
||||||
, ((modMask, xK_p ), spawn "exe=`dmenu_path | dmenu` && exec $exe")
|
, ((modMask, xK_p ), spawn "exe=`dmenu_path | dmenu` && exec $exe")
|
||||||
, ((modMask .|. shiftMask, xK_p ), spawn "gmrun")
|
, ((modMask .|. shiftMask, xK_p ), spawn "gmrun")
|
||||||
|
, ((modMask .|. shiftMask, xK_c ), kill)
|
||||||
|
|
||||||
|
-- rotate through the available layout algorithms
|
||||||
, ((modMask, xK_space ), switchLayout)
|
, ((modMask, xK_space ), switchLayout)
|
||||||
|
|
||||||
-- 'nudge': resize viewed windows to the correct size.
|
-- 'nudge': resize viewed windows to the correct size.
|
||||||
, ((modMask, xK_n ), refresh)
|
, ((modMask, xK_n ), refresh)
|
||||||
|
|
||||||
, ((modMask, xK_Tab ), focusRight)
|
-- move focus up or down the window stack
|
||||||
, ((modMask, xK_j ), focusRight)
|
, ((modMask, xK_Tab ), focusDown)
|
||||||
, ((modMask, xK_k ), focusLeft)
|
, ((modMask, xK_j ), focusDown)
|
||||||
|
, ((modMask, xK_k ), focusUp)
|
||||||
|
|
||||||
, ((modMask, xK_Left ), swapLeft)
|
-- modifying the window order
|
||||||
, ((modMask, xK_Right ), swapRight)
|
, ((modMask, xK_Return), swapMaster)
|
||||||
|
, ((modMask .|. shiftMask, xK_j ), swapDown)
|
||||||
|
, ((modMask .|. shiftMask, xK_k ), swapUp)
|
||||||
|
|
||||||
|
-- resizing the master/slave ratio
|
||||||
, ((modMask, xK_h ), sendMessage Shrink)
|
, ((modMask, xK_h ), sendMessage Shrink)
|
||||||
, ((modMask, xK_l ), sendMessage Expand)
|
, ((modMask, xK_l ), sendMessage Expand)
|
||||||
|
|
||||||
, ((modMask .|. shiftMask, xK_j ), sendMessage (IncMasterN 1))
|
-- increase or decrease number of windows in the master area
|
||||||
, ((modMask .|. shiftMask, xK_k ), sendMessage (IncMasterN (-1)))
|
, ((modMask , xK_comma ), sendMessage (IncMasterN 1))
|
||||||
|
, ((modMask , xK_period), sendMessage (IncMasterN (-1)))
|
||||||
, ((modMask .|. shiftMask, xK_c ), kill)
|
|
||||||
|
|
||||||
|
-- quit, or restart
|
||||||
, ((modMask .|. shiftMask, xK_q ), io $ exitWith ExitSuccess)
|
, ((modMask .|. shiftMask, xK_q ), io $ exitWith ExitSuccess)
|
||||||
, ((modMask .|. shiftMask .|. controlMask, xK_q ), restart Nothing True)
|
, ((modMask .|. shiftMask .|. controlMask, xK_q ), restart Nothing True)
|
||||||
|
|
||||||
-- Cycle the current tiling order
|
|
||||||
, ((modMask, xK_Return), swapMaster)
|
|
||||||
|
|
||||||
] ++
|
] ++
|
||||||
-- Keybindings to get to each workspace:
|
-- Keybindings to get to each workspace:
|
||||||
[((m .|. modMask, k), f i)
|
[((m .|. modMask, k), f i)
|
||||||
|
@@ -43,7 +43,7 @@ manage w = do
|
|||||||
selectInput d w $ structureNotifyMask .|. enterWindowMask .|. propertyChangeMask
|
selectInput d w $ structureNotifyMask .|. enterWindowMask .|. propertyChangeMask
|
||||||
mapWindow d w
|
mapWindow d w
|
||||||
setWindowBorderWidth d w borderWidth
|
setWindowBorderWidth d w borderWidth
|
||||||
windows $ W.insertLeft w
|
windows $ W.insertUp w
|
||||||
|
|
||||||
-- | unmanage. A window no longer exists, remove it from the window
|
-- | unmanage. A window no longer exists, remove it from the window
|
||||||
-- list, on whatever workspace it is.
|
-- list, on whatever workspace it is.
|
||||||
@@ -51,11 +51,11 @@ unmanage :: Window -> X ()
|
|||||||
unmanage = windows . W.delete
|
unmanage = windows . W.delete
|
||||||
|
|
||||||
-- | focus. focus window to the left or right.
|
-- | focus. focus window to the left or right.
|
||||||
focusLeft, focusRight, swapLeft, swapRight :: X ()
|
focusUp, focusDown, swapUp, swapDown :: X ()
|
||||||
focusLeft = windows W.focusLeft
|
focusUp = windows W.focusUp
|
||||||
focusRight = windows W.focusRight
|
focusDown = windows W.focusDown
|
||||||
swapLeft = windows W.swapLeft
|
swapUp = windows W.swapUp
|
||||||
swapRight = windows W.swapRight
|
swapDown = windows W.swapDown
|
||||||
|
|
||||||
-- | swapMaster. Move the currently focused window into the master frame
|
-- | swapMaster. Move the currently focused window into the master frame
|
||||||
swapMaster :: X ()
|
swapMaster :: X ()
|
||||||
|
91
StackSet.hs
91
StackSet.hs
@@ -76,9 +76,9 @@
|
|||||||
--
|
--
|
||||||
module StackSet (
|
module StackSet (
|
||||||
StackSet(..), Workspace(..), Screen(..), Stack(..),
|
StackSet(..), Workspace(..), Screen(..), Stack(..),
|
||||||
new, view, lookupWorkspace, peek, index, focusLeft, focusRight,
|
new, view, lookupWorkspace, peek, index, focusUp, focusDown,
|
||||||
focusWindow, member, findIndex, insertLeft, delete, shift,
|
focusWindow, member, findIndex, insertUp, delete, shift,
|
||||||
swapMaster, swapLeft, swapRight, modify -- needed by users
|
swapMaster, swapUp, swapDown, modify -- needed by users
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Maybe (listToMaybe)
|
import Data.Maybe (listToMaybe)
|
||||||
@@ -91,10 +91,10 @@ import qualified Data.List as L (delete,find,genericSplitAt)
|
|||||||
-- view,
|
-- view,
|
||||||
-- index,
|
-- index,
|
||||||
-- peek, -- was: peek/peekStack
|
-- peek, -- was: peek/peekStack
|
||||||
-- focusLeft, focusRight, -- was: rotate
|
-- focusUp, focusDown, -- was: rotate
|
||||||
-- swapLeft, swapRight
|
-- swapUp, swapDown
|
||||||
-- focus -- was: raiseFocus
|
-- focus -- was: raiseFocus
|
||||||
-- insertLeft, -- was: insert/push
|
-- insertUp, -- was: insert/push
|
||||||
-- delete,
|
-- delete,
|
||||||
-- swapMaster, -- was: promote/swap
|
-- swapMaster, -- was: promote/swap
|
||||||
-- member,
|
-- member,
|
||||||
@@ -131,9 +131,15 @@ data Workspace i a = Workspace { tag :: !i, stack :: Stack a }
|
|||||||
--
|
--
|
||||||
-- A stack is a cursor onto a (possibly empty) window list.
|
-- A stack is a cursor onto a (possibly empty) window list.
|
||||||
-- The data structure tracks focus by construction, and
|
-- The data structure tracks focus by construction, and
|
||||||
-- the master window is by convention the left most item.
|
-- the master window is by convention the top-most item.
|
||||||
-- Focus operations will not reorder the list that results from
|
-- Focus operations will not reorder the list that results from
|
||||||
-- flattening the cursor.
|
-- flattening the cursor. The structure can be envisaged as:
|
||||||
|
--
|
||||||
|
-- +-- master: < '7' >
|
||||||
|
-- up | [ '2' ]
|
||||||
|
-- +--------- [ '3' ]
|
||||||
|
-- focus: < '4' >
|
||||||
|
-- dn +----------- [ '8' ]
|
||||||
--
|
--
|
||||||
-- A 'Stack' can be viewed as a list with a hole punched in it to make
|
-- A 'Stack' can be viewed as a list with a hole punched in it to make
|
||||||
-- the focused position. Under the zipper/calculus view of such
|
-- the focused position. Under the zipper/calculus view of such
|
||||||
@@ -142,8 +148,8 @@ data Workspace i a = Workspace { tag :: !i, stack :: Stack a }
|
|||||||
--
|
--
|
||||||
data Stack a = Empty
|
data Stack a = Empty
|
||||||
| Node { focus :: !a -- focused thing in this set
|
| Node { focus :: !a -- focused thing in this set
|
||||||
, left :: [a] -- clowns to the left
|
, up :: [a] -- clowns to the left
|
||||||
, right :: [a] } -- jokers to the right
|
, down :: [a] } -- jokers to the right
|
||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
|
|
||||||
|
|
||||||
@@ -247,32 +253,32 @@ index = with [] $ \(Node t l r) -> reverse l ++ t : r
|
|||||||
--
|
--
|
||||||
-- /O(1), O(w) on the wrapping case/.
|
-- /O(1), O(w) on the wrapping case/.
|
||||||
--
|
--
|
||||||
-- focusLeft, focusRight. Move the window focus left or
|
-- focusUp, focusDown. Move the window focus up or down the stack,
|
||||||
-- right, wrapping if we reach the end. The wrapping should model a
|
-- wrapping if we reach the end. The wrapping should model a -- 'cycle'
|
||||||
-- 'cycle' on the current stack. The 'master' window, and window order,
|
-- on the current stack. The 'master' window, and window order,
|
||||||
-- are unaffected by movement of focus.
|
-- are unaffected by movement of focus.
|
||||||
--
|
--
|
||||||
-- swapLeft, swapRight. Swap the focused window with its left or right
|
-- swapUp, swapDown, swap the neighbour in the stack ordering, wrapping
|
||||||
-- neighbour in the stack ordering, wrapping if we reach the end. Again
|
-- if we reach the end. Again the wrapping model should 'cycle' on
|
||||||
-- the wrapping model should 'cycle' on the current stack.
|
-- the current stack.
|
||||||
--
|
--
|
||||||
focusLeft, focusRight, swapLeft, swapRight :: StackSet i a s -> StackSet i a s
|
focusUp, focusDown, swapUp, swapDown :: StackSet i a s -> StackSet i a s
|
||||||
focusLeft = modify Empty $ \c -> case c of
|
focusUp = modify Empty $ \c -> case c of
|
||||||
Node _ [] [] -> c
|
Node _ [] [] -> c
|
||||||
Node t (l:ls) rs -> Node l ls (t:rs)
|
Node t (l:ls) rs -> Node l ls (t:rs)
|
||||||
Node t [] rs -> Node x (xs ++ [t]) [] where (x:xs) = reverse rs
|
Node t [] rs -> Node x (xs ++ [t]) [] where (x:xs) = reverse rs
|
||||||
|
|
||||||
focusRight = modify Empty $ \c -> case c of
|
focusDown = modify Empty $ \c -> case c of
|
||||||
Node _ [] [] -> c
|
Node _ [] [] -> c
|
||||||
Node t ls (r:rs) -> Node r (t:ls) rs
|
Node t ls (r:rs) -> Node r (t:ls) rs
|
||||||
Node t ls [] -> Node x [] (xs ++ [t]) where (x:xs) = reverse ls
|
Node t ls [] -> Node x [] (xs ++ [t]) where (x:xs) = reverse ls
|
||||||
|
|
||||||
swapLeft = modify Empty $ \c -> case c of
|
swapUp = modify Empty $ \c -> case c of
|
||||||
Node _ [] [] -> c
|
Node _ [] [] -> c
|
||||||
Node t (l:ls) rs -> Node t ls (l:rs)
|
Node t (l:ls) rs -> Node t ls (l:rs)
|
||||||
Node t [] rs -> Node t (reverse rs) []
|
Node t [] rs -> Node t (reverse rs) []
|
||||||
|
|
||||||
swapRight = modify Empty $ \c -> case c of
|
swapDown = modify Empty $ \c -> case c of
|
||||||
Node _ [] [] -> c
|
Node _ [] [] -> c
|
||||||
Node t ls (r:rs) -> Node t (r:ls) rs
|
Node t ls (r:rs) -> Node t (r:ls) rs
|
||||||
Node t ls [] -> Node t [] (reverse ls)
|
Node t ls [] -> Node t [] (reverse ls)
|
||||||
@@ -285,7 +291,7 @@ focusWindow :: (Integral i, Eq s, Eq a) => a -> StackSet i a s -> StackSet i a s
|
|||||||
focusWindow w s | Just w == peek s = s
|
focusWindow w s | Just w == peek s = s
|
||||||
| otherwise = maybe s id $ do
|
| otherwise = maybe s id $ do
|
||||||
n <- findIndex w s
|
n <- findIndex w s
|
||||||
return $ until ((Just w ==) . peek) focusLeft (view n s)
|
return $ until ((Just w ==) . peek) focusUp (view n s)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Finding if a window is in the stackset is a little tedious. We could
|
-- Finding if a window is in the stackset is a little tedious. We could
|
||||||
@@ -310,34 +316,34 @@ findIndex a s = listToMaybe
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- /O(n)/. (Complexity due to duplicate check). Insert a new element into
|
-- /O(n)/. (Complexity due to duplicate check). Insert a new element into
|
||||||
-- the stack, to the left of the currently focused element.
|
-- the stack, above the currently focused element.
|
||||||
--
|
--
|
||||||
-- The new element is given focus, and is set as the master window.
|
-- The new element is given focus, and is set as the master window.
|
||||||
-- The previously focused element is moved to the right. The previously
|
-- The previously focused element is moved down. The previously
|
||||||
-- 'master' element is forgotten. (Thus, 'insert' will cause a retiling).
|
-- 'master' element is forgotten. (Thus, 'insert' will cause a retiling).
|
||||||
--
|
--
|
||||||
-- If the element is already in the stackset, the original stackset is
|
-- If the element is already in the stackset, the original stackset is
|
||||||
-- returned unmodified.
|
-- returned unmodified.
|
||||||
--
|
--
|
||||||
-- Semantics in Huet's paper is that insert doesn't move the cursor.
|
-- Semantics in Huet's paper is that insert doesn't move the cursor.
|
||||||
-- However, we choose to insert to the left, and move the focus.
|
-- However, we choose to insert above, and move the focus.
|
||||||
--
|
--
|
||||||
insertLeft :: Eq a => a -> StackSet i a s -> StackSet i a s
|
insertUp :: Eq a => a -> StackSet i a s -> StackSet i a s
|
||||||
insertLeft a s = if member a s then s else insert
|
insertUp a s = if member a s then s else insert
|
||||||
where insert = modify (Node a [] []) (\(Node t l r) -> Node a l (t:r)) s
|
where insert = modify (Node a [] []) (\(Node t l r) -> Node a l (t:r)) s
|
||||||
|
|
||||||
-- insertRight :: a -> StackSet i a s -> StackSet i a s
|
-- insertDown :: a -> StackSet i a s -> StackSet i a s
|
||||||
-- insertRight a = modify (Node a [] []) $ \(Node t l r) -> Node a (t:l) r
|
-- insertDown a = modify (Node a [] []) $ \(Node t l r) -> Node a (t:l) r
|
||||||
-- Old semantics, from Huet.
|
-- Old semantics, from Huet.
|
||||||
-- > w { right = a : right w }
|
-- > w { down = a : down w }
|
||||||
|
|
||||||
--
|
--
|
||||||
-- /O(1) on current window, O(n) in general/. Delete window 'w' if it exists.
|
-- /O(1) on current window, O(n) in general/. Delete window 'w' if it exists.
|
||||||
-- There are 4 cases to consider:
|
-- There are 4 cases to consider:
|
||||||
--
|
--
|
||||||
-- * delete on an Empty workspace leaves it Empty
|
-- * delete on an Empty workspace leaves it Empty
|
||||||
-- * otherwise, try to move focus to the right
|
-- * otherwise, try to move focus to the down
|
||||||
-- * otherwise, try to move focus to the left
|
-- * otherwise, try to move focus to the up
|
||||||
-- * otherwise, you've got an empty workspace, becomes Empty
|
-- * otherwise, you've got an empty workspace, becomes Empty
|
||||||
--
|
--
|
||||||
-- Behaviour with respect to the master:
|
-- Behaviour with respect to the master:
|
||||||
@@ -353,13 +359,13 @@ delete w s | Just w == peek s = remove s -- common case.
|
|||||||
removeWindow o n = foldr ($) s [view o,remove,view n]
|
removeWindow o n = foldr ($) s [view o,remove,view n]
|
||||||
|
|
||||||
-- actual removal logic, and focus/master logic:
|
-- actual removal logic, and focus/master logic:
|
||||||
remove = modify Empty $ \c ->
|
remove = modify Empty $ \c ->
|
||||||
if focus c == w
|
if focus c == w
|
||||||
then case c of
|
then case c of
|
||||||
Node _ ls (r:rs) -> Node r ls rs -- try right first
|
Node _ ls (r:rs) -> Node r ls rs -- try down first
|
||||||
Node _ (l:ls) [] -> Node l ls [] -- else left.
|
Node _ (l:ls) [] -> Node l ls [] -- else up
|
||||||
Node _ [] [] -> Empty
|
Node _ [] [] -> Empty
|
||||||
else c { left = w `L.delete` left c, right = w `L.delete` right c }
|
else c { up = w `L.delete` up c, down = w `L.delete` down c }
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
-- Setting the master window
|
-- Setting the master window
|
||||||
@@ -372,8 +378,7 @@ swapMaster = modify Empty $ \c -> case c of
|
|||||||
Node _ [] _ -> c -- already master.
|
Node _ [] _ -> c -- already master.
|
||||||
Node t ls rs -> Node t [] (ys ++ x : rs) where (x:ys) = reverse ls
|
Node t ls rs -> Node t [] (ys ++ x : rs) where (x:ys) = reverse ls
|
||||||
|
|
||||||
-- natural! keep focus, move current to furthest left, move furthest
|
-- natural! keep focus, move current to the top, move top to current.
|
||||||
-- left to current position.
|
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
-- Composite operations
|
-- Composite operations
|
||||||
@@ -381,13 +386,13 @@ swapMaster = modify Empty $ \c -> case c of
|
|||||||
|
|
||||||
-- /O(w)/. shift. Move the focused element of the current stack to stack
|
-- /O(w)/. shift. Move the focused element of the current stack to stack
|
||||||
-- 'n', leaving it as the focused element on that stack. The item is
|
-- 'n', leaving it as the focused element on that stack. The item is
|
||||||
-- inserted to the left of the currently focused element on that
|
-- inserted above the currently focused element on that workspace. --
|
||||||
-- workspace. The actual focused workspace doesn't change. If there is
|
-- The actual focused workspace doesn't change. If there is -- no
|
||||||
-- no element on the current stack, the original stackSet is returned.
|
-- element on the current stack, the original stackSet is returned.
|
||||||
--
|
--
|
||||||
shift :: (Eq a, Eq s, Integral i) => i -> StackSet i a s -> StackSet i a s
|
shift :: (Eq a, Eq s, Integral i) => i -> StackSet i a s -> StackSet i a s
|
||||||
shift n s = if and [n >= 0,n < size s,n /= tag (workspace (current s))]
|
shift n s = if and [n >= 0,n < size s,n /= tag (workspace (current s))]
|
||||||
then maybe s go (peek s) else s
|
then maybe s go (peek s) else s
|
||||||
where go w = foldr ($) s [view (tag (workspace (current s))),insertLeft w,view n,delete w]
|
where go w = foldr ($) s [view (tag (workspace (current s))),insertUp w,view n,delete w]
|
||||||
-- ^^ poor man's state monad :-)
|
-- ^^ poor man's state monad :-)
|
||||||
|
|
||||||
|
@@ -70,11 +70,11 @@ fromList (n,m,fs,xs) | n < 0 || n >= genericLength xs
|
|||||||
fromList (o,m,fs,xs) =
|
fromList (o,m,fs,xs) =
|
||||||
let s = view o $
|
let s = view o $
|
||||||
foldr (\(i,ys) s ->
|
foldr (\(i,ys) s ->
|
||||||
foldr insertLeft (view i s) ys)
|
foldr insertUp (view i s) ys)
|
||||||
(new (genericLength xs) m) (zip [0..] xs)
|
(new (genericLength xs) m) (zip [0..] xs)
|
||||||
in foldr (\f t -> case f of
|
in foldr (\f t -> case f of
|
||||||
Nothing -> t
|
Nothing -> t
|
||||||
Just i -> foldr (const focusLeft) t [0..i] ) s fs
|
Just i -> foldr (const focusUp) t [0..i] ) s fs
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ invariant (s :: T) = and
|
|||||||
]
|
]
|
||||||
|
|
||||||
where
|
where
|
||||||
ws = concat [ focus t : left t ++ right t
|
ws = concat [ focus t : up t ++ down t
|
||||||
| w <- workspace (current s) : map workspace (visible s) ++ hidden s
|
| w <- workspace (current s) : map workspace (visible s) ++ hidden s
|
||||||
, let t = stack w, t /= Empty ] :: [Char]
|
, let t = stack w, t /= Empty ] :: [Char]
|
||||||
noDuplicates = nub ws == ws
|
noDuplicates = nub ws == ws
|
||||||
@@ -140,18 +140,18 @@ prop_empty_I (n :: Positive Int) = forAll (choose (1,fromIntegral n)) $ \m ->
|
|||||||
prop_view_I (n :: NonNegative Int) (x :: T) =
|
prop_view_I (n :: NonNegative Int) (x :: T) =
|
||||||
fromIntegral n < size x ==> invariant $ view (fromIntegral n) x
|
fromIntegral n < size x ==> invariant $ view (fromIntegral n) x
|
||||||
|
|
||||||
prop_focusLeft_I (n :: NonNegative Int) (x :: T) =
|
prop_focusUp_I (n :: NonNegative Int) (x :: T) =
|
||||||
invariant $ foldr (const focusLeft) x [1..n]
|
invariant $ foldr (const focusUp) x [1..n]
|
||||||
prop_focusRight_I (n :: NonNegative Int) (x :: T) =
|
prop_focusDown_I (n :: NonNegative Int) (x :: T) =
|
||||||
invariant $ foldr (const focusRight) x [1..n]
|
invariant $ foldr (const focusDown) x [1..n]
|
||||||
|
|
||||||
prop_focus_I (n :: NonNegative Int) (x :: T) =
|
prop_focus_I (n :: NonNegative Int) (x :: T) =
|
||||||
case peek x of
|
case peek x of
|
||||||
Nothing -> True
|
Nothing -> True
|
||||||
Just _ -> let w = focus . stack . workspace . current $ foldr (const focusLeft) x [1..n]
|
Just _ -> let w = focus . stack . workspace . current $ foldr (const focusUp) x [1..n]
|
||||||
in invariant $ focusWindow w x
|
in invariant $ focusWindow w x
|
||||||
|
|
||||||
prop_insertLeft_I n (x :: T) = invariant $ insertLeft n x
|
prop_insertUp_I n (x :: T) = invariant $ insertUp n x
|
||||||
|
|
||||||
prop_delete_I (x :: T) = invariant $
|
prop_delete_I (x :: T) = invariant $
|
||||||
case peek x of
|
case peek x of
|
||||||
@@ -161,9 +161,9 @@ prop_delete_I (x :: T) = invariant $
|
|||||||
prop_swap_master_I (x :: T) = invariant $ swapMaster x
|
prop_swap_master_I (x :: T) = invariant $ swapMaster x
|
||||||
|
|
||||||
prop_swap_left_I (n :: NonNegative Int) (x :: T) =
|
prop_swap_left_I (n :: NonNegative Int) (x :: T) =
|
||||||
invariant $ foldr (const swapLeft ) x [1..n]
|
invariant $ foldr (const swapUp ) x [1..n]
|
||||||
prop_swap_right_I (n :: NonNegative Int) (x :: T) =
|
prop_swap_right_I (n :: NonNegative Int) (x :: T) =
|
||||||
invariant $ foldr (const swapRight) x [1..n]
|
invariant $ foldr (const swapDown) x [1..n]
|
||||||
|
|
||||||
prop_shift_I (n :: NonNegative Int) (x :: T) =
|
prop_shift_I (n :: NonNegative Int) (x :: T) =
|
||||||
fromIntegral n < size x ==> invariant $ shift (fromIntegral n) x
|
fromIntegral n < size x ==> invariant $ shift (fromIntegral n) x
|
||||||
@@ -262,7 +262,7 @@ prop_index_length (x :: T) =
|
|||||||
Node {} -> length (index x) == length list
|
Node {} -> length (index x) == length list
|
||||||
where
|
where
|
||||||
it = stack . workspace . current $ x
|
it = stack . workspace . current $ x
|
||||||
list = focus it : left it ++ right it
|
list = focus it : up it ++ down it
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
-- rotating focus
|
-- rotating focus
|
||||||
@@ -273,9 +273,9 @@ prop_index_length (x :: T) =
|
|||||||
-- The tiling order, and master window, of a stack is unaffected by focus changes.
|
-- The tiling order, and master window, of a stack is unaffected by focus changes.
|
||||||
--
|
--
|
||||||
prop_focus_left_master (n :: NonNegative Int) (x::T) =
|
prop_focus_left_master (n :: NonNegative Int) (x::T) =
|
||||||
index (foldr (const focusLeft) x [1..n]) == index x
|
index (foldr (const focusUp) x [1..n]) == index x
|
||||||
prop_focus_right_master (n :: NonNegative Int) (x::T) =
|
prop_focus_right_master (n :: NonNegative Int) (x::T) =
|
||||||
index (foldr (const focusRight) x [1..n]) == index x
|
index (foldr (const focusDown) x [1..n]) == index x
|
||||||
prop_focusWindow_master (n :: NonNegative Int) (x :: T) =
|
prop_focusWindow_master (n :: NonNegative Int) (x :: T) =
|
||||||
case peek x of
|
case peek x of
|
||||||
Nothing -> True
|
Nothing -> True
|
||||||
@@ -284,8 +284,8 @@ prop_focusWindow_master (n :: NonNegative Int) (x :: T) =
|
|||||||
in index (focusWindow (s !! i) x) == index x
|
in index (focusWindow (s !! i) x) == index x
|
||||||
|
|
||||||
-- shifting focus is trivially reversible
|
-- shifting focus is trivially reversible
|
||||||
prop_focus_left (x :: T) = (focusLeft (focusRight x)) == x
|
prop_focus_left (x :: T) = (focusUp (focusDown x)) == x
|
||||||
prop_focus_right (x :: T) = (focusRight (focusLeft x)) == x
|
prop_focus_right (x :: T) = (focusDown (focusUp x)) == x
|
||||||
|
|
||||||
-- focusWindow actually leaves the window focused...
|
-- focusWindow actually leaves the window focused...
|
||||||
prop_focusWindow_works (n :: NonNegative Int) (x :: T) =
|
prop_focusWindow_works (n :: NonNegative Int) (x :: T) =
|
||||||
@@ -296,16 +296,16 @@ prop_focusWindow_works (n :: NonNegative Int) (x :: T) =
|
|||||||
in (focus . stack . workspace . current) (focusWindow (s !! i) x) == (s !! i)
|
in (focus . stack . workspace . current) (focusWindow (s !! i) x) == (s !! i)
|
||||||
|
|
||||||
-- rotation through the height of a stack gets us back to the start
|
-- rotation through the height of a stack gets us back to the start
|
||||||
prop_focus_all_l (x :: T) = (foldr (const focusLeft) x [1..n]) == x
|
prop_focus_all_l (x :: T) = (foldr (const focusUp) x [1..n]) == x
|
||||||
where n = length (index x)
|
where n = length (index x)
|
||||||
prop_focus_all_r (x :: T) = (foldr (const focusRight) x [1..n]) == x
|
prop_focus_all_r (x :: T) = (foldr (const focusDown) x [1..n]) == x
|
||||||
where n = length (index x)
|
where n = length (index x)
|
||||||
|
|
||||||
-- prop_rotate_all (x :: T) = f (f x) == f x
|
-- prop_rotate_all (x :: T) = f (f x) == f x
|
||||||
-- f x' = foldr (\_ y -> rotate GT y) x' [1..n]
|
-- f x' = foldr (\_ y -> rotate GT y) x' [1..n]
|
||||||
|
|
||||||
-- focus is local to the current workspace
|
-- focus is local to the current workspace
|
||||||
prop_focus_local (x :: T) = hidden_spaces (focusRight x) == hidden_spaces x
|
prop_focus_local (x :: T) = hidden_spaces (focusDown x) == hidden_spaces x
|
||||||
|
|
||||||
prop_focusWindow_local (n :: NonNegative Int) (x::T ) =
|
prop_focusWindow_local (n :: NonNegative Int) (x::T ) =
|
||||||
case peek x of
|
case peek x of
|
||||||
@@ -326,43 +326,43 @@ prop_findIndex (x :: T) =
|
|||||||
| w <- workspace (current x) : map workspace (visible x) ++ hidden x
|
| w <- workspace (current x) : map workspace (visible x) ++ hidden x
|
||||||
, let t = stack w
|
, let t = stack w
|
||||||
, t /= Empty
|
, t /= Empty
|
||||||
, i <- focus (stack w) : left (stack w) ++ right (stack w)
|
, i <- focus (stack w) : up (stack w) ++ down (stack w)
|
||||||
]
|
]
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
-- 'insert'
|
-- 'insert'
|
||||||
|
|
||||||
-- inserting a item into an empty stackset means that item is now a member
|
-- inserting a item into an empty stackset means that item is now a member
|
||||||
prop_insert_empty i (n :: Positive Int) (m :: Positive Int) = member i (insertLeft i x)
|
prop_insert_empty i (n :: Positive Int) (m :: Positive Int) = member i (insertUp i x)
|
||||||
where x = new (fromIntegral n) (fromIntegral m) :: T
|
where x = new (fromIntegral n) (fromIntegral m) :: T
|
||||||
|
|
||||||
-- insert should be idempotent
|
-- insert should be idempotent
|
||||||
prop_insert_idem i (x :: T) = insertLeft i x == insertLeft i (insertLeft i x)
|
prop_insert_idem i (x :: T) = insertUp i x == insertUp i (insertUp i x)
|
||||||
|
|
||||||
-- insert when an item is a member should leave the stackset unchanged
|
-- insert when an item is a member should leave the stackset unchanged
|
||||||
prop_insert_duplicate i (x :: T) = member i x ==> insertLeft i x == x
|
prop_insert_duplicate i (x :: T) = member i x ==> insertUp i x == x
|
||||||
|
|
||||||
-- push shouldn't change anything but the current workspace
|
-- push shouldn't change anything but the current workspace
|
||||||
prop_insert_local (x :: T) i = not (member i x) ==> hidden_spaces x == hidden_spaces (insertLeft i x)
|
prop_insert_local (x :: T) i = not (member i x) ==> hidden_spaces x == hidden_spaces (insertUp i x)
|
||||||
|
|
||||||
-- Inserting a (unique) list of items into an empty stackset should
|
-- Inserting a (unique) list of items into an empty stackset should
|
||||||
-- result in the last inserted element having focus.
|
-- result in the last inserted element having focus.
|
||||||
prop_insert_peek (n :: Positive Int) (m :: Positive Int) (NonEmptyNubList is) =
|
prop_insert_peek (n :: Positive Int) (m :: Positive Int) (NonEmptyNubList is) =
|
||||||
peek (foldr insertLeft x is) == Just (head is)
|
peek (foldr insertUp x is) == Just (head is)
|
||||||
where
|
where
|
||||||
x = new (fromIntegral n) (fromIntegral m) :: T
|
x = new (fromIntegral n) (fromIntegral m) :: T
|
||||||
|
|
||||||
-- insert >> delete is the identity, when i `notElem` .
|
-- insert >> delete is the identity, when i `notElem` .
|
||||||
-- Except for the 'master', which is reset on insert and delete.
|
-- Except for the 'master', which is reset on insert and delete.
|
||||||
--
|
--
|
||||||
prop_insert_delete n x = not (member n x) ==> delete n (insertLeft n y) == (y :: T)
|
prop_insert_delete n x = not (member n x) ==> delete n (insertUp n y) == (y :: T)
|
||||||
where
|
where
|
||||||
y = swapMaster x -- sets the master window to the current focus.
|
y = swapMaster x -- sets the master window to the current focus.
|
||||||
-- otherwise, we don't have a rule for where master goes.
|
-- otherwise, we don't have a rule for where master goes.
|
||||||
|
|
||||||
-- inserting n elements increases current stack size by n
|
-- inserting n elements increases current stack size by n
|
||||||
prop_size_insert is (n :: Positive Int) (m :: Positive Int) =
|
prop_size_insert is (n :: Positive Int) (m :: Positive Int) =
|
||||||
size (foldr insertLeft x ws ) == (length ws)
|
size (foldr insertUp x ws ) == (length ws)
|
||||||
where
|
where
|
||||||
ws = nub is
|
ws = nub is
|
||||||
x = new (fromIntegral n) (fromIntegral m) :: T
|
x = new (fromIntegral n) (fromIntegral m) :: T
|
||||||
@@ -385,7 +385,7 @@ prop_delete x =
|
|||||||
prop_delete_insert (x :: T) =
|
prop_delete_insert (x :: T) =
|
||||||
case peek x of
|
case peek x of
|
||||||
Nothing -> True
|
Nothing -> True
|
||||||
Just n -> insertLeft n (delete n y) == y
|
Just n -> insertUp n (delete n y) == y
|
||||||
where
|
where
|
||||||
y = swapMaster x
|
y = swapMaster x
|
||||||
|
|
||||||
@@ -399,11 +399,11 @@ prop_delete_local (x :: T) =
|
|||||||
prop_delete_focus n (x :: T) = member n x && Just n /= peek x ==> peek (delete n x) == peek x
|
prop_delete_focus n (x :: T) = member n x && Just n /= peek x ==> peek (delete n x) == peek x
|
||||||
|
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
-- swapLeft, swapRight, swapMaster: reordiring windows
|
-- swapUp, swapDown, swapMaster: reordiring windows
|
||||||
|
|
||||||
-- swap is trivially reversible
|
-- swap is trivially reversible
|
||||||
prop_swap_left (x :: T) = (swapLeft (swapRight x)) == x
|
prop_swap_left (x :: T) = (swapUp (swapDown x)) == x
|
||||||
prop_swap_right (x :: T) = (swapRight (swapLeft x)) == x
|
prop_swap_right (x :: T) = (swapDown (swapUp x)) == x
|
||||||
-- TODO swap is reversible
|
-- TODO swap is reversible
|
||||||
-- swap is reversible, but involves moving focus back the window with
|
-- swap is reversible, but involves moving focus back the window with
|
||||||
-- master on it. easy to do with a mouse...
|
-- master on it. easy to do with a mouse...
|
||||||
@@ -421,18 +421,18 @@ prop_swap_master_focus (x :: T) = peek x == (peek $ swapMaster x)
|
|||||||
-- = case peek x of
|
-- = case peek x of
|
||||||
-- Nothing -> True
|
-- Nothing -> True
|
||||||
-- Just f -> focus (stack (workspace $ current (swap x))) == f
|
-- Just f -> focus (stack (workspace $ current (swap x))) == f
|
||||||
prop_swap_left_focus (x :: T) = peek x == (peek $ swapLeft x)
|
prop_swap_left_focus (x :: T) = peek x == (peek $ swapUp x)
|
||||||
prop_swap_right_focus (x :: T) = peek x == (peek $ swapRight x)
|
prop_swap_right_focus (x :: T) = peek x == (peek $ swapDown x)
|
||||||
|
|
||||||
-- swap is local
|
-- swap is local
|
||||||
prop_swap_master_local (x :: T) = hidden_spaces x == hidden_spaces (swapMaster x)
|
prop_swap_master_local (x :: T) = hidden_spaces x == hidden_spaces (swapMaster x)
|
||||||
prop_swap_left_local (x :: T) = hidden_spaces x == hidden_spaces (swapLeft x)
|
prop_swap_left_local (x :: T) = hidden_spaces x == hidden_spaces (swapUp x)
|
||||||
prop_swap_right_local (x :: T) = hidden_spaces x == hidden_spaces (swapRight x)
|
prop_swap_right_local (x :: T) = hidden_spaces x == hidden_spaces (swapDown x)
|
||||||
|
|
||||||
-- rotation through the height of a stack gets us back to the start
|
-- rotation through the height of a stack gets us back to the start
|
||||||
prop_swap_all_l (x :: T) = (foldr (const swapLeft) x [1..n]) == x
|
prop_swap_all_l (x :: T) = (foldr (const swapUp) x [1..n]) == x
|
||||||
where n = length (index x)
|
where n = length (index x)
|
||||||
prop_swap_all_r (x :: T) = (foldr (const swapRight) x [1..n]) == x
|
prop_swap_all_r (x :: T) = (foldr (const swapDown) x [1..n]) == x
|
||||||
where n = length (index x)
|
where n = length (index x)
|
||||||
|
|
||||||
prop_swap_master_idempotent (x :: T) = swapMaster (swapMaster x) == swapMaster x
|
prop_swap_master_idempotent (x :: T) = swapMaster (swapMaster x) == swapMaster x
|
||||||
@@ -513,8 +513,8 @@ main = do
|
|||||||
|
|
||||||
,("index/length" , mytest prop_index_length)
|
,("index/length" , mytest prop_index_length)
|
||||||
|
|
||||||
,("focus left : invariant", mytest prop_focusLeft_I)
|
,("focus left : invariant", mytest prop_focusUp_I)
|
||||||
,("focus right: invariant", mytest prop_focusRight_I)
|
,("focus right: invariant", mytest prop_focusDown_I)
|
||||||
,("focusWindow: invariant", mytest prop_focus_I)
|
,("focusWindow: invariant", mytest prop_focus_I)
|
||||||
,("focus left/master" , mytest prop_focus_left_master)
|
,("focus left/master" , mytest prop_focus_left_master)
|
||||||
,("focus right/master" , mytest prop_focus_right_master)
|
,("focus right/master" , mytest prop_focus_right_master)
|
||||||
@@ -529,7 +529,7 @@ main = do
|
|||||||
|
|
||||||
,("findIndex" , mytest prop_findIndex)
|
,("findIndex" , mytest prop_findIndex)
|
||||||
|
|
||||||
,("insert: invariant" , mytest prop_insertLeft_I)
|
,("insert: invariant" , mytest prop_insertUp_I)
|
||||||
,("insert/new" , mytest prop_insert_empty)
|
,("insert/new" , mytest prop_insert_empty)
|
||||||
,("insert is idempotent", mytest prop_insert_idem)
|
,("insert is idempotent", mytest prop_insert_idem)
|
||||||
,("insert is reversible", mytest prop_insert_delete)
|
,("insert is reversible", mytest prop_insert_delete)
|
||||||
@@ -546,17 +546,17 @@ main = do
|
|||||||
,("delete/focus" , mytest prop_delete_focus)
|
,("delete/focus" , mytest prop_delete_focus)
|
||||||
|
|
||||||
,("swapMaster: invariant", mytest prop_swap_master_I)
|
,("swapMaster: invariant", mytest prop_swap_master_I)
|
||||||
,("swapLeft: invariant" , mytest prop_swap_left_I)
|
,("swapUp: invariant" , mytest prop_swap_left_I)
|
||||||
,("swapRight: invariant", mytest prop_swap_right_I)
|
,("swapDown: invariant", mytest prop_swap_right_I)
|
||||||
,("swapMaster id on focus", mytest prop_swap_master_focus)
|
,("swapMaster id on focus", mytest prop_swap_master_focus)
|
||||||
,("swapLeft id on focus", mytest prop_swap_left_focus)
|
,("swapUp id on focus", mytest prop_swap_left_focus)
|
||||||
,("swapRight id on focus", mytest prop_swap_right_focus)
|
,("swapDown id on focus", mytest prop_swap_right_focus)
|
||||||
,("swapMaster is idempotent", mytest prop_swap_master_idempotent)
|
,("swapMaster is idempotent", mytest prop_swap_master_idempotent)
|
||||||
,("swap all left " , mytest prop_swap_all_l)
|
,("swap all left " , mytest prop_swap_all_l)
|
||||||
,("swap all right " , mytest prop_swap_all_r)
|
,("swap all right " , mytest prop_swap_all_r)
|
||||||
,("swapMaster is local" , mytest prop_swap_master_local)
|
,("swapMaster is local" , mytest prop_swap_master_local)
|
||||||
,("swapLeft is local" , mytest prop_swap_left_local)
|
,("swapUp is local" , mytest prop_swap_left_local)
|
||||||
,("swapRight is local" , mytest prop_swap_right_local)
|
,("swapDown is local" , mytest prop_swap_right_local)
|
||||||
|
|
||||||
,("shift: invariant" , mytest prop_shift_I)
|
,("shift: invariant" , mytest prop_shift_I)
|
||||||
,("shift is reversible" , mytest prop_shift_reversible)
|
,("shift is reversible" , mytest prop_shift_reversible)
|
||||||
|
Reference in New Issue
Block a user