Discussion:
Scripting problem
Seb Haezebrouck
2009-06-01 14:20:19 UTC
Permalink
Hi,

Since I do not like having empty frames on my screen, I figured I'll try and
write a small function that would close the frame if I close the last client
in a frame. This is the (wrong) code I came up with. Could not find a better
way than this io.write thing to debug what was going on.

function close_test(wmp)
local c = WMPlex.mx_count(wmp)
io.output("/tmp/dbg.ionscript")
io.write("Number of children: ", c, ".\n")
if WRegion.rqclose_propagate(wmp, _sub) then
io.write("Closed one child.\n")
if c == 1 then
while WMPlex.mx_count(wmp) == 1 do
io.write("Still one child seen.\n")
end
WRegion.rqclose(wmp)
end
end
end

... and as I half expected - this goes into an infinite loop when I try and
use it on a frame in which there is only one client (and the client is not
destroyed).

I am sure Ion3 can do what I want... but could someone tell me what is wrong
with my script, and what is the proper way, if any to make this function not
blocking?

Looks like a hook (deinit ?) is probably what I really need, but I am afraid
I might run into the same type of issue. And all my feebles attempts to
implement hooks so far miserably failed.

Thanks,

Seb

PS: I am using ion3-20090110.
Tuomo Valkonen
2009-06-02 07:19:11 UTC
Permalink
Post by Seb Haezebrouck
... and as I half expected - this goes into an infinite loop when I try and
use it on a frame in which there is only one client (and the client is not
destroyed).
rqclose is asynchronous. Generally, the code should return to the
main loop for the actions to take effect; and for client windows,
you have to wait for the client to take action, if it does. Ion can
only get to know of this, when it returns to the... main loop.
Post by Seb Haezebrouck
I am sure Ion3 can do what I want... but could someone tell me what is wrong
with my script, and what is the proper way, if any to make this function not
blocking?
You should listen to frame_managed_changed_hook. No need to make
new bindings, just check when a frame becomes empty in that hook.
min_tabs.lua from the scripts repository might provide some useful
bits.
--
Stop Gnomes and other pests! Purchase Windows today!
Seb Haezebrouck
2009-06-03 20:20:00 UTC
Permalink
Post by Tuomo Valkonen
You should listen to frame_managed_changed_hook. No need to make
new bindings, just check when a frame becomes empty in that hook.
min_tabs.lua from the scripts repository might provide some useful
bits.
Thanks - I did just this, but face yet another issue, this time with the
below code:

local function close_empty_frame(ftable)
if ftable.mode ~= 'remove' then return end
local wmp = ftable.reg
-- Should probably test that wmp is not nil here - or is it guaranteed
to contain sth meaningful ?
if WMPlex.mx_count(wmp) == 0 then
ioncore.defer(WRegion.rqclose(wmp))
end
end

local hk=ioncore.get_hook("frame_managed_changed_hook")
hk:add(close_empty_frame)

Now the code does not hang anymore, but I get "ion3: Attempt to call an
unsafe function "rqclose" in restricted mode." each time I close the last
client in a frame.

I thought ioncore.defer would do the trick and defer the execution of the
rqclose until I am back in the main loop (so probably out of "restricted"
mode), but it looks like it does not... What am I still missing ?

Seb
Ole Jørgen Brønner
2009-06-03 20:29:35 UTC
Permalink
ioncore.defer takes a _function_. In your code WRegion.rqclose(wmp) will
be executed and the result will be passed to defer.

You need to wrap the function call in a lamba like this:
ioncore.defer(function () WRegion.rqclose(wmp) end)

--
Ole Jørgen Brønner
Post by Seb Haezebrouck
Post by Tuomo Valkonen
You should listen to frame_managed_changed_hook. No need to make
new bindings, just check when a frame becomes empty in that hook.
min_tabs.lua from the scripts repository might provide some useful
bits.
Thanks - I did just this, but face yet another issue, this time with the
local function close_empty_frame(ftable)
if ftable.mode ~= 'remove' then return end
local wmp = ftable.reg
-- Should probably test that wmp is not nil here - or is it guaranteed
to contain sth meaningful ?
if WMPlex.mx_count(wmp) == 0 then
ioncore.defer(WRegion.rqclose(wmp))
end
end
local hk=ioncore.get_hook("frame_managed_changed_hook")
hk:add(close_empty_frame)
Now the code does not hang anymore, but I get "ion3: Attempt to call an
unsafe function "rqclose" in restricted mode." each time I close the last
client in a frame.
I thought ioncore.defer would do the trick and defer the execution of the
rqclose until I am back in the main loop (so probably out of "restricted"
mode), but it looks like it does not... What am I still missing ?
Seb
Seb Haezebrouck
2009-06-06 09:09:38 UTC
Permalink
<Reposting since it seems my first answer did not appear in the mailing
list>

Working fine - thank you.

BTW, I also had to change the default behaviour of the splitting bindings.

By default, they have the 'attach_current' parameter set to true. This
prevented splitting a frame which had only one client: the frame was split,
the only client of the previous frame was moved to the new split, the hook
triggered and the previous frame (now empty) was destroyed.

In this situation, I would see is the frame briefly flashing, but no split
occurring.

Changing the default split binding to use 'attach_current' false fixed this.

Thanks a lot for your answers,

Seb

"Ole Jørgen Brønner" <olejorgenb-***@public.gmane.org> a écrit dans
le message de news: ***@tabole-debian...
ioncore.defer takes a _function_. In your code WRegion.rqclose(wmp) will
be executed and the result will be passed to defer.

You need to wrap the function call in a lamba like this:
ioncore.defer(function () WRegion.rqclose(wmp) end)

--
Ole Jørgen Brønner
Marc Hartstein
2009-06-06 17:47:51 UTC
Permalink
Post by Seb Haezebrouck
<Reposting since it seems my first answer did not appear in the mailing
list>
I received your first answer. Check your list subscription information
and your mail user agent configuration to find what's behaving
differently than you expect? Many mailing lists by default don't send
messages back to the person who sent them.

Loading...