Example #1
0
File: gtk.go Project: jwilkins/pond
func NewGTKUI() *GTKUI {
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetPosition(gtk.GTK_WIN_POS_CENTER)
	window.SetTitle("Pond")
	window.SetDefaultSize(1000, 800)

	ui := &GTKUI{
		window:  window,
		actions: make(chan interface{}, uiActionsQueueLen),
		events:  make(chan interface{}, 8),
	}
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		close(ui.events)
		for {
			if _, ok := <-ui.actions; !ok {
				break
			}
		}
		gtk.MainQuit()
	})
	if err := syscall.Pipe(ui.pipe[:]); err != nil {
		panic(err)
	}
	syscall.SetNonblock(ui.pipe[0], true)

	glib.FdWatchAdd(ui.pipe[0], glib.IOIn, func(conditions int) bool {
		ui.onAction()
		return true
	})

	return ui
}
Example #2
0
File: gtk.go Project: jwilkins/pond
func (ui *GTKUI) onAction() {
	buf := make([]byte, 8)
	for {
		n, _ := syscall.Read(ui.pipe[0], buf)
		if n < 1 {
			break
		}
	}

	for {
		select {
		case v, ok := <-ui.actions:
			if !ok {
				gtk.MainQuit()
				return
			}
			ui.handle(v)
		default:
			return
		}
	}
}