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 | |
Skyler Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 5 | import qualified DBus as D |
| 6 | import qualified DBus.Client as D |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 7 | |
Skyler Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 8 | import qualified Codec.Binary.UTF8.String as UTF8 |
| 9 | import XMonad.Actions.WorkspaceNames (workspaceNamesPP) |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 10 | import XMonad.Hooks.StatusBar.PP |
Skyler Grey | 7030149 | 2023-02-24 09:04:51 +0000 | [diff] [blame] | 11 | import XMonad.Util.Replace (replace) |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 12 | |
| 13 | xmonadLog :: IO D.Client |
| 14 | xmonadLog = 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 | |
| 20 | dbusOutput :: D.Client -> String -> IO () |
| 21 | dbusOutput 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 | |
| 29 | polybarHook :: D.Client -> PP |
| 30 | polybarHook 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 Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 37 | green = "#98c379" |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 38 | red = "#e06c75" |
| 39 | in def { ppOutput = dbusOutput dbus |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 40 | , ppCurrent = wrapper red |
Skyler Grey | 3a9a2b1 | 2023-02-13 08:04:05 +0000 | [diff] [blame] | 41 | , ppVisible = wrapper orange |
| 42 | , ppUrgent = wrapper green |
Skyler Grey | 0808276 | 2023-01-26 00:35:19 +0000 | [diff] [blame] | 43 | , ppHidden = wrapper blue |
Skyler Grey | 51a0c61 | 2022-11-05 09:59:04 +0000 | [diff] [blame] | 44 | , ppHiddenNoWindows = wrapper grey |
| 45 | , ppTitle = shorten 100 . wrapper purple |
| 46 | } |