]> git.decadent.org.uk Git - ion3.git/blob - ioncore/ioncore_misc.lua
[svn-upgrade] Integrating new upstream version, ion3 (20070203)
[ion3.git] / ioncore / ioncore_misc.lua
1 --
2 -- ion/share/ioncore_misc.lua
3 -- 
4 -- Copyright (c) Tuomo Valkonen 2004-2007.
5 --
6 -- Ion is free software; you can redistribute it and/or modify it under
7 -- the terms of the GNU Lesser General Public License as published by
8 -- the Free Software Foundation; either version 2.1 of the License, or
9 -- (at your option) any later version.
10 --
11
12 local group_tmpl = { type="WGroupWS" }
13
14 local default_tmpl = { switchto=true }
15
16 local empty = { type="WGroupWS", managed={} }
17
18 local layouts={
19     empty = empty,
20     default = empty,
21 }
22
23 --DOC 
24 -- Define a new workspace layout with name \var{name}, and
25 -- attach/creation parameters given in \var{tab}. The layout
26 -- "empty" may not be defined.
27 function ioncore.deflayout(name, tab)
28     assert(layout ~= "empty")
29     
30     if name=="default" and not tab then
31         layouts[name] = empty
32     else
33         layouts[name] = table.join(tab, group_tmpl)
34     end
35 end
36
37 --DOC
38 -- Get named layout (or all of the latter parameter is set,
39 -- but this is for internal use only).
40 function ioncore.getlayout(name, all)
41     if all then
42         return layouts
43     else
44         return layouts[name]
45     end
46 end
47
48 ioncore.set{_get_layout=ioncore.getlayout}
49
50 --DOC
51 -- Create new workspace on screen \var{scr}. The table \var{tmpl}
52 -- may be used to override parts of the layout named with \code{layout}.
53 -- If no \var{layout} is given, "default" is used.
54 function ioncore.create_ws(scr, tmpl, layout)
55     local lo=ioncore.getlayout(layout or "default")
56     
57     assert(lo, TR("Unknown layout"))
58     
59     return scr:attach_new(table.join(tmpl or default_tmpl, lo))
60 end
61
62
63 --DOC
64 -- Find an object with type name \var{t} managing \var{obj} or one of
65 -- its managers.
66 function ioncore.find_manager(obj, t)
67     while obj~=nil do
68         if obj_is(obj, t) then
69             return obj
70         end
71         obj=obj:manager()
72     end
73 end
74
75
76 --DOC
77 -- gettext+string.format
78 function ioncore.TR(s, ...)
79     return string.format(ioncore.gettext(s), unpack(arg))
80 end
81
82
83 --[[DOC
84 -- Run \var{cmd} with the environment variable DISPLAY set to point to the
85 -- root window of the X screen \var{reg} is on.
86 function ioncore.exec_on(reg, cmd)
87     return ioncore.do_exec_rw(reg:rootwin_of(), cmd)
88 end
89 --]]