From fef700ed415225e50996b35978911e0c643c06bb Mon Sep 17 00:00:00 2001 From: hunchulchoi Date: Thu, 4 Jun 2026 18:01:08 +0900 Subject: [PATCH] feat: implement automatic focus-based mouse toggling for logs view --- pkg/gui/focus.go | 17 +++++++++ pkg/gui/keybindings.go | 8 +--- pkg/gui/main_panel.go | 83 ------------------------------------------ pkg/gui/views.go | 3 +- 4 files changed, 19 insertions(+), 92 deletions(-) diff --git a/pkg/gui/focus.go b/pkg/gui/focus.go index cc414a53..5ced85e0 100644 --- a/pkg/gui/focus.go +++ b/pkg/gui/focus.go @@ -46,6 +46,23 @@ func (gui *Gui) switchFocusAux(newView *gocui.View) error { gui.g.Cursor = newView.Editable + // Automatically control mouse capture mode depending on focus + if newView.Name() == "main" { + if gui.g.Mouse { + gui.g.Mouse = false + gocui.Screen.DisableMouse() + } + } else { + if !gui.Config.UserConfig.Gui.IgnoreMouseEvents { + if !gui.g.Mouse { + gui.g.Mouse = true + gocui.Screen.EnableMouse() + } + } + } + // Force refresh the bottom information panel with updated status text + _ = gui.renderString(gui.g, "information", gui.getInformationContent()) + if err := gui.renderPanelOptions(); err != nil { return err } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 302ffb46..79d0fad6 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -74,13 +74,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Modifier: gocui.ModNone, Handler: gui.quit, }, - { - ViewName: "", - Key: 'M', // Shift+M - Modifier: gocui.ModNone, - Handler: wrappedHandler(gui.handleToggleMouse), - Description: "Toggle mouse mode (ON/OFF)", - }, + { ViewName: "", Key: gocui.KeyPgup, diff --git a/pkg/gui/main_panel.go b/pkg/gui/main_panel.go index 9a6eca3f..004147be 100644 --- a/pkg/gui/main_panel.go +++ b/pkg/gui/main_panel.go @@ -2,8 +2,6 @@ package gui import ( "math" - "sync" - "time" "github.com/jesseduffield/gocui" ) @@ -113,84 +111,3 @@ func (gui *Gui) handleMainClick() error { return gui.switchFocus(gui.Views.Main) } - -var ( - mouseTimerMutex sync.Mutex - mouseTimer *time.Timer - mouseTicker *time.Ticker - mouseTicksLeft int -) - -func (gui *Gui) handleToggleMouse() error { - mouseTimerMutex.Lock() - defer mouseTimerMutex.Unlock() - - if gui.g.Mouse { - // Disable Mouse - gui.g.Mouse = false - gocui.Screen.DisableMouse() - - if mouseTimer != nil { - mouseTimer.Stop() - } - if mouseTicker != nil { - mouseTicker.Stop() - } - - mouseTicksLeft = 15 - mouseTimer = time.AfterFunc(15*time.Second, func() { - gui.g.Update(func(g *gocui.Gui) error { - mouseTimerMutex.Lock() - defer mouseTimerMutex.Unlock() - - if !gui.g.Mouse { - gui.g.Mouse = true - gocui.Screen.EnableMouse() - if mouseTicker != nil { - mouseTicker.Stop() - } - _ = gui.renderString(gui.g, "information", gui.getInformationContent()) - } - return nil - }) - }) - - mouseTicker = time.NewTicker(1 * time.Second) - go func() { - for range mouseTicker.C { - gui.g.Update(func(g *gocui.Gui) error { - mouseTimerMutex.Lock() - defer mouseTimerMutex.Unlock() - - if gui.g.Mouse { - return nil - } - mouseTicksLeft-- - if mouseTicksLeft <= 0 { - if mouseTicker != nil { - mouseTicker.Stop() - } - return nil - } - _ = gui.renderString(gui.g, "information", gui.getInformationContent()) - return nil - }) - } - }() - - } else { - // Enable Mouse manually - gui.g.Mouse = true - gocui.Screen.EnableMouse() - - if mouseTimer != nil { - mouseTimer.Stop() - } - if mouseTicker != nil { - mouseTicker.Stop() - } - } - - _ = gui.renderString(gui.g, "information", gui.getInformationContent()) - return nil -} diff --git a/pkg/gui/views.go b/pkg/gui/views.go index c29924e1..f3361c6d 100644 --- a/pkg/gui/views.go +++ b/pkg/gui/views.go @@ -1,7 +1,6 @@ package gui import ( - "fmt" "os" "github.com/fatih/color" @@ -199,7 +198,7 @@ func (gui *Gui) getInformationContent() string { mouseStatus := "Mouse: ON" if !gui.g.Mouse { - mouseStatus = fmt.Sprintf("Mouse: OFF (%ds left)", mouseTicksLeft) + mouseStatus = "Mouse: OFF (Drag to copy)" } informationStr = mouseStatus + " | " + informationStr