func main() { log.SetFlags(log.Llongfile) l, err := proto.ListenPath("/run/user/1000/wayland-1") if err != nil { log.Fatal(err) } defer l.Close() for { c, err := l.Accept() if err != nil { log.Print(err) break } s, err := proto.Dial() if err != nil { log.Print(err) c.Close() break } go proxy(c, s, "c->s") go proxy(s, c, "s->c") } }
func main() { flag.Usage = func() { fmt.Fprintf(os.Stderr, "usage: %s <font file>\n", os.Args[0]) flag.PrintDefaults() } flag.Parse() if flag.NArg() != 1 { flag.Usage() os.Exit(2) } fontFile, err := os.Open(flag.Arg(0)) if err != nil { fmt.Fprint(os.Stderr, "Error opening font file: %s", err) os.Exit(1) } defer fontFile.Close() fontData, err := ioutil.ReadAll(fontFile) if err != nil { fmt.Fprint(os.Stderr, "Error reading font: %s", err) } fn, err := freetype.ParseFont(fontData) if err != nil { fmt.Fprint(os.Stderr, "Error reading font: %s", err) } ctx := freetype.NewContext() ctx.SetDPI(108) ctx.SetFont(fn) ctx.SetFontSize(*size) ctx.SetSrc(image.Black) pt := freetype.Pt(4, 2+int(ctx.PointToFix32(*size)>>8)) conn, err := proto.Dial() if err != nil { fmt.Fprint(os.Stderr, "Error: %s\n", err) os.Exit(1) } defer conn.Close() c, err := newClock(conn, int32(*width), int32(*height), ctx, pt, *format) ticker := time.Tick(*tickDuration) wlMsg := make(chan *proto.Message) wlErr := make(chan error, 1) barrier := make(chan bool) go func() { for { msg, err := conn.ReadMessage() if err != nil { wlErr <- err close(wlMsg) close(wlErr) return } wlMsg <- msg <-barrier } }() c.Print() c.Tick(time.Now()) mainloop: for { select { case t := <-ticker: if err = c.Tick(t); err != nil { break mainloop } case msg := <-wlMsg: if err = conn.Dispatch(msg); err != nil { break mainloop } barrier <- true case err = <-wlErr: break mainloop } } if err != nil { fmt.Fprintf(os.Stderr, "Error: %s\n", err) os.Exit(1) } }