Expose XWarpPointer to lua as rootwin:warp_pointer, for region_do_warp_alt
[notion.git] / contrib / scripts / autoprop.lua
blob8d21b423256779a99952cbbdea42cc101c2f6f52
1 -- Authors: pinko, Etan Reisner <deryni@gmail.com>
2 -- License: Unknown
3 -- Last Changed: Unknown
4 --
5 -- Automatically create a winprop for the WClientWin given.
6 -- Basic functionality by pinko
7 -- Extended by Etan Reisner <deryni@gmail.com>
9 --defbindings("WFrame", {
10 ---- add winprop permanentlu
11 -- kpress(META.."W", "autoprop(_sub, _, true)", "_sub:WGroupCW"),
12 ---- add winprop for this session only
13 -- kpress(META.."E", "autoprop(_sub, _, false)", "_sub:WGroupCW"),
14 ---- remove winprop (permanently)
15 -- kpress(META.."Q", "autoprop(_sub, nil, X)"),
16 --})
18 -- Use autoprop(_sub, nil, X) to remove a winprop
20 local savefile="autoprops"
21 local autoprops={}
23 function autoprop(cwin_group, dest, save)
24 -- if obj_typename(cwin_group) ~= "WGroupCW" then
25 -- return
26 -- end
27 local p={}
29 local cwin = cwin_group:bottom()
31 if type(dest)=="nil" then
32 name=nil
33 else
34 name=dest:name()
35 end
37 p.class="*"
38 p.role="*"
39 p.instance="*"
40 p.target=name
42 p=table.join(cwin:get_ident(), p)
43 defwinprop{
44 class=p.class,
45 instance=p.instance,
46 role=p.role,
47 target=name
50 if save and p.target then
51 autoprops[p.class..p.role..p.instance]=p
52 end
54 if p.target==nil then
55 autoprops[p.class..p.role..p.instance]=nil
56 end
57 end
59 local function save_autoprops()
60 ioncore.write_savefile(savefile, autoprops)
61 end
63 local function load_autoprops()
64 local d=ioncore.read_savefile(savefile)
65 if not d then
66 return
67 end
69 table.foreach(d, function(k, tab)
70 defwinprop{
71 class=tab.class,
72 instance=tab.instance,
73 role=tab.role,
74 target=tab.target
76 autoprops[tab.class..tab.role..tab.instance]=tab
77 end)
78 end
80 local function init()
81 load_autoprops()
82 ioncore.get_hook("ioncore_snapshot_hook"):add(save_autoprops)
83 end
85 init()