Esempio n. 1
0
// KeyboardHandler handle events from keyboard
func KeyboardHandler(event chan *keyhandler.KeyPressEvent, window *gtk.Window,
	repl *gtk.Entry, URLEntry *gtk.Entry, notebook *gtk.Notebook) {
	for {
		kpe := <-event
		log.Printf("[DEBUG] KeyPressEvent : %v", kpe)
		gdk.ThreadsEnter()
		switch kpe.KeyVal {
		case gdk.KEY_Escape:
			repl.SetVisible(false)
			break
		case gdk.KEY_colon:
			if !repl.IsFocus() && !URLEntry.IsFocus() {
				repl.SetVisible(true)
				repl.GrabFocus()
				repl.SetText(":")
				repl.SetPosition(1)
			}
			break
		case gdk.KEY_Return:
			if repl.IsFocus() {
				text := repl.GetText()
				log.Printf("Repl text : %s", text)
				if len(text) > 0 {
					command.Run(text, window, "")
				}
				repl.SetText("")
			}
			break
		// case gdk.KEY_w:
		// 	if kpe.GetModifier() == keyhandler.CTRL {
		// 		log.Printf("[DEBUG] nb : %d", notebook.GetNPages())
		// 		notebook.RemovePage(notebook.GetCurrentPage())
		// 		log.Printf("[DEBUG] nb : %d", notebook.GetNPages())
		// 	}
		// 	break
		case gdk.KEY_t:
			if kpe.GetModifier() == keyhandler.CTRL {
				log.Printf("[DEBUG] New tab")
				log.Printf("[DEBUG] nb : %d", notebook.GetNPages())
				log.Printf("[DEBUG] current : %d",
					notebook.GetCurrentPage())
				tab := ui.NewBrowser("")
				page := gtk.NewFrame("")
				//fmt.Sprintf("%d", notebook.GetNPages()+1))
				notebook.AppendPage(page, gtk.NewLabel("New tab"))
				page.Add(tab.VBox)
				log.Printf("[DEBUG] nb : %d", notebook.GetNPages())
				notebook.ShowAll()
			}
			break
		case gdk.KEY_q:
			if kpe.GetModifier() == keyhandler.CTRL {
				gtk.MainQuit()
			}
			break
		}
		gdk.ThreadsLeave()
	}
}
Esempio n. 2
0
func runGUI() {

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle(getApplicationTitle())
	window.Connect("destroy", gtk.MainQuit)

	keyboardEventsChan := make(chan *keyhandler.KeyPressEvent)
	window.Connect("key-press-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		kpe := keyhandler.KeyPressEvent{int(kev.Keyval), 0}
		if (gdk.ModifierType(kev.State) & gdk.CONTROL_MASK) != 0 {
			kpe.Modifier = gdk.CONTROL_MASK
		}
		keyboardEventsChan <- &kpe
	})

	// motionEvent := make(chan interface{})
	// window.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
	// 	arg := ctx.Args(0)
	// 	motionEvent <- *(**gdk.EventMotion)(unsafe.Pointer(&arg))
	// })
	// go events.MotionHandler(motionEvent)

	buttonEventChan := make(chan interface{})
	window.Connect("button-press-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		buttonEventChan <- *(**gdk.EventButton)(unsafe.Pointer(&arg))
	})
	go events.ButtonHandler(buttonEventChan)

	setupProxy()

	vbox := gtk.NewVBox(false, 1)

	notebook := gtk.NewNotebook()

	tab := ui.NewBrowser(homePage)
	page := gtk.NewFrame("")
	notebook.AppendPage(page, gtk.NewLabel("Home"))
	page.Add(tab.VBox)
	vbox.PackStart(notebook, true, true, 0)

	statusbar := gtk.NewStatusbar()
	contextID := statusbar.GetContextId("actarus")
	statusbar.Push(contextID, "Welcome to Actarus.")
	vbox.PackStart(statusbar, false, false, 0)

	replEntry := gtk.NewEntry()
	replEntry.Hide()
	vbox.PackEnd(replEntry, false, false, 0)

	window.Add(vbox)

	window.SetSizeRequest(defaultWinWidth, defaultWinHeight)
	window.ShowAll()

	replEntry.GrabFocus()
	replEntry.SetVisible(false)

	// Handlers
	go events.KeyboardHandler(
		keyboardEventsChan,
		window,
		replEntry,
		tab.URLEntry,
		notebook)

	gtk.Main()
}