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