Implement focus tracking in kitten infrastructure

This commit is contained in:
Kovid Goyal 2025-05-16 12:48:21 +05:30
parent ce59ef8c6e
commit e015ebefab
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 11 additions and 2 deletions

View file

@ -121,6 +121,9 @@ type Loop struct {
// Called when the terminal's color scheme changes
OnColorSchemeChange func(ColorPreference) error
// Called on focus in/out events
OnFocusChange func(bool) error
}
func New(options ...func(self *Loop)) (*Loop, error) {

View file

@ -113,6 +113,12 @@ func (self *Loop) handle_csi(raw []byte) (err error) {
return nil
}
}
} else if csi == "I" || csi == "O" {
if self.OnFocusChange != nil {
return self.OnFocusChange(csi == "I")
}
return nil
}
ke := KeyEventFromCSI(csi)
if ke != nil {

View file

@ -129,9 +129,9 @@ func (self *TerminalStateOptions) SetStateEscapeCodes() string {
}
sb.WriteString(DECSACE_DEFAULT_REGION_SELECT)
reset_modes(&sb,
IRM, DECKM, DECSCNM, BRACKETED_PASTE, FOCUS_TRACKING,
IRM, DECKM, DECSCNM, BRACKETED_PASTE,
MOUSE_BUTTON_TRACKING, MOUSE_MOTION_TRACKING, MOUSE_MOVE_TRACKING, MOUSE_UTF8_MODE, MOUSE_SGR_MODE)
set_modes(&sb, DECARM, DECAWM, DECTCEM)
set_modes(&sb, DECARM, DECAWM, DECTCEM, FOCUS_TRACKING)
if self.in_band_resize_notification {
set_modes(&sb, INBAND_RESIZE_NOTIFICATION)
}