aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/Workspaces.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Rahm/Desktop/Workspaces.hs')
-rw-r--r--src/Rahm/Desktop/Workspaces.hs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Rahm/Desktop/Workspaces.hs b/src/Rahm/Desktop/Workspaces.hs
index 72e929b..50a04d2 100644
--- a/src/Rahm/Desktop/Workspaces.hs
+++ b/src/Rahm/Desktop/Workspaces.hs
@@ -6,7 +6,7 @@ module Rahm.Desktop.Workspaces
lastWorkspaceId,
firstWorkspaceId,
windowsInCurrentWorkspace,
- getHorizontallyOrderedScreens,
+ getOrderedScreens,
accompanyingWorkspace,
adjacentWorkspaceNotVisible,
adjacentWorkspace,
@@ -93,15 +93,21 @@ windowsInCurrentWorkspace = withWindowSet $
\(W.StackSet (W.Screen (W.Workspace _ _ s) _ _) _ _ _) -> do
return $ W.integrate' s
-getHorizontallyOrderedScreens ::
+getOrderedScreens ::
W.StackSet wid l a ScreenId ScreenDetail ->
[(Bool, W.Screen wid l a ScreenId ScreenDetail)]
--- ^ Returns a list of screens ordered from leftmost to rightmost.
-getHorizontallyOrderedScreens windowSet =
- flip sortBy screens $ \sc1 sc2 ->
- let (SD (Rectangle x1 _ _ _)) = W.screenDetail (snd sc1)
- (SD (Rectangle x2 _ _ _)) = W.screenDetail (snd sc2)
- in x1 `compare` x2
+-- ^ Returns a list of screens ordered top to bottom, left to right (based on center point).
+getOrderedScreens windowSet =
+ flip sortBy screens $ \(b1, sc1) (b2, sc2) ->
+ let (SD (Rectangle x1 y1 w1 h1)) = W.screenDetail sc1
+ (SD (Rectangle x2 y2 w2 h2)) = W.screenDetail sc2
+ xCenter1 = fromIntegral x1 + (fromIntegral w1 / 2)
+ yCenter1 = fromIntegral y1 + (fromIntegral h1 / 2)
+ xCenter2 = fromIntegral x2 + (fromIntegral w2 / 2)
+ yCenter2 = fromIntegral y2 + (fromIntegral h2 / 2)
+ in case yCenter1 `compare` yCenter2 of
+ EQ -> xCenter1 `compare` xCenter2
+ other -> other
where
screens = (True, W.current windowSet) : map (False,) (W.visible windowSet)
@@ -157,14 +163,14 @@ viewAdjacentTo wsM (Selector sel) = runMaybeT_ $ do
adjacentScreen :: Selector -> X WorkspaceId
adjacentScreen (Selector f) = do
(screens, current) <-
- withWindowSet $ return . (getHorizontallyOrderedScreens &&& W.current)
+ withWindowSet $ return . (getOrderedScreens &&& W.current)
return $ W.tag $ W.workspace $ maybe current snd (f fst screens)
withScreen :: (WorkspaceId -> WindowSet -> WindowSet) -> Int -> X ()
withScreen fn n = do
windows $ \windowSet ->
- case map snd (getHorizontallyOrderedScreens windowSet) !! n of
+ case map snd (getOrderedScreens windowSet) !! n of
Nothing -> windowSet
Just screen -> fn (W.tag $ W.workspace screen) windowSet