mirror of
https://github.com/MeexReay/poshlostios.git
synced 2025-06-24 10:32:59 +03:00
keybind for resizing and moving
This commit is contained in:
parent
389dcb6d0e
commit
fb80e3f0da
@ -66,6 +66,7 @@ function moveWindowToTop(wid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let pressedKeys = []
|
let pressedKeys = []
|
||||||
|
let pressedButtons = [false, false, false]
|
||||||
|
|
||||||
function isPressed(key) {
|
function isPressed(key) {
|
||||||
return pressedKeys.indexOf(key) !== -1
|
return pressedKeys.indexOf(key) !== -1
|
||||||
@ -76,8 +77,6 @@ async function onKeyDown(ctx, key) {
|
|||||||
pressedKeys.push(key)
|
pressedKeys.push(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(pressedKeys)
|
|
||||||
|
|
||||||
if ((isPressed("Alt") || isPressed("Meta")) && isPressed("Shift") && isPressed("Q")) {
|
if ((isPressed("Alt") || isPressed("Meta")) && isPressed("Shift") && isPressed("Q")) {
|
||||||
disableGraphics()
|
disableGraphics()
|
||||||
return
|
return
|
||||||
@ -103,8 +102,6 @@ async function onKeyUp(ctx, key) {
|
|||||||
pressedKeys.splice(index, 1)
|
pressedKeys.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(pressedKeys)
|
|
||||||
|
|
||||||
if (selected_window != null) getWindow(selected_window).onkeyup(key)
|
if (selected_window != null) getWindow(selected_window).onkeyup(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,39 +129,57 @@ function isMouseOnCorner(window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onMouseDown(ctx, button) {
|
async function onMouseDown(ctx, button) {
|
||||||
|
if (button >= 0 && button <= 2) {
|
||||||
|
pressedButtons[button] = true
|
||||||
|
}
|
||||||
|
|
||||||
for (let window of listWindows()) {
|
for (let window of listWindows()) {
|
||||||
if (isMouseOnHeader(window)) {
|
if (isMouseOnHeader(window) ||
|
||||||
|
((selected_window == window.wid || isMouseInside(window))
|
||||||
|
&& isPressed("Alt") && button == 0)) {
|
||||||
dragging_window = window["wid"]
|
dragging_window = window["wid"]
|
||||||
selected_window = window["wid"]
|
selected_window = window["wid"]
|
||||||
setGraphicsCursor("grabbing")
|
setGraphicsCursor("grabbing")
|
||||||
moveWindowToTop(window.wid)
|
moveWindowToTop(window.wid)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (isMouseOnCorner(window) ||
|
||||||
|
((selected_window == window.wid || isMouseInside(window))
|
||||||
|
&& isPressed("Alt") && button == 2)) {
|
||||||
|
resizing_window = window["wid"]
|
||||||
|
selected_window = window["wid"]
|
||||||
|
setGraphicsCursor("nwse-resize")
|
||||||
|
moveWindowToTop(window.wid)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if (isMouseInside(window)) {
|
if (isMouseInside(window)) {
|
||||||
selected_window = window["wid"]
|
selected_window = window["wid"]
|
||||||
moveWindowToTop(window.wid)
|
moveWindowToTop(window.wid)
|
||||||
window.onmousedown(button)
|
window.onmousedown(button)
|
||||||
}
|
break
|
||||||
if (isMouseOnCorner(window)) {
|
|
||||||
resizing_window = window["wid"]
|
|
||||||
selected_window = window["wid"]
|
|
||||||
setGraphicsCursor("nwse-resize")
|
|
||||||
moveWindowToTop(window.wid)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onMouseUp(ctx, button) {
|
async function onMouseUp(ctx, button) {
|
||||||
for (let window of listWindows()) {
|
if (button >= 0 && button <= 2) {
|
||||||
if (isMouseOnHeader(window)) {
|
pressedButtons[button] = false
|
||||||
dragging_window = null
|
}
|
||||||
|
|
||||||
|
if (dragging_window != null) {
|
||||||
|
if (isMouseOnHeader(getWindow(dragging_window)))
|
||||||
setGraphicsCursor("grab")
|
setGraphicsCursor("grab")
|
||||||
}
|
dragging_window = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resizing_window != null) {
|
||||||
|
resizing_window = null
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let window of listWindows()) {
|
||||||
if (isMouseInside(window)) {
|
if (isMouseInside(window)) {
|
||||||
window.onmouseup(button)
|
window.onmouseup(button)
|
||||||
}
|
}
|
||||||
if (isMouseOnCorner(window)) {
|
|
||||||
resizing_window = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,18 +190,26 @@ async function onMouseMove(ctx, x, y) {
|
|||||||
|
|
||||||
if (dragging_window != null) {
|
if (dragging_window != null) {
|
||||||
let window = getWindow(dragging_window)
|
let window = getWindow(dragging_window)
|
||||||
if (isMouseOnHeader(window)) {
|
moveWindow(
|
||||||
moveWindow(dragging_window, window.x + (x - mouse_position[0]), window.y + (y - mouse_position[1]), window.width, window.height)
|
dragging_window,
|
||||||
cursor = "grabbing"
|
window.x + (x - mouse_position[0]),
|
||||||
}
|
window.y + (y - mouse_position[1]),
|
||||||
|
window.width,
|
||||||
|
window.height
|
||||||
|
)
|
||||||
|
cursor = "grabbing"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resizing_window != null) {
|
if (resizing_window != null) {
|
||||||
let window = getWindow(resizing_window)
|
let window = getWindow(resizing_window)
|
||||||
if (isMouseOnCorner(window)) {
|
moveWindow(
|
||||||
moveWindow(resizing_window, window.x, window.y, window.width + (x - mouse_position[0]), window.height + (y - mouse_position[1]))
|
resizing_window,
|
||||||
cursor = "nwse-resize"
|
window.x,
|
||||||
}
|
window.y,
|
||||||
|
window.width + (x - mouse_position[0]),
|
||||||
|
window.height + (y - mouse_position[1])
|
||||||
|
)
|
||||||
|
cursor = "nwse-resize"
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse_position = [x, y]
|
mouse_position = [x, y]
|
||||||
|
@ -15,6 +15,10 @@ function enableGraphics(options={}) {
|
|||||||
graphics_canvas.height = window.innerHeight.toString()
|
graphics_canvas.height = window.innerHeight.toString()
|
||||||
graphics_canvas.setAttribute("tabindex", "0")
|
graphics_canvas.setAttribute("tabindex", "0")
|
||||||
|
|
||||||
|
graphics_canvas.addEventListener('contextmenu', event => {
|
||||||
|
event.preventDefault()
|
||||||
|
})
|
||||||
|
|
||||||
if ("onmousemove" in options) {
|
if ("onmousemove" in options) {
|
||||||
graphics_canvas.onmousemove = e => {
|
graphics_canvas.onmousemove = e => {
|
||||||
options.onmousemove(e.x, e.y)
|
options.onmousemove(e.x, e.y)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user