Skip to content

Commit 3f45538

Browse files
authored
Rename time_stamp -> timestamp, and tweak js implementation (#5)
1 parent 782b241 commit 3f45538

3 files changed

Lines changed: 29 additions & 28 deletions

File tree

src/renderview.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function getModifiers (ev) {
6969
}
7070

7171
function getTimestamp () {
72-
return Date.now() / 1000
72+
return performance.now() / 1000
7373
}
7474

7575
function arraysEqual (a, b) {
@@ -395,7 +395,7 @@ class BaseRenderView {
395395
this._isVisible = isVisible
396396
const event = {
397397
event_type: isVisible ? 'show' : 'hide',
398-
time_stamp: getTimestamp()
398+
t: getTimestamp()
399399
}
400400
this.onEvent(event)
401401
}
@@ -462,7 +462,7 @@ class BaseRenderView {
462462
pwidth: physicalWidth,
463463
pheight: physicalHeight,
464464
pixel_ratio: ratio,
465-
time_stamp: getTimestamp()
465+
timestamp: getTimestamp()
466466
}
467467
this.onEvent(event)
468468
})
@@ -509,7 +509,7 @@ class BaseRenderView {
509509
modifiers,
510510
ntouches: 0, // TODO later: maybe via https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent
511511
touches: {},
512-
time_stamp: getTimestamp()
512+
timestamp: getTimestamp()
513513
}
514514
this.onEvent(event)
515515
},
@@ -560,7 +560,7 @@ class BaseRenderView {
560560
modifiers,
561561
ntouches: 0,
562562
touches: {},
563-
time_stamp: getTimestamp()
563+
timestamp: getTimestamp()
564564
}
565565
if (this._moveThrottle > 0) {
566566
sendMoveEvent() // Send previous (if any)
@@ -595,7 +595,7 @@ class BaseRenderView {
595595
modifiers,
596596
ntouches: 0,
597597
touches: {},
598-
time_stamp: getTimestamp()
598+
timestamp: getTimestamp()
599599
}
600600
this.onEvent(event)
601601
},
@@ -624,7 +624,7 @@ class BaseRenderView {
624624
modifiers,
625625
ntouches: 0,
626626
touches: {},
627-
time_stamp: getTimestamp()
627+
timestamp: getTimestamp()
628628
}
629629
this.onEvent(event)
630630
},
@@ -653,7 +653,7 @@ class BaseRenderView {
653653
modifiers,
654654
ntouches: 0,
655655
touches: {},
656-
time_stamp: getTimestamp()
656+
timestamp: getTimestamp()
657657
}
658658
this.onEvent(event)
659659
},
@@ -682,7 +682,7 @@ class BaseRenderView {
682682
buttons,
683683
modifiers,
684684
// no touches here
685-
time_stamp: getTimestamp()
685+
timestamp: getTimestamp()
686686
}
687687
this.onEvent(event)
688688
},
@@ -736,7 +736,7 @@ class BaseRenderView {
736736
dy: ev.deltaY * scale,
737737
buttons,
738738
modifiers,
739-
time_stamp: getTimestamp()
739+
timestamp: getTimestamp()
740740
}
741741
if (this._wheelThrottle > 0) {
742742
sendWheelEvent() // Send previous (if any)
@@ -769,7 +769,7 @@ class BaseRenderView {
769769
event_type: 'key_down',
770770
key: KEY_MAP[ev.key] || ev.key,
771771
modifiers,
772-
time_stamp: getTimestamp()
772+
timestamp: getTimestamp()
773773
}
774774
this.onEvent(event)
775775
},
@@ -787,7 +787,7 @@ class BaseRenderView {
787787
event_type: 'key_up',
788788
key: KEY_MAP[ev.key] || ev.key,
789789
modifiers,
790-
time_stamp: getTimestamp()
790+
timestamp: getTimestamp()
791791
}
792792
this.onEvent(event)
793793
},
@@ -810,7 +810,7 @@ class BaseRenderView {
810810
is_composing: ev.isComposing,
811811
input_type: ev.inputType,
812812
// repeat: ev.repeat, // n.a.
813-
time_stamp: getTimestamp()
813+
timestamp: getTimestamp()
814814
}
815815
this.onEvent(event)
816816
},

src/spec.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Fields:
7171
* `pwidth`: The width in physical pixels.
7272
* `pheight`: The height in physical pixels.
7373
* `pixel_ratio`: The pixel ratio between logical and physical pixels.
74-
* `time_stamp`: A timestamp in seconds.
74+
* `timestamp`: A timestamp in seconds.
7575

7676

