Skip to content

Instantly share code, notes, and snippets.

@nekolinuxblog
Last active February 20, 2021 04:58
Show Gist options
  • Save nekolinuxblog/5c1c53073c492a60dffbaf8f8d8a9102 to your computer and use it in GitHub Desktop.
Save nekolinuxblog/5c1c53073c492a60dffbaf8f8d8a9102 to your computer and use it in GitHub Desktop.
dbusを呼ぶxmonad.hsのメイン周辺
-- dbus呼び出しの纏め
-- 必要なライブラリの呼び出し
import XMonad
import XMonad.Hooks.DynamicLog
import qualified DBus as D
import qualified DBus.Client as D
import qualified Codec.Binary.UTF8.String as UTF8
-- xmonad.hsの実行入り口部分
main = do
-- xmonadを呼ぶ前にdbusを作成
dbus <- D.connectSession
-- Request access to the DBus name
D.requestName dbus (D.busName_ "org.xmonad.Log")
[D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue]
-- xmonadに渡すデータのlogHookをmyPolybarHook関数とdbusに基づいて作り直す。
xmonad $ def { terminal = "xterm"
, modMask = mod4Mask
, logHook = dynamicLogWithPP (myPolybarPP dbus)
}
-- xmonadに紐づけたdbusに出力するためのアクションのための関数定義
-- from https://github.com/xintron/xmonad-log
dbusOutput :: D.Client -> String -> IO ()
dbusOutput dbus str = do
let signal = (D.signal objectPath interfaceName memberName) {
D.signalBody = [D.toVariant $ UTF8.decodeString str]
}
D.emit dbus signal
where
objectPath = D.objectPath_ "/org/xmonad/Log"
interfaceName = D.interfaceName_ "org.xmonad.Log"
memberName = D.memberName_ "Update"
-- デフォルトのlogHookの出力先等を上書きするためのPP
myPolybarPP :: D.Client -> PP
myPolybarPP dbus =
def { ppOutput = dbusOutput dbus
, ppCurrent = wrap "[" "]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment