From 8e168883155a61d98bdeb6782515231f962a02b5 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 18 Dec 2023 05:30:47 -0700 Subject: Add ability to add a hole to the layout. Doesn't work perfectly. --- src/Rahm/Desktop/Keys.hs | 34 +++++++++++++++++++++++----------- src/Rahm/Desktop/Layout.hs | 10 ++++++---- src/Rahm/Desktop/Layout/Hole.hs | 30 ++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 21 deletions(-) (limited to 'src/Rahm/Desktop') diff --git a/src/Rahm/Desktop/Keys.hs b/src/Rahm/Desktop/Keys.hs index 8945201..9b72494 100644 --- a/src/Rahm/Desktop/Keys.hs +++ b/src/Rahm/Desktop/Keys.hs @@ -675,6 +675,25 @@ bindings = do altMod $ spawnX "sudo -A systemctl suspend && xsecurelock" + bind xK_x $ do + shiftMod $ + doc "Reset the holes" $ do + logs Debug "reset hole" + sendMessage resetHole + logs Debug "/reset hole" + + justMod $ + doc "Add hole next to the current window" $ do + logs Debug "Add hole" + withFocused $ \foc -> + withWindowSet $ \ws -> do + logs Debug "/Add hole at %s" (show foc) + whenJust (W.windowTilePosition foc ws) $ \tp -> do + logs Debug "Tile position: %s" (show tp) + (X.broadcastMessage . addHole) tp + refresh + logs Debug "/Add hole" + bind xK_space $ do justMod $ doc "Layout-related bindings" $ @@ -719,12 +738,10 @@ bindings = do doc "Jump to the middle layout." $ sendMessage (toIndexedLayout (nLayouts `div` 2)) - bind xK_x $ - (noMod -|- justMod) $ - doc "Toggle the hole" $ do - logs Debug "reset hole" - sendMessage resetHole - logs Debug "/reset hole" + bind xK_x $ do + justMod $ + doc "Toggles respect for struts." $ + sendMessage ToggleStruts bind xK_g $ (noMod -|- justMod) @@ -777,11 +794,6 @@ bindings = do doc "Spawn a floating terminal" $ spawnX =<< asks ((++ " -t Floating\\ Term") . terminal . config) - bind xK_x $ do - justMod $ - doc "Toggles respect for struts." $ - sendMessage ToggleStruts - bind xK_z $ do justMod $ doc "Less often used keybindings." $ diff --git a/src/Rahm/Desktop/Layout.hs b/src/Rahm/Desktop/Layout.hs index 17a7b1e..5dc47b6 100644 --- a/src/Rahm/Desktop/Layout.hs +++ b/src/Rahm/Desktop/Layout.hs @@ -37,14 +37,16 @@ import XMonad.Layout.LayoutModifier (ModifiedLayout (..)) import XMonad.Layout.MosaicAlt ( MosaicAlt (..), ) +import XMonad.Layout.NoBorders (SmartBorder, smartBorders) import XMonad.Layout.Spacing (Border (..), spacingRaw) import XMonad.Layout.Spiral (spiral) myLayout = - fullscreenFull $ - hole $ - pinnable $ - avoidStruts myLayoutList + smartBorders $ + fullscreenFull $ + hole $ + pinnable $ + avoidStruts myLayoutList mySpacing = spacingRaw True (Border 5 5 5 5) True (Border 5 5 5 5) True diff --git a/src/Rahm/Desktop/Layout/Hole.hs b/src/Rahm/Desktop/Layout/Hole.hs index 8bebb36..4b7eefc 100644 --- a/src/Rahm/Desktop/Layout/Hole.hs +++ b/src/Rahm/Desktop/Layout/Hole.hs @@ -8,6 +8,7 @@ module Rahm.Desktop.Layout.Hole addHoleForWindow, removeHoleForWindow, resetHole, + addHole, ) where @@ -29,7 +30,7 @@ import XMonad ) data Hole (l :: * -> *) (a :: *) - = Hole (Map WorkspaceId [(W.TilePosition WorkspaceId, Window)]) (l a) + = Hole (Map WorkspaceId [(W.TilePosition WorkspaceId, Maybe Window)]) (l a) deriving instance Show (l a) => Show (Hole l a) @@ -46,7 +47,19 @@ addHoleForWindow p@(W.TilePosition wid _) win = ManageHole $ \(Hole m l) -> Hole ( Map.alter ( \(fromMaybe [] -> existing) -> - Just $ (p, win) : existing + Just $ (p, Just win) : existing + ) + wid + m + ) + l + +addHole :: W.TilePosition WorkspaceId -> ManageHole +addHole p@(W.TilePosition wid _) = ManageHole $ \(Hole m l) -> + Hole + ( Map.alter + ( \(fromMaybe [] -> existing) -> + Just $ (p, Nothing) : existing ) wid m @@ -57,7 +70,7 @@ removeHoleForWindow :: Window -> ManageHole removeHoleForWindow win = ManageHole $ \(Hole m l) -> Hole ( Map.mapMaybe - (Just . filter ((/= win) . snd)) + (Just . filter ((/= Just win) . snd)) m ) l @@ -85,6 +98,11 @@ instance (LayoutClass l a, a ~ Window) => LayoutClass (Hole l) a where (rects, maybeNewLayout) <- runLayout (app holes $ W.Workspace t l a) rect return (filter ((> 0) . fst) rects, fmap (Hole holes) maybeNewLayout) where + app :: + (Ord i1) => + Map i1 [(TilePosition i, Maybe Window)] -> + W.Workspace i1 l1 Window -> + W.Workspace i1 l1 Window app mp (W.Workspace t l (Just s)) | Just positions <- sortIt <$> Map.lookup t mp = let integrated = W.integrate s @@ -96,11 +114,11 @@ instance (LayoutClass l a, a ~ Window) => LayoutClass (Hole l) a where ( \((idx, pos, fakeid), ret) w -> case pos of ((TilePosition _ n, win) : tpos) - | n == idx && win `notElem` integrated -> + | n == idx && maybe True (`notElem` integrated) win -> ((idx + 1, tpos, fakeid - 1), w : fakeid : ret) _ -> ((idx + 1, pos, fakeid), w : ret) ) - ((0, positions, -1), []) + ((0, positions, 10000000), []) integrated app _ w = w @@ -108,7 +126,7 @@ instance (LayoutClass l a, a ~ Window) => LayoutClass (Hole l) a where addr integrated ((idx, pos, fakeid), ret) = case pos of - ((TilePosition _ n, win) : _) | n == idx && win `notElem` integrated -> fakeid : ret + ((TilePosition _ n, win) : _) | n == idx && maybe True (`notElem` integrated) win -> fakeid : ret _ -> ret handleMessage h (fromMessage -> Just (ManageHole f)) = -- cgit From 382d813c7d051fb2619cab1120dc72ee88a154be Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 29 Dec 2023 12:07:50 -0700 Subject: Remove broken smartBorders from layout --- src/Rahm/Desktop/Layout.hs | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Rahm/Desktop') diff --git a/src/Rahm/Desktop/Layout.hs b/src/Rahm/Desktop/Layout.hs index 5dc47b6..8c2daf7 100644 --- a/src/Rahm/Desktop/Layout.hs +++ b/src/Rahm/Desktop/Layout.hs @@ -37,12 +37,10 @@ import XMonad.Layout.LayoutModifier (ModifiedLayout (..)) import XMonad.Layout.MosaicAlt ( MosaicAlt (..), ) -import XMonad.Layout.NoBorders (SmartBorder, smartBorders) import XMonad.Layout.Spacing (Border (..), spacingRaw) import XMonad.Layout.Spiral (spiral) myLayout = - smartBorders $ fullscreenFull $ hole $ pinnable $ -- cgit