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.hs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Rahm/Desktop/Workspaces.hs b/src/Rahm/Desktop/Workspaces.hs
index 6f0c08a..0c70591 100644
--- a/src/Rahm/Desktop/Workspaces.hs
+++ b/src/Rahm/Desktop/Workspaces.hs
@@ -15,6 +15,8 @@ module Rahm.Desktop.Workspaces
adjacentScreen,
withScreen,
workspaceWithWindow,
+ getScreensOnSamePlane,
+ getScreensOnDifferentPlane,
WorkspaceState (..),
)
where
@@ -26,9 +28,11 @@ import Data.Char (isUpper, toLower, toUpper)
import Data.List (find, sort, sortBy, sortOn, (\\))
import Data.List.Safe ((!!))
import Data.Maybe (fromMaybe, mapMaybe)
+import Debug.Trace
import Rahm.Desktop.Common (getCurrentWorkspace, gotoWorkspace, runMaybeT_)
import Rahm.Desktop.Logger
import qualified Rahm.Desktop.StackSet as W
+import Text.Printf (printf)
import XMonad
( Rectangle (Rectangle),
ScreenDetail (SD),
@@ -100,6 +104,48 @@ getHorizontallyOrderedScreens windowSet =
where
screens = (True, W.current windowSet) : map (False,) (W.visible windowSet)
+getVerticallyOrderedScreens ::
+ W.StackSet wid l a ScreenId ScreenDetail ->
+ [(Bool, W.Screen wid l a ScreenId ScreenDetail)]
+-- ^ Returns a list of screens ordered from top to bottom
+getVerticallyOrderedScreens windowSet =
+ flip sortBy screens $ \sc1 sc2 ->
+ let (SD (Rectangle _ y1 _ _)) = W.screenDetail (snd sc1)
+ (SD (Rectangle _ y2 _ _)) = W.screenDetail (snd sc2)
+ in y1 `compare` y2
+ where
+ screens = (True, W.current windowSet) : map (False,) (W.visible windowSet)
+
+-- | Returns screens which are horizontally ordered, but are on the same "plane"
+-- as the current screen. A screen is considered on the same "plane" if it's
+-- middle point is vertically oriented within the vertical boundaries of the
+-- current screen.
+getScreensOnSamePlane ::
+ W.StackSet wid l a ScreenId ScreenDetail ->
+ [(Bool, W.Screen wid l a ScreenId ScreenDetail)]
+getScreensOnSamePlane ss =
+ filter matchesYCenter $ getHorizontallyOrderedScreens ss
+ where
+ yCenter
+ | (SD (Rectangle _ y _ h)) <- W.screenDetail . W.current $ ss =
+ (y + fromIntegral h) `div` 2
+ matchesYCenter (_, W.screenDetail -> (SD (Rectangle _ y _ h))) =
+ y < yCenter && y + fromIntegral h > yCenter
+
+-- | Returns screens which are vertically ordered, but are on a different plane
+-- from the current screen.
+getScreensOnDifferentPlane ::
+ W.StackSet wid l a ScreenId ScreenDetail ->
+ [(Bool, W.Screen wid l a ScreenId ScreenDetail)]
+getScreensOnDifferentPlane ss =
+ filter (not . matchesScreen . getYCenter . snd) $ getVerticallyOrderedScreens ss
+ where
+ getYCenter (W.screenDetail -> SD (Rectangle _ y _ h)) =
+ y + (fromIntegral h `div` 2)
+ matchesScreen yCenter
+ | (SD (Rectangle _ y _ h)) <- W.screenDetail (W.current ss) =
+ yCenter < y + fromIntegral h && yCenter > y
+
accompaningWorkspace :: WorkspaceId -> WorkspaceId
accompaningWorkspace [s] =
return $