From 0a8e438d4dd8b4bfe6b753e66bcfdb667a3c996a Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Sat, 29 Apr 2023 18:34:25 +0300 Subject: [PATCH] Fix windows dragging --- resources/sys/finder/finder.js | 5 +++- resources/wde.js | 42 ++++++++++++++++++++++++++++++---- templates/finder/app.tmpl | 2 +- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/resources/sys/finder/finder.js b/resources/sys/finder/finder.js index ec993f0..ef72590 100644 --- a/resources/sys/finder/finder.js +++ b/resources/sys/finder/finder.js @@ -38,9 +38,12 @@ class Finder{ }) if (!WebDesktopEnvironment.isMobile){ - let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector + // let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector + console.log(newWindow.querySelector("#closeWindowButton")) newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) { + WebDesktopEnvironment.CloseWindow(newWindow) + }) } }) diff --git a/resources/wde.js b/resources/wde.js index aa7da97..b58cd79 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -205,13 +205,41 @@ var getJSON = function(url, callback) { class WindowsCompositor{ windowLayer = undefined movingElement = null - xPosInit = 0 - yPosInit = 0 + // xPosInit = 0 + // yPosInit = 0 //TODO refactor this to dynamic add/remove listeners constructor(){ this.windowLayer = document.body.querySelector('#windows-layer') - // if (!WebDesktopEnvironment.isMobile) { + if (!WebDesktopEnvironment.isMobile) { + let startDrag = function(event) { + let targetClasses = event.target.className.split(' ') + if (targetClasses[targetClasses.length - 1] != 'DragArea'){ + return + } + // if (event.target.event.target.className != "DragArea"){} + let xPosInit = event.offsetX + let yPosInit = event.offsetY + let window = event.target.closest('.StandartApplicationWindow') + let dragWindow = function(event){ + // console.log(window) + // console.log(event.clientX) + // console.log(event.clientX - xPosInit, event.clientY - yPosInit) + WindowsCompositor.dragElement(window,event.clientX - xPosInit, event.clientY - yPosInit) + } + let stopDrag = function(){ + removeEventListener('mousemove', dragWindow) + removeEventListener('mouseup', stopDrag) + } + + addEventListener('mousemove', dragWindow) + addEventListener('mouseup', stopDrag) + // console.log(event) + } + + this.windowLayer.addEventListener('mousedown', startDrag) + } + if (false) { //FIXME addEventListener("mousedown", (event) => { this.xPosInit = event.offsetX @@ -262,8 +290,14 @@ class WindowsCompositor{ * @param {number} posX * @param {number} posY */ - dragElement(element, posX, posY) { //TODO + static dragElement(element, posX, posY) { //TODO element.style.left = `${posX}px` element.style.top = `${posY}px` } + + startDrag(){ + this.windowLayer.addEventListener('mousemove', () => { + console.log("move") + }) + } } diff --git a/templates/finder/app.tmpl b/templates/finder/app.tmpl index e7d05f2..880e052 100644 --- a/templates/finder/app.tmpl +++ b/templates/finder/app.tmpl @@ -1,5 +1,5 @@ {{ define "finder/app.tmpl" }} -
+