Browse Source

Add more layouts, make some keybindings easier to use

master
Peter J. Jones 3 months ago
parent
commit
3d43c92a06
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
4 changed files with 131 additions and 42 deletions
  1. 4
    0
      .envrc
  2. 27
    0
      shell.nix
  3. 38
    15
      src/XMonad/Local/Keys.hs
  4. 62
    27
      src/XMonad/Local/Layout.hs

+ 4
- 0
.envrc View File

@@ -0,0 +1,4 @@
# -*- sh -*-

# Load in the shell.nix file:
use nix

+ 27
- 0
shell.nix View File

@@ -0,0 +1,27 @@
{ pkgs ? (import <nixpkgs> {}).pkgs
}:

let
nix-hs-src = fetchGit {
url = "https://code.devalot.com/pjones/nix-hs.git";
rev = "4a9ea2c8c6712ae3cb5892bc74dc051906535238";
};

nix-hs = (import "${nix-hs-src}/default.nix" {inherit pkgs;});

in

pkgs.mkShell {
buildInputs = with pkgs; [

# Haskell Dependencies:
haskellPackages.ghc
haskellPackages.cabal-install

# For IDEs:
nix-hs
haskellPackages.hoogle
haskellPackages.hlint
# haskellPackages.cabal-dependency-licenses
];
}

+ 38
- 15
src/XMonad/Local/Keys.hs View File

@@ -37,14 +37,13 @@ import XMonad.Actions.TagWindows (addTag, delTag, withTagged)
import XMonad.Actions.UpdatePointer (updatePointer)
import XMonad.Hooks.ManageDocks (ToggleStruts(..))
import XMonad.Hooks.UrgencyHook (focusUrgent)
import XMonad.Layout.ComboP (PartitionWins(..))
import XMonad.Layout.Gaps (GapMessage(..))
import XMonad.Layout.LayoutBuilder (IncLayoutN(..))
import XMonad.Layout.ResizableTile
import XMonad.Layout.Spacing (incWindowSpacing, decWindowSpacing, toggleWindowSpacingEnabled)
import XMonad.Layout.ToggleLayouts (ToggleLayout(..))
import XMonad.Prompt
import XMonad.Prompt.Shell (shellPrompt)
import XMonad.Prompt.Window (WindowPrompt(..), windowPrompt, windowMultiPrompt, allWindows, wsWindows)
import XMonad.Prompt.XMonad (xmonadPrompt)
import XMonad.Util.EZConfig (mkKeymap)
import XMonad.Util.NamedScratchpad (namedScratchpadAction)

@@ -91,8 +90,7 @@ withUpdatePointer = map addAction
baseKeys :: XConfig Layout -> [(String, X ())]
baseKeys _ =
[ ("M-x r", restartIntoDebugging)
, ("M-x <Space>", xmonadPrompt Local.promptConfig)
, ("M-x <Esc>", spawn "systemctl --user restart compton.service")
, ("M-x <Space>", messageMenu Local.promptConfig)
]

--------------------------------------------------------------------------------
@@ -111,7 +109,7 @@ windowKeys _ =
, ("M-k", windowGo U True)
, ("M-l", windowGo R True)
, ("M-h", windowGo L True)
, ("M-w m", windows W.focusMaster)
, ("M-C-m", windows W.focusMaster)

-- Moving Windows:
, ("M-M1-l", windowSwap R False)
@@ -152,11 +150,11 @@ windowTagKeys _ =
where
addFocusTag :: X ()
addFocusTag = do withFocused (addTag "focus")
sendMessage PartitionWins
sendMessage (IncLayoutN 0)

rmFocusTag :: X ()
rmFocusTag = do withFocused (delTag "focus")
sendMessage PartitionWins
sendMessage (IncLayoutN 0)

