aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2024-10-14 11:38:15 -0600
committerJosh Rahm <rahm@google.com>2024-10-14 11:38:44 -0600
commit9b0750ba68aee61aacf7538b5b14d8f265e934e5 (patch)
tree19b9bc2b2421d4ab94f28f1e8089b3d568fc2315 /src/Rahm
parent08eacc1d437b08863ebe521446e040bc4fa219a2 (diff)
downloadrde-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')
-rw-r--r--src/Rahm/Desktop/Keys/Wml.hs21
-rw-r--r--src/Rahm/Desktop/Workspaces.hs46
2 files changed, 57 insertions, 10 deletions
diff --git a/src/Rahm/Desktop/Keys/Wml.hs b/src/Rahm/Desktop/Keys/Wml.hs
index 0c09fd1..792ff74 100644
--- a/src/Rahm/Desktop/Keys/Wml.hs
+++ b/src/Rahm/Desktop/Keys/Wml.hs
@@ -93,7 +93,7 @@ import Rahm.Desktop.History
)
import Rahm.Desktop.Keys.KeyFeed
import Rahm.Desktop.Layout.PinWindow (pinnedWindows)
-import Rahm.Desktop.Logger (LogLevel (Info, Trace), logs)
+import Rahm.Desktop.Logger
import Rahm.Desktop.Marking
( farLeftWindow,
farRightWindow,
@@ -105,14 +105,6 @@ import Rahm.Desktop.Marking
import qualified Rahm.Desktop.StackSet as W
import Rahm.Desktop.Submap (mapNextStringWithKeysym)
import Rahm.Desktop.Workspaces
- ( accompaningWorkspace,
- adjacentWorkspace,
- adjacentWorkspaceNotVisible,
- getHorizontallyOrderedScreens,
- next,
- prev,
- workspaceWithWindow,
- )
import Rahm.Desktop.XMobarLog.PendingBuffer
( addStringToPendingBuffer,
setPendingBuffer,
@@ -474,12 +466,21 @@ readNextWorkspace =
screens <-
liftXToFeed $
map (W.tag . W.workspace . snd)
- <$> withWindowSet (return . getHorizontallyOrderedScreens)
+ <$> withWindowSet (return . getScreensOnSamePlane)
let (_, rest) = break ((== workspaceName ws) . Just) (screens ++ screens)
justWorkspace <$> hoistMaybe (head $ tail rest)
+ -- Workspace on the screen above the current workspace..
+ (_, _, "+") -> do
+ screens <-
+ liftXToFeed $
+ map (W.tag . W.workspace . snd)
+ <$> withWindowSet (return . getScreensOnDifferentPlane)
+
+ justWorkspace <$> hoistMaybe (head screens)
+
-- Workspace to the next screen to the left of the next workspace.
(_, _, ";") -> do
ws <- readNextWorkspace
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 $