Fix textarea focus for touchscreens with keyboard (#30)

* check if touchscreen has mouse.

* add inputMode to props.

* fix formatting.
This commit is contained in:
Miroslav Šedivý 2023-04-18 10:19:52 +02:00 committed by GitHub
parent ddfa3a7aef
commit d3514b9698
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -36,6 +36,7 @@
:implicitControl="state.settings.implicit_hosting && session.profile.can_host" :implicitControl="state.settings.implicit_hosting && session.profile.can_host"
:inactiveCursors="state.settings.inactive_cursors && session.profile.sends_inactive_cursor" :inactiveCursors="state.settings.inactive_cursors && session.profile.sends_inactive_cursor"
:fps="fps" :fps="fps"
:hasMobileKeyboard="is_touch_device"
@updateKeyboardModifiers="updateKeyboardModifiers($event)" @updateKeyboardModifiers="updateKeyboardModifiers($event)"
@uploadDrop="uploadDrop($event)" @uploadDrop="uploadDrop($event)"
@mobileKeyboardOpen="state.mobile_keyboard_open = $event" @mobileKeyboardOpen="state.mobile_keyboard_open = $event"
@ -138,6 +139,10 @@
@Prop({ type: Number, default: 0 }) @Prop({ type: Number, default: 0 })
private readonly fps!: number private readonly fps!: number
// auto / touch / mouse
@Prop({ type: String, default: 'auto' })
private readonly inputMode!: String
///////////////////////////// /////////////////////////////
// Public state // Public state
///////////////////////////// /////////////////////////////
@ -236,6 +241,20 @@
return this.state.settings.private_mode && !this.is_admin return this.state.settings.private_mode && !this.is_admin
} }
public get is_touch_device() {
if (this.inputMode == 'mouse') return false
if (this.inputMode == 'touch') return true
return (
// check if the device has a touch screen
('ontouchstart' in window || navigator.maxTouchPoints > 0) &&
// we also check if the device has a pointer
!matchMedia('(pointer:fine)').matches &&
// and is capable of hover, then it probably has a mouse
!matchMedia('(hover:hover)').matches
)
}
@Watch('private_mode_enabled') @Watch('private_mode_enabled')
private setWebRTCPaused(paused: boolean) { private setWebRTCPaused(paused: boolean) {
this.connection.webrtc.paused = paused this.connection.webrtc.paused = paused

View File

@ -112,6 +112,9 @@
@Prop() @Prop()
private readonly fps!: number private readonly fps!: number
@Prop()
private readonly hasMobileKeyboard!: boolean
get cursor(): string { get cursor(): string {
if (!this.isControling || !this.cursorImage) { if (!this.isControling || !this.cursorImage) {
return 'default' return 'default'
@ -121,10 +124,6 @@
return 'url(' + uri + ') ' + x + ' ' + y + ', default' return 'url(' + uri + ') ' + x + ' ' + y + ', default'
} }
get isTouchDevice(): boolean {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0
}
mounted() { mounted() {
// register mouseup globally as user can release mouse button outside of overlay // register mouseup globally as user can release mouse button outside of overlay
window.addEventListener('mouseup', this.onMouseUp, true) window.addEventListener('mouseup', this.onMouseUp, true)
@ -386,7 +385,7 @@
onMouseEnter(e: MouseEvent) { onMouseEnter(e: MouseEvent) {
// focus opens the keyboard on mobile (only for android) // focus opens the keyboard on mobile (only for android)
if (!this.isTouchDevice) { if (!this.hasMobileKeyboard) {
this._textarea.focus() this._textarea.focus()
} }
@ -678,7 +677,7 @@
public mobileKeyboardShow() { public mobileKeyboardShow() {
// skip if not a touch device // skip if not a touch device
if (!this.isTouchDevice) return if (!this.hasMobileKeyboard) return
this.kbdShow = true this.kbdShow = true
this.kbdOpen = false this.kbdOpen = false
@ -690,7 +689,7 @@
public mobileKeyboardHide() { public mobileKeyboardHide() {
// skip if not a touch device // skip if not a touch device
if (!this.isTouchDevice) return if (!this.hasMobileKeyboard) return
this.kbdShow = false this.kbdShow = false
this.kbdOpen = false this.kbdOpen = false