Initial commit
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2016 Marcus Carlsson
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
67
README.md
Normal file
67
README.md
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# xmonad-log
|
||||||
|
|
||||||
|
xmonad-log is a DBus monitoring solution that can easily be used to display
|
||||||
|
xmonad in a statusbar like [polybar](https://github.com/jaagr/polybar),
|
||||||
|
[lemonbar](https://github.com/LemonBoy/bar) and similar.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
xmonad-log is written in Go with one dependency:
|
||||||
|
[dbus](https://github.com/godbus/dbus). [Binary
|
||||||
|
packages](https://github.com/xintron/xmonad-log/releases) are available.
|
||||||
|
|
||||||
|
### Building from source
|
||||||
|
|
||||||
|
This package has been tested with Go 1.7 and above.
|
||||||
|
|
||||||
|
To build from source:
|
||||||
|
1. Clone this repository into `$GOPATH/src/github.com/xintron/xmonad-log`.
|
||||||
|
2. Build it within the directory with `go build`.
|
||||||
|
|
||||||
|
This should leave a `xmonad-log` binary in the directory. Move this to an
|
||||||
|
appropriate directory in your `$PATH`.
|
||||||
|
|
||||||
|
## Configure xmonad
|
||||||
|
|
||||||
|
To configure xmonad to send log events over DBus the haskell
|
||||||
|
[dbus](http://hackage.haskell.org/package/dbus) package is required. Once
|
||||||
|
installed the following can be added to your `.xmonad/xmonad.hs` configuration
|
||||||
|
to add DBus support.
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
import XMonad
|
||||||
|
import XMonad.Hooks.DynamicLog
|
||||||
|
|
||||||
|
import qualified DBus as D
|
||||||
|
import qualified DBus.Client as D
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
dbus <- D.connectSession
|
||||||
|
-- Request access to the DBus name
|
||||||
|
D.requestName dbus (D.busName_ "org.xmonad.Log")
|
||||||
|
[D.nameAllowReplacement, D.nameReplaceExisting, D.nameDoNotQueue]
|
||||||
|
|
||||||
|
xmonad $ def { logHook = dynamicLogWithPP (myLogHook dbus) }
|
||||||
|
|
||||||
|
-- Override the PP values as you would otherwise, adding colors etc depending
|
||||||
|
-- on the statusbar used
|
||||||
|
myLogHook :: D.Client -> PP
|
||||||
|
myLogHook dbus = def { ppOutput = dbusOutput dbus }
|
||||||
|
|
||||||
|
-- Emit a DBus signal on log updates
|
||||||
|
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"
|
||||||
|
```
|
||||||
|
|
||||||
|
View [this
|
||||||
|
xmonad-config](https://github.com/xintron/configs/blob/22a33b41587c180172392f80318883921c543053/.xmonad/lib/Config.hs#L199)
|
||||||
|
for a fully working polybar example using statusbar coloring.
|
6
glide.lock
generated
Normal file
6
glide.lock
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
hash: 48b3e28efd90a1084dce6680bc7084d562049fddbf497c5e48d0c78e2c1e4896
|
||||||
|
updated: 2016-12-29T15:49:27.387756858+01:00
|
||||||
|
imports:
|
||||||
|
- name: github.com/godbus/dbus
|
||||||
|
version: 5f6efc7ef2759c81b7ba876593971bfce311eab3
|
||||||
|
testImports: []
|
4
glide.yaml
Normal file
4
glide.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
package: github.com/xintron/xmonad-log
|
||||||
|
import:
|
||||||
|
- package: github.com/godbus/dbus
|
||||||
|
version: ^4.0.0
|
32
main.go
Normal file
32
main.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/godbus/dbus"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
conn, err := dbus.SessionBus()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
|
||||||
|
"type='signal',path='/org/xmonad/Log',interface='org.xmonad.Log',member='Update'")
|
||||||
|
|
||||||
|
c := make(chan *dbus.Signal, 10)
|
||||||
|
conn.Signal(c)
|
||||||
|
for s := range c {
|
||||||
|
if len(s.Body) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Convert the result to a slice of strings
|
||||||
|
res, ok := s.Body[0].(string)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println(res)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user