How can I reliably resize a window via metaWindow.move_resize_frame(boolean, x, y, width, height)

I was looking at How can I reliably resize a window via metaWindow.move_resize_frame(boolean, x, y, width, height)

What I understood is, I should replace:

window.move_resize_frame(false, x, y, width, height);

with

GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
    window.move_resize_frame(false, x, y, width, height);
    return GLib.SOURCE_REMOVE;
});

I did and it works.

However, the move seems slow.

Then i looked at metaWindowActor.connect('first-frame'. I think it will be faster.

When i replaced:

window.move_resize_frame(false, x, y, width, height);

with

let windowReadyId = 0;
Meta.WindowActor.connect('first-frame', () => {
    windowReadyId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
        meta_window.move_resize_frame(false, x, y, width, height);
        windowReadyId = 0
        return GLib.SOURCE_REMOVE;
    });
});
meta_window.connect('unmanaging', () => {
    if (windowReadyId)
        GLib.Source.remove(windowReadyId);
});

it does not work. Am i missing some imports or something.

Do you mean that is visually slow/laggy, or that it seems like it happen later than expected?

You aren’t missing any imports, most likely events are not unfolding in the order you expect.

I don’t have the time just now to dig into this (sorry!), but I can recommend connecting to all relevant signals and adding e.g. console.log() calls inside the handlers and idle callbacks.

Sometimes the order of resolution in the main loop is quite surprising, and mutter tries quite hard to be efficient.

Thank you very much for your time.

It seems like it happen later than expected.

So, the code:

let windowReadyId = 0;
Meta.WindowActor.connect('first-frame', () => {
    windowReadyId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
        meta_window.move_resize_frame(false, x, y, width, height);
        windowReadyId = 0
        return GLib.SOURCE_REMOVE;
    });
});
meta_window.connect('unmanaging', () => {
    if (windowReadyId)
        GLib.Source.remove(windowReadyId);
});

is the replacement for meta_window.move_resize_frame(false, x, y, width, height);. am i right.

If this code is correct then i will try to sort rest of it by myself.

Use the window actor’s realize signal instead.

2 Likes