// #include /lib/std // #include /lib/win const drag = f => ({ pointerdown: e => (e.target === e.currentTarget || e.target.closest('[data-drag]')) && e.currentTarget.setPointerCapture(e.pointerId), pointermove: e => e.buttons === 1 && e.currentTarget.hasPointerCapture(e.pointerId) && f(e.movementX, e.movementY) }), stk = () => val('/srv/win/stack').split(' ').filter(Boolean), raise = pid => { stk().at(-1) !== pid && put('/srv/win/stack', [...stk().filter(x => x !== pid), pid].join(' ')) }, geo = pid => val('/srv/win/' + pid + '/xywh', '10 10 400 400').split(' ').map(Number), spawn = (id = stk().at(-1), [x, y] = id ? geo(id) : [-6, -6]) => [x + 16, y + 16, 400, 400].join(' '), sel = () => val('/srv/win/sel').split(' ').filter(Boolean), tog = pid => put('/srv/win/sel', (sel().includes(pid) ? sel().filter(x => x !== pid) : [...sel(), pid]).join(' ')), Win = (p, pid) => { const xywh = () => val(p + 'xywh', '0 0 0 0').split(' ').map(Number), move = drag((dx, dy, [x, y, w, h] = xywh()) => put(p + 'xywh', [x + dx, y + dy, w, h].join(' '))), resize = drag((dx, dy, [x, y, w, h] = xywh()) => put(p + 'xywh', [x, y, w + dx, h + dy].join(' '))) return Div({ cls: 'ba flx col bgc', handlers: { pointerdown: e => mod(e) || put(p + 'ctl', 'activate') } }, Div({ cls: 'flx pad aic bb g mv', handlers: { ...move, click: e => mod(e) && tog(pid), dblclick: e => !mod(e) && put(put('/srv/proc/new', '/bin/req') + 'fs/head', 'get /srv/proc/' + pid + '/') } }, Div({ cls: 'fg1 ell', dataset: { drag: '' } }).props(() => ({ textContent: val(p + 'label') })), Div({ cls: 'ba fs0 ptr', style: 'width:12px;height:12px', click: () => put(p + 'ctl', 'close') }) ).props(() => ({ className: cx(stk().at(-1) === pid && 'hl') })), Div({ id: get(p + 'name'), cls: 'ovh flx col fg1' }), Div({ style: 'position:absolute;right:-8px;bottom:-8px;width:12px;height:12px;cursor:nwse-resize', handlers: resize }) ).props(() => { const [x, y, w, h] = xywh(); return { className: cx(sel().includes(pid) && 'rng'), style: 'position:absolute;left:' + x + 'px;top:' + y + 'px;width:' + w + 'px;height:' + h + 'px;z-index:' + (stk().indexOf(pid) + 1) + (stk().at(-1) === pid ? ';border-color:var(--hb)' : '') } }) } mount('/srv/win/', (v, p, d, n) => { const [, pid, file] = p.split('/') if (v === 'get' && pid && file === '') return n() + '\n=> name\n=> ctl' if (file === 'name') return 'paw-' + pid if (file === 'ctl') return v !== 'put' ? err('not allowed') : d === 'close' ? put('/srv/proc/' + pid + '/ctl', 'close') : d === 'activate' ? raise(pid) : err('unknown control message "' + (d ?? '') + '"') return n() }) put('/srv/dom/paw'); tra({ dis: () => del('/srv/dom/paw') }) document.getElementById('paw').replaceChildren(tra(List( () => lsd('/srv/win/'), pid => { const p = '/srv/win/' + pid + '/' def(p + 'label', 'untitled') def(p + 'xywh', spawn()) stk().includes(pid) || raise(pid) return Win(p, pid) }, { key: pid => pid, cls: 'scr usn', style: 'position:relative', handlers: { dblclick: e => { if (e.target !== e.currentTarget) return const pid = put('/srv/proc/new', '/bin/req').split('/').at(-2) put('/srv/win/' + pid + '/xywh', [e.offsetX, e.offsetY, 400, 400].join(' ')) } } } )).$e) document.getElementById('paw').prepend(tra(H('style').props(() => ({ textContent: val('/lib/css') }))).$e) sub(() => lsd('/srv/proc/'), l => lsd('/srv/win/').filter(x => !l.includes(x)).forEach(x => del('/srv/win/' + x))) sub(() => lsd('/srv/win/'), l => put('/srv/win/stack', stk().filter(x => l.includes(x)).join(' '))) sub(() => lsd('/srv/win/'), l => put('/srv/win/sel', sel().filter(x => l.includes(x)).join(' ')))