示例#1
0
文件: xinit.go 项目: minusnine/taowm
func initDesktop(xScreen *xp.ScreenInfo) {
	xFont, err := xp.NewFontId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	xCursor, err := xp.NewCursorId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	err = xp.OpenFontChecked(xConn, xFont, uint16(len("cursor")), "cursor").Check()
	if err != nil {
		log.Fatal(err)
	}
	const xcLeftPtr = 68 // XC_left_ptr from cursorfont.h.
	err = xp.CreateGlyphCursorChecked(
		xConn, xCursor, xFont, xFont, xcLeftPtr, xcLeftPtr+1,
		0xffff, 0xffff, 0xffff, 0, 0, 0).Check()
	if err != nil {
		log.Fatal(err)
	}
	err = xp.CloseFontChecked(xConn, xFont).Check()
	if err != nil {
		log.Fatal(err)
	}

	desktopXWin, err = xp.NewWindowId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	desktopXGC, err = xp.NewGcontextId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	desktopWidth = xScreen.WidthInPixels
	desktopHeight = xScreen.HeightInPixels

	if err := xp.CreateWindowChecked(
		xConn, xScreen.RootDepth, desktopXWin, xScreen.Root,
		0, 0, desktopWidth, desktopHeight, 0,
		xp.WindowClassInputOutput,
		xScreen.RootVisual,
		xp.CwOverrideRedirect|xp.CwEventMask,
		[]uint32{
			1,
			xp.EventMaskExposure,
		},
	).Check(); err != nil {
		log.Fatal(err)
	}

	if len(xSettings) != 0 {
		initXSettings()
	}

	if err := xp.ConfigureWindowChecked(
		xConn,
		desktopXWin,
		xp.ConfigWindowStackMode,
		[]uint32{
			xp.StackModeBelow,
		},
	).Check(); err != nil {
		log.Fatal(err)
	}

	if err := xp.ChangeWindowAttributesChecked(
		xConn,
		desktopXWin,
		xp.CwBackPixel|xp.CwCursor,
		[]uint32{
			xScreen.BlackPixel,
			uint32(xCursor),
		},
	).Check(); err != nil {
		log.Fatal(err)
	}

	if err := xp.CreateGCChecked(
		xConn,
		desktopXGC,
		xp.Drawable(xScreen.Root),
		0,
		nil,
	).Check(); err != nil {
		log.Fatal(err)
	}

	if err := xp.MapWindowChecked(xConn, desktopXWin).Check(); err != nil {
		log.Fatal(err)
	}
}
示例#2
0
文件: window.go 项目: lucas8/notifier
func loadGC(name string, c *xgb.Conn, scr *xproto.ScreenInfo) error {
	var gc gcontext

	/* Foreground GC */
	id, err := xproto.NewGcontextId(c)
	if err != nil {
		return err
	}
	var mask uint32 = xproto.GcForeground | xproto.GcBackground |
		xproto.GcLineWidth | xproto.GcFont
	values := defaultGCValues(c)
	{
		cl, e := config.String(name + ".gc.fg")
		if e == nil {
			values[0], e = openColor(c, scr, readColor(cl))
			if e != nil {
				return e
			}
		}
		cl, e = config.String(name + ".gc.bg")
		if e == nil {
			values[1], e = openColor(c, scr, readColor(cl))
			if e != nil {
				return e
			}
		}
		wd, e := config.Int(name + ".gc.width")
		if e == nil {
			values[2] = uint32(wd)
		}
		cl, e = config.String(name + ".gc.font")
		if e == nil {
			fn, e := openFont(c, cl)
			if e != nil {
				return e
			}
			values[3] = uint32(fn)
		}
	}
	err = xproto.CreateGCChecked(c, id, xproto.Drawable(scr.Root), mask, values).Check()
	if err != nil {
		return err
	}
	gc.fg = id
	gc.font = xproto.Font(values[3])
	gc.border = values[2]

	/* Query the font height */
	{
		rep, e := xproto.QueryFont(c, xproto.Fontable(gc.font)).Reply()
		if e != nil {
			return e
		}
		gc.fontHeight = uint32(rep.FontAscent) + uint32(rep.FontDescent)
		gc.fontUp = uint32(rep.FontAscent)
	}

	/* Background GC */
	id, err = xproto.NewGcontextId(c)
	if err != nil {
		return err
	}
	mask = xproto.GcForeground | xproto.GcBackground | xproto.GcLineWidth
	values[0], values[1] = values[1], values[0]
	err = xproto.CreateGCChecked(c, id, xproto.Drawable(scr.Root), mask, values).Check()
	if err != nil {
		return err
	}
	gc.bg = id

	/* Border GC */
	id, err = xproto.NewGcontextId(c)
	if err != nil {
		return err
	}
	{
		cl, e := config.String(name + ".gc.bc")
		if e == nil {
			values[0], e = openColor(c, scr, readColor(cl))
			if e != nil {
				return e
			}
		} else {
			values[0] = defaultgc.bc
		}
	}
	values[1] = values[0]
	err = xproto.CreateGCChecked(c, id, xproto.Drawable(scr.Root), mask, values).Check()
	if err != nil {
		return err
	}
	gc.bc = id

	/* Width */
	{
		wd, e := config.Int(name + ".width")
		if e == nil {
			gc.width = uint32(wd)
		} else {
			gc.width = defaultgc.width
		}
	}

	ctxs[name] = &gc
	return nil
}