Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): multiple window-size-events #82

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -177,9 +177,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
Loading