Expose XWarpPointer to lua as rootwin:warp_pointer, for region_do_warp_alt
[notion.git] / contrib / scripts / show_submap.lua
blobdbc811dafff04d54a1ad2a757d430135033e1864
1 -- Authors: Etan Reisner <deryni@gmail.com>
2 -- License: MIT, see http://opensource.org/licenses/mit-license.php
3 -- Last Changed: 2007-07-04
4 --
5 --[[
6 Author: Etan Reisner
7 Email: deryni@unreliablesource.net
8 Summary: Displays an infowin with the currently active submap.
9 Version: 0.1
10 Last Updated: 2007-07-04
12 Copyright (c) Etan Reisner 2007.
14 This software is released under the terms of the MIT license. For more
15 information, see http://opensource.org/licenses/mit-license.php .
16 --]]
18 local sswins = setmetatable({}, {__mode="kv"})
20 local function sswin_set_hidden(sswin, state)
21 if not sswin then
22 return
23 end
25 local mgr = ioncore.find_manager(sswin, "WScreen")
26 mgr:set_hidden(sswin, state)
27 end
29 function show_submap_win(reg, keystr)
30 local scr, sswin
32 scr = reg:screen_of()
33 sswin = sswins[scr]
34 ioncore.defer(function()
35 if not sswin then
36 sswin = scr:attach_new({
37 type="WInfoWin",
38 name="show_submap_iw"..scr:id(),
39 hidden=true,
40 unnumbered=true,
41 sizepolicy="free",
42 geom={x=0, y=0, w=1, h=1},
43 style="show_submap",
45 sswins[scr] = sswin
46 end
47 sswin_set_hidden(sswin, "unset")
48 sswin:set_text(keystr or "", -1)
49 end)
50 end
52 function hide_submap_win()
53 local scr = ioncore.current():screen_of()
54 sswin_set_hidden(sswins[scr], "set")
55 end
57 function setup()
58 local hook = ioncore.get_hook("ioncore_submap_ungrab_hook")
60 if hook then
61 hook:add(hide_submap_win)
62 end
64 for section, bindings in pairs(ioncore.getbindings()) do
65 for _,binds in pairs(bindings) do
66 if binds.submap then
67 defbindings(section, {submap(binds.kcb, {submap_enter("show_submap_win(_, '"..binds.kcb.."')")})})
68 end
69 end
70 end
71 end
73 setup()
75 -- vim: set sw=4 sts=4 et: