blob: b07485c61b0e35df0f54ef436cf755ff65561c8d [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"
36 red = "#e06c75"
37 in def { ppOutput = dbusOutput dbus
Skyler Grey08082762023-01-26 00:35:19 +000038 , ppCurrent = wrapper red
39 , ppVisible = wrapper blue
Skyler Grey51a0c612022-11-05 09:59:04 +000040 , ppUrgent = wrapper orange
Skyler Grey08082762023-01-26 00:35:19 +000041 , ppHidden = wrapper blue
Skyler Grey51a0c612022-11-05 09:59:04 +000042 , ppHiddenNoWindows = wrapper grey
43 , ppTitle = shorten 100 . wrapper purple
44 }