mirror of
https://github.com/gdamore/tcell.git
synced 2025-04-24 13:48:51 +08:00
fixes #669 Focus event support for Windows console
This commit is contained in:
parent
a58de98116
commit
547b1102d3
@ -51,6 +51,7 @@ type cScreen struct {
|
||||
oimode uint32
|
||||
oomode uint32
|
||||
cells CellBuffer
|
||||
focusEnable bool
|
||||
|
||||
mouseEnabled bool
|
||||
wg sync.WaitGroup
|
||||
@ -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() {
|
||||
@ -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 {
|
||||
@ -460,6 +469,10 @@ type mouseRecord struct {
|
||||
flags uint32
|
||||
}
|
||||
|
||||
type focusRecord struct {
|
||||
focused int32 // actually BOOL
|
||||
}
|
||||
|
||||
const (
|
||||
mouseHWheeled uint32 = 0x8
|
||||
mouseVWheeled uint32 = 0x4
|
||||
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user