Skip to content

Commit

Permalink
Try TextInput.blur calling on_gameport_resize
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Oct 24, 2024
1 parent c9f9e13 commit 7ee4f3f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/glkote/web/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ import {is_pinch_zoomed} from '../../common/misc.js'
import * as protocol from '../../common/protocol.js'

import {apply_text_run_styles, type Window} from './windows.js'
import type Metrics from './metrics.js'

const MAX_HISTORY_LENGTH = 25

export class TextInput {
el: JQuery<HTMLElement>
history_index = 0
is_line = false
metrics: Metrics
window: Window

constructor(window: Window) {
this.metrics = window.manager.glkote.metrics_calculator
this.window = window

// We use a textarea rather than an input because mobile Chrome shows an extra bar which can't be removed
Expand Down Expand Up @@ -54,6 +57,7 @@ export class TextInput {
}

private onblur() {
this.metrics.on_visualViewport_resize()
scroll_window()
}

Expand Down
7 changes: 6 additions & 1 deletion src/glkote/web/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export default class Metrics {
private glkote: WebGlkOte
private observer?: ResizeObserver

logs: string[] = []

constructor(glkote: WebGlkOte) {
this.glkote = glkote
this.metrics = glkote.current_metrics
Expand Down Expand Up @@ -173,6 +175,7 @@ export default class Metrics {
this.on_gameport_resize()
return
}
this.glkote.warning('on_gameport_resize 4')
const oldmetrics = Object.assign({}, this.metrics)
await this.measure()
if (metrics_differ(this.metrics, oldmetrics)) {
Expand All @@ -185,7 +188,9 @@ export default class Metrics {
if (is_pinch_zoomed()){
return
}

this.logs.push(`ovr (${visualViewport!.height | 0} ${window.innerHeight})`)
setTimeout(() => {this.logs.push(`ovr 200 (${visualViewport!.height | 0} ${window.innerHeight})`)}, 200)
setTimeout(() => {this.logs.push(`ovr 500 (${visualViewport!.height | 0} ${window.innerHeight})`)}, 500)
// The iOS virtual keyboard does not change the gameport height, but it does change the viewport
// Try to account for this by setting the gameport to the viewport height
const gameport = this.glkote.dom.gameport()
Expand Down
4 changes: 3 additions & 1 deletion src/glkote/web/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class WebGlkOte extends GlkOte.GlkOteBase implements GlkOte.GlkOt
prefix: '',
windowport_id: 'windowport',
})
private metrics_calculator: Metrics
metrics_calculator: Metrics
private showing_error = false
private showing_loading = true
private transcript_recorder?: TranscriptRecorder
Expand Down Expand Up @@ -350,6 +350,8 @@ export default class WebGlkOte extends GlkOte.GlkOteBase implements GlkOte.GlkOt
}

update(data: protocol.Update) {
this.warning(this.metrics_calculator.logs.join('\n'))
this.metrics_calculator.logs = []
if (this.showing_loading) {
this.hide_loading()
}
Expand Down
2 changes: 1 addition & 1 deletion src/glkote/web/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ export default class Windows extends Map<number, Window> {
blorb?: Blorb // Note will be set after this is constructed, in WebGlkOte.init
canvasResizeObserver?: ResizeObserver // Will only be created if the browser's ResizeObserver supports devicePixelContentBoxSize
private dom: DOM
private glkote: WebGlkOte
glkote: WebGlkOte
history: string[] = []
private metrics: protocol.NormalisedMetrics
send_event: EventFunc
Expand Down

0 comments on commit 7ee4f3f

Please sign in to comment.