aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Actions/Plane.hs
diff options
context:
space:
mode:
authorMarco TĂșlio Gontijo e Silva <marcot@riseup.net>2008-07-06 19:28:29 +0200
committerMarco TĂșlio Gontijo e Silva <marcot@riseup.net>2008-07-06 19:28:29 +0200
commitbb5969422f22df0f0597c540fa5171606941cb60 (patch)
tree3088219d49c03f58b642e17c898352bbf4de734c /XMonad/Actions/Plane.hs
parent6c0021d7d8fa8501c1743029734ba34f93c04f27 (diff)
downloadXMonadContrib-bb5969422f22df0f0597c540fa5171606941cb60.tar.gz
XMonadContrib-bb5969422f22df0f0597c540fa5171606941cb60.tar.xz
XMonadContrib-bb5969422f22df0f0597c540fa5171606941cb60.zip
XMonad.Actions.Plane: Improvements in code quality
darcs-hash:20080706172829-7641b-d730d4371bf6d6acab773adb992f291442357563.gz
Diffstat (limited to 'XMonad/Actions/Plane.hs')
-rw-r--r--XMonad/Actions/Plane.hs88
1 files changed, 66 insertions, 22 deletions
diff --git a/XMonad/Actions/Plane.hs b/XMonad/Actions/Plane.hs
index edf5dc3..7e65117 100644
--- a/XMonad/Actions/Plane.hs
+++ b/XMonad/Actions/Plane.hs
@@ -137,42 +137,86 @@ plane function numberLines_ limits direction = do
return 1
let
- horizontal f =
- if line < areasLine
- then mod (f column) columns + lineNumber
- else mod (f column) areasColumn + lineNumber
-
- vertical f =
- if column >= areasColumn
- then mod (f currentWS columns) $ areasLine * columns
- else mod (f currentWS columns) $ (areasLine + 1) * columns
-
- lineNumber = line * columns
+ circular_ :: Int
+ circular_ = circular currentWS
+
+ circular :: Int -> Int
+ circular =
+ [ onLine pred
+ , onColumn pred
+ , onLine succ
+ , onColumn succ
+ ]
+ !! fromEnum direction
+
+ onLine :: (Int -> Int) -> Int -> Int
+ onLine f currentWS_
+ | line < areasLine = mod_ columns
+ | otherwise = mod_ areasColumn
+ where
+ line, column :: Int
+ (line, column) = split currentWS_
+
+ mod_ :: Int -> Int
+ mod_ columns_ = compose line $ mod (f column) columns_
+
+ onColumn :: (Int -> Int) -> Int -> Int
+ onColumn f currentWS_
+ | column < areasColumn || areasColumn == 0 = mod_ numberLines
+ | otherwise = mod_ $ pred numberLines
+ where
+ line, column :: Int
+ (line, column) = split currentWS_
+
+ mod_ :: Int -> Int
+ mod_ lines_ = compose (mod (f line) lines_) column
+
+ compose :: Int -> Int -> Int
+ compose line column = line * columns + column
+
+ split :: Int -> (Int, Int)
+ split currentWS_ =
+ (operation div, operation mod)
+ where
+ operation :: (Int -> Int -> Int) -> Int
+ operation f = f currentWS_ columns
+
+ areasLine :: Int
areasLine = div areas columns
+
+ areasColumn :: Int
areasColumn = mod areas columns
- line = div currentWS columns
- column = mod currentWS columns
+ columns :: Int
columns =
if mod areas numberLines == 0 then preColumns else preColumns + 1
+ currentWS :: Int
currentWS = fromJust mCurrentWS
+
+ preColumns :: Int
preColumns = div areas numberLines
+
+ mCurrentWS :: Maybe Int
mCurrentWS = elemIndex (currentTag $ windowset state) areaNames
+
+ areas :: Int
areas = length areaNames
- run condition position =
- when (limits == Circular || condition) $
- windows $ function $ areaNames !! position
+ run :: (Int -> Int) -> X ()
+ run f = windows $ function $ areaNames !! f currentWS
- areaNames = workspaces $ config $ xconf
+ areaNames :: [String]
+ areaNames = workspaces $ config xconf
when (isJust mCurrentWS) $
- case direction of
- ToUp -> run (line /= 0 ) $ vertical (-)
- ToDown -> run (currentWS + columns < areas) $ vertical (+)
- ToLeft -> run (column /= 0 ) $ horizontal pred
- ToRight -> run (column /= columns - 1 ) $ horizontal succ
+ case limits of
+ Finite ->
+ when ((replicate 2 (circular_ < currentWS) ++ replicate 2 (circular_ > currentWS)) !! fromEnum direction)
+ $ run circular
+
+ Circular ->
+ run circular
gconftool :: String
gconftool = "gconftool-2"