X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=ioncore%2Fioncore_quasiact.lua;fp=ioncore%2Fioncore_quasiact.lua;h=ce4116d1d8a17024eb3fc7be5f2c2b30bc2822f7;hp=0000000000000000000000000000000000000000;hb=f869221ce49f0fb7cca48eee28daff8684305963;hpb=720e6978185b09f2b2f60a6b96018238085a7238 diff --git a/ioncore/ioncore_quasiact.lua b/ioncore/ioncore_quasiact.lua new file mode 100644 index 0000000..ce4116d --- /dev/null +++ b/ioncore/ioncore_quasiact.lua @@ -0,0 +1,74 @@ +-- +-- ion/share/ioncore_quasiact.lua -- Frame quasiactivation support +-- +-- Copyright (c) Tuomo Valkonen 2007. +-- +-- See the included file LICENSE for details. +-- + +local qa_source={} +local qa_target={} + +local function quasi_activated(frame, src) + local old=qa_source[frame] + if old then + qa_target[old]=nil + end + qa_source[frame]=src + qa_target[src]=frame + ioncore.defer(function() frame:set_grattr("quasiactive", "set") end) +end + +local function quasi_inactivated(frame, src) + qa_source[frame]=nil + qa_target[src]=nil + ioncore.defer(function() frame:set_grattr("quasiactive", "unset") end) +end + +local function activated(src) + local tgt=src:__return_target() + if obj_is(tgt, "WFrame") then + quasi_activated(tgt, src) + elseif obj_is(tgt, "WGroup") then + local mgr=tgt:manager() + if obj_is(mgr, "WFrame") then + quasi_activated(mgr, src) + end + end +end + +local function inactivated(src) + local tgt=qa_target[src] + if tgt then + quasi_inactivated(tgt, src) + return true + end +end + +local function deinit(tgt) + local src=qa_source[tgt] + if src then + qa_target[src]=nil + qa_source[tgt]=nil + end +end + +local function quasiact_notify(reg, how) + if how=="activated" or how=="pseudoactivated" then + activated(reg) + elseif how=="inactivated" or how=="pseudoinactivated" then + inactivated(reg) + elseif how=="set_return" then + if reg:is_active(true--[[pseudoact--]]) then + activated(reg) + end + elseif how=="unset_return" then + inactivated(reg) + elseif how=="deinit" then + inactivated(reg) + deinit(reg) + end +end + + +ioncore.get_hook("region_notify_hook"):add(quasiact_notify)