Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 1 | -- spell-checker:words xmonad,dbus,polybar,mempty |
| 2 | |
| 3 | module XMonadLog where |
| 4 | |
| 5 | import qualified DBus as D |
| 6 | import qualified DBus.Client as D |
| 7 | |
| 8 | import qualified Codec.Binary.UTF8.String as UTF8 |
| 9 | import XMonad.Hooks.StatusBar.PP |
| 10 | import XMonad.Util.Replace (replace) |
| 11 | |
| 12 | xmonadLog :: IO D.Client |
| 13 | xmonadLog = 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 | |
| 19 | dbusOutput :: D.Client -> String -> IO () |
| 20 | dbusOutput 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 | |
| 28 | polybarHook :: D.Client -> PP |
| 29 | polybarHook 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 Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame^] | 38 | , ppCurrent = wrapper red |
| 39 | , ppVisible = wrapper blue |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 40 | , ppUrgent = wrapper orange |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame^] | 41 | , ppHidden = wrapper blue |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 42 | , ppHiddenNoWindows = wrapper grey |
| 43 | , ppTitle = shorten 100 . wrapper purple |
| 44 | } |