aboutsummaryrefslogtreecommitdiffstats
path: root/lib/LaNinpreConfig.hs
blob: 92df432b9a34b2d99c720344aa3168b87f9732f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
{-# OPTIONS_HADDOCK ignore-exports, prune #-}
----------------------------------------------------------------------
-- |
-- Module       :   LaNinpreConfig
-- Description  :   personal stuff for xmonad
-- Maintainer   :   la-ninpre
--
-- this module exists because i find it more convenient to manage some things
-- from here instead of doing it right in xmonad config
--
----------------------------------------------------------------------

module LaNinpreConfig (
                      -- * global
                      -- $global
                      myFonts,
                      myColor,
                      myModMask,
                      myTerminal,
                      myBrowser,
                      myGeminiClient,
                      myFileMgr,
                      myMocp,
                      myEditor,
                      myBorderWidth,
                      myNormColor,
                      myFocusColor,
                      myAppGrid,
                      myWorkspaces,
                      myScratchPads,
                      myManageHook,
                      myStartupHook
                      ) where

import Data.List
import Data.Map as M
import Data.Maybe
import Data.Monoid

import XMonad
import qualified XMonad.StackSet as W
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.SetWMName
import XMonad.Util.NamedScratchpad
import XMonad.Util.SpawnOnce

-- $global
--
-- constants and functions starting with \'my\' are exported and used in
-- xmonad config.

-- * constants

-- $constants
-- these are set up to avoid unnecessary repetition of replacements, when
-- things change.

-- ** fonts
--
-- $fonts
-- default fonts and helper functions for them.

-- | default lato font
fontLatoDef = fontXft "Lato" "regular" 14

-- | font for @ShowWMName@
--
--   normal variant
--
--   > fontSWN = fontXft "Press Start 2P" "regular" 60
--
--   sitelen pona pona variant
--
--   > fontSWN = fontXft "sitelen\\-pona" "regular" 80
fontSWN = fontXft "linja pona" "regular" 80

-- | fonts list
myFonts :: [String]
myFonts = [ fontLatoDef
          , fontSWN
          ]

-- *** helper functions
--
-- | font constructor
--
--   it is just a helper function to simplify the process of specifying font
--   with xft.
fontXft :: String   -- ^ font family
        -> String   -- ^ font style
        -> Int      -- ^ font style
        -> String

fontXft font style size = intercalate ":" [ "xft"
                                , font
                                , style
                                , "size=" ++ show size
                                , "antialias=true"
                                , "hinting=true"
                                ]


-- ** colors

-- $colorTheme
--
-- > bg             #19191a
-- > fg             #cadcde
-- > grey0          #232324
-- > grey1          #363638
-- > grey2          #66666a
-- > black          #393838
-- > red            #c74444
-- > green          #7f9848
-- > yellow         #d7a06d
-- > blue           #4e96d5
-- > magenta        #bc5fa7
-- > cyan           #55b795
-- > white          #c3b2f7
-- > black-bright   #5a514b
-- > red-bright     #ed7c68
-- > green-bright   #c7ea76
-- > yellow-bright  #ffdb9d
-- > blue-bright    #a6d5fe
-- > magenta-bright #edbbe9
-- > cyan-bright    #7fe2c5
-- > white-bright   #e2d6ff

-- | color theme structure
myColorTheme :: [(String,String)]
myColorTheme = [ ("bg",             "#19191a")
               , ("fg",             "#cadcde")
               , ("gray0",          "#232324")
               , ("gray1",          "#363638")
               , ("gray2",          "#5c5c60")
               , ("gray3",          "#66666a")
               , ("gray4",          "#ececf0")
               , ("black",          "#393838")
               , ("red",            "#c74444")
               , ("green",          "#7f9848")
               , ("yellow",         "#d7a06d")
               , ("blue",           "#4e96d5")
               , ("magenta",        "#bc5fa7")
               , ("cyan",           "#55b795")
               , ("white",          "#c3b2f7")
               , ("black-bright",   "#5a514b")
               , ("red-bright",     "#ed7c68")
               , ("green-bright",   "#c7ea76")
               , ("yellow-bright",  "#ffdb9d")
               , ("blue-bright",    "#a6d5fe")
               , ("magenta-bright", "#edbbe9")
               , ("cyan-bright",    "#7fe2c5")
               , ("white-bright",   "#e2d6ff")
               ]

-- | unfocused window border colour
myNormColor :: String
myNormColor = myColor "gray0"

-- | focused window border colour
myFocusColor :: String
myFocusColor = myColor "blue"

-- *** helper functions
--
-- | get color from color theme
myColor :: String -> String
myColor c = fromMaybe "" (M.lookup c theme)
            where
                theme = fromList myColorTheme


-- ** software constants
--
-- | set terminal emulator
myTerminal :: String
myTerminal = "alacritty"

-- | set default browser
myBrowser :: String
myBrowser = "brave"

-- | set gemini client
myGeminiClient :: String
myGeminiClient = "amfora"

-- | set file manager
myFileMgr :: String
myFileMgr = "thunar"

-- | music on console
--
--   this is to avoid spamming strings everywhere. @moc@ doesn't comply with
--   XDG_CONFIG_HOME, so we force it to do so.
myMocp :: String
myMocp = "mocp -M '~/.config/moc'"

-- | set editor
myEditor :: String
myEditor = myTerminal ++ " -e vim"

-- ** other constants
--
-- | set windows key as modkey
myModMask :: KeyMask
myModMask = mod4Mask

-- | specify border width
myBorderWidth :: Dimension
myBorderWidth = 1

-- | app grid for @GridSelect@ layout
myAppGrid :: [(String,String)]
myAppGrid = [ ("discord",   "discord")
            , ("steam",     "steam")
            , ("cadence",   "cadence")
            , ("blender",   "blender")
            , ("inkscape",  "inkscape")
            , ("obs",       "obs")
            , ("gimp",      "gimp")
            , ("element",   "element-desktop")
            , ("ardour",    "ardour6")
            , ("kdenlive",  "kdenlive")
            , ("writer",    "lowriter")
            ]

-- * hooks
--
-- ** startup hook
--
-- $startupHook
--
-- start things at login.

-- | actual instance
myStartupHook :: X ()
myStartupHook = do
    spawnOnce "dunst &"
    spawnOnce "lxsession &"
    spawnOnce "picom &"
    spawnOnce "nm-applet &"
    spawnOnce "volumeicon &"
    spawnOnce "setxkbmap -layout us,ru -option 'grp:alt_shift_toggle'"
    spawnOnce "kbdd"
    spawnOnce ("trayer --edge top "
              ++ "--align right "
              ++ "--widthtype request "
              ++ "--SetDockType true --SetPartialStrut true --expand false "
              ++ "--monitor 0 --transparent true --alpha 0 "
              ++ "--tint 0x19191a  --height 24 &"
              )
    spawnOnce "nitrogen --restore &"
    setWMName "LG3D"

-- ** manage hook
--
-- $managehook
--
-- @doFloat@ forces a window to float. useful for dialog boxes and such.
-- using @doShift (myWorkspaces !! 7)@ sends program to workspace 8
-- i'm doing it this way because otherwise i would have to write out the full
-- name of my workspaces and the names would be very long if using clickable workspaces.

-- | manage hook
myManageHook :: Query (Endo WindowSet)
myManageHook = composeAll
     [ className =? "confirm"         --> doFloat
     , className =? "file_progress"   --> doFloat
     , className =? "dialog"          --> doFloat
     , className =? "download"        --> doFloat
     , className =? "error"           --> doFloat
     , className =? "Gimp"            --> doFloat
     , className =? "notification"    --> doFloat
     , className =? "pinentry-gtk-2"  --> doFloat
     , className =? "splash"          --> doFloat
     , className =? "toolbar"         --> doFloat
     , className =? "Cadence"         --> doFloat
     , className =? "Steam"           --> doFloat
     , className =? "Image Lounge"    --> doFloat
     , title =? "Oracle VM VirtualBox Manager"  --> doFloat
     -- web workspace
     , title =? "Mozilla Firefox"     --> doShift ( myWorkspaces !! 1 )
     , className =? "Brave-browser"   --> doShift ( myWorkspaces !! 1 )
     , className =? "amfora"          --> doShift ( myWorkspaces !! 1 )
     , className =? "qutebrowser"     --> doShift ( myWorkspaces !! 1 )
     -- doc workspace
     , className =? "Geary"           --> doShift ( myWorkspaces !! 3 )
     , className =? "libreoffice-writer"  --> doShift ( myWorkspaces !! 3 )
     , className =? "libreoffice-impress" --> doShift ( myWorkspaces !! 3 )
     -- vm workspace
     , className =? "VirtualBox Manager"  --> doShift ( myWorkspaces !! 4 )
     -- chat workspace
     , className =? "discord"         --> doShift ( myWorkspaces !! 5 )
     , className =? "TelegramDesktop" --> doShift ( myWorkspaces !! 5 )
     , className =? "Element"         --> doShift ( myWorkspaces !! 5 )
     , className =? "Steam"           --> doShift ( myWorkspaces !! 5 )
     -- full workspace
     , isFullscreen                   --> doShift ( myWorkspaces !! 6 )
     -- vid workspace
     , className =? "Deadbeef"        --> doShift ( myWorkspaces !! 7 )
     , appName   =? "mpv"             --> doShift ( myWorkspaces !! 7 )
     , className =? "vlc"             --> doShift ( myWorkspaces !! 7 )
     -- gfx workspace
     , className =? "Gimp"            --> doShift ( myWorkspaces !! 8 )
     , className =? "Blender"         --> doShift ( myWorkspaces !! 8 )
     , className =? "obs"             --> doShift ( myWorkspaces !! 8 )
     , isFullscreen -->  doFullFloat
     ] <+> namedScratchpadManageHook myScratchPads

-- * scratchpads
--
-- $scratchpads
--
-- currently i have:
--
--     *   plain terminal scratchpad
--
--     *   music on console
--     
--     *   calculator (qalculate-gtk)
--
--     *   mpv instance that plays playlist in @~\/Video\/sp_playlist.m3u@

-- | scratchpad list
myScratchPads :: [NamedScratchpad]
myScratchPads = [ NS "terminal" spawnTerm findTerm manageTerm
                , NS "mocp" spawnMocp findMocp manageMocp
                , NS "calculator" spawnCalc findCalc manageCalc
                , NS "mpvfloat" spawnMpv findMpv manageMpv
                ]
  where
    -- terminal
    spawnTerm  = myTerminal ++ " -t scratchpad"
    findTerm   = title =? "scratchpad"
    manageTerm = customFloating $ W.RationalRect l t w h
               where
                 h = 0.9
                 w = 0.9
                 t = 0.95 - h
                 l = 0.95 - w
    -- music on console
    spawnMocp  = myTerminal ++ " -t mocp -e " ++ myMocp
    findMocp   = title =? "mocp"
    manageMocp = customFloating $ W.RationalRect l t w h
               where
                 h = 0.9
                 w = 0.9
                 t = 0.95 - h
                 l = 0.95 - w 
    -- calculator
    spawnCalc  = "qalculate-gtk"
    findCalc   = className =? "Qalculate-gtk"
    manageCalc = customFloating $ W.RationalRect l t w h
               where
                 h = 0.5
                 w = 0.4
                 t = 0.75 - h
                 l = 0.70 - w
    -- mpv scratchpad to watch some stuff listed in ~/Video/sp_playlist.m3u
    spawnMpv  = "mpv --pause -x11-name mpv-sp ~/Video/sp_playlist.m3u"
                ++ mpvGeometry mpvPercentage mpvPercentage
    findMpv   = appName =? "mpv-sp"
    manageMpv = customFloating $ W.RationalRect l t w h
               where
                 h = mpvPercentage
                 w = mpvPercentage
                 t = 0.03
                 l = 0.996 - w

-- ** helper functions
--
-- | percentage of mpv scratchpad at start
mpvPercentage :: Rational
mpvPercentage = 1/4

-- | mpv needs geometry of window at start, so it won't resize itself, when
--   playing next video on a playlist
mpvGeometry :: RealFrac a 
              => a  -- ^ relative height of window
              -> a  -- ^ relative width of window
              -> String

mpvGeometry h w = " --geometry=" ++ show pw ++ "x" ++ show ph
                  where
                      pw = ceiling (1920 * w)
                      ph = ceiling (1080 * h)

-- * workspaces
--
-- $workspaces
--
-- i've got three ways of specifying them. first one is pretty close to the
-- original dt's config. second is using sitelen pona pona font by jackhumbert
-- (check it out [here](https://jackhumbert.github.io/sitelen-pona-pona/)).
-- and third one is using linja pona font by jan same
-- (check it out [here](http://musilili.net/linja-pona/)).
--
--      *   normal variant
--
--          > myWorkspaces = [ "dev"
--          >                , "www"
--          >                , "sys"
--          >                , "doc"
--          >                , "vm"
--          >                , "chat"
--          >                , "full"
--          >                , "vid"
--          >                , "gfx"
--          >                ]
--
--      *   one using sitelen pona pona by jackhumbert
--
--          this is specified with actual glyph codes because xmobar
--          don't allow for ligatures and otf features.
--
--          > myWorkspaces = [ "\xee3d" -- nanpa
--          >                , "\xee3b" -- musi
--          >                , "\xee49" -- pali
--          >                , "\xee2a" -- lipu
--          >                , "\xee53" -- poki
--          >                , "\xee6c" -- toki
--          >                , "\xee63" -- suli
--          >                , "\xee60" -- sitelen
--          >                , "\xee1e" -- kule
--          >                ]

-- | workspaces container
myWorkspaces = [ "\xe661\xe921" -- sona nanpa
               , "\xe63b"       -- musi
               , "\xe649"       -- pali
               , "\xe62a\xf105" -- lipu ale
               , "\xe653\xf115" -- poki ilo
               , "\xe66c"       -- toki
               , "\xe62a\xf200" -- lipu suli
               , "\xf010\xe915" -- sitelen tawa
               , "\xf010\xf107" -- sitelen ante
               ]