diff options
| author | Josh Rahm <rahm@google.com> | 2024-10-14 11:38:15 -0600 |
|---|---|---|
| committer | Josh Rahm <rahm@google.com> | 2024-10-14 11:38:44 -0600 |
| commit | 9b0750ba68aee61aacf7538b5b14d8f265e934e5 (patch) | |
| tree | 19b9bc2b2421d4ab94f28f1e8089b3d568fc2315 /src/Rahm/Desktop/Workspaces.hs | |
| parent | 08eacc1d437b08863ebe521446e040bc4fa219a2 (diff) | |
| download | rde-9b0750ba68aee61aacf7538b5b14d8f265e934e5.tar.gz rde-9b0750ba68aee61aacf7538b5b14d8f265e934e5.tar.bz2 rde-9b0750ba68aee61aacf7538b5b14d8f265e934e5.zip | |
Add some support for vertially ordered screens.
Add's the workspace '+' as the first workspace that's not on the same
'plane' as the current workspace.
A screen, screen1 is considered on the same plane as screen2 if
screen2's vertical center point is within screen1's vertical bounds.
Diffstat (limited to 'src/Rahm/Desktop/Workspaces.hs')
| -rw-r--r-- | src/Rahm/Desktop/Workspaces.hs | 46 |
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 $ |