Add mouse handler stub and keep track of focus

This commit is contained in:
Tulir Asokan 2018-03-24 22:14:17 +02:00
parent 1321e1a06a
commit e414e20215
2 changed files with 26 additions and 3 deletions

View File

@ -43,6 +43,8 @@ type MainView struct {
currentRoomIndex int currentRoomIndex int
roomIDs []string roomIDs []string
lastFocusTime time.Time
matrix ifc.MatrixContainer matrix ifc.MatrixContainer
gmx ifc.Gomuks gmx ifc.Gomuks
config *config.Config config *config.Config
@ -78,6 +80,10 @@ func (ui *GomuksUI) NewMainView() tview.Primitive {
return mainView return mainView
} }
func (view *MainView) BumpFocus() {
view.lastFocusTime = time.Now()
}
func (view *MainView) InputChanged(roomView *widget.RoomView, text string) { func (view *MainView) InputChanged(roomView *widget.RoomView, text string) {
if len(text) == 0 { if len(text) == 0 {
go view.matrix.SendTyping(roomView.Room.ID, false) go view.matrix.SendTyping(roomView.Room.ID, false)
@ -175,7 +181,9 @@ func (view *MainView) HandleCommand(roomView *widget.RoomView, command string, a
} }
} }
func (view *MainView) InputKeyHandler(roomView *widget.RoomView, key *tcell.EventKey) *tcell.EventKey { func (view *MainView) KeyEventHandler(roomView *widget.RoomView, key *tcell.EventKey) *tcell.EventKey {
view.BumpFocus()
k := key.Key() k := key.Key()
if key.Modifiers() == tcell.ModCtrl || key.Modifiers() == tcell.ModAlt { if key.Modifiers() == tcell.ModCtrl || key.Modifiers() == tcell.ModAlt {
if k == tcell.KeyDown { if k == tcell.KeyDown {
@ -198,13 +206,20 @@ func (view *MainView) InputKeyHandler(roomView *widget.RoomView, key *tcell.Even
} else { } else {
msgView.MoveDown(k == tcell.KeyPgDn) msgView.MoveDown(k == tcell.KeyPgDn)
} }
view.parent.Render()
} else { } else {
return key return key
} }
return nil return nil
} }
func (view *MainView) MouseEventHandler(roomView *widget.RoomView, event *tcell.EventMouse) *tcell.EventMouse {
if event.Buttons() != tcell.ButtonNone {
view.BumpFocus()
}
return event
}
func (view *MainView) CurrentRoomID() string { func (view *MainView) CurrentRoomID() string {
if len(view.roomIDs) == 0 { if len(view.roomIDs) == 0 {
return "" return ""
@ -253,7 +268,8 @@ func (view *MainView) addRoom(index int, room string) {
SetInputSubmitFunc(view.InputSubmit). SetInputSubmitFunc(view.InputSubmit).
SetInputChangedFunc(view.InputChanged). SetInputChangedFunc(view.InputChanged).
SetTabCompleteFunc(view.InputTabComplete). SetTabCompleteFunc(view.InputTabComplete).
SetInputCapture(view.InputKeyHandler) SetInputCapture(view.KeyEventHandler).
SetMouseCapture(view.MouseEventHandler)
view.rooms[room] = roomView view.rooms[room] = roomView
view.roomView.AddPage(room, roomView, true, false) view.roomView.AddPage(room, roomView, true, false)
roomView.UpdateUserList() roomView.UpdateUserList()

View File

@ -95,6 +95,13 @@ func (view *RoomView) SetInputCapture(fn func(room *RoomView, event *tcell.Event
return view return view
} }
func (view *RoomView) SetMouseCapture(fn func(room *RoomView, event *tcell.EventMouse) *tcell.EventMouse) *RoomView {
view.input.SetMouseCapture(func(event *tcell.EventMouse) *tcell.EventMouse {
return fn(view, event)
})
return view
}
func (view *RoomView) SetInputSubmitFunc(fn func(room *RoomView, text string)) *RoomView { func (view *RoomView) SetInputSubmitFunc(fn func(room *RoomView, text string)) *RoomView {
view.input.SetDoneFunc(func(key tcell.Key) { view.input.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEnter { if key == tcell.KeyEnter {