blob: fb5bbe7365ef0685df95308c80c93f9be5b34dd9 [file] [log] [blame]
Skyler Grey51a0c612022-11-05 09:59:04 +00001-- spell-checker:words xmonad,dbus,polybar,mempty
2
3module XMonadLog where
4
5import qualified DBus as D
6import qualified DBus.Client as D
7
8import qualified Codec.Binary.UTF8.String as UTF8
9import XMonad.Hooks.StatusBar.PP
10import XMonad.Util.Replace (replace)
11
12xmonadLog :: IO D.Client
13xmonadLog = let opts = [D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue]
14 in do
15 dbus <- D.connectSession
16 D.requestName dbus (D.busName_ "org.xmonad.Log") opts
17 return dbus
18
19dbusOutput :: D.Client -> String -> IO ()
20dbusOutput dbus str =
21 let objectPath = D.objectPath_ "/org/xmonad/Log"
22 interfaceName = D.interfaceName_ "org.xmonad.Log"
23 memberName = D.memberName_ "Update"
24 signal = D.signal objectPath interfaceName memberName
25 body = [D.toVariant str]
26 in D.emit dbus $ signal { D.signalBody = body }
27
28polybarHook :: D.Client -> PP
29polybarHook dbus =
30 let wrapper c s | s /= "NSP" = wrap ("%{F" <> c <> "} ") " %{F-}" s
31 | otherwise = mempty
32 blue = "#61afef"
33 grey = "#474e5d"
34 orange = "#e5c07b"
35 purple = "#c678dd"
Skyler Grey3a9a2b12023-02-13 08:04:05 +000036 green = "#98c379"
Skyler Grey51a0c612022-11-05 09:59:04 +000037 red = "#e06c75"
38 in def { ppOutput = dbusOutput dbus
Skyler Grey08082762023-01-26 00:35:19 +000039 , ppCurrent = wrapper red
Skyler Grey3a9a2b12023-02-13 08:04:05 +000040 , ppVisible = wrapper orange
41 , ppUrgent = wrapper green
Skyler Grey08082762023-01-26 00:35:19 +000042 , ppHidden = wrapper blue
Skyler Grey51a0c612022-11-05 09:59:04 +000043 , ppHiddenNoWindows = wrapper grey
44 , ppTitle = shorten 100 . wrapper purple
45 }