all repos — xmonad-config @ 2b9608c9779758a9417e475e24f1d60a428b805d

personal xmonad config

lib/LaNinpreConfig.hs (view raw)

  1{-# OPTIONS_HADDOCK prune #-}
  2----------------------------------------------------------------------
  3-- |
  4-- Module       :   LaNinpreConfig
  5-- Description  :   personal stuff for xmonad
  6-- Maintainer   :   la-ninpre
  7-- License      :   ISC
  8-- Copyright    :   la-ninpre <aaoth AT aaoth DOT xyz>
  9--
 10-- this module exists because i find it more convenient to manage some things
 11-- from here instead of doing it right in xmonad config
 12--
 13----------------------------------------------------------------------
 14
 15module LaNinpreConfig (
 16                      -- $global
 17
 18                      -- * fonts
 19                      -- $fonts
 20                      myFonts,
 21
 22                      -- * colors
 23                      -- $colors
 24                      MyColorTheme(..),
 25                      def,
 26                      myNormColor,
 27                      myFocusColor,
 28
 29                      -- * software constants
 30                      -- $software
 31                      myTerminal,
 32                      myBrowser,
 33                      myGeminiClient,
 34                      myFileMgr,
 35                      myMocp,
 36                      myEditor,
 37
 38                      -- * hooks
 39                      -- $hooks
 40                      myManageHook,
 41                      myStartupHook,
 42
 43                      -- * scratchpads
 44                      -- $scratchpads
 45                      myScratchPads,
 46
 47                      -- * workspaces
 48                      -- $workspaces
 49                      myWorkspaces,
 50
 51                      -- * misc
 52                      -- $misc
 53                      myModMask,
 54                      myBorderWidth,
 55                      myAppGrid,
 56                      ) where
 57
 58import Data.List
 59import Data.Map as M
 60import Data.Maybe
 61import Data.Monoid
 62
 63import XMonad
 64import qualified XMonad.StackSet as W
 65import XMonad.Hooks.ManageHelpers
 66import XMonad.Hooks.SetWMName
 67import XMonad.Util.NamedScratchpad
 68import XMonad.Util.SpawnOnce
 69
 70-- $global
 71--
 72-- constants and functions starting with \'my\' are exported and used in
 73-- xmonad config.
 74
 75-- $fonts
 76--
 77-- default fonts and helper functions for them.
 78
 79-- | default lato font
 80fontLatoDef :: String
 81fontLatoDef = fontXft "Lato" "regular" 14
 82
 83-- | font for @ShowWMName@
 84--
 85--   normal variant
 86--
 87--   > fontSWN = fontXft "Press Start 2P" "regular" 60
 88--
 89--   sitelen pona pona variant
 90--
 91--   > fontSWN = fontXft "sitelen\\-pona" "regular" 80
 92fontSWN :: String
 93fontSWN = fontXft "linja pona" "regular" 80
 94
 95-- | fonts list
 96myFonts :: [String]
 97myFonts = [ fontLatoDef
 98          , fontSWN
 99          ]
100
101-- ** helper functions
102--
103-- | font constructor
104--
105--   it is just a helper function to simplify the process of specifying font
106--   with xft.
107fontXft :: String   -- ^ font family
108        -> String   -- ^ font style
109        -> Int      -- ^ font size
110        -> String
111
112fontXft font style size = intercalate ":" [ "xft"
113                                , font
114                                , style
115                                , "size=" ++ show size
116                                , "antialias=true"
117                                , "hinting=true"
118                                ]
119
120-- $colors
121--
122-- color theme and stuff
123
124myColorTheme :: MyColorTheme
125myColorTheme = MyColorTheme "#111111" "#ccbbcc" "#223333" "#ffaaaa"
126
127-- | unfocused window border colour
128myNormColor :: String
129myNormColor = col_bg def
130
131-- | focused window border colour
132myFocusColor :: String
133myFocusColor = col_bg_alt def
134
135-- | color theme datatype
136--
137-- 'Default' instance gives simple four-color colorscheme
138data MyColorTheme = MyColorTheme {
139    col_bg     :: String,
140    col_fg     :: String,
141    col_bg_alt :: String,
142    col_fg_alt :: String
143}
144
145instance Default MyColorTheme where
146    def = myColorTheme
147
148
149-- $software
150--
151-- these are just contstants
152
153-- | set terminal emulator
154myTerminal :: String
155myTerminal = "alacritty"
156
157-- | set default browser
158myBrowser :: String
159myBrowser = "firefox"
160
161-- | set gemini client
162myGeminiClient :: String
163myGeminiClient = "amfora"
164
165-- | set file manager
166myFileMgr :: String
167myFileMgr = "thunar"
168
169-- | music on console
170--
171--   this is to avoid spamming strings everywhere. @moc@ doesn't comply with
172--   XDG_CONFIG_HOME, so we force it to do so.
173myMocp :: String
174myMocp = "mocp -M '~/.config/moc'"
175
176-- | set editor
177myEditor :: String
178myEditor = myTerminal ++ " -e vim"
179
180-- $hooks
181--
182-- hooks for xmonad config
183
184-- ** startup hook
185--
186-- start things at login.
187
188-- | actual instance
189myStartupHook :: X ()
190myStartupHook = do
191    --spawnOnce "dunst &"
192    --spawnOnce "lxsession &"
193    --spawnOnce "picom &"
194    --spawnOnce "nm-applet &"
195    --spawnOnce "volumeicon &"
196    spawnOnce "setxkbmap -layout us,ru -option 'grp:alt_shift_toggle'"
197    spawnOnce "kbdd"
198    {-spawnOnce ("trayer --edge top "
199              ++ "--align right "
200              ++ "--widthtype request "
201              ++ "--SetDockType true --SetPartialStrut true --expand false "
202              ++ "--monitor 0 --transparent true --alpha 0 "
203              ++ "--tint 0x19191a  --height 24 &"
204              )
205	      -}
206    spawnOnce "~/.fehbg &"
207    setWMName "LG3D"
208
209-- ** manage hook
210--
211-- @doFloat@ forces a window to float. useful for dialog boxes and such.
212-- using @doShift (myWorkspaces !! 7)@ sends program to workspace 8
213-- i'm doing it this way because otherwise i would have to write out the full
214-- name of my workspaces and the names would be very long if using clickable workspaces.
215
216-- | manage hook
217myManageHook :: Query (Endo WindowSet)
218myManageHook = composeAll
219     [ className =? "confirm"         --> doFloat
220     , className =? "file_progress"   --> doFloat
221     , className =? "dialog"          --> doFloat
222     , className =? "download"        --> doFloat
223     , className =? "error"           --> doFloat
224     , className =? "Gimp"            --> doFloat
225     , className =? "notification"    --> doFloat
226     , className =? "pinentry-gtk-2"  --> doFloat
227     , className =? "splash"          --> doFloat
228     , className =? "toolbar"         --> doFloat
229     , className =? "Cadence"         --> doFloat
230     , className =? "Steam"           --> doFloat
231     , className =? "Image Lounge"    --> doFloat
232     , title =? "Oracle VM VirtualBox Manager"  --> doFloat
233     -- web workspace
234     , title =? "Mozilla Firefox"     --> doShift ( myWorkspaces !! 1 )
235     , className =? "Brave-browser"   --> doShift ( myWorkspaces !! 1 )
236     , className =? "amfora"          --> doShift ( myWorkspaces !! 1 )
237     , className =? "qutebrowser"     --> doShift ( myWorkspaces !! 1 )
238     -- doc workspace
239     , className =? "Geary"           --> doShift ( myWorkspaces !! 3 )
240     , className =? "libreoffice-writer"  --> doShift ( myWorkspaces !! 3 )
241     , className =? "libreoffice-impress" --> doShift ( myWorkspaces !! 3 )
242     -- vm workspace
243     , className =? "VirtualBox Manager"  --> doShift ( myWorkspaces !! 4 )
244     -- chat workspace
245     , className =? "discord"         --> doShift ( myWorkspaces !! 5 )
246     , className =? "TelegramDesktop" --> doShift ( myWorkspaces !! 5 )
247     , className =? "Element"         --> doShift ( myWorkspaces !! 5 )
248     , className =? "Steam"           --> doShift ( myWorkspaces !! 5 )
249     -- full workspace
250     , isFullscreen                   --> doShift ( myWorkspaces !! 6 )
251     -- vid workspace
252     , className =? "Deadbeef"        --> doShift ( myWorkspaces !! 7 )
253     , appName   =? "mpv"             --> doShift ( myWorkspaces !! 7 )
254     , className =? "vlc"             --> doShift ( myWorkspaces !! 7 )
255     -- gfx workspace
256     , className =? "Gimp"            --> doShift ( myWorkspaces !! 8 )
257     , className =? "Blender"         --> doShift ( myWorkspaces !! 8 )
258     , className =? "obs"             --> doShift ( myWorkspaces !! 8 )
259     , isFullscreen -->  doFullFloat
260     ] <+> namedScratchpadManageHook myScratchPads
261
262-- $scratchpads
263--
264-- currently i have:
265--
266--     *   plain terminal scratchpad
267--
268--     *   music on console
269--     
270--     *   calculator (qalculate-gtk)
271--
272--     *   mpv instance that plays playlist in @~\/Video\/sp_playlist.m3u@
273
274-- | scratchpad list
275myScratchPads :: [NamedScratchpad]
276myScratchPads = [ NS "terminal" spawnTerm findTerm manageTerm
277                , NS "mocp" spawnMocp findMocp manageMocp
278                , NS "calculator" spawnCalc findCalc manageCalc
279                , NS "mpvfloat" spawnMpv findMpv manageMpv
280                ]
281  where
282    -- terminal
283    spawnTerm  = myTerminal ++ " -t scratchpad"
284    findTerm   = title =? "scratchpad"
285    manageTerm = customFloating $ W.RationalRect l t w h
286               where
287                 h = 0.9
288                 w = 0.9
289                 t = 0.95 - h
290                 l = 0.95 - w
291    -- music on console
292    spawnMocp  = myTerminal ++ " -t mocp -e " ++ myMocp
293    findMocp   = title =? "mocp"
294    manageMocp = customFloating $ W.RationalRect l t w h
295               where
296                 h = 0.9
297                 w = 0.9
298                 t = 0.95 - h
299                 l = 0.95 - w 
300    -- calculator
301    spawnCalc  = "qalculate-gtk"
302    findCalc   = className =? "Qalculate-gtk"
303    manageCalc = customFloating $ W.RationalRect l t w h
304               where
305                 h = 0.5
306                 w = 0.4
307                 t = 0.75 - h
308                 l = 0.70 - w
309    -- mpv scratchpad to watch some stuff listed in ~/Video/sp_playlist.m3u
310    spawnMpv  = "mpv --pause -x11-name mpv-sp ~/Video/sp_playlist.m3u"
311                ++ mpvGeometry mpvPercentage mpvPercentage
312    findMpv   = appName =? "mpv-sp"
313    manageMpv = customFloating $ W.RationalRect l t w h
314               where
315                 h = mpvPercentage
316                 w = mpvPercentage
317                 t = 0.03
318                 l = 0.996 - w
319
320-- ** helper functions
321--
322-- | percentage of mpv scratchpad at start
323mpvPercentage :: Rational
324mpvPercentage = 1/4
325
326-- | mpv needs geometry of window at start, so it won't resize itself, when
327--   playing next video on a playlist
328mpvGeometry :: RealFrac a 
329              => a  -- ^ relative height of window
330              -> a  -- ^ relative width of window
331              -> String
332
333mpvGeometry h w = " --geometry=" ++ show pw ++ "x" ++ show ph
334                  where
335                      pw = ceiling (1920 * w)
336                      ph = ceiling (1080 * h)
337
338-- $workspaces
339--
340-- i've got three ways of specifying them. first one is pretty close to the
341-- original dt's config. second is using sitelen pona pona font by jackhumbert
342-- (check it out [here](https://jackhumbert.github.io/sitelen-pona-pona/)).
343-- and third one is using linja pona font by jan same
344-- (check it out [here](http://musilili.net/linja-pona/)).
345--
346--      *   normal variant
347--
348--          > myWorkspaces = [ "dev"
349--          >                , "www"
350--          >                , "sys"
351--          >                , "doc"
352--          >                , "vm"
353--          >                , "chat"
354--          >                , "full"
355--          >                , "vid"
356--          >                , "gfx"
357--          >                ]
358--
359--      *   one using sitelen pona pona by jackhumbert
360--
361--          this is specified with actual glyph codes because xmobar
362--          don't allow for ligatures and otf features.
363--
364--          > myWorkspaces = [ "\xee3d" -- nanpa
365--          >                , "\xee3b" -- musi
366--          >                , "\xee49" -- pali
367--          >                , "\xee2a" -- lipu
368--          >                , "\xee53" -- poki
369--          >                , "\xee6c" -- toki
370--          >                , "\xee63" -- suli
371--          >                , "\xee60" -- sitelen
372--          >                , "\xee1e" -- kule
373--          >                ]
374
375-- | workspaces container
376myWorkspaces :: [String]
377myWorkspaces = [ "\xe661\xe921" -- sona nanpa
378               , "\xe63b"       -- musi
379               , "\xe649"       -- pali
380               , "\xe62a\xf105" -- lipu ale
381               , "\xe653\xf115" -- poki ilo
382               , "\xe66c"       -- toki
383               , "\xe62a\xf200" -- lipu suli
384               , "\xf010\xe915" -- sitelen tawa
385               , "\xf010\xf107" -- sitelen ante
386               ]
387
388-- $misc
389--
390-- misc constants
391
392-- | set windows key as modkey
393myModMask :: KeyMask
394myModMask = mod4Mask
395
396-- | specify border width
397myBorderWidth :: Dimension
398myBorderWidth = 1
399
400-- | app grid for 'GridSelect' layout
401myAppGrid :: [(String,String)]
402myAppGrid = [ ("discord"   ,"discord"    )
403            , ("steam"     ,"steam"      )
404            , ("mail"      ,"thunderbird")
405            , ("files"     ,"thunar"     )
406            , ("blender"   ,"blender-3.1")
407            , ("inkscape"  ,"inkscape"   )
408            , ("obs"       ,"obs"        )
409            , ("gimp"      ,"gimp"       )
410            , ("ardour"    ,"ardour6"    )
411            , ("kdenlive"  ,"kdenlive"   )
412            ]