Log In  

When windows or process lose visibility, the window manager sends the "lost_visibility" event to the process. This unsets the "running" bit (controls whether a process is running or suspended):

-- /system/lib/events.lua - lines 275-277
if (msg.event == "lost_visibility") then
  if (pid() > 3) poke(0x547f, peek(0x547f) & ~0x1) -- safety: only userland processes can lose visibility
end

The way we can get around this is having our process define a custom implementation of poke that avoids setting that bit. Copy and paste the following into any process that you'd like to keep running, even when it loses visibility:

-- get a reference to the system-defined poke()
local _sys_poke = poke
local is_visible = true
-- define a custom version of the function
poke = function(loc, val)
    -- if we see incoming parameters that would suspend our process...
    if loc == 0x547f and val == peek(0x547f) & ~0x1 then
        is_visible = false
        return -- don't set the lost_visibility flag
    end
    if loc == 0x547f and val == peek(0x547f) | 0x1 then
        is_visible = true
    end
    -- otherwise, just continue with poke()
    _sys_poke(loc, val)
end

Be careful with this power, as it will make your process consume CPU resources until a user initiates some sort of way to kill the process. To reduce CPU resource consumption, just wrap all of your draw code in this way:

function _draw()
    if is_visible then
        -- draw code goes here
    end
end

NOTE: this is just a temporary hack. There are comments zep has left in the system files that state that official background process support is coming in the future.

P#144309 2024-03-24 17:24 ( Edited 2024-03-24 18:01)


[Please log in to post a comment]