Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
3e849f2e5c committed Jan 29, 2020
1 parent 46cba48 commit 614046d
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"fmt"
"github.com/godbus/dbus"
"os"
)

func main() {
var connection, err = dbus.ConnectSessionBus()
if err != nil {
fmt.Println("Bruh " + err.Error())
os.Exit(1)
}

defer connection.Close()

const monitor = "org.freedesktop.DBus.Monitoring.BecomeMonitor"
const rule = "type='signal',sender='org.fcitx.Fcitx',interface='org.fcitx.Fcitx.Status'"

var call = connection.BusObject().Call(monitor, 0, []string{rule}, uint(0))

if call.Err != nil {
fmt.Println("Bruh " + call.Err.Error())
os.Exit(1)
}

var messages = make(chan *dbus.Message)
connection.Eavesdrop(messages)

var oldMode = "あ"

fmt.Println(oldMode)
for v := range messages {
if len(v.Body) >= 3 {
var newMode = v.Body[1].(string)
if oldMode != newMode {
switch newMode {
case "A":
fmt.Println("A")
break
case "ア":
fmt.Println("ア\u2423")
break
default:
fmt.Println(newMode)
}
oldMode = newMode
}
}
}
}

0 comments on commit 614046d

Please sign in to comment.