rmFocusTagAll :: X ()
rmFocusTagAll = withTagged "focus" (delTag "focus")
@@ -188,12 +186,10 @@ workspaceKeys _ =
-- Layout switching and manipulation.
layoutKeys :: XConfig Layout -> [(String, X ())]
layoutKeys c =
[ ("M-[", selectLayoutByName Local.promptConfig)
, ("M-]", sendMessage NextLayout)
[ ("M-<Backspace>", selectLayoutByName Local.promptConfig)
, ("M-w <Esc>", setLayout (layoutHook c)) -- Reset to default layout.
, ("M-<Backspace>", sendMessage (Toggle "Full"))
, ("M-S-1", sendMessage ToggleLayout)
, ("M-S-8", cycleThroughLayouts ["Auto", "Focus"])
, ("M-w g", sendMessage ToggleGaps)
, ("M-w s", toggleWindowSpacingEnabled)
, ("M-w M-s", sendMessage ToggleStruts)
, ("M-C-S-=", incWindowSpacing 5)
@@ -204,9 +200,9 @@ layoutKeys c =
-- Keys to manipulate screens (actual physical monitors).
screenKeys :: XConfig Layout -> [(String, X ())]
screenKeys _ =
[ ("M-)", onNextNeighbour def W.view)
, ("M-(", onPrevNeighbour def W.view)
, ("M-\\", screenSwap L True)
[ ("M-S-0", onNextNeighbour def W.view)
, ("M-S-9", onPrevNeighbour def W.view)
, ("M-\\", screenSwap L True)
]

--------------------------------------------------------------------------------
@@ -251,3 +247,30 @@ windowPromptGoto = windowMultiPrompt Local.promptConfig modes
windowPromptGoto' :: X ()
windowPromptGoto' = windowMultiPrompt Local.promptConfig modes
where modes = [(Goto, wsWindows), (Goto, allWindows)]

--------------------------------------------------------------------------------
-- | A menu of less frequently used actions:
data MessageMenu = MessageMenu

instance XPrompt MessageMenu where
showXPrompt MessageMenu = "X Action: "

messageMenu :: XPConfig -> X ()
messageMenu conf =
mkXPrompt MessageMenu conf (Local.aListCompFunc conf actions) go

where
go :: String -> X ()
go selected =
case lookup selected actions of
Nothing -> return ()
Just a -> a

actions :: [ (String, X ()) ]
actions = [ ("IncLayoutN", sendMessage (IncLayoutN 1))
, ("DecLayoutN", sendMessage (IncLayoutN (-1)))
, ("IncMasterN", sendMessage (IncMasterN 1))
, ("DecMasterN", sendMessage (IncMasterN (-1)))
, ("ToggleStruts", sendMessage ToggleStruts)
, ("ToggleSpacing", toggleWindowSpacingEnabled)
]

+ 62
- 27
src/XMonad/Local/Layout.hs View File

@@ -15,14 +15,18 @@ module XMonad.Local.Layout (layoutHook, selectLayoutByName) where
--------------------------------------------------------------------------------
import XMonad hiding ((|||), layoutHook, float)
import XMonad.Layout.Accordion (Accordion(..))
import XMonad.Layout.CenteredMaster (centerMaster)
import XMonad.Layout.ComboP (PartitionWins(..), combineTwoP)
import XMonad.Layout.Gaps (gaps)
import XMonad.Layout.Cross (Cross(..))
import XMonad.Layout.Grid (Grid(Grid))
import XMonad.Layout.GridVariants (SplitGrid(..))
import qualified XMonad.Layout.GridVariants as Grid
import XMonad.Layout.IfMax (ifMax)
import XMonad.Layout.LayoutCombinators
import XMonad.Layout.Magnifier (magnifiercz)
import XMonad.Layout.Master (mastered)
import XMonad.Layout.NoBorders (noBorders)
import XMonad.Layout.OneBig (OneBig(..))
import XMonad.Layout.Reflect (reflectHoriz, reflectVert)
import XMonad.Layout.Renamed (Rename(..), renamed)
import XMonad.Layout.ResizableTile (ResizableTall(..))
@@ -30,51 +34,77 @@ import XMonad.Layout.Spacing (Border(..), spacingRaw)
import XMonad.Layout.ThreeColumns (ThreeCol(..))
import XMonad.Layout.ToggleLayouts (toggleLayouts)
import XMonad.Layout.TwoPane (TwoPane(..))
import XMonad.Layout.ZoomRow (zoomRow)
import XMonad.Local.Prompt (aListCompFunc)
import XMonad.Prompt
import XMonad.Util.Types (Direction2D(..))
import XMonad.Util.WindowProperties (Property(..))

import XMonad.Layout.LayoutBuilder
( SubBox(..)
, SubMeasure(..)
, layoutN
, layoutP
, layoutAll
, relBox
)

--------------------------------------------------------------------------------
-- | XMonad layout hook. No type signature because it's freaking
-- nasty and I can't come up with a way to make it generic.
layoutHook = toggleLayouts solo allLays
layoutHook = toggleLayouts oneCol allLays
where
uniformGaps n = [(U, n), (D, n), (L, n), (R, n)] :: [(Direction2D,Int)]
uniformBorder n = Border n n n n
spacing = spacingRaw False (uniformBorder 0) False (uniformBorder 10) True
spacing = spacingRaw False (uniformBorder 0) False (uniformBorder 10) True
spacing' = spacingRaw False (uniformBorder 0) False (uniformBorder 2) True

full = noBorders Full
solo = noBorders $ gaps (uniformGaps 60) Full
cmaster = centerMaster grid
big = spacing $ OneBig (3/4) (3/4)
oneCol = spacing' $ magnifiercz 0.9 Accordion
threeCols = spacing $ reflectHoriz $ ThreeColMid 1 (1/100) (3/8)
twoCols = spacing $ mastered (1/100) (1/2) Accordion
twoPane = spacing $ TwoPane (1/100) (1/2)
tall = spacing $ ResizableTall 1 (1/100) (3/5) []
focusTag = spacing $ only (Tagged "focus")
grid = spacing $ SplitGrid Grid.L 2 2 (2/3) (1/2) 1
auto = ifMax 1 centFull $ ifMax 2 twoPane threeCols
-- One window, centered on the screen.
centFull = spacingRaw False (Border 20 20 400 400)
True (Border 0 0 0 0) False Full
grid = spacing Grid
sgrid = spacing $ SplitGrid Grid.L 2 2 (2/3) (1/2) 1
cross = spacing $ Cross (4/5) (1/100)
ten80 = centered 2560 (1930, 1090) -- Account for border width
cgrid = layoutAll (relBox (1/8) (1/8) (7/8) (7/8)) grid
auto = ifMax 1 (noBorders cgrid) $ ifMax 2 twoPane threeCols

-- A layout where windows you want to focus on are specified using
-- @WindowProperties@. Windows matching the given properties will
-- be placed into the main layout. Other windows are pushed to
-- the top of the screen in a small @Accordion@.
only = combineTwoP (reflectVert $ Mirror $ TwoPane 0 (9/10))
twoCols (Mirror Accordion)
-- the bottom of the screen into a single row.
only prop =
let topBox = relBox 0 0 1 (7/8)
botBox = relBox 0 (7/8) 1 1
in layoutP prop topBox Nothing threeCols $
layoutAll botBox zoomRow

-- Center the master window horizontally, locked to the given
-- width and height, display all other windows below in a grid.
centered x (w, h) =
let centerBox = SubBox (Abs ((x - w) `div` 2)) (Abs 10) (Abs w) (Abs h)
bottomBox = SubBox (Rel 0) (Abs (h + 10)) (Rel 1) (Rel 1)
in layoutN 1 centerBox Nothing Grid $
layoutAll bottomBox (spacing zoomRow)

-- All layouts put together.
allLays =
renamed [Replace "Auto"] auto |||
renamed [Replace "Tall"] tall |||
renamed [Replace "3C"] threeCols |||
renamed [Replace "2C"] twoCols |||
renamed [Replace "2P"] twoPane |||
renamed [Replace "Focus"] focusTag |||
renamed [Replace "Grid"] grid |||
renamed [Replace "Full"] full
renamed [Replace "Auto"] auto |||
renamed [Replace "Tall"] tall |||
renamed [Replace "3C"] threeCols |||
renamed [Replace "2C"] twoCols |||
renamed [Replace "2P"] twoPane |||
renamed [Replace "Focus"] focusTag |||
renamed [Replace "Cross"] cross |||
renamed [Replace "Grid"] grid |||
renamed [Replace "SGrid"] sgrid |||
renamed [Replace "Big"] big |||
renamed [Replace "1080p"] ten80 |||
renamed [Replace "Centered"] cmaster |||
renamed [Replace "Full"] full

--------------------------------------------------------------------------------
-- | A data type for the @XPrompt@ class.
@@ -100,11 +130,16 @@ selectLayoutByName conf =
layoutNames :: [(String, String)]
layoutNames =
[ ("Auto", "Auto")
, ("1080p", "1080p")
, ("Big", "Big")
, ("Centered", "Centered")
, ("Cross", "Cross")
, ("Focus", "Focus")
, ("Full", "Full")
, ("Grid", "Grid")
, ("Split Grid", "SGrid")
, ("Tall", "Tall")
, ("Three Columns (3C)", "3C")
, ("Two Columns (2C)", "2C")
, ("Two Pane (2P)", "2P")
, ("Full", "Full")
, ("Focus", "Focus")
, ("Grid", "Grid")
]

Loading…
Cancel
Save