From e414e20215db3a80bb1cf511390406324e742ebf Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 24 Mar 2018 22:14:17 +0200 Subject: Add mouse handler stub and keep track of focus --- ui/view-main.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'ui/view-main.go') diff --git a/ui/view-main.go b/ui/view-main.go index 5515004..e5c6792 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -43,6 +43,8 @@ type MainView struct { currentRoomIndex int roomIDs []string + lastFocusTime time.Time + matrix ifc.MatrixContainer gmx ifc.Gomuks config *config.Config @@ -78,6 +80,10 @@ func (ui *GomuksUI) NewMainView() tview.Primitive { return mainView } +func (view *MainView) BumpFocus() { + view.lastFocusTime = time.Now() +} + func (view *MainView) InputChanged(roomView *widget.RoomView, text string) { if len(text) == 0 { 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() if key.Modifiers() == tcell.ModCtrl || key.Modifiers() == tcell.ModAlt { if k == tcell.KeyDown { @@ -198,13 +206,20 @@ func (view *MainView) InputKeyHandler(roomView *widget.RoomView, key *tcell.Even } else { msgView.MoveDown(k == tcell.KeyPgDn) } - view.parent.Render() } else { return key } 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 { if len(view.roomIDs) == 0 { return "" @@ -253,7 +268,8 @@ func (view *MainView) addRoom(index int, room string) { SetInputSubmitFunc(view.InputSubmit). SetInputChangedFunc(view.InputChanged). SetTabCompleteFunc(view.InputTabComplete). - SetInputCapture(view.InputKeyHandler) + SetInputCapture(view.KeyEventHandler). + SetMouseCapture(view.MouseEventHandler) view.rooms[room] = roomView view.roomView.AddPage(room, roomView, true, false) roomView.UpdateUserList() -- cgit v1.2.3