diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2026-03-01 16:22:07 -0700 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2026-03-01 16:22:56 -0700 |
| commit | 54378edd2c2a0fe930ec241bb9ecb1173d4eeac0 (patch) | |
| tree | ed9da925a772b599f0e8613e94a9aa232109036d | |
| parent | 9839efd016f43c892e935c7d4063e30c23b81e1f (diff) | |
| download | rde-main.tar.gz rde-main.tar.bz2 rde-main.zip | |
| -rw-r--r-- | src/Rahm/Desktop/Geometry.hs | 44 | ||||
| -rw-r--r-- | src/Rahm/Desktop/Workspaces.hs | 3 |
2 files changed, 30 insertions, 17 deletions
diff --git a/src/Rahm/Desktop/Geometry.hs b/src/Rahm/Desktop/Geometry.hs index a0e8c92..5048205 100644 --- a/src/Rahm/Desktop/Geometry.hs +++ b/src/Rahm/Desktop/Geometry.hs @@ -1,9 +1,9 @@ module Rahm.Desktop.Geometry where -import Data.List (minimumBy) +import Data.List (minimumBy, intercalate) import Data.Maybe (listToMaybe) import Data.Ord (comparing) -import Debug.Trace (trace) +import Debug.Trace (trace, traceM) import Text.Printf (printf) data GeomRectangle = GeomRectangle @@ -22,29 +22,42 @@ center r = (rectX r + rectWidth r / 2, rectY r + rectHeight r / 2) distanceToEdgeInDirection :: Direction -> GeomRectangle -> GeomRectangle -> Double distanceToEdgeInDirection dir ref cand = let (rx, ry) = center ref - (cx, cy) = center cand left = rectX cand right = rectX cand + rectWidth cand top = rectY cand bottom = rectY cand + rectHeight cand + + dxToSpan + | rx < left = left - rx + | rx > right = rx - right + | otherwise = 0 + + dyToSpan + | ry < top = top - ry + | ry > bottom = ry - bottom + | otherwise = 0 + in case dir of - N -> -- candidate is above: closest point is on bottom edge - let dx = if rx < left then left - rx else if rx > right then right - rx else 0 - dy = top - ry - in sqrt (dx*dx + dy*dy) - S -> -- candidate is below: closest point is on top edge - let dx = if rx < left then left - rx else if rx > right then right - rx else 0 + N -> -- candidate above: nearest point is on its bottom edge + let dx = dxToSpan dy = ry - bottom in sqrt (dx*dx + dy*dy) - W -> -- candidate is to the left: closest point is on right edge - let dy = if ry < top then top - ry else if ry > bottom then bottom - ry else 0 - dx = left - rx + + S -> -- candidate below: nearest point is on its top edge + let dx = dxToSpan + dy = top - ry in sqrt (dx*dx + dy*dy) - E -> -- candidate is to the right: closest point is on left edge - let dy = if ry < top then top - ry else if ry > bottom then bottom - ry else 0 + + W -> -- candidate left: nearest point is on its right edge + let dy = dyToSpan dx = rx - right in sqrt (dx*dx + dy*dy) + E -> -- candidate right: nearest point is on its left edge + let dy = dyToSpan + dx = left - rx + in sqrt (dx*dx + dy*dy) + boundingBox :: [GeomRectangle] -> (Double, Double, Double, Double) boundingBox rs = @@ -81,7 +94,7 @@ tileCandidates dir sw sh r = E -> [r, translate r sw 0] closestInDirection :: - (Eq a) => + (Eq a, Show a) => [(GeomRectangle, a)] -> a -> Direction -> @@ -100,7 +113,6 @@ closestInDirection rects tag dir = do virt <- tileCandidates dir sw' sh' r, whollyInDirection dir virt ref ] - case candidates of [] -> Nothing _ -> Just (r, t) diff --git a/src/Rahm/Desktop/Workspaces.hs b/src/Rahm/Desktop/Workspaces.hs index 96e4d99..1b08e38 100644 --- a/src/Rahm/Desktop/Workspaces.hs +++ b/src/Rahm/Desktop/Workspaces.hs @@ -25,7 +25,7 @@ module Rahm.Desktop.Workspaces where import Control.Arrow (Arrow ((&&&))) -import Control.Monad.Trans (lift) +import Control.Monad.Trans (lift, MonadIO (liftIO)) import Control.Monad.Trans.Maybe (MaybeT (MaybeT)) import Data.Char (chr, isDigit, isUpper, ord, toLower, toUpper) import Data.Int (Int32) @@ -48,6 +48,7 @@ import XMonad withWindowSet, ) import Prelude hiding ((!!)) +import System.IO (stderr, hPutStrLn) newtype Selector = Selector (forall a. (a -> Bool) -> [a] -> Maybe a) |