summaryrefslogtreecommitdiff
path: root/uitask_unix.go
blob: 67d815ef42bd7bb38c26795f8c2b045292265f04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// +build !windows,!darwin,!plan9

// 16 february 2014
//package ui
package main

import (
	"fmt"
	"runtime"
)

var uitask chan func()

func ui(initDone chan error) {
	runtime.LockOSThread()

	uitask = make(chan func())
	if gtk_init() != true {
		initDone <- fmt.Errorf("gtk_init failed (reason unknown; TODO)")
		return
	}
	initDone <- nil

	// thanks to tristan in irc.gimp.net/#gtk
	gdk_threads_add_idle(func() bool {
		select {
		case f := <-uitask:
			f()
		default:		// do not block
		}
		return true	// don't destroy the callback
	})
	gtk_main()
}

// temporary
func MsgBox(string, string, ...interface{}) {}
func MsgBoxError(title string, text string, args ...interface{}) {panic(title+"\n"+fmt.Sprintf(text,args...))}