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
26 changes: 13 additions & 13 deletions src/renderview.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function getModifiers (ev) {
}

function getTimestamp () {
return Date.now() / 1000
return performance.now() / 1000
}

function arraysEqual (a, b) {
Expand Down Expand Up @@ -395,7 +395,7 @@ class BaseRenderView {
this._isVisible = isVisible
const event = {
event_type: isVisible ? 'show' : 'hide',
time_stamp: getTimestamp()
t: getTimestamp()
}
this.onEvent(event)
}
Expand Down Expand Up @@ -462,7 +462,7 @@ class BaseRenderView {
pwidth: physicalWidth,
pheight: physicalHeight,
pixel_ratio: ratio,
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
})
Expand Down Expand Up @@ -509,7 +509,7 @@ class BaseRenderView {
modifiers,
ntouches: 0, // TODO later: maybe via https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent
touches: {},
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand Down Expand Up @@ -560,7 +560,7 @@ class BaseRenderView {
modifiers,
ntouches: 0,
touches: {},
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
if (this._moveThrottle > 0) {
sendMoveEvent() // Send previous (if any)
Expand Down Expand Up @@ -595,7 +595,7 @@ class BaseRenderView {
modifiers,
ntouches: 0,
touches: {},
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand Down Expand Up @@ -624,7 +624,7 @@ class BaseRenderView {
modifiers,
ntouches: 0,
touches: {},
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand Down Expand Up @@ -653,7 +653,7 @@ class BaseRenderView {
modifiers,
ntouches: 0,
touches: {},
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand Down Expand Up @@ -682,7 +682,7 @@ class BaseRenderView {
buttons,
modifiers,
// no touches here
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand Down Expand Up @@ -736,7 +736,7 @@ class BaseRenderView {
dy: ev.deltaY * scale,
buttons,
modifiers,
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
if (this._wheelThrottle > 0) {
sendWheelEvent() // Send previous (if any)
Expand Down Expand Up @@ -769,7 +769,7 @@ class BaseRenderView {
event_type: 'key_down',
key: KEY_MAP[ev.key] || ev.key,
modifiers,
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand All @@ -787,7 +787,7 @@ class BaseRenderView {
event_type: 'key_up',
key: KEY_MAP[ev.key] || ev.key,
modifiers,
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand All @@ -810,7 +810,7 @@ class BaseRenderView {
is_composing: ev.isComposing,
input_type: ev.inputType,
// repeat: ev.repeat, // n.a.
time_stamp: getTimestamp()
timestamp: getTimestamp()
}
this.onEvent(event)
},
Expand Down
29 changes: 15 additions & 14 deletions src/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Fields:
* `pwidth`: The width in physical pixels.
* `pheight`: The height in physical pixels.
* `pixel_ratio`: The pixel ratio between logical and physical pixels.
* `time_stamp`: A timestamp in seconds.
* `timestamp`: A timestamp in seconds.


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

* `event_type`: 'close'
* `time_stamp`: A timestamp in seconds.
* `timestamp`: A timestamp in seconds.


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

* `event_type`: 'show'
* `time_stamp`: A timestamp in seconds.
* `timestamp`: A timestamp in seconds.


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

* `event_type`: 'hide'
* `time_stamp`: A timestamp in seconds.
* `timestamp`: A timestamp in seconds.


### pointer_down
Expand All @@ -120,7 +120,7 @@ Fields:
* `modifiers`: A tuple of modifier keys being pressed down.
* `ntouches`: Experimental.
* `touches`: Experimental.
* `time_stamp`: A timestamp in seconds.
* `timestamp`: A timestamp in seconds.

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

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

* `event_type`: 'pointer_enter'
* `time_stamp`: A timestamp in seconds.
* `timestamp`: A timestamp in seconds.


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

* `event_type`: 'pointer_enter'
* `time_stamp`: A timestamp in seconds.
* `timestamp`: A timestamp in seconds.


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


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

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

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

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


### char
Expand All @@ -267,10 +267,11 @@ Fields:
## Details


### Time stamps
### Timestamps

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.
In multi-process environments you can therefore not compare the timestamps to e.g. `time.time()`.
The timestamps are intended to compare the time *between* events. The reference
for the used time stamps is not defined by this spec. They could be Unix
timestamps or something like `time.perf_counter()`.


### Coordinate frame
Expand Down
2 changes: 1 addition & 1 deletion src/tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}
}

const floatKeys = ['x', 'y', 'dx', 'dy', 'time_stamp']
const floatKeys = ['x', 'y', 'dx', 'dy', 'timestamp']
function eventToString(event) {
let s = '{ '
for (let [key, value] of Object.entries(event)) {
Expand Down
Loading