]> git.decadent.org.uk Git - ion3.git/blob - ioncore/ioncore_quasiact.lua
13749965167e2c12d53eb90ddcbc01962a659fcd
[ion3.git] / ioncore / ioncore_quasiact.lua
1 --
2 -- ion/share/ioncore_quasiact.lua -- Frame quasiactivation support
3 -- 
4 -- Copyright (c) Tuomo Valkonen 2007-2008.
5 --
6 -- See the included file LICENSE for details.
7 --
8
9 local qa_source={}
10 local qa_target={}
11
12 local function quasi_activated(frame, src)
13     local old=qa_source[frame]
14     if old then
15         qa_target[old]=nil
16     end
17     qa_source[frame]=src
18     qa_target[src]=frame
19     ioncore.defer(function() frame:set_grattr("quasiactive", "set") end)
20 end
21
22 local function quasi_inactivated(frame, src)
23     qa_source[frame]=nil
24     qa_target[src]=nil
25     ioncore.defer(function() frame:set_grattr("quasiactive", "unset") end)
26 end
27
28 local function activated(src)
29     local tgt=src:__return_target()
30     if obj_is(tgt, "WFrame") then
31         quasi_activated(tgt, src)
32     elseif obj_is(tgt, "WGroup") then
33         local mgr=tgt:manager()
34         if obj_is(mgr, "WFrame") then
35             quasi_activated(mgr, src)
36         end
37     end
38 end
39
40 local function inactivated(src)
41     local tgt=qa_target[src]
42     if tgt then
43         quasi_inactivated(tgt, src)
44         return true
45     end
46 end
47
48 local function deinit(tgt)
49     local src=qa_source[tgt]
50     if src then
51         qa_target[src]=nil
52         qa_source[tgt]=nil
53     end
54 end
55
56 local function quasiact_notify(reg, how)
57     if how=="activated" or how=="pseudoactivated" then
58         activated(reg)
59     elseif how=="inactivated" or how=="pseudoinactivated" then
60         inactivated(reg)
61     elseif how=="set_return" then
62         if reg:is_active(true--[[pseudoact--]]) then
63             activated(reg)
64         end
65     elseif how=="unset_return" then
66         inactivated(reg)
67     elseif how=="deinit" then
68         inactivated(reg)
69         deinit(reg)
70     end
71 end
72
73
74 ioncore.get_hook("region_notify_hook"):add(quasiact_notify)