From: Ian Jackson Date: Wed, 30 Sep 2020 23:11:26 +0000 (+0100) Subject: wip key events X-Git-Tag: otter-0.2.0~810 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=225b1d63daf3a15e615d6fae3bca3c7f88440357;p=otter.git wip key events Signed-off-by: Ian Jackson --- diff --git a/templates/script.ts b/templates/script.ts index 446de6f9..7227fdd6 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -208,6 +208,72 @@ function piece_element(base: string, piece: PieceId): SVGGraphicsElement | null return svg_element(base+piece); } +// ----- key handling ----- + +function recompute_keybindings() { + uo_map = Object.create(null); + for (let piece of Object.keys(pieces)) { + let p = pieces[piece]; + if (p.held != us) continue; + for (var uo of p.uos) { + let currently = uo_map[uo.def_key]; + if (currently === null) continue; + if (currently !== undefined) { + if (currently.opname != uo.opname) { + uo_map[uo.def_key] = null; + continue; + } + } else { + currently = { + targets: [], + ...uo + }; + uo_map[uo.def_key] = currently; + } + currently.desc = currently.desc < uo.desc ? currently.desc : uo.desc; + currently.targets!.push(piece); + } + } + uo_map['W'] = { + kind: 'ClientExtra', + def_key: 'W', + opname: 'wrest', + desc: 'Enter wresting mode', + targets: null, + wrc: 'Predictable', + } + var uo_keys = Object.keys(uo_map); + uo_keys.sort(function (ak,bk) { + let a = uo_map[ak]!; + let b = uo_map[bk]!; + return uo_kind_prec[a.kind] - uo_kind_prec[b.kind] + || ak.localeCompare(bk); + }); + let out = document.createElement('div'); + out.setAttribute('class','uokeys'); + for (var kk of uo_keys) { + let uo = uo_map[kk]!; + let ent = document.createElement('div'); + ent.setAttribute('class','uokey-'+uo.kind); + ent.innerHTML = '' + kk + ' ' + uo.desc; + out.appendChild(ent); + } + uos_node.firstChild!.replaceWith(out); +} + +function some_keydown(e: KeyboardEvent) { + // https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event + // says to do this, something to do with CJK composition. + // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent + // says that keyCode is deprecated + // my tsc says this isComposing thing doesn't exist. wat. + if ((e as any).isComposing /* || e.keyCode === 229 */) return; + + let uo = uo_map[e.key]; + if (uo === undefined) return; + + console.log('KEY UO', e, uo); +} // ----- clicking/dragging pieces ----- @@ -642,57 +708,6 @@ function test_swap_stack() { window.setTimeout(test_swap_stack, 1000); } -function recompute_keybindings() { - uo_map = Object.create(null); - for (let piece of Object.keys(pieces)) { - let p = pieces[piece]; - if (p.held != us) continue; - for (var uo of p.uos) { - let currently = uo_map[uo.def_key]; - if (currently === null) continue; - if (currently !== undefined) { - if (currently.opname != uo.opname) { - uo_map[uo.def_key] = null; - continue; - } - } else { - currently = { - targets: [], - ...uo - }; - uo_map[uo.def_key] = currently; - } - currently.desc = currently.desc < uo.desc ? currently.desc : uo.desc; - currently.targets!.push(piece); - } - } - uo_map['W'] = { - kind: 'ClientExtra', - def_key: 'W', - opname: 'wrest', - desc: 'Enter wresting mode', - targets: null, - wrc: 'Predictable', - } - var uo_keys = Object.keys(uo_map); - uo_keys.sort(function (ak,bk) { - let a = uo_map[ak]!; - let b = uo_map[bk]!; - return uo_kind_prec[a.kind] - uo_kind_prec[b.kind] - || ak.localeCompare(bk); - }); - let out = document.createElement('div'); - out.setAttribute('class','uokeys'); - for (var kk of uo_keys) { - let uo = uo_map[kk]!; - let ent = document.createElement('div'); - ent.setAttribute('class','uokey-'+uo.kind); - ent.innerHTML = '' + kk + ' ' + uo.desc; - out.appendChild(ent); - } - uos_node.firstChild!.replaceWith(out); -} - function startup() { var body = document.getElementById("main-body")!; ctoken = body.dataset.ctoken!; @@ -761,8 +776,8 @@ function startup() { }) } recompute_keybindings(); - -// test_swap_stack(); + space.addEventListener('mousedown', some_mousedown); + space.addEventListener('keydown', some_keydown); } function doload(){ diff --git a/templates/session.tera b/templates/session.tera index 65b9e655..52acd882 100644 --- a/templates/session.tera +++ b/templates/session.tera @@ -28,7 +28,6 @@