7777
### close
@@ -81,7 +81,7 @@ This event is emitted when the canvas is closed (i.e. destroyed).
8181
Fields:
8282

8383
* `event_type`: 'close'
84-
* `time_stamp`: A timestamp in seconds.
84+
* `timestamp`: A timestamp in seconds.
8585

8686

8787
### show
@@ -93,7 +93,7 @@ shown. If this is not the case, the implementation should emit a 'hide' event.
9393
Fields:
9494

9595
* `event_type`: 'show'
96-
* `time_stamp`: A timestamp in seconds.
96+
* `timestamp`: A timestamp in seconds.
9797

9898

9999
### hide
@@ -103,7 +103,7 @@ This event is emitted when the canvas is hidden. It can e.g. be minimized or scr
103103
Fields:
104104

105105
* `event_type`: 'hide'
106-
* `time_stamp`: A timestamp in seconds.
106+
* `timestamp`: A timestamp in seconds.
107107

108108

109109
### pointer_down
@@ -120,7 +120,7 @@ Fields:
120120
* `modifiers`: A tuple of modifier keys being pressed down.
121121
* `ntouches`: Experimental.
122122
* `touches`: Experimental.
123-
* `time_stamp`: A timestamp in seconds.
123+
* `timestamp`: A timestamp in seconds.
124124

125125
The mouse buttons are defined as follows, which is different from JavaScript (although close to the JS `buttons` bitmask):
126126

@@ -162,7 +162,7 @@ This event is emitted when the user moves a pointer into the boundary of the can
162162
Fields:
163163

164164
* `event_type`: 'pointer_enter'
165-
* `time_stamp`: A timestamp in seconds.
165+
* `timestamp`: A timestamp in seconds.
166166

167167

168168
### pointer_leave
@@ -172,7 +172,7 @@ This event is emitted when the user moves a pointer out of the boundary of the c
172172
Fields:
173173

174174
* `event_type`: 'pointer_enter'
175-
* `time_stamp`: A timestamp in seconds.
175+
* `timestamp`: A timestamp in seconds.
176176

177177

178178
### double_click
@@ -187,7 +187,7 @@ Fields:
187187
* `button`: The button to which this event applies.
188188
* `buttons`: A tuple of buttons being pressed down.
189189
* `modifiers`: A tuple of modifier keys being pressed down. See section below for details.
190-
* `time_stamp`: A timestamp in seconds.
190+
* `timestamp`: A timestamp in seconds.
191191

192192

193193
### wheel
@@ -205,7 +205,7 @@ Fields:
205205
* `y`: The mouse vertical position during the scroll.
206206
* `buttons`: aA tuple of buttons being pressed down.
207207
* `modifiers` *: A tuple of modifier keys being pressed down.
208-
* `time_stamp`: A timestamp in seconds.
208+
* `timestamp`: A timestamp in seconds.
209209

210210
Similar to the JS wheel event, the values of the deltas depend on the
211211
platform and whether the mouse-wheel, trackpad or a touch-gesture is
@@ -230,7 +230,7 @@ Fields:
230230
* `event_type`: 'key_down'
231231
* `key`: The key being pressed as a string.
232232
* `modifiers`: A tuple of modifier keys being pressed down.
233-
* `time_stamp`: A timestamp in seconds.
233+
* `timestamp`: A timestamp in seconds.
234234

235235
The key names follow the [browser spec](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent).
236236

@@ -247,7 +247,7 @@ This event is emitted when a key is released.
247247
* `event_type`: 'key_up'
248248
* `key`: The key being released as a string.
249249
* `modifiers`: A tuple of modifier keys being pressed down.
250-
* `time_stamp`: A timestamp in seconds.
250+
* `timestamp`: A timestamp in seconds.
251251

252252

253253
### char
@@ -267,10 +267,11 @@ Fields:
267267
## Details
268268

269269

270-
### Time stamps
270+
### Timestamps
271271

272-
The reference for the used time stamps is not defined by this spec. They could be Unix timestamps or something that starts at application start.
273-
In multi-process environments you can therefore not compare the timestamps to e.g. `time.time()`.
272+
The timestamps are intended to compare the time *between* events. The reference
273+
for the used time stamps is not defined by this spec. They could be Unix
274+
timestamps or something like `time.perf_counter()`.
274275

275276

276277
### Coordinate frame

src/tester.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
}
7777
}
7878

79-
const floatKeys = ['x', 'y', 'dx', 'dy', 'time_stamp']
79+
const floatKeys = ['x', 'y', 'dx', 'dy', 'timestamp']
8080
function eventToString(event) {
8181
let s = '{ '
8282
for (let [key, value] of Object.entries(event)) {

0 commit comments

Comments
 (0)