Exemplo n.º 1
0
func Open() (*Fifo, error) {
	var pipe Fifo
	pipe.path = defaultPath
	if config.Has("global.fifo") {
		pipe.path, _ = config.String("config.fifo")
	}

	if _, err := os.Stat(pipe.path); err == nil {
		err = os.Remove(pipe.path)
		if err != nil {
			return nil, err
		}
	}

	if err := syscall.Mkfifo(pipe.path, 0777); err != nil {
		return nil, err
	}

	fd, err := syscall.Open(pipe.path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0777)
	if err != nil {
		return nil, err
	}

	pipe.fd = fdReader(fd)
	pipe.rd = bufio.NewReader(pipe.fd)
	pipe.cmds = make([]Command, 0, 5)
	return &pipe, nil
}
Exemplo n.º 2
0
func loadGCS(c *xgb.Conn, scr *xproto.ScreenInfo) error {
	if !config.Has("global.list") {
		return InvalidConfig("no global.list")
	}
	err := loadDefaultGC(c, scr)
	if err != nil {
		return err
	}

	list, _ := config.String("global.list")
	entries := strings.Split(list, ",")
	for _, entry := range entries {
		err = loadGC(entry, c, scr)
		if err != nil {
			/* TODO Clean previously loaded gcs */
			return err
		}
	}
	return nil
}
Exemplo n.º 3
0
func Open(c *xgb.Conn) (*Queue, error) {
	var q Queue
	q.conn = c
	q.scrs = make([]*notif, screens.Count())

	q.gravity = grTopRight
	if gr, err := config.String("global.gravity"); err == nil {
		switch gr {
		case "top_left":
			q.gravity = grTopLeft
		case "top_right":
			q.gravity = grTopRight
		case "bottom_right":
			q.gravity = grBottomRight
		case "bottom_left":
			q.gravity = grBottomLeft
		}
	}

	q.vertPad = 15
	if nb, err := config.Int("global.padding.vert"); err == nil {
		q.vertPad = uint32(nb)
	}

	q.horiPad = 15
	if nb, err := config.Int("global.padding.hori"); err == nil {
		q.horiPad = uint32(nb)
	}

	q.space = 15
	if nb, err := config.Int("global.padding.space"); err == nil {
		q.space = uint32(nb)
	}

	q.mid = 0
	return &q, nil
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
func loadDefaultGC(c *xgb.Conn, scr *xproto.ScreenInfo) error {
	var font string
	if config.Has("global.gc.font") {
		font, _ = config.String("global.gc.font")
	} else {
		font = defaultFont
	}
	fnt, err := openFont(c, font)
	if err != nil {
		return err
	}
	defaultgc.font = uint32(fnt)

	if config.Has("global.width") {
		wd, _ := config.Int("global.width")
		defaultgc.width = uint32(wd)
	} else {
		defaultgc.width = 500
	}

	if config.Has("global.gc.width") {
		wd, _ := config.Int("global.gc.width")
		defaultgc.border = uint32(wd)
	} else {
		defaultgc.border = 5
	}

	var cl color
	if config.Has("global.gc.fg") {
		str, _ := config.String("global.gc.fg")
		cl = readColor(str)
	} else {
		cl = color{255, 255, 255}
	}
	defaultgc.fg, err = openColor(c, scr, cl)
	if err != nil {
		return err
	}

	if config.Has("global.gc.bg") {
		str, _ := config.String("global.gc.bg")
		cl = readColor(str)
	} else {
		cl = color{0, 0, 0}
	}
	defaultgc.bg, err = openColor(c, scr, cl)
	if err != nil {
		return err
	}

	if config.Has("global.gc.bc") {
		str, _ := config.String("global.gc.bc")
		cl = readColor(str)
	} else {
		cl = color{255, 255, 255}
	}
	defaultgc.bc, err = openColor(c, scr, cl)
	if err != nil {
		return err
	}
	return nil
}