当前位置: 首页>>代码示例>>Golang>>正文


Golang XUtil.Setup方法代码示例

本文整理汇总了Golang中github.com/BurntSushi/xgbutil.XUtil.Setup方法的典型用法代码示例。如果您正苦于以下问题:Golang XUtil.Setup方法的具体用法?Golang XUtil.Setup怎么用?Golang XUtil.Setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/BurntSushi/xgbutil.XUtil的用法示例。


在下文中一共展示了XUtil.Setup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetFormat

// GetFormat searches SetupInfo for a Format matching the depth provided.
func GetFormat(X *xgbutil.XUtil, depth byte) *xproto.Format {
	for _, pixForm := range X.Setup().PixmapFormats {
		if pixForm.Depth == depth {
			return &pixForm
		}
	}
	return nil
}
开发者ID:JessonChan,项目名称:xgbutil,代码行数:9,代码来源:new.go

示例2: checkCompatibility

// checkCompatibility reads info in the X setup info struct and emits
// messages to stderr if they don't correspond to values that xgraphics
// supports.
// The idea is that in the future, we'll support more values.
// The real reason for checkCompatibility is to make debugging easier. Without
// it, if the values weren't what we'd expect, we'd see garbled images in the
// best case, and probably BadLength errors in the worst case.
func checkCompatibility(X *xgbutil.XUtil) {
	s := X.Setup()
	scrn := X.Screen()
	failed := false

	if s.ImageByteOrder != xproto.ImageOrderLSBFirst {
		log.Printf("Your X server uses MSB image byte order. Unfortunately, " +
			"xgraphics currently requires LSB image byte order. You may see " +
			"weird things. Please report this.")
		failed = true
	}
	if s.BitmapFormatBitOrder != xproto.ImageOrderLSBFirst {
		log.Printf("Your X server uses MSB bitmap bit order. Unfortunately, " +
			"xgraphics currently requires LSB bitmap bit order. If you " +
			"aren't using X bitmaps, you should be able to proceed normally. " +
			"Please report this.")
		failed = true
	}
	if s.BitmapFormatScanlineUnit != 32 {
		log.Printf("xgraphics expects that the scanline unit is set to 32, "+
			"but your X server has it set to '%d'. "+
			"Namely, xgraphics hasn't been tested on other values. Things "+
			"may still work. Particularly, if you aren't using X bitmaps, "+
			"you should be completely unaffected. Please report this.",
			s.BitmapFormatScanlineUnit)
		failed = true
	}
	if scrn.RootDepth != 24 {
		log.Printf("xgraphics expects that the root window has a depth of 24, "+
			"but yours has depth '%d'. Its possible things will still work "+
			"if your value is 32, but will be unlikely to work with values "+
			"less than 24. Please report this.", scrn.RootDepth)
		failed = true
	}

	// Look for the default format for pixmaps and make sure bits per pixel
	// is 32.
	format := xgraphics.GetFormat(X, scrn.RootDepth)
	if format.BitsPerPixel != 32 {
		log.Printf("xgraphics expects that the bits per pixel for the root "+
			"window depth is 32. On your system, the root depth is %d and "+
			"the bits per pixel is %d. Things will most certainly not work. "+
			"Please report this.",
			scrn.RootDepth, format.BitsPerPixel)
		failed = true
	}

	// Give instructions on reporting the issue.
	if failed {
		log.Printf("Please report the aforementioned error message(s) at " +
			"https://github.com/BurntSushi/xgbutil. Please also include the " +
			"entire output of the `xdpyinfo` command in your report. Thanks!")
	} else {
		log.Printf("No compatibility issues detected.")
	}
}
开发者ID:auroralaboratories,项目名称:corona-api,代码行数:63,代码来源:main.go

示例3: minMaxKeycodeGet

// minMaxKeycodeGet a simple accessor to the X setup info to return the
// minimum and maximum keycodes. They are typically 8 and 255, respectively.
func minMaxKeycodeGet(xu *xgbutil.XUtil) (xproto.Keycode, xproto.Keycode) {
	return xu.Setup().MinKeycode, xu.Setup().MaxKeycode
}
开发者ID:droundy,项目名称:xgbutil,代码行数:5,代码来源:keybind.go

示例4: readDrawableData

// readDrawableData uses Format information to read data from an X pixmap
// into an xgraphics.Image.
// readPixmapData does not take into account all information possible to read
// X pixmaps and bitmaps. Of particular note is bit order/byte order.
func readDrawableData(X *xgbutil.XUtil, ximg *Image, did xproto.Drawable,
	imgData *xproto.GetImageReply, width, height int) error {

	format := GetFormat(X, imgData.Depth)
	if format == nil {
		return fmt.Errorf("Could not find valid format for pixmap %d "+
			"with depth %d", did, imgData.Depth)
	}

	switch format.Depth {
	case 1: // We read bitmaps in as alpha masks.
		if format.BitsPerPixel != 1 {
			return fmt.Errorf("The image returned for pixmap id %d with "+
				"depth %d has an unsupported value for bits-per-pixel: %d",
				did, format.Depth, format.BitsPerPixel)
		}

		// Calculate the padded width of our image data.
		pad := int(X.Setup().BitmapFormatScanlinePad)
		paddedWidth := width
		if width%pad != 0 {
			paddedWidth = width + pad - (width % pad)
		}

		// Process one scanline at a time. Each 'y' represents a
		// single scanline.
		for y := 0; y < height; y++ {
			// Each scanline has length 'width' padded to
			// BitmapFormatScanlinePad, which is found in the X setup info.
			// 'i' is the index to the starting byte of the yth scanline.
			i := y * paddedWidth / 8
			for x := 0; x < width; x++ {
				b := imgData.Data[i+x/8] >> uint(x%8)
				if b&1 > 0 { // opaque
					ximg.Set(x, y, BGRA{0x0, 0x0, 0x0, 0xff})
				} else { // transparent
					ximg.Set(x, y, BGRA{0xff, 0xff, 0xff, 0x0})
				}
			}
		}
	case 24:
		if format.BitsPerPixel != 24 && format.BitsPerPixel != 32 {
			return fmt.Errorf("The image returned for pixmap id %d has "+
				"an unsupported value for bits-per-pixel: %d",
				did, format.BitsPerPixel)
		}
		bytesPer := int(format.BitsPerPixel) / 8
		var i int
		ximg.For(func(x, y int) BGRA {
			i = y*width*bytesPer + x*bytesPer
			return BGRA{
				B: imgData.Data[i],
				G: imgData.Data[i+1],
				R: imgData.Data[i+2],
				A: 0xff,
			}
		})
	default:
		return fmt.Errorf("The image returned for pixmap id %d has an "+
			"unsupported value for depth: %d", did, format.Depth)
	}

	return nil
}
开发者ID:JessonChan,项目名称:xgbutil,代码行数:68,代码来源:new.go


注:本文中的github.com/BurntSushi/xgbutil.XUtil.Setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。