// findIconEwmh helps FindIcon by trying to return an ewmh-style icon that is
// closest to the preferred size specified.
338717
func findIconEwmh(X *xgbutil.XUtil, wid xproto.Window,
	width, height int) (*Image, error) {

	icons, err := ewmh.WmIconGet(X, wid)
	if err != nil {
		return nil, err
	}

	icon := FindBestEwmhIcon(width, height, icons)
	if icon == nil {
		return nil, fmt.Errorf("Could not find any _NET_WM_ICON icon.")
	}

	return NewEwmhIcon(X, icon), nil
}
461145
func (api *Client) GetEmoji() (map[string]string, error) {
	return api.GetEmojiContext(context.Background())
}
556259
func (c *Cascade) Find(m image.Image) []image.Rectangle {
	// TODO(crawshaw): Consider de-duping strategies.
	matches := []image.Rectangle{}
	w := newWindow(m)

	b := m.Bounds()
	origScale := c.Size
	for s := origScale; s.X < b.Dx() && s.Y < b.Dy(); s = s.Add(s.Div(10)) {
		// translate region and classify
		tx := image.Pt(s.X/10, 0)
		ty := image.Pt(0, s.Y/10)
		for r := image.Rect(0, 0, s.X, s.Y).Add(b.Min); r.In(b); r = r.Add(ty) {
			for r1 := r; r1.In(b); r1 = r1.Add(tx) {
				if c.classify(w.subWindow(r1)) {
					matches = append(matches, r1)
				}
			}
		}
	}
	return matches
}
178690
func CorrectWidthHeight(c *chronograf.DashboardCell) {
	if c.W < 1 {
		c.W = DefaultWidth
	}
	if c.H < 1 {
		c.H = DefaultHeight
	}
}
907221
func FindMessage(d *pb.DescriptorProto, name string) int {
	for i, x := range d.GetNestedType() {
		if x.GetName() == name {
			return i
		}
	}
	return -1
}
308216
func (t *winTray) setIcon(src string) error {
	const IMAGE_ICON = 1               // Loads an icon
	const LR_LOADFROMFILE = 0x00000010 // Loads the stand-alone image from the file
	const LR_DEFAULTSIZE = 0x00000040  // Loads default-size icon for windows(SM_CXICON x SM_CYICON) if cx, cy are set to zero
	const NIF_ICON = 0x00000002

	// Save and reuse handles of loaded images
	h, ok := t.loadedImages[src]
	if !ok {
		srcPtr, err := windows.UTF16PtrFromString(src)
		if err != nil {
			return err
		}
		res, _, err := pLoadImage.Call(
			0,
			uintptr(unsafe.Pointer(srcPtr)),
			IMAGE_ICON,
			0,
			0,
			LR_LOADFROMFILE|LR_DEFAULTSIZE,
		)
		if res == 0 {
			return err
		}
		h = windows.Handle(res)
		t.loadedImages[src] = h
	}

	t.nid.Icon = h
	t.nid.Flags |= NIF_ICON
	t.nid.Size = uint32(unsafe.Sizeof(*t.nid))

	return t.nid.modify()
}
1209107
func WmIconGeometryGet(xu *xgbutil.XUtil,
	win xproto.Window) (*WmIconGeometry, error) {

	geom, err := xprop.PropValNums(xprop.GetProperty(xu, win,
		"_NET_WM_ICON_GEOMETRY"))
	if err != nil {
		return nil, err
	}

	return &WmIconGeometry{
		X:      int(geom[0]),
		Y:      int(geom[1]),
		Width:  geom[2],
		Height: geom[3],
	}, nil
}
562359
func findDiskWWIDs(wwid string, io ioHandler, deviceUtil volumeutil.DeviceUtil) (string, string) {
	// Example wwid format:
	//   3600508b400105e210000900000490000
	//   <VENDOR NAME> <IDENTIFIER NUMBER>
	// Example of symlink under by-id:
	//   /dev/by-id/scsi-3600508b400105e210000900000490000
	//   /dev/by-id/scsi-<VENDOR NAME>_<IDENTIFIER NUMBER>
	// The wwid could contain white space and it will be replaced
	// underscore when wwid is exposed under /dev/by-id.

	fcPath := "scsi-" + wwid
	devID := byID
	if dirs, err := io.ReadDir(devID); err == nil {
		for _, f := range dirs {
			name := f.Name()
			if name == fcPath {
				disk, err := io.EvalSymlinks(devID + name)
				if err != nil {
					klog.V(2).Infof("fc: failed to find a corresponding disk from symlink[%s], error %v", devID+name, err)
					return "", ""
				}
				dm := deviceUtil.FindMultipathDeviceForDevice(disk)
				klog.Infof("fc: find disk: %v, dm: %v", disk, dm)
				return disk, dm
			}
		}
	}
	klog.V(2).Infof("fc: failed to find a disk [%s]", devID+fcPath)
	return "", ""
}
1330253
func FindReviewIssueByCommitItem(
	client *github.Client,
	owner string,
	repo string,
	commitSHA string,
) (*github.Issue, error) {

	// Use the first 7 chars from the commit hexsha.
	shortSHA := commitSHA[:7]

	// Commit item regexp.
	re := regexp.MustCompile(fmt.Sprintf(`[-*] \[[xX ]\] %v[:]`, shortSHA))

	// Perform the search.
	return findReviewIssue(client, owner, repo, shortSHA, "in:body", matchesBodyRe(re))
}
197766
func (m *metricMap) getMetricWithHashAndLabelValues(
	h uint64, lvs []string, curry []curriedLabelValue,
) (Metric, bool) {
	metrics, ok := m.metrics[h]
	if ok {
		if i := findMetricWithLabelValues(metrics, lvs, curry); i < len(metrics) {
			return metrics[i].metric, true
		}
	}
	return nil, false
}
344647
func (extr *ContentExtractor) GetFavicon(document *goquery.Document) string {
	favicon := ""
	document.Find("link").EachWithBreak(func(i int, s *goquery.Selection) bool {
		attr, exists := s.Attr("rel")
		if exists && strings.Contains(attr, "icon") {
			favicon, _ = s.Attr("href")
			return false
		}
		return true
	})
	return favicon
}
892814
func (f *Finder) FindImage(img string, asc string) (*types.Hash, error) {
	ensureLogger(f.Debug)

	// Check if it's an hash
	if _, err := types.NewHash(img); err == nil {
		h, err := f.getHashFromStore(img)
		if err != nil {
			return nil, err
		}
		return h, nil
	}

	d, err := DistFromImageString(img)
	if err != nil {
		return nil, err
	}

	// urls, names, paths have to be fetched, potentially remotely
	ft := (*Fetcher)(f)
	h, err := ft.FetchImage(d, img, asc)
	if err != nil {
		return nil, err
	}
	return h, nil
}
493096
func (t *Template) GetAWSAppMeshVirtualNodeWithName(name string) (*resources.AWSAppMeshVirtualNode, error) {
	if untyped, ok := t.Resources[name]; ok {
		switch resource := untyped.(type) {
		case *resources.AWSAppMeshVirtualNode:
			return resource, nil
		}
	}
	return nil, fmt.Errorf("resource %q of type AWSAppMeshVirtualNode not found", name)
}
732381
func (c *VSphereCloud) FindVMUUID(vm *string) (string, error) {
	f := find.NewFinder(c.Client.Client, true)
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	dc, err := f.Datacenter(ctx, c.Datacenter)
	if err != nil {
		return "", err
	}
	f.SetDatacenter(dc)

	vmRef, err := f.VirtualMachine(ctx, *vm)
	if err != nil {
		return "", err
	}

	var vmResult mo.VirtualMachine

	pc := property.DefaultCollector(c.Client.Client)
	err = pc.RetrieveOne(ctx, vmRef.Reference(), []string{"config.uuid"}, &vmResult)
	if err != nil {
		return "", err
	}
	glog.V(4).Infof("vm property collector result :%+v\n", vmResult)
	glog.V(3).Infof("retrieved vm uuid as %q for vm %q", vmResult.Config.Uuid, *vm)
	return vmResult.Config.Uuid, nil
}
283246
func searchHook(charmDir, hook string) (string, error) {
	hookFile := filepath.Join(charmDir, hook)
	if jujuos.HostOS() != jujuos.Windows {
		// we are not running on windows,
		// there is no need to look for suffixed hooks
		return lookPath(hookFile)
	}
	for _, suffix := range windowsSuffixOrder {
		file := fmt.Sprintf("%s%s", hookFile, suffix)
		foundHook, err := lookPath(file)
		if err != nil {
			if charmrunner.IsMissingHookError(err) {
				// look for next suffix
				continue
			}
			return "", err
		}
		return foundHook, nil
	}
	return "", charmrunner.NewMissingHookError(hook)
}
767022
func (o *Obstacle) GetXYWH() (x, y, w, h float32) {
	p := o.GetPosition()
	s := o.GetScale()
	return p.X, p.Y, s.W, s.H
}
1274200
func RetrieveIcon(destination, iconFile string) (int64, error) {
	fullFilePath := fmt.Sprintf("%s/%s", destination, iconFile)

	// Check to see if we've already gotten that icon file.  If so, use it
	// rather than getting it again.
	if _, err := os.Stat(fullFilePath); err != nil {
		response, err := http.Get(fmt.Sprintf(iconURL, iconFile))
		if err != nil {
			return 0, err
		}
		defer response.Body.Close()

		// Create the icon file
		out, err := os.Create(fullFilePath)
		if err != nil {
			return 0, err
		}
		defer out.Close()

		// Fill the empty file with the actual content
		n, err := io.Copy(out, response.Body)
		if err != nil {
			return 0, err
		}
		return n, nil
	}
	return 0, nil
}