示例#1
0
文件: queue.go 项目: lucas8/notifier
/* Will run processing incoming orders from c until it is killed (return nil)
 * or a fatal error happen (return it)
 */
func (q *Queue) Run(c chan types.Order) error {
	o, ok := <-c
	for ok {
		switch ord := o.(type) {
		case types.KillOrder:
			return nil
		case types.CloseOrder:
			if ord.All {
				q.closeAllNotif()
			} else if ord.Top {
				scr := screens.Focused(q.conn)
				q.closeNotif(q.scrs[scr])
			} else {
				q.closeNotif(q.findNotifById(ord.Id))
			}
		case types.NotifOrder:
			q.openNotif(ord.Level, ord.Text, ord.Time)
		case types.RedrawOrder:
			q.redraw()
		}
		o, ok = <-c
	}
	return ClosedChannelError{}
}
示例#2
0
文件: queue.go 项目: lucas8/notifier
func (q *Queue) openNotif(lvl, txt string, time uint32) {
	/* TODO handle time */
	var not notif
	scr := screens.Focused(q.conn)
	not.onScreen = false
	not.screen = int(scr)
	not.id = q.mid
	q.mid++
	not.win, _ = window.Open(q.conn, lvl, "Notification", txt)
	not.next = nil

	if q.scrs[scr] == nil {
		not.prev = nil
		q.scrs[scr] = &not
	} else {
		p := q.scrs[scr]
		for p.next != nil {
			p = p.next
		}
		p.next = &not
		not.prev = p
	}
	q.updatePos(int(scr))
}