Expose XWarpPointer to lua as rootwin:warp_pointer, for region_do_warp_alt
[notion.git] / contrib / scripts / tabmenu.lua
blob158cfbc034c1c18b55c0bfa4f7224173e08b578f
1 -- Authors: Tuomo Valkonen
2 -- License: Unknown
3 -- Last Changed: 2007
4 --
5 -- tabmenu.lua
6 --
7 -- By Tuomo Valkonen, 2007.
8 --
9 -- This script introduces a tabmenu function that can be used to
10 -- display a grabmenu corresponding to the tabs of a frame. It can
11 -- be useful if you choose to disable the tab-bars of frames, to
12 -- replace the META+K N/P bindings with the following:
14 -- ioncore.defbindings("WFrame.toplevel", {
15 -- submap(META.."K", {
16 -- kpress("N", "tabmenu.tabmenu(_, _sub, 'next')"),
17 -- kpress("P", "tabmenu.tabmenu(_, _sub, 'prev')"),
18 -- })
19 -- })
23 tabmenu={}
25 -- WRegion.displayname isn't exported ATM, so here's a hacky
26 -- implementation.
27 function tabmenu.hack_displayname(reg)
28 local name=reg:name()
29 if obj_is(reg, "WGroupCW") then
30 local b=reg:bottom()
31 if b then
32 name=b:name()
33 end
34 end
35 return name
36 end
39 function tabmenu.tabmenu(_, _sub, index)
40 local i=1
41 local m={}
42 _:mx_i(function(r)
43 local e=menuentry(tabmenu.hack_displayname(r),
44 function() r:goto() end)
45 table.insert(m, e)
46 if r==_sub
47 then i=#m
48 end
49 return true
50 end)
52 if #m==0 then
53 table.insert(m, menuentry("<empty frame>", function() end))
54 i=nil
55 elseif index=='next' then
56 i=((i==#m and 1) or i+1)
57 elseif index=='prev' then
58 i=((i==1 and #m) or i-1)
59 elseif index=='first' then
60 i=1
61 elseif index=='last' then
62 i=#m
63 end
65 mod_menu.grabmenu(_, nil, m, {initial=i})
66 end