Skip to content

Commit

Permalink
fix(input): multiple window-size-events
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 17, 2024
1 parent 993171a commit 47cd60e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions input/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type Driver struct {
// up button events.
prevMouseState coninput.ButtonState // nolint: unused

// lastWinsizeEvent keeps track of the last window size event to prevent
// multiple size events from firing.
lastWinsizeEvent coninput.WindowBufferSizeEventRecord // nolint: unused

flags int // control the behavior of the driver.
}

Expand Down
13 changes: 8 additions & 5 deletions input/driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (d *Driver) handleConInput(

var evs []Event
for _, event := range events {
if e := parseConInputEvent(event, &d.prevMouseState); e != nil {
if e := parseConInputEvent(event, &d.prevMouseState, &d.lastWinsizeEvent); e != nil {
evs = append(evs, e)
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ loop:
return events
}

func parseConInputEvent(event coninput.InputRecord, ps *coninput.ButtonState) Event {
func parseConInputEvent(event coninput.InputRecord, ps *coninput.ButtonState, ws *coninput.WindowBufferSizeEventRecord) Event {
switch e := event.Unwrap().(type) {
case coninput.KeyEventRecord:
event := parseWin32InputKeyEvent(e.VirtualKeyCode, e.VirtualScanCode,
Expand Down Expand Up @@ -171,9 +171,12 @@ func parseConInputEvent(event coninput.InputRecord, ps *coninput.ButtonState) Ev
return KeyUpEvent(key)

case coninput.WindowBufferSizeEventRecord:
return WindowSizeEvent{
Width: int(e.Size.X),
Height: int(e.Size.Y),
if e != *ws {
*ws = e
return WindowSizeEvent{
Width: int(e.Size.X),
Height: int(e.Size.Y),
}
}
case coninput.MouseEventRecord:
mevent := mouseEvent(*ps, e)
Expand Down

0 comments on commit 47cd60e

Please sign in to comment.