本文整理匯總了Golang中github.com/BurntSushi/xgb.Conn.WaitForEvent方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.WaitForEvent方法的具體用法?Golang Conn.WaitForEvent怎麽用?Golang Conn.WaitForEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/BurntSushi/xgb.Conn
的用法示例。
在下文中一共展示了Conn.WaitForEvent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: start_server
func start_server(c *xgb.Conn, s *xproto.ScreenInfo, rl_execute_atom xproto.Atom) {
win, err := xproto.NewWindowId(c)
if err != nil {
panic(err)
}
// Make a window which can be communicated with
err = xproto.CreateWindowChecked(c, s.RootDepth, win, s.Root, 0, 0, 1, 1, 0, 0, 0, 0, nil).Check()
if err != nil {
panic(err)
}
err = xproto.ChangePropertyChecked(c, xproto.PropModeReplace, win,
rl_execute_atom, xproto.AtomString, 8, xproto.PropModeReplace,
[]byte("\x00")).Check()
if err != nil {
panic(err)
}
err = xproto.ChangeWindowAttributesChecked(c, win, xproto.CwEventMask, []uint32{xproto.EventMaskPropertyChange}).Check()
if err != nil {
panic(err)
}
get_execute_value := func() string {
response, err := xproto.GetProperty(c, false, win, rl_execute_atom,
xproto.GetPropertyTypeAny, 0, 1024).Reply()
if err != nil {
panic(err)
}
result := string(response.Value)
return result
}
log.Print("Ready and waiting..")
// Event loop
for {
reply, err := c.WaitForEvent()
if err != nil {
log.Panic("Error in event loop:", err)
}
switch event := reply.(type) {
case xproto.PropertyNotifyEvent:
if event.Window == win && event.Atom == rl_execute_atom {
values := strings.Split(get_execute_value(), "\x00")
run(values)
}
}
}
}
示例2: xloop
func xloop(conn *xgb.Conn, c chan types.Order) {
for {
ev, xerr := conn.WaitForEvent()
if ev == nil && xerr == nil {
c <- types.KillOrder{}
}
if ev != nil {
switch ev.(type) {
case xproto.ExposeEvent:
c <- types.RedrawOrder{}
}
}
}
}