aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui/view-main.go22
-rw-r--r--ui/widget/room-view.go7
2 files changed, 26 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()
diff --git a/ui/widget/room-view.go b/ui/widget/room-view.go
index 2e82a2d..2da3023 100644
--- a/ui/widget/room-view.go
+++ b/ui/widget/room-view.go
@@ -95,6 +95,13 @@ func (view *RoomView) SetInputCapture(fn func(room *RoomView, event *tcell.Event
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 {
view.input.SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEnter {