Skip to content

Commit

Permalink
fix(windows): prevent firing multiple window size events
Browse files Browse the repository at this point in the history
On Windows, changing the alt-screen-buffer triggers a window-size-event.
This might cause issues with some applications. Cache the last
window-size-event and compare before sending it the model.

Fixes: #1019
  • Loading branch information
aymanbagabas committed May 17, 2024
1 parent 920d07b commit 09f4ef0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions key_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func readInputs(ctx context.Context, msgs chan<- Msg, input io.Reader) error {
}

func readConInputs(ctx context.Context, msgsch chan<- Msg, con windows.Handle) error {
var ps coninput.ButtonState // keep track of previous mouse state
var ps coninput.ButtonState // keep track of previous mouse state
var ws coninput.WindowBufferSizeEventRecord // keep track of the last window size event
for {
events, err := coninput.ReadNConsoleInputs(con, 16)
if err != nil {
Expand All @@ -45,10 +46,13 @@ func readConInputs(ctx context.Context, msgsch chan<- Msg, con windows.Handle) e
})
}
case coninput.WindowBufferSizeEventRecord:
msgs = append(msgs, WindowSizeMsg{
Width: int(e.Size.X),
Height: int(e.Size.Y),
})
if e != ws {
ws = e
msgs = append(msgs, WindowSizeMsg{
Width: int(e.Size.X),
Height: int(e.Size.Y),
})
}
case coninput.MouseEventRecord:
event := mouseEvent(ps, e)
if event.Type != MouseUnknown {
Expand Down

0 comments on commit 09f4ef0

Please sign in to comment.