aboutsummaryrefslogtreecommitdiff
path: root/ui/view-main.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-24 22:14:17 +0200
committerTulir Asokan <tulir@maunium.net>2018-03-24 22:14:17 +0200
commite414e20215db3a80bb1cf511390406324e742ebf (patch)
treef4375b7d9f8a8c277b8633bc3eeba3d8f105a7bd /ui/view-main.go
parent1321e1a06ac8d8db13014e9c94aa52e1ffa32c1a (diff)
Add mouse handler stub and keep track of focus
Diffstat (limited to 'ui/view-main.go')
-rw-r--r--ui/view-main.go22
1 files changed, 19 insertions, 3 deletions
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()