From 1479a4dfbbbc7acb2da963dc30a1a925d7723bf3 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Sat, 22 Mar 2025 01:53:17 +0300 Subject: [PATCH] mxwm zcom implementation --- app/mxwm/package.json | 8 ++++ app/mxwm/startz.js | 20 ++++++++++ app/mxwm/zcom.js | 88 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 app/mxwm/package.json create mode 100644 app/mxwm/startz.js create mode 100644 app/mxwm/zcom.js diff --git a/app/mxwm/package.json b/app/mxwm/package.json new file mode 100644 index 0000000..649c11c --- /dev/null +++ b/app/mxwm/package.json @@ -0,0 +1,8 @@ +{ + "name": "mxwm", + "version": "0.1.0", + "description": "Mega eXtreme Window Manager", + "author": "MeexReay", + "apps": [ "zcom.js", "startz.js" ], + "configs": [] +} \ No newline at end of file diff --git a/app/mxwm/startz.js b/app/mxwm/startz.js new file mode 100644 index 0000000..81441ec --- /dev/null +++ b/app/mxwm/startz.js @@ -0,0 +1,20 @@ +eval(readFile("/app/zcom.js")) + +async function main(args) { + enableGraphics() + + window.mxwm_windows = [] + + let ctx = getGraphics() + + while (true) { + ctx.fillStyle = "black" + ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height) + + for (const win of window.mxwm_windows) { + ctx.drawImage(win.canvas, win.x, win.y); + } + } + + disableGraphics() +} \ No newline at end of file diff --git a/app/mxwm/zcom.js b/app/mxwm/zcom.js new file mode 100644 index 0000000..880dfa7 --- /dev/null +++ b/app/mxwm/zcom.js @@ -0,0 +1,88 @@ +function hasGraphicsImplementation() { + return true +} + +/** returns wid and context */ +function createWindow(options) { + let canvas = document.createElement("canvas") + + let win = { + "title": options["title"], + "x": options["x"] || 0, + "y": options["y"] || 0, + "width": options["width"] || options["w"] || 200, + "height": options["height"] || options["h"] || 200, + "wid": Date.now().toString() + Math.round(Math.random() * 100).toString(), + "on_signal": options["on_signal"] || options["callback"] || (o => {}) + } + + canvas.width = win["width"].toString() + canvas.height = win["height"].toString() + + let context = canvas.getContext("2d") + + win["canvas"] = canvas + win["context"] = context + + if ("mxwm_windows" in window) { + window.mxwm_windows.push(win) + } else { + window.mxwm_windows = [ win ] + } +} + +function moveWindow(wid, x, y, w, h) { + if (!("mxwm_windows" in window)) { + window.mxwm_windows = [ ] + } + + for (const win of window.mxwm_windows) { + if (win["wid"] == wid) { + win.x = x + win.y = y + win.width = w + win.height = h + } + } +} + +function signalWindow(wid, signal) { + if (!("mxwm_windows" in window)) { + window.mxwm_windows = [ ] + } + + for (const win of window.mxwm_windows) { + if (win["wid"] == wid) { + win.on_signal(signal) + } + } +} + +function closeWindow(wid) { + if (!("mxwm_windows" in window)) { + window.mxwm_windows = [ ] + } + + window.mxwm_windows = window.mxwm_windows.filter(o => o.wid != wid) +} + +function getWindow(wid) { + if (!("mxwm_windows" in window)) { + window.mxwm_windows = [ ] + } + + for (const win of window.mxwm_windows) { + if (win["wid"] == wid) { + return win + } + } + return null +} + +function listWindows() { + if (!("mxwm_windows" in window)) { + window.mxwm_windows = [ ] + } + + return window.mxwm_windows +} \ No newline at end of file