Browse Source

Add more layouts, make some keybindings easier to use

master
Peter J. Jones 1 month 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 @@
1
+# -*- sh -*-
2
+
3
+# Load in the shell.nix file:
4
+use nix

+ 27
- 0
shell.nix View File

@@ -0,0 +1,27 @@
1
+{ pkgs ? (import <nixpkgs> {}).pkgs
2
+}:
3
+
4
+let
5
+  nix-hs-src = fetchGit {
6
+    url = "https://code.devalot.com/pjones/nix-hs.git";
7
+    rev = "4a9ea2c8c6712ae3cb5892bc74dc051906535238";
8
+  };
9
+
10
+  nix-hs = (import "${nix-hs-src}/default.nix" {inherit pkgs;});
11
+
12
+in
13
+
14
+pkgs.mkShell {
15
+  buildInputs = with pkgs; [
16
+
17
+    # Haskell Dependencies:
18
+    haskellPackages.ghc
19
+    haskellPackages.cabal-install
20
+
21
+    # For IDEs:
22
+    nix-hs
23
+    haskellPackages.hoogle
24
+    haskellPackages.hlint
25
+    # haskellPackages.cabal-dependency-licenses
26
+  ];
27
+}

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

@@ -37,14 +37,13 @@ import XMonad.Actions.TagWindows (addTag, delTag, withTagged)
37 37
 import XMonad.Actions.UpdatePointer (updatePointer)
38 38
 import XMonad.Hooks.ManageDocks (ToggleStruts(..))
39 39
 import XMonad.Hooks.UrgencyHook (focusUrgent)
40
-import XMonad.Layout.ComboP (PartitionWins(..))
41
-import XMonad.Layout.Gaps (GapMessage(..))
40
+import XMonad.Layout.LayoutBuilder (IncLayoutN(..))
42 41
 import XMonad.Layout.ResizableTile
43 42
 import XMonad.Layout.Spacing (incWindowSpacing, decWindowSpacing, toggleWindowSpacingEnabled)
44 43
 import XMonad.Layout.ToggleLayouts (ToggleLayout(..))
44
+import XMonad.Prompt
45 45
 import XMonad.Prompt.Shell (shellPrompt)
46 46
 import XMonad.Prompt.Window (WindowPrompt(..), windowPrompt, windowMultiPrompt, allWindows, wsWindows)
47
-import XMonad.Prompt.XMonad (xmonadPrompt)
48 47
 import XMonad.Util.EZConfig (mkKeymap)
49 48
 import XMonad.Util.NamedScratchpad (namedScratchpadAction)
50 49
 
@@ -91,8 +90,7 @@ withUpdatePointer = map addAction
91 90
 baseKeys :: XConfig Layout -> [(String, X ())]
92 91
 baseKeys _ =
93 92
   [ ("M-x r",       restartIntoDebugging)
94
-  , ("M-x <Space>", xmonadPrompt Local.promptConfig)
95
-  , ("M-x <Esc>",   spawn "systemctl --user restart compton.service")
93
+  , ("M-x <Space>", messageMenu Local.promptConfig)
96 94
   ]
97 95
 
98 96
 --------------------------------------------------------------------------------
@@ -111,7 +109,7 @@ windowKeys _ =
111 109
   , ("M-k",     windowGo U True)
112 110
   , ("M-l",     windowGo R True)
113 111
   , ("M-h",     windowGo L True)
114
-  , ("M-w m",   windows W.focusMaster)
112
+  , ("M-C-m",   windows W.focusMaster)
115 113
 
116 114
   -- Moving Windows:
117 115
   , ("M-M1-l",  windowSwap R False)
@@ -152,11 +150,11 @@ windowTagKeys _ =
152 150
   where
153 151
     addFocusTag :: X ()
154 152
     addFocusTag = do withFocused (addTag "focus")
155
-                     sendMessage PartitionWins
153
+                     sendMessage (IncLayoutN 0)
156 154
 
157 155
     rmFocusTag :: X ()
158 156
     rmFocusTag = do withFocused (delTag "focus")
