Example #1
0
/*
Create a new menu object.
Dispatches a call to ThrustCore to generate the object and return the new
TargetID in a reply.
*/
func NewMenu() *Menu {
	menu := Menu{}
	menuCreate := Command{
		Action:     "create",
		ObjectType: "menu",
	}
	menu.Sync = MenuSync{
		ReadyChan:        make(chan bool),
		DisplayedChan:    make(chan bool),
		ChildStableChan:  make(chan uint),
		TreeStableChan:   make(chan bool),
		ReadyQueue:       make([]*Command, 0),
		DisplayedQueue:   make([]*Command, 0),
		ChildStableQueue: make([]*ChildCommand, 0),
		TreeStableQueue:  make([]*Command, 0),
	}
	menu.ReplyHandlers = make(map[uint]func(reply CommandResponse, item *MenuItem))
	menu.SetSendChannel(connection.GetInputChannels())
	menu.WaitingResponses = append(menu.WaitingResponses, &menuCreate)
	dispatcher.RegisterHandler(menu.DispatchResponse)

	go menu.SendThread()
	menu.Send(&menuCreate)

	return &menu
}
Example #2
0
/*
Create a new EventHandler for a give event.
*/
func NewHandler(event string, fn interface{}) (ThrustEventHandler, error) {
	h := ThrustEventHandler{}
	h.Event = event
	h.Type = "event"
	err := h.SetHandleFunc(fn)
	dispatcher.RegisterHandler(h)
	return h, err
}
Example #3
0
func NewWindow(options Options) *Window {
	w := Window{}
	w.setOptions(options)
	_, sendChannel := connection.GetCommunicationChannels()

	size := options.Size
	if options.Size == (SizeHW{}) {
		size = SizeHW{
			Width:  1024,
			Height: 768,
		}
	}

	windowCreate := Command{
		Action:     "create",
		ObjectType: "window",
		Args: CommandArguments{
			RootUrl:  w.Url,
			Title:    spawn.ApplicationName,
			Size:     size,
			HasFrame: !options.HasFrame,
		},
	}
	dispatcher.RegisterHandler(w.DispatchResponse)
	if options.Session == nil {
		w.SetSendChannel(sendChannel)
		w.WaitingResponses = append(w.WaitingResponses, &windowCreate)
		w.Send(&windowCreate)
	} else {
		go func() {
			for {
				if options.Session.TargetID != 0 {
					fmt.Println("sess", options.Session.TargetID)
					windowCreate.Args.SessionID = options.Session.TargetID
					w.SetSendChannel(sendChannel)
					w.WaitingResponses = append(w.WaitingResponses, &windowCreate)
					w.Send(&windowCreate)
					return
				}
				time.Sleep(time.Microsecond * 10)
			}
		}()
	}
	return &w
}