Skip to content

Commit

Permalink
fixes #669 Focus event support for Windows console
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Feb 17, 2024
1 parent 216e30a commit b994de9
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions console_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type cScreen struct {
oimode uint32
oomode uint32
cells CellBuffer
focusEnable bool

mouseEnabled bool
wg sync.WaitGroup
Expand Down Expand Up @@ -280,9 +281,17 @@ func (s *cScreen) EnablePaste() {}

func (s *cScreen) DisablePaste() {}

func (s *cScreen) EnableFocus() {}
func (s *cScreen) EnableFocus() {
s.Lock()
s.focusEnable = true
s.Unlock()
}

func (s *cScreen) DisableFocus() {}
func (s *cScreen) DisableFocus() {
s.Lock()
s.focusEnable = false
s.Unlock()
}

func (s *cScreen) Fini() {
s.finiOnce.Do(func() {
Expand Down Expand Up @@ -448,8 +457,8 @@ const (
keyEvent uint16 = 1
mouseEvent uint16 = 2
resizeEvent uint16 = 4
// menuEvent uint16 = 8 // don't use
// focusEvent uint16 = 16 // don't use
menuEvent uint16 = 8 // don't use
focusEvent uint16 = 16
)

type mouseRecord struct {
Expand All @@ -460,6 +469,10 @@ type mouseRecord struct {
flags uint32
}

type focusRecord struct {
focused int32 // actually BOOL
}

const (
mouseHWheeled uint32 = 0x8
mouseVWheeled uint32 = 0x4
Expand Down Expand Up @@ -754,6 +767,16 @@ func (s *cScreen) getConsoleInput() error {
rrec.y = geti16(rec.data[2:])
s.postEvent(NewEventResize(int(rrec.x), int(rrec.y)))

case focusEvent:
var focus focusRecord
focus.focused = geti32(rec.data[0:])
s.Lock()
enabled := s.focusEnable
s.Unlock()
if enabled {
s.postEvent(NewEventFocus(focus.focused != 0))
}

default:
}
default:
Expand Down

0 comments on commit b994de9

Please sign in to comment.