159
-                    sendMessage PartitionWins
157
+                    sendMessage (IncLayoutN 0)
160 158
 
161 159
     rmFocusTagAll :: X ()
162 160
     rmFocusTagAll = withTagged "focus" (delTag "focus")
@@ -188,12 +186,10 @@ workspaceKeys _ =
188 186
 -- Layout switching and manipulation.
189 187
 layoutKeys :: XConfig Layout -> [(String, X ())]
190 188
 layoutKeys c =
191
-  [ ("M-[",           selectLayoutByName Local.promptConfig)
192
-  , ("M-]",           sendMessage NextLayout)
189
+  [ ("M-<Backspace>", selectLayoutByName Local.promptConfig)
193 190
   , ("M-w <Esc>",     setLayout (layoutHook c)) -- Reset to default layout.
194
-  , ("M-<Backspace>", sendMessage (Toggle "Full"))
191
+  , ("M-S-1",         sendMessage ToggleLayout)
195 192
   , ("M-S-8",         cycleThroughLayouts ["Auto", "Focus"])
196
-  , ("M-w g",         sendMessage ToggleGaps)
197 193
   , ("M-w s",         toggleWindowSpacingEnabled)
198 194
   , ("M-w M-s",       sendMessage ToggleStruts)
199 195
   , ("M-C-S-=",       incWindowSpacing 5)
@@ -204,9 +200,9 @@ layoutKeys c =
204 200
 -- Keys to manipulate screens (actual physical monitors).
205 201
 screenKeys :: XConfig Layout -> [(String, X ())]
206 202
 screenKeys _ =
207
-  [ ("M-)",  onNextNeighbour def W.view)
208
-  , ("M-(",  onPrevNeighbour def W.view)
209
-  , ("M-\\", screenSwap L True)
203
+  [ ("M-S-0", onNextNeighbour def W.view)
204
+  , ("M-S-9", onPrevNeighbour def W.view)
205
+  , ("M-\\",  screenSwap L True)
210 206
   ]
211 207
 
212 208
 --------------------------------------------------------------------------------
@@ -251,3 +247,30 @@ windowPromptGoto = windowMultiPrompt Local.promptConfig modes
251 247
 windowPromptGoto' :: X ()
252 248
 windowPromptGoto' = windowMultiPrompt Local.promptConfig modes
253 249
   where modes = [(Goto, wsWindows), (Goto, allWindows)]
250
+
251
+--------------------------------------------------------------------------------
252
+-- | A menu of less frequently used actions:
253
+data MessageMenu = MessageMenu
254
+
255
+instance XPrompt MessageMenu where
256
+  showXPrompt MessageMenu = "X Action: "
257
+
258
+messageMenu :: XPConfig -> X ()
259
+messageMenu conf =
260
+  mkXPrompt MessageMenu conf (Local.aListCompFunc conf actions) go
261
+
262
+  where
263
+    go :: String -> X ()
264
+    go selected =
265
+      case lookup selected actions of
266
+        Nothing   -> return ()
267
+        Just a    -> a
268
+
269
+    actions :: [ (String, X ()) ]
270
+    actions = [ ("IncLayoutN",    sendMessage (IncLayoutN 1))
271
+              , ("DecLayoutN",    sendMessage (IncLayoutN (-1)))
272
+              , ("IncMasterN",    sendMessage (IncMasterN 1))
273
+              , ("DecMasterN",    sendMessage (IncMasterN (-1)))
274
+              , ("ToggleStruts",  sendMessage ToggleStruts)
275
+              , ("ToggleSpacing", toggleWindowSpacingEnabled)
276
+              ]

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

@@ -15,14 +15,18 @@ module XMonad.Local.Layout (layoutHook, selectLayoutByName) where
15 15
 --------------------------------------------------------------------------------
16 16
 import XMonad hiding ((|||), layoutHook, float)
17 17
 import XMonad.Layout.Accordion (Accordion(..))
18
+import XMonad.Layout.CenteredMaster (centerMaster)
18 19
 import XMonad.Layout.ComboP (PartitionWins(..), combineTwoP)
19
-import XMonad.Layout.Gaps (gaps)
20
+import XMonad.Layout.Cross (Cross(..))
21
+import XMonad.Layout.Grid (Grid(Grid))
20 22
 import XMonad.Layout.GridVariants (SplitGrid(..))
21 23
 import qualified XMonad.Layout.GridVariants as Grid
22 24
 import XMonad.Layout.IfMax (ifMax)
23 25
 import XMonad.Layout.LayoutCombinators
26
+import XMonad.Layout.Magnifier (magnifiercz)
24 27
 import XMonad.Layout.Master (mastered)
25 28
 import XMonad.Layout.NoBorders (noBorders)
29
+import XMonad.Layout.OneBig (OneBig(..))
26 30
 import XMonad.Layout.Reflect (reflectHoriz, reflectVert)
27 31
 import XMonad.Layout.Renamed (Rename(..), renamed)
28 32
 import XMonad.Layout.ResizableTile (ResizableTall(..))
@@ -30,51 +34,77 @@ import XMonad.Layout.Spacing (Border(..), spacingRaw)
30 34
 import XMonad.Layout.ThreeColumns (ThreeCol(..))
31 35
 import XMonad.Layout.ToggleLayouts (toggleLayouts)
32 36
 import XMonad.Layout.TwoPane (TwoPane(..))
37
+import XMonad.Layout.ZoomRow (zoomRow)
33 38
 import XMonad.Local.Prompt (aListCompFunc)
34 39
 import XMonad.Prompt
35
-import XMonad.Util.Types (Direction2D(..))
36 40
 import XMonad.Util.WindowProperties (Property(..))
37 41
 
42
+import XMonad.Layout.LayoutBuilder
43
+  ( SubBox(..)
44
+  , SubMeasure(..)
45
+  , layoutN
46
+  , layoutP
47
+  , layoutAll
48
+  , relBox
49
+  )
50
+
38 51
 --------------------------------------------------------------------------------
39 52
 -- | XMonad layout hook.  No type signature because it's freaking
40 53
 -- nasty and I can't come up with a way to make it generic.
41
-layoutHook = toggleLayouts solo allLays
54
+layoutHook = toggleLayouts oneCol allLays
42 55
   where
43
-    uniformGaps n = [(U, n), (D, n), (L, n), (R, n)] :: [(Direction2D,Int)]
44 56
     uniformBorder n = Border n n n n
45
-    spacing = spacingRaw False (uniformBorder 0) False (uniformBorder 10) True
57
+    spacing  = spacingRaw False (uniformBorder 0) False (uniformBorder 10) True
58
+    spacing' = spacingRaw False (uniformBorder 0) False (uniformBorder 2)  True
46 59
 
47 60
     full       = noBorders Full
48
-    solo       = noBorders $ gaps (uniformGaps 60) Full
61
+    cmaster    = centerMaster grid
62
+    big        = spacing $ OneBig (3/4) (3/4)
63
+    oneCol     = spacing' $ magnifiercz 0.9 Accordion
49 64
     threeCols  = spacing $ reflectHoriz $ ThreeColMid 1 (1/100) (3/8)
50 65
     twoCols    = spacing $ mastered (1/100) (1/2) Accordion
51 66
     twoPane    = spacing $ TwoPane (1/100) (1/2)
52 67
     tall       = spacing $ ResizableTall 1 (1/100) (3/5) []
53 68
     focusTag   = spacing $ only (Tagged "focus")
54
-    grid       = spacing $ SplitGrid Grid.L 2 2 (2/3) (1/2) 1
55
-    auto       = ifMax 1 centFull $ ifMax 2 twoPane threeCols
56
-
57
-    -- One window, centered on the screen.
58
-    centFull  = spacingRaw False (Border 20 20 400 400)
59
-                           True  (Border 0 0 0 0) False Full
69
+    grid       = spacing Grid
70
+    sgrid      = spacing $ SplitGrid Grid.L 2 2 (2/3) (1/2) 1
71
+    cross      = spacing $ Cross (4/5) (1/100)
72
+    ten80      = centered 2560 (1930, 1090) -- Account for border width
73
+    cgrid      = layoutAll (relBox (1/8) (1/8) (7/8) (7/8)) grid
74
+    auto       = ifMax 1 (noBorders cgrid) $ ifMax 2 twoPane threeCols
60 75
 
61 76
     -- A layout where windows you want to focus on are specified using
62 77
     -- @WindowProperties@.  Windows matching the given properties will
63 78
     -- be placed into the main layout.  Other windows are pushed to
64
-    -- the top of the screen in a small @Accordion@.
65
-    only = combineTwoP (reflectVert $ Mirror $ TwoPane 0 (9/10))
66
-                       twoCols (Mirror Accordion)
79
+    -- the bottom of the screen into a single row.
80
+    only prop =
81
+      let topBox = relBox 0 0 1 (7/8)
82
+          botBox = relBox 0 (7/8) 1 1
83
+      in layoutP prop topBox Nothing threeCols $
84
+           layoutAll botBox zoomRow
85
+
86
+    -- Center the master window horizontally, locked to the given
87
+    -- width and height, display all other windows below in a grid.
88
+    centered x (w, h) =
89
+      let centerBox = SubBox (Abs ((x - w) `div` 2)) (Abs 10) (Abs w) (Abs h)
90
+          bottomBox = SubBox (Rel 0) (Abs (h + 10)) (Rel 1) (Rel 1)
91
+      in layoutN 1 centerBox Nothing Grid $
92
+           layoutAll bottomBox (spacing zoomRow)
67 93
 
68
-    -- All layouts put together.
69 94
     allLays =
70
-      renamed [Replace "Auto"]  auto     |||
71
-      renamed [Replace "Tall"]  tall      |||
72
-      renamed [Replace "3C"]    threeCols |||
73
-      renamed [Replace "2C"]    twoCols   |||
74
-      renamed [Replace "2P"]    twoPane   |||
75
-      renamed [Replace "Focus"] focusTag  |||
76
-      renamed [Replace "Grid"]  grid      |||
77
-      renamed [Replace "Full"]  full
95
+      renamed [Replace "Auto"]     auto      |||
96
+      renamed [Replace "Tall"]     tall      |||
97
+      renamed [Replace "3C"]       threeCols |||
98
+      renamed [Replace "2C"]       twoCols   |||
99
+      renamed [Replace "2P"]       twoPane   |||
100
+      renamed [Replace "Focus"]    focusTag  |||
101
+      renamed [Replace "Cross"]    cross     |||
102
+      renamed [Replace "Grid"]     grid      |||
103
+      renamed [Replace "SGrid"]    sgrid     |||
104
+      renamed [Replace "Big"]      big       |||
105
+      renamed [Replace "1080p"]    ten80     |||
106
+      renamed [Replace "Centered"] cmaster   |||
107
+      renamed [Replace "Full"]     full
78 108
 
79 109
 --------------------------------------------------------------------------------
80 110
 -- | A data type for the @XPrompt@ class.
@@ -100,11 +130,16 @@ selectLayoutByName conf =
100 130
     layoutNames :: [(String, String)]
101 131
     layoutNames =
102 132
       [ ("Auto",               "Auto")
133
+      , ("1080p",              "1080p")
134
+      , ("Big",                "Big")
135
+      , ("Centered",           "Centered")
136
+      , ("Cross",              "Cross")
137
+      , ("Focus",              "Focus")
138
+      , ("Full",               "Full")
139
+      , ("Grid",               "Grid")
140
+      , ("Split Grid",         "SGrid")
103 141
       , ("Tall",               "Tall")
104 142
       , ("Three Columns (3C)", "3C")
105 143
       , ("Two Columns (2C)",   "2C")
106 144
       , ("Two Pane (2P)",      "2P")
107
-      , ("Full",               "Full")
108
-      , ("Focus",              "Focus")
109
-      , ("Grid",               "Grid")
110 145
       ]

Loading…
Cancel
Save