From 6bd1f6d49d52df0e59f951fd3472c3355ec7f7a9 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sat, 20 Aug 2022 23:38:33 +0200 Subject: [PATCH] Fixes - fixed a bug where program still listens to other events (even the program is using a filter for pullEvent) - fixed a focus bug, now if a program is focused and you terminate, the program will be terminated instead of basalt) --- Basalt/Frame.lua | 17 +++++++++-------- Basalt/Object.lua | 3 +++ Basalt/libraries/process.lua | 6 +++++- Basalt/main.lua | 1 - Basalt/objects/Program.lua | 11 +++++------ 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index 800d2c0..b29820e 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -38,7 +38,7 @@ return function(name, parent, pTerm, basalt) local isMovable = false local isDragging =false - local focusedOBjectCache + local focusedObjectCache local focusedObject local autoSize = true local autoScroll = true @@ -339,14 +339,15 @@ return function(name, parent, pTerm, basalt) end local function focusSystem(self) - if(focusedObject~=focusedOBjectCache)then + if(focusedObject~=focusedObjectCache)then if(focusedObject~=nil)then focusedObject:loseFocusHandler() end - if(focusedOBjectCache~=nil)then - focusedOBjectCache:getFocusHandler() + if(focusedObjectCache~=nil)then + focusedObjectCache:getFocusHandler() end - focusedObject = focusedOBjectCache + focusedObject = focusedObjectCache + focusedObjectCache = nil end end @@ -371,7 +372,7 @@ return function(name, parent, pTerm, basalt) end; setFocusedObject = function(self, obj) - focusedOBjectCache = obj + focusedObjectCache = obj return self end; @@ -447,7 +448,7 @@ return function(name, parent, pTerm, basalt) end; removeFocusedObject = function(self) - focusedOBjectCache = nil + focusedObjectCache = nil return self end; @@ -667,7 +668,7 @@ return function(name, parent, pTerm, basalt) loseFocusHandler = function(self) base.loseFocusHandler(self) - if(focusedObject~=nil)then focusedObject:loseFocusHandler() end + if(focusedObject~=nil)then focusedObject:loseFocusHandler() focusedObject = nil end end; getFocusHandler = function(self) diff --git a/Basalt/Object.lua b/Basalt/Object.lua index 042346a..69d1d93 100644 --- a/Basalt/Object.lua +++ b/Basalt/Object.lua @@ -1,5 +1,6 @@ local basaltEvent = require("basaltEvent") local utils = require("utils") +local log = require("basaltLogs") local split = utils.splitString local numberFromString = utils.numberFromString local xmlValue = utils.getValueFromXML @@ -828,6 +829,7 @@ return function(name) getFocusHandler = function(self) local val = eventSystem:sendEvent("get_focus", self) if(val~=nil)then return val end + log("Focus "..self:getName()) return true end; @@ -835,6 +837,7 @@ return function(name) isDragging = false local val = eventSystem:sendEvent("lose_focus", self) if(val~=nil)then return val end + log("Losefocus "..self:getName()) return true end; diff --git a/Basalt/libraries/process.lua b/Basalt/libraries/process.lua index eadf1ae..2de4672 100644 --- a/Basalt/libraries/process.lua +++ b/Basalt/libraries/process.lua @@ -17,12 +17,16 @@ end function process:resume(event, ...) term.redirect(self.window) + if(self.filter~=nil)then + if(event~=self.filter)then return end + self.filter=nil + end local ok, result = coroutine.resume(self.coroutine, event, ...) self.window = term.current() if ok then self.filter = result else - basalt.debug(result) + error(result) end end diff --git a/Basalt/main.lua b/Basalt/main.lua index 3fbc654..0628231 100644 --- a/Basalt/main.lua +++ b/Basalt/main.lua @@ -2,7 +2,6 @@ local basaltEvent = require("basaltEvent")() local Frame = require("Frame") local theme = require("theme") local utils = require("utils") -local log = require("basaltLogs") local uuid = utils.uuid local createText = utils.createText diff --git a/Basalt/objects/Program.lua b/Basalt/objects/Program.lua index 9449e76..6a5df05 100644 --- a/Basalt/objects/Program.lua +++ b/Basalt/objects/Program.lua @@ -675,7 +675,7 @@ return function(name, parent) end end end - end; + end, loseFocusHandler = function(self) base.loseFocusHandler(self) @@ -686,7 +686,7 @@ return function(name, parent) end end end - end; + end, eventHandler = function(self, event, p1, p2, p3, p4) if(base.eventHandler(self, event, p1, p2, p3, p4))then @@ -721,6 +721,7 @@ return function(name, parent) end if (event == "terminate") then + log(self:isFocused()) curProcess:resume(event) self.parent:setCursor(false) return true @@ -730,8 +731,9 @@ return function(name, parent) table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } }) end end + return false end - end; + end, draw = function(self) if (base.draw(self)) then @@ -739,9 +741,6 @@ return function(name, parent) local obx, oby = self:getAnchorPosition() local w,h = self:getSize() pWindow.basalt_reposition(obx, oby) - if(self.bgColor~=false)then - self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor) - end pWindow.basalt_update() end end