當前位置: 首頁>>代碼示例>>Golang>>正文


Golang xwindow.Create函數代碼示例

本文整理匯總了Golang中github.com/BurntSushi/xgbutil/xwindow.Create函數的典型用法代碼示例。如果您正苦於以下問題:Golang Create函數的具體用法?Golang Create怎麽用?Golang Create使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Create函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: newCycleItem

// newCycleItem sets up the windows and images associated with a particular
// CycleChoice. This is the meat of (*Cycle).AddItem.
func newCycleItem(cycle *Cycle, choice CycleChoice) *CycleItem {
	ci := &CycleItem{
		cycle:  cycle,
		choice: choice,
	}
	t := ci.cycle.theme

	ci.win = xwindow.Must(xwindow.Create(ci.cycle.X, ci.cycle.win.Id))
	ci.active = xwindow.Must(xwindow.Create(ci.cycle.X, ci.win.Id))
	ci.inactive = xwindow.Must(xwindow.Create(ci.cycle.X, ci.win.Id))
	ci.text = xwindow.Must(xwindow.Create(ci.cycle.X, ci.cycle.win.Id))

	ci.active.MoveResize(t.IconBorderSize, t.IconBorderSize,
		t.IconSize, t.IconSize)
	ci.inactive.MoveResize(t.IconBorderSize, t.IconBorderSize,
		t.IconSize, t.IconSize)
	ci.text.MoveResize(t.BorderSize+t.Padding, t.BorderSize+t.Padding,
		1, 1)

	// If the text overruns, make sure it's below the borders.
	ci.text.StackSibling(ci.cycle.bRht.Id, xproto.StackModeBelow)

	ci.UpdateImage()
	ci.UpdateText()

	ci.unhighlight()

	return ci
}
開發者ID:cshapeshifter,項目名稱:wingo,代碼行數:31,代碼來源:cycle_item.go

示例2: initPopup

