2 -- By Jeremy Hankins <nowan@nowan.org>
3 -- Multi-head support added by Johannes Segitz
4 -- Cycling contributed by
5 -- Antti Kaihola <antti.kaihola@linux-aktivaattori.org>
7 -- Time-stamp: <2005-11-16 12:02:46 Jeremy Hankins>
8 -- <2005-08-26 11:35:00 kaihola>
10 -- With these functions you can bind a key to start an application if
11 -- it's not already running, or cycle its windows if it is. You can
12 -- use it by doing something like this in your bindings file:
14 -- kpress(META.."C", "app.byname('xterm -title shell', 'shell')"),
15 -- kpress(META.."T", "app.byclass('emacs', 'Emacs')"),
16 -- kpress(META.."M", "app.byinstance('xterm -name muttTerm -e mutt', 'XTerm', 'muttTerm')"),
18 -- The byname function expects an executable and a window title, the
19 -- byclass expects a class, the byinstance expects a class and an
22 -- NOTE: cycling windows requires ioncore.current(), so it will only
23 -- work with snapshot XXX or later.
25 -- If you use a multihead setup you can use something like this to start
26 -- applictions on your current screen
28 -- kpress(MOD1.."C", "app.byname('xterm -title shell', 'shell', _)"),
29 -- kpress(MOD1.."T", "app.byclass('emacs', 'Emacs', _)"),
31 -- For emacs users there's also app.emacs_eval, and app.query_editfile,
32 -- which interacts with any currently running emacs process (using
33 -- gnuclient), or starts emacs to run the given command.
34 -- app.query_editfile is a replacement for query_lib.query_editfile to
35 -- use the currently running emacs rather than ion-edit.
40 function app
.match_class(class
, instance
)
41 -- Return matching client windows as a table.
42 -- If the current window is among them, it's placed last on the list
43 -- and its successor at the beginning of the list. This facilitates
44 -- cycling multiple windows of an application.
47 local currwin
= ioncore
.current()
48 ioncore
.clientwin_i(function (win
)
49 if class
== win
:get_ident().class
then
51 if instance
== win
:get_ident().instance
then
52 table.insert(result
, table.getn(result
)-offset
+1, win
)
55 table.insert(result
, table.getn(result
)-offset
+1, win
)
58 if win
== currwin
then
59 -- Current client window found, continue filling the table from
61 offset
= table.getn(result
)
69 function app
.byname(prog
, name
, where
)
70 local win
= ioncore
.lookup_clientwin(name
)
72 ioncore
.defer(function () win
:goto() end)
75 ioncore
.exec_on(where
, prog
)
82 function app
.byclass(prog
, class
, where
)
83 local win
= app
.match_class(class
)[1]
85 ioncore
.defer(function () win
:goto() end)
88 ioncore
.exec_on(where
, prog
)
95 function app
.byinstance(prog
, class
, instance
, where
)
96 local win
= app
.match_class(class
, instance
)[1]
98 ioncore
.defer(function () win
:goto() end)
101 ioncore
.exec_on(where
, prog
)
108 function app
.emacs_eval(expr
)
109 local emacswin
= app
.match_class("Emacs")[1]
111 ioncore
.exec("gnuclient -batch -eval '"..expr
.."'")
112 ioncore
.defer(function () emacswin
:goto() end)
114 ioncore
.exec("emacs -eval '"..expr
.."'")
118 function app
.query_editfile(mplex
, dir
)
119 local function handler(file
)
120 app
.emacs_eval("(find-file \""..file
.."\")")
123 mod_query
.do_query(mplex
,
125 dir
or mod_query
.get_initdir(),
127 mod_query
.file_completor
)
130 -----------------------------------------------------------------------
131 -- By ASCHE <asche0@gmail.com>
132 -- based on named_scratchpad.lua by Etan Reisner
134 -- With this function you can bind a key to start an application in
135 -- pad if it's not already running, or show pad its windows if it is.
137 -- Last updated: 2008-02-26
138 -- Worked at: ion-3rc-20080103
140 -----------------------------------------------------------------------
145 -- instance = "instance",
151 -- instance = "instance",
152 -- target = "instance",
155 -- defbindings("WMPlex.toplevel", {
156 -- kpress("binding", "app.pad_byclass ('command', 'class', width, height, _)")
157 -- kpress("binding", "app.pad_byinstance('command', 'instance', width, height, _)")
159 -----------------------------------------------------------------------
163 -- class = "Linuxdcpp",
164 -- instance = "linuxdcpp",
165 -- target = "Linuxdcpp",
170 -- instance = "my_xterm",
171 -- target = "my_xterm",
174 -- defbindings("WMPlex.toplevel", {
175 -- kpress("F1", "app.pad_byclass ('linuxdcpp', 'Linuxdcpp', 1024, 768, _)")
176 -- kpress("F2", "app.pad_byinstance('xterm -name my_xterm', 'my_xterm', 640, 480, _)")
178 -----------------------------------------------------------------------
180 function app
.toggle_pad(reg
, name
, width
, height
)
181 local named_sp
= ioncore
.lookup_region(name
, "WFrame")
184 local scr
= reg
:screen_of()
185 local geom_scr
= scr
:geom()
191 geom_loc
.x
= (geom_scr
.w
- geom_loc
.w
) / 2
192 geom_loc
.y
= (geom_scr
.h
- geom_loc
.h
) / 2
194 named_sp
= scr
:attach_new({
205 WRegion
.rqorder(reg
, "back")
206 mod_sp
.set_shown(named_sp
, "toggle")
209 -----------------------------------------------------------------------
211 function app
.pad_byclass(prog
, class
, width
, height
, reg
)
212 app
.toggle_pad(reg
, class
, width
, height
)
214 local win
= app
.match_class(class
)[1]
216 ioncore
.exec_on(reg
, prog
)
220 -----------------------------------------------------------------------
222 function app
.pad_byinstance(prog
, instance
, width
, height
, reg
)
223 app
.toggle_pad(reg
, instance
, width
, height
)
225 local win
= app
.match_class("XTerm", instance
)[1]
227 ioncore
.exec_on(reg
, prog
)
231 -----------------------------------------------------------------------