From d7f41f2bce51bd481b24bc6614b43af42f486f11 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 4 May 2020 16:41:35 -0600 Subject: [PATCH] multishell/kernel support for windows on different devices --- sys/init/7.multishell.lua | 48 ++++++++++++++++++++++----------------- sys/kernel.lua | 21 ++++++++++++----- sys/modules/opus/ui.lua | 32 ++++++++++++-------------- 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/sys/init/7.multishell.lua b/sys/init/7.multishell.lua index 1f44a0d..4b581bd 100644 --- a/sys/init/7.multishell.lua +++ b/sys/init/7.multishell.lua @@ -296,40 +296,46 @@ kernel.hook('term_resize', function(_, eventData) end) kernel.hook('mouse_click', function(_, eventData) - local x, y = eventData[2], eventData[3] + if not eventData[4] then + local x, y = eventData[2], eventData[3] - if y == 1 then - if x == 1 then - multishell.setFocus(overviewId) - elseif x == w then - local currentTab = kernel.getFocused() - if currentTab then - multishell.terminate(currentTab.uid) - end - else - for _,tab in pairs(kernel.routines) do - if not tab.hidden and tab.sx then - if x >= tab.sx and x <= tab.ex then - multishell.setFocus(tab.uid) - break + if y == 1 then + if x == 1 then + multishell.setFocus(overviewId) + elseif x == w then + local currentTab = kernel.getFocused() + if currentTab then + multishell.terminate(currentTab.uid) + end + else + for _,tab in pairs(kernel.routines) do + if not tab.hidden and tab.sx then + if x >= tab.sx and x <= tab.ex then + multishell.setFocus(tab.uid) + break + end end end end + return true end - return true + eventData[3] = eventData[3] - 1 end - eventData[3] = eventData[3] - 1 end) kernel.hook({ 'mouse_up', 'mouse_drag' }, function(_, eventData) - eventData[3] = eventData[3] - 1 + if not eventData[4] then + eventData[3] = eventData[3] - 1 + end end) kernel.hook('mouse_scroll', function(_, eventData) - if eventData[3] == 1 then - return true + if not eventData[4] then + if eventData[3] == 1 then + return true + end + eventData[3] = eventData[3] - 1 end - eventData[3] = eventData[3] - 1 end) kernel.hook('kernel_ready', function() diff --git a/sys/kernel.lua b/sys/kernel.lua index 546300d..ea4233c 100644 --- a/sys/kernel.lua +++ b/sys/kernel.lua @@ -50,13 +50,19 @@ function kernel.hook(event, fn) end end --- you can only unhook from within the function that hooked +-- you *should* only unhook from within the function that hooked function kernel.unhook(event, fn) - local eventHooks = kernel.hooks[event] - if eventHooks then - Array.removeByValue(eventHooks, fn) - if #eventHooks == 0 then - kernel.hooks[event] = nil + if type(event) == 'table' then + for _,v in pairs(event) do + kernel.unhook(v, fn) + end + else + local eventHooks = kernel.hooks[event] + if eventHooks then + Array.removeByValue(eventHooks, fn) + if #eventHooks == 0 then + kernel.hooks[event] = nil + end end end end @@ -107,6 +113,9 @@ function Routine:resume(event, ...) end if coroutine.status(self.co) == 'dead' then Array.removeByValue(kernel.routines, self) + if self.onDestroy then + self.onDestroy(self) + end if #kernel.routines > 0 then switch(kernel.routines[1]) end diff --git a/sys/modules/opus/ui.lua b/sys/modules/opus/ui.lua index 4f4efb5..36afdc2 100644 --- a/sys/modules/opus/ui.lua +++ b/sys/modules/opus/ui.lua @@ -75,11 +75,11 @@ function UI:init() term_resize = resize, monitor_resize = resize, - mouse_scroll = function(_, direction, x, y) + mouse_scroll = function(_, direction, x, y, side) local ie = Input:translate('mouse_scroll', direction, x, y) local currentPage = self:getActivePage() - if currentPage then + if currentPage and currentPage.parent.device.side == side then local event = currentPage:pointToChild(x, y) event.type = ie.code event.ie = { code = ie.code, x = event.x, y = event.y } @@ -97,23 +97,21 @@ function UI:init() end end, - mouse_click = function(_, button, x, y) + mouse_click = function(_, button, x, y, side) local ie = Input:translate('mouse_click', button, x, y) local currentPage = self:getActivePage() - if currentPage then - if not currentPage.parent.device.side then - local event = currentPage:pointToChild(x, y) - if event.element.focus and not event.element.inactive then - currentPage:setFocus(event.element) - currentPage:sync() - end - self:click(currentPage, ie) + if currentPage and currentPage.parent.device.side == side then + local event = currentPage:pointToChild(x, y) + if event.element.focus and not event.element.inactive then + currentPage:setFocus(event.element) + currentPage:sync() end + self:click(currentPage, ie) end end, - mouse_up = function(_, button, x, y) + mouse_up = function(_, button, x, y, side) local ie = Input:translate('mouse_up', button, x, y) local currentPage = self:getActivePage() @@ -124,18 +122,16 @@ function UI:init() args = { event.element }, focused = true }) - elseif ie and currentPage then - if not currentPage.parent.device.side then - self:click(currentPage, ie) - end + elseif ie and currentPage and currentPage.parent.device.side == side then + self:click(currentPage, ie) end end, - mouse_drag = function(_, button, x, y) + mouse_drag = function(_, button, x, y, side) local ie = Input:translate('mouse_drag', button, x, y) local currentPage = self:getActivePage() - if ie and currentPage then + if ie and currentPage and currentPage.parent.device.side == side then self:click(currentPage, ie) end end,