func (ct *CommandTray) initPopup() {
	var err error

	ct.popup, err = xwindow.Create(ct.X, ct.X.RootWin())
	utils.FailMeMaybe(err)

	ct.pu_img.For(func(x, y int) xgraphics.BGRA {
		if y%ct.Height == ct.Height-1 || x == 0 || x == ct.Width-1 {
			return xgraphics.BGRA{128, 128, 128, 255}
		}
		return xgraphics.BGRA{64, 64, 64, 255}
	})

	utils.FailMeMaybe(ewmh.WmDesktopSet(ct.X, ct.popup.Id, 0xffffffff))

	utils.FailMeMaybe(ewmh.WmWindowTypeSet(ct.X, ct.popup.Id, []string{
		"_NET_WM_WINDOW_TYPE_DOCK",
	}))

	utils.FailMeMaybe(ct.popup.Listen(xproto.EventMaskKeyPress | xproto.EventMaskStructureNotify))

	ct.popup.Resize(ct.Width, ct.Height*10)
	ct.popup.Move(ct.Position, ct.Height)

	ct.pu_img.XSurfaceSet(ct.popup.Id)
	ct.pu_img.XDraw()
	ct.pu_img.XPaint(ct.popup.Id)
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:28,代碼來源:commandtray.go

示例3: NewInput

// NewInput constructs Input values. It needs an X connection, a parent window,
// the width of the input box, and theme information related for the font
// and background. Padding separating the text and the edges of the window
// may also be specified.
//
// While NewInput returns an *Input, a Input value also has an xwindow.Window
// value embedded into it. Thus, an Input can also be treated as a normal
// window on which you can assign callbacks, close, destroy, etc.
//
// As with all windows, the Input window should be destroyed when it is no
// longer in used.
func NewInput(X *xgbutil.XUtil, parent xproto.Window, width int, padding int,
	font *truetype.Font, fontSize float64,
	fontColor, bgColor render.Color) *Input {

	_, height := xgraphics.TextMaxExtents(font, fontSize, "M")
	height += misc.TextBreathe

	width, height = width+2*padding, height+2*padding

	img := xgraphics.New(X, image.Rect(0, 0, width, height))
	win := xwindow.Must(xwindow.Create(X, parent))
	win.Listen(xproto.EventMaskKeyPress)
	win.Resize(width, height)

	ti := &Input{
		Window:    win,
		img:       img,
		Text:      make([]rune, 0, 50),
		font:      font,
		fontSize:  fontSize,
		fontColor: fontColor,
		bgColor:   bgColor,
		padding:   padding,
	}

	ti.Render()
	return ti
}
開發者ID:dlintw,項目名稱:wingo,代碼行數:39,代碼來源:input.go

示例4: newSelectItem

func newSelectItem(slct *Select, choice SelectChoice) *SelectItem {
	si := &SelectItem{
		slct:   slct,
		choice: choice,
	}

	si.regular = xwindow.Must(xwindow.Create(si.slct.X, si.slct.win.Id))
	si.highlighted = xwindow.Must(xwindow.Create(si.slct.X, si.slct.win.Id))

	// If the text overruns, make sure it's below the borders.
	si.regular.StackSibling(si.slct.bRht.Id, xproto.StackModeBelow)
	si.highlighted.StackSibling(si.slct.bRht.Id, xproto.StackModeBelow)

	si.UpdateText()

	return si
}
開發者ID:flying99999,項目名稱:wingo,代碼行數:17,代碼來源:select_item.go

示例5: NewInput

func NewInput(X *xgbutil.XUtil, theme *InputTheme, config InputConfig) *Input {
	input := &Input{
		X:       X,
		theme:   theme,
		config:  config,
		showing: false,
		do:      nil,
		history: make([]string, 0, 100),
	}

	// Create all windows used for the base of the input prompt.
	cwin := func(p xproto.Window) *xwindow.Window {
		return xwindow.Must(xwindow.Create(X, p))
	}
	input.win = cwin(X.RootWin())
	input.label = cwin(input.win.Id)
	input.input = text.NewInput(X, input.win.Id, 1000, theme.Padding,
		theme.Font, theme.FontSize, theme.FontColor, theme.BgColor)
	input.bInp = cwin(input.win.Id)
	input.bTop, input.bBot = cwin(input.win.Id), cwin(input.win.Id)
	input.bLft, input.bRht = cwin(input.win.Id), cwin(input.win.Id)

	// Make the top-level window override redirect so the window manager
	// doesn't mess with us.
	input.win.Change(xproto.CwOverrideRedirect, 1)
	input.win.Listen(xproto.EventMaskFocusChange)
	input.input.Listen(xproto.EventMaskKeyPress)

	// Colorize the windows.
	cclr := func(w *xwindow.Window, clr render.Color) {
		w.Change(xproto.CwBackPixel, clr.Uint32())
	}
	cclr(input.win, input.theme.BgColor)
	cclr(input.bInp, input.theme.BorderColor)
	cclr(input.bTop, input.theme.BorderColor)
	cclr(input.bBot, input.theme.BorderColor)
	cclr(input.bLft, input.theme.BorderColor)
	cclr(input.bRht, input.theme.BorderColor)

	// Map the sub-windows once.
	input.label.Map()
	input.input.Map()
	input.bInp.Map()
	input.bTop.Map()
	input.bBot.Map()
	input.bLft.Map()
	input.bRht.Map()

	// Connect the key response handler.
	// The handler is responsible for tab completion and quitting if the
	// cancel key has been pressed.
	input.keyResponse().Connect(X, input.input.Id)
	input.focusResponse().Connect(X, input.win.Id)

	return input
}
開發者ID:Pursuit92,項目名稱:wingo,代碼行數:56,代碼來源:input.go

示例6: Window

// Window is a convenience function for painting the provided
// Image value to a new window, destroying the pixmap created by that image,
// and returning the window value.
// The window is sized to the dimensions of the image.
func (im *Image) Window(parent xproto.Window) *xwindow.Window {
	win := xwindow.Must(xwindow.Create(im.X, parent))
	win.Resize(im.Bounds().Dx(), im.Bounds().Dy())

	im.XSurfaceSet(win.Id)
	im.XDraw()
	im.XPaint(win.Id)
	im.Destroy()

	return win
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:15,代碼來源:image.go

示例7: NewCycle

// NewCycle creates a new prompt. As many prompts as you want can be created,
// and they could even technically be shown simultaneously so long as at most
// one of them is using a grab. (The grab will fail for the others and they
// will not be shown.)
//
// CycleTheme and CycleConfig values can either use DefaultCycle{Theme,Config}
// values found in this package, or custom ones can be created using
// composite literals.
func NewCycle(X *xgbutil.XUtil, theme *CycleTheme, config CycleConfig) *Cycle {
	cycle := &Cycle{
		X:        X,
		theme:    theme,
		config:   config,
		showing:  false,
		selected: -1,
		grabMods: 0,
	}

	// Create all windows used for the base of the cycle prompt.
	// This obviously doesn't include the windows representing the items.
	cwin := func(p xproto.Window) *xwindow.Window {
		return xwindow.Must(xwindow.Create(X, p))
	}
	cycle.win = cwin(X.RootWin())
	cycle.bTop, cycle.bBot = cwin(cycle.win.Id), cwin(cycle.win.Id)
	cycle.bLft, cycle.bRht = cwin(cycle.win.Id), cwin(cycle.win.Id)

	// Make the top-level window override redirect so the window manager
	// doesn't mess with us.
	cycle.win.Change(xproto.CwOverrideRedirect, 1)

	// Set the colors of each window.
	cclr := func(w *xwindow.Window, clr render.Color) {
		w.Change(xproto.CwBackPixel, uint32(clr.Int()))
	}
	cclr(cycle.win, cycle.theme.BgColor)
	cclr(cycle.bTop, cycle.theme.BorderColor)
	cclr(cycle.bBot, cycle.theme.BorderColor)
	cclr(cycle.bLft, cycle.theme.BorderColor)
	cclr(cycle.bRht, cycle.theme.BorderColor)

	// Map the sub-windows once. (Real mapping only happens when
	// cycle.win is mapped.)
	cycle.bTop.Map()
	cycle.bBot.Map()
	cycle.bLft.Map()
	cycle.bRht.Map()

	// Connect the key response handler (i.e., the alt-tab'ing, canceling, etc.)
	cycle.keyResponse().Connect(X, X.Dummy())

	// Guess the maximum font height.
	_, cycle.fontHeight = xgraphics.TextMaxExtents(
		cycle.theme.Font, cycle.theme.FontSize, "A")
	cycle.fontHeight += misc.TextBreathe

	return cycle
}
開發者ID:yannicklm,項目名稱:wingo,代碼行數:58,代碼來源:cycle.go

示例8: NewMessage

func NewMessage(X *xgbutil.XUtil,
	theme *MessageTheme, config MessageConfig) *Message {

	msg := &Message{
		X:             X,
		theme:         theme,
		config:        config,
		showing:       false,
		duration:      0,
		hidden:        nil,
		cancelTimeout: make(chan struct{}, 0),
		textWins:      make([]*xwindow.Window, 0),
	}

	// Create all windows used for the base of the message prompt.
	cwin := func(p xproto.Window) *xwindow.Window {
		return xwindow.Must(xwindow.Create(X, p))
	}
	msg.win = cwin(X.RootWin())
	msg.bTop, msg.bBot = cwin(msg.win.Id), cwin(msg.win.Id)
	msg.bLft, msg.bRht = cwin(msg.win.Id), cwin(msg.win.Id)

	// Make the top-level window override redirect so the window manager
	// doesn't mess with us.
	msg.win.Change(xproto.CwOverrideRedirect, 1)
	msg.win.Listen(xproto.EventMaskFocusChange)
	msg.bTop.Listen(xproto.EventMaskKeyPress)

	// Colorize the windows.
	cclr := func(w *xwindow.Window, clr render.Color) {
		w.Change(xproto.CwBackPixel, clr.Uint32())
	}
	cclr(msg.win, msg.theme.BgColor)
	cclr(msg.bTop, msg.theme.BorderColor)
	cclr(msg.bBot, msg.theme.BorderColor)
	cclr(msg.bLft, msg.theme.BorderColor)
	cclr(msg.bRht, msg.theme.BorderColor)

	// Map the sub-windows once.
	msg.bTop.Map()
	msg.bBot.Map()
	msg.bLft.Map()
	msg.bRht.Map()

	msg.keyResponse().Connect(X, msg.bTop.Id)
	msg.focusResponse().Connect(X, msg.win.Id)

	return msg
}
開發者ID:flying99999,項目名稱:wingo,代碼行數:49,代碼來源:message.go

示例9: Init

func (ct *CommandTray) Init() {
	var err error

	ct.img = xgraphics.New(ct.X, image.Rect(0, 0, ct.Width, ct.Height))
	ct.pu_img = xgraphics.New(ct.X, image.Rect(0, 0, ct.Width, ct.Height*10))

	ct.window, err = xwindow.Create(ct.X, ct.Parent.Id)
	utils.FailMeMaybe(err)

	utils.FailMeMaybe(ct.img.XSurfaceSet(ct.window.Id))

	ct.window.Move(ct.Position, 0)
	ct.window.Resize(ct.Width, ct.Height)
	ct.window.Map()
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:15,代碼來源:commandtray.go

示例10: newSelectGroupItem

func newSelectGroupItem(slct *Select, group SelectGroup) *SelectGroupItem {
	si := &SelectGroupItem{
		slct:  slct,
		group: group,
	}

	si.win = xwindow.Must(xwindow.Create(si.slct.X, si.slct.win.Id))
	si.win.Change(xproto.CwBackPixel, si.slct.theme.BgColor.Uint32())

	// If the text overruns, make sure it's below the borders.
	si.win.StackSibling(si.slct.bRht.Id, xproto.StackModeBelow)

	si.UpdateText()

	return si
}
開發者ID:pascience,項目名稱:foci,代碼行數:16,代碼來源:select_group.go

示例11: Init

func (c *Clock) Init() {
	var err error
	c.img = xgraphics.New(c.X, image.Rect(0, 0, c.Width, c.Height))
	c.window, err = xwindow.Create(c.X, c.Parent.Id)
	utils.FailMeMaybe(err)

	c.window.Resize(c.Width, c.Height)
	c.window.Move(c.Position, 0)
	c.img.XSurfaceSet(c.window.Id)

	c.window.Map()

	c.Draw()

	go c.tickTock()
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:16,代碼來源:clock.go

示例12: Init

func (sb *StatusBar) Init() {
	sb.img = xgraphics.New(sb.X, image.Rect(0, 0, sb.Width, sb.Height))
	var err error

	sb.window, err = xwindow.Create(sb.X, sb.Parent.Id)
	utils.FailMeMaybe(err)

	sb.window.Move(sb.Position, 0)
	sb.window.Resize(sb.Width, sb.Height)
	sb.window.Map()

	sb.img.XSurfaceSet(sb.window.Id)

	utils.FailMeMaybe(sb.initTray())

	sb.Draw()
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:17,代碼來源:statbar.go

示例13: main

func main() {
	X, err := xgbutil.NewConn()
	failMeMaybe(err)

	tray, err := NewSystemTray(X)
	failMeMaybe(err)

	hdlr := &Handler{
		X: X,
	}

	hdlr.Window, err = xwindow.Create(X, X.RootWin())
	failMeMaybe(err)

	hdlr.Window.Move(0, 24)
	hdlr.Window.Map()

	tray.Handler = hdlr

	xevent.Main(X)
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:21,代碼來源:main.go

示例14: Init

func (t *Tracker) Init() {
	var err error
	t.img = xgraphics.New(t.X, image.Rect(0, 0, t.Size, t.Size))
	t.window, err = xwindow.Create(t.X, t.Parent.Id)
	utils.FailMeMaybe(err)

	t.window.Resize(t.Size, t.Size)
	t.window.Move(t.Position, 0)

	t.img.XSurfaceSet(t.window.Id)

	t.window.Map()

	t.stopMe = true

	l := startup.Listener{
		X:         t.X,
		Callbacks: t,
	}

	l.Initialize()

	t.Draw()
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:24,代碼來源:tracker.go

示例15: main

func main() {
	// Signal Handling.

	sigChan := make(chan os.Signal)

	signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)

	paths := basedir.Paths{
		XDGSuffix:    "gobar",
		GoImportPath: "github.com/AmandaCameron/gobar/data",
	}

	file, err := paths.ConfigFile("config.wini")
	utils.FailMeMaybe(err)

	cfg := loadConfig(file) //os.Getenv("HOME") + "/.config/gobar/config.wini")

	// Load Images.

	images.Init(paths)

	// Setup the X Connection

	X, err := xgbutil.NewConn()
	utils.FailMeMaybe(err)

	win, err := xwindow.Create(X, X.RootWin())
	utils.FailMeMaybe(err)

	win.Resize(cfg.BarWidth, cfg.BarSize)

	// Setup the EWMH Stuff

	utils.FailMeMaybe(ewmh.RestackWindow(X, win.Id))

	var strut *ewmh.WmStrutPartial

	if cfg.Position == "Top" {
		strut = &ewmh.WmStrutPartial{
			Top:       uint(cfg.BarSize),
			TopStartX: 0,
			TopEndX:   uint(cfg.BarWidth),
		}

		win.Move(0, 0)
	} else if cfg.Position == "Bottom" {
		strut = &ewmh.WmStrutPartial{
			Bottom:       uint(cfg.BarSize),
			BottomStartX: 0,
			BottomEndX:   uint(cfg.BarWidth),
		}

		win.Move(0, 600-cfg.BarSize)
	} else {
		println("Invalid Position:", cfg.Position)
		os.Exit(1)
	}

	utils.FailMeMaybe(ewmh.WmStrutPartialSet(X, win.Id, strut))

	utils.FailMeMaybe(ewmh.WmWindowTypeSet(X, win.Id, []string{
		"_NET_WM_WINDOW_TYPE_DOCK",
	}))

	// Put us everywhere.
	utils.FailMeMaybe(ewmh.WmDesktopSet(X, win.Id, 0xFFFFFFFF))

	win.Map()

	keybind.Initialize(X)

	// Get the DE settings, if we can.

	xs, err := xsettings.New(X)
	if err != nil {
		// Maybe this should be an error, maybe not?
		xs = nil
	}

	// Draw the background

	bg := xgraphics.BGRA{
		R: 64,
		G: 64,
		B: 64,
		A: 255,
	}

	img := xgraphics.New(X, image.Rect(0, 0, cfg.BarWidth, cfg.BarSize))

	img.For(func(x, y int) xgraphics.BGRA {
		return bg
	})

	utils.FailMeMaybe(img.XSurfaceSet(win.Id))
	img.XDraw()
	img.XPaint(win.Id)

	// Connect to DBus

//.........這裏部分代碼省略.........
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:101,代碼來源:gobar.go


注:本文中的github.com/BurntSushi/xgbutil/xwindow.Create函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。