Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ extension KeyboardStageScene {
copy.keys = keys.map { key in
let pressLevel = interaction.pressed[key.keyCode] ?? 0
let holdLevel = interaction.held[key.keyCode] ?? 0
let level = max(pressLevel, holdLevel)
guard abs(level) > 0.001 else { return key }
// Gate on the signed components, not their collapsed max: during
// the rebound a plain tap has pressLevel slightly negative and no
// hold level, and max(negative, 0) would discard exactly the
// frames the above-rest lift exists for.
guard abs(pressLevel) > 0.001 || abs(holdLevel) > 0.001 else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid retaining pressed opacity during the negative rebound

When a tapped key's authored opacity is below 0.98 (including most standard and dimmed keys), allowing its negative pressLevel through this guard also executes responsiveKey.opacity = max(responsiveKey.opacity, 0.98). The rebound frame therefore has zero interaction level and pressure but remains visibly highlighted until it abruptly returns to its base opacity when the transition settles, contrary to the intended no-residual-press-styling behavior. Apply the signed level only to the translation rebound, or gate the opacity boost on a positive press/hold level.

Useful? React with 👍 / 👎.

return key
}

var responsiveKey = key
responsiveKey.opacity = max(responsiveKey.opacity, 0.98)
responsiveKey.interactionLevel = max(0, level)
responsiveKey.interactionLevel = max(0, max(pressLevel, holdLevel))
let positivePress = max(0, pressLevel)
let positiveHold = max(0, holdLevel)
// The sub-linear press term makes the glow linger behind the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@
dim(keys: &keys, except: [capsKeyID], opacity: 0.88)
keys[capsIndex].role = .escape
keys[capsIndex].pressure = 0.12
keys[capsIndex].translation.y = 0.12 * 0.023
keys[capsIndex].glow = 0.85
keys[capsIndex].opacity = 1
keys[capsIndex].scale = 0.78
keys[capsIndex].translation = KeyboardStagePoint(x: -0.48, y: -0.52)
// The authored transform pose owns the base translation; the
// physical press travel is applied on top of it.
keys[capsIndex].translation = KeyboardStagePoint(
x: -0.48,
y: -0.52 + 0.12 * 0.023
)
keys[capsIndex].legend = KeyboardStageLegend(
primary: "esc",
previous: "caps lock",
Expand Down Expand Up @@ -576,7 +580,7 @@
("control", "⌃", [KeyCode.leftControl, KeyCode.rightControl]),
("option", "⌥", [KeyCode.leftOption, KeyCode.rightOption]),
("shift", "⇧", [KeyCode.leftShift, KeyCode.rightShift]),
("command", "⌘", [KeyCode.leftCommand, KeyCode.rightCommand]),

Check warning on line 583 in Sources/KeyPathAppKit/UI/KeyboardStage/KeyboardStageSceneBuilder.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]

return descriptors.enumerated().compactMap { index, descriptor in
Expand Down Expand Up @@ -739,7 +743,7 @@
25, // 9
29, // 0
27, // -
24, // =

Check warning on line 746 in Sources/KeyPathAppKit/UI/KeyboardStage/KeyboardStageSceneBuilder.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]
static let tab: UInt16 = 48
static let space: UInt16 = 49
Expand All @@ -762,7 +766,7 @@
leftOption,
rightOption,
leftControl,
rightControl,

Check warning on line 769 in Sources/KeyPathAppKit/UI/KeyboardStage/KeyboardStageSceneBuilder.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]
}
}
15 changes: 15 additions & 0 deletions Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"hyper-token-control": [59, 62],
"hyper-token-option": [58, 61],
"hyper-token-shift": [56, 60],
"hyper-token-command": [54, 55],

Check warning on line 66 in Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]

for token in modifierTokens(in: scene) {
Expand Down Expand Up @@ -329,7 +329,7 @@
PhysicalKey(keyCode: 122, label: "f1", x: 1.05, y: 0),
PhysicalKey(keyCode: PhysicalKey.unmappedKeyCode, label: "touch id", x: 2.1, y: 0),
PhysicalKey(keyCode: 18, label: "1", x: 0, y: 1.05),
PhysicalKey(keyCode: 57, label: "caps", x: 0, y: 2.1, width: 1.5),

Check warning on line 332 in Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]
)

Expand Down Expand Up @@ -361,7 +361,7 @@
PhysicalKey(keyCode: 56, label: "shift", x: 0, y: 3.15, width: 2),
PhysicalKey(keyCode: 59, label: "control", x: 2.05, y: 3.15),
PhysicalKey(keyCode: 58, label: "option", x: 3.1, y: 3.15),
PhysicalKey(keyCode: 55, label: "command", x: 4.15, y: 3.15),

Check warning on line 364 in Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]
)
let scene = KeyboardStageSceneBuilder.make(
Expand Down Expand Up @@ -393,7 +393,7 @@
name: "Keyboard Stage Selected Keymap Legends",
keys: [
PhysicalKey(keyCode: 18, label: "1", x: 0, y: 0),
PhysicalKey(keyCode: 19, label: "2", x: 1.05, y: 0),

Check warning on line 396 in Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]
)
let keymap = LogicalKeymap(
Expand Down Expand Up @@ -521,6 +521,21 @@
XCTAssertEqual(otherKey, originalOtherKey)
}

func testReleaseReboundLiftsTheCapAboveRest() throws {
let scene = makeScene(moment: .capsInstalled)
let responsiveScene = scene.applyingInteraction(
KeyboardStageInteractionLevels(pressed: [57: -0.025], held: [:])
)
let caps = try capsKey(in: responsiveScene)
let baseCaps = try capsKey(in: scene)

// The underdamped release dips slightly negative; the cap must rise
// a hair above its rest position, with no residual press styling.
XCTAssertLessThan(caps.translation.y, baseCaps.translation.y)
XCTAssertEqual(caps.interactionLevel, 0)
XCTAssertEqual(caps.pressure, baseCaps.pressure)
}

func testLivePressRespondsOnANeutralNonCapsKey() throws {
let scene = makeScene(moment: .capsInstalled)
let neutral = try XCTUnwrap(scene.keys.first { key in
Expand Down Expand Up @@ -574,7 +589,7 @@
func testLivePressUsesAnAccentFaceAndReadableLegendThroughoutRelease() {
let roles: [KeyboardStageKeyRole] = [
.standard, .modifier, .dimmed, .recommended, .escape,
.hyper, .launcher, .installed,

Check warning on line 592 in Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]
let levels = stride(from: Float(0.005), through: 1, by: 0.005)
for appearance in [KeyboardStageDisplayMode.Appearance.light, .dark] {
Expand Down Expand Up @@ -605,7 +620,7 @@

func testInstructionalRolesKeepAPhysicalKeyFaceAndUseTheRimForEmphasis() {
let roles: [KeyboardStageKeyRole] = [
.recommended, .escape, .hyper, .launcher, .installed,

Check warning on line 623 in Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]

for appearance in [KeyboardStageDisplayMode.Appearance.light, .dark] {
Expand Down Expand Up @@ -671,7 +686,7 @@
.hyperApplying,
.hyperInstalled,
.launcher,
.handoff,

Check warning on line 689 in Tests/KeyPathTests/KeyboardStage/KeyboardStageSceneTests.swift

View workflow job for this annotation

GitHub Actions / code-quality

Collection literals should not have trailing commas (trailing_comma)
]
}

Expand Down
Loading