mirror of
https://github.com/MeexReay/poshlostios.git
synced 2025-06-24 10:32:59 +03:00
fix window selection + add typed keys to zterm
This commit is contained in:
parent
3a1b74a55c
commit
e750cfc79e
@ -39,7 +39,14 @@ async function onStart(screen_ctx) {
|
|||||||
"width": 500,
|
"width": 500,
|
||||||
"height": 500,
|
"height": 500,
|
||||||
"x": 50,
|
"x": 50,
|
||||||
"y": 50
|
"y": 50,
|
||||||
|
"onkeydown": key => {
|
||||||
|
ctx.fillStyle = "#222";
|
||||||
|
ctx.font = "bold 14px sans-serif";
|
||||||
|
ctx.textBaseline = "middle";
|
||||||
|
ctx.textAlign = "left";
|
||||||
|
ctx.fillText(key, 10, 10);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.fillStyle = "cyan"
|
ctx.fillStyle = "cyan"
|
||||||
@ -50,29 +57,35 @@ async function onKeyDown(ctx, key) {
|
|||||||
if (key == "Escape") {
|
if (key == "Escape") {
|
||||||
disableGraphics()
|
disableGraphics()
|
||||||
}
|
}
|
||||||
getWindow(selected_window).onkeydown(key)
|
if (selected_window != null) getWindow(selected_window).onkeydown(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onKeyUp(ctx, key) {
|
async function onKeyUp(ctx, key) {
|
||||||
getWindow(selected_window).onkeyup(key)
|
if (selected_window != null) getWindow(selected_window).onkeyup(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
let dragging_window = null
|
let dragging_window = null
|
||||||
|
let selected_window = null
|
||||||
|
|
||||||
function isMouseOnHeader(window) {
|
function isMouseOnHeader(window) {
|
||||||
return window.x < mouse_position[0] && mouse_position[0] < window.x + window.width &&
|
return window.x < mouse_position[0] && mouse_position[0] < window.x + window.width &&
|
||||||
window.y - headerHeight < mouse_position[1] && mouse_position[1] < window.y
|
window.y - headerHeight < mouse_position[1] && mouse_position[1] < window.y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isMouseInside(window) {
|
||||||
|
return mouse_position[0] >= window.x &&
|
||||||
|
mouse_position[1] >= window.y &&
|
||||||
|
mouse_position[0] <= window.x + window.width &&
|
||||||
|
mouse_position[1] <= window.y + window.height
|
||||||
|
}
|
||||||
|
|
||||||
async function onMouseDown(ctx, button) {
|
async function onMouseDown(ctx, button) {
|
||||||
for (let window of listWindows()) {
|
for (let window of listWindows()) {
|
||||||
if (isMouseOnHeader(window)) {
|
if (isMouseOnHeader(window)) {
|
||||||
dragging_window = window["wid"]
|
dragging_window = window["wid"]
|
||||||
|
selected_window = window["wid"]
|
||||||
}
|
}
|
||||||
if (mouse_position[0] >= window.x &&
|
if (isMouseInside(window)) {
|
||||||
mouse_position[1] >= window.y &&
|
|
||||||
mouse_position[0] + window.width <= window.x &&
|
|
||||||
mouse_position[1] + window.height <= window.y) {
|
|
||||||
selected_window = window["wid"]
|
selected_window = window["wid"]
|
||||||
window.onmousedown(button)
|
window.onmousedown(button)
|
||||||
}
|
}
|
||||||
@ -80,17 +93,13 @@ async function onMouseDown(ctx, button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onMouseUp(ctx, button) {
|
async function onMouseUp(ctx, button) {
|
||||||
let window = getWindow(dragging_window)
|
for (let window of listWindows()) {
|
||||||
|
if (isMouseOnHeader(window)) {
|
||||||
if (isMouseOnHeader(window)) {
|
dragging_window = null
|
||||||
dragging_window = null
|
}
|
||||||
}
|
if (isMouseInside(window)) {
|
||||||
|
window.onmouseup(button)
|
||||||
if (mouse_position[0] >= window.x &&
|
}
|
||||||
mouse_position[1] >= window.y &&
|
|
||||||
mouse_position[0] + window.width <= window.x &&
|
|
||||||
mouse_position[1] + window.height <= window.y) {
|
|
||||||
window.onmouseup(button)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,11 +116,10 @@ async function onMouseMove(ctx, x, y) {
|
|||||||
|
|
||||||
mouse_position = [x, y]
|
mouse_position = [x, y]
|
||||||
|
|
||||||
if (mouse_position[0] >= window.x &&
|
for (let window of listWindows()) {
|
||||||
mouse_position[1] >= window.y &&
|
if (isMouseInside(window)) {
|
||||||
mouse_position[0] + window.width <= window.x &&
|
window.onmousemove(mouse_position[0] - window.x, mouse_position[1] - window.y)
|
||||||
mouse_position[1] + window.height <= window.y) {
|
}
|
||||||
window.onmousemove(mouse_position[0] - window.x, mouse_position[1] - window.y)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user