Skip to content

Commit

Permalink
fix: holding a button while page changes should always fire the relea…
Browse files Browse the repository at this point in the history
…se on the button that the press was for
  • Loading branch information
Julusian committed Jun 4, 2023
1 parent db19510 commit 3cbe808
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/Surface/Handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class SurfaceHandler extends CoreBase {
*/
currentPincodeEntry = ''

/** Currently pressed buttons, and what they are keeping pressed */
#currentButtonPresses = {}

/**
* Whether the surface is currently locked
*/
Expand All @@ -68,8 +71,6 @@ class SurfaceHandler extends CoreBase {
this.isSurfaceLocked = isLocked

this.currentPage = 1 // The current page of the device
this.lastpress = ''
this.lastpage = 0

// Fill in max offsets
const keysPerRow = this.panel.info.keysPerRow || 0
Expand Down Expand Up @@ -300,18 +301,13 @@ class SurfaceHandler extends CoreBase {

let thisPage = this.currentPage

// TODO - what is lastpress vs lastpage. This flow looks weird and like it might get things wrong sometimes..
let thispress = this.currentPage
if (pressed) {
this.lastpress = thispress
this.lastpage = this.currentPage
} else if (thispress != this.lastpress) {
// page changed on this device before button released
// release the old page+bank
thisPage = this.lastpage
this.lastpress = ''
// Track what page was pressed for this key
this.#currentButtonPresses[key] = thisPage
} else {
this.lastpress = ''
// Release the same page that was previously pressed
thisPage = this.#currentButtonPresses[key] ?? thisPage
delete this.#currentButtonPresses[key]
}

// allow the xkeys to span pages
Expand Down

0 comments on commit 3cbe808

Please sign in to comment.