code: func attachCallback(xu *xgbutil.XUtil, evtype int, win xproto.Window,
  	fun xgbutil.Callback) {
  
  	xu.CallbacksLck.Lock()
  	defer xu.CallbacksLck.Unlock()
  
  	if _, ok := xu.Callbacks[evtype]; !ok {
  		xu.Callbacks[evtype] = make(map[xproto.Window][]xgbutil.Callback, 20)
  	}
  	if _, ok := xu.Callbacks[evtype][win]; !ok {
  		xu.Callbacks[evtype][win] = make([]xgbutil.Callback, 0)
  	}
  
  	// COW
  	newCallbacks := make([]xgbutil.Callback, len(xu.Callbacks[evtype][win]))
  	copy(newCallbacks, xu.Callbacks[evtype][win])
  	newCallbacks = append(newCallbacks, fun)
  	xu.Callbacks[evtype][win] = newCallbacks
  }
docs: // attachCallback associates a (event, window) tuple with an event.
  // Use copy on write since we run callbacks *a lot* more than attaching them.
  // (The copy on write only applies to the slice of callbacks rather than
  // the map itself, since the initial allocation is guaranteed to come before
  // any use of it.)