Re: Moving newly created windows



Am So 09 Sep 2012 00:19:30 CEST schrieb Alessandro Crismani:

Hi everybody,

I'm trying to write an extension that mimics the smart window
positioning of other WMs.

The core of the extension is summarised as:
this._windowCreatedId =
display.connect_after('window-created', Lang.bind(this, this._move));

this._move = function (display, win) {
/* ... Calculate the new x and y positions of the created
window ... */
win.move_frame(true, x, y);
}

where the _move function, which calculates the new position of the
window and moves it, is fired when the window-created signal is emitted.

Unfortunately this does not work, and I believe it fails because
move_frame is called too soon and the window is not there yet. Hence,
the window is created at its "default" position, and not at (x, y).

As a workaround, I found that the same procedure works if I add a
win.activate(time) before the move_frame action. In such a case the
window moves!

However, this hack has its own drawback, in the sense that the new
window is positioned on the screen at its "default" position, and only
then is moved at (x, y). Such animation looks horrible! (I would have
linked a video, but the Gnome-Shell recorder appears to be broken on
my system, anyone who can suggest a pipeline for recording to avi
while waiting for the webm codec to un-break itself?)

The bottom line: can anybody recommend an approach that allows me to
move newly created windows, without the activate hack, and that
possibly moves them before they are shown for avoiding the ugly and
distracting repositioning?

Thanks a lot,
Alessandro




_______________________________________________
gnome-shell-list mailing list
gnome-shell-list gnome org
https://mail.gnome.org/mailman/listinfo/gnome-shell-list


hi,

I had similar problems when i implemented moving new window to position in my extension (put window). Check the "Auto move window" extension (https://extensions.gnome.org/extension/16/auto-move-windows/) it helped my implementing this. After a window is created you must wait until the Shell.WindowTracker recognices it. You can check this in your _move function:

_init: function() {
....
   // get the default instance of the windowTracker
   this._windowTracker = Shell.WindowTracker.get_default();

  // connect to window-created
  display.connect_after('window-created', Lang.bind(this, this._move));
  ....
},

_move: function(display, win, secondTime) {
    if (!this._windowTracker.is_window_interesting(win)) {
        return;
    }

    let app = this._windowTracker.get_window_app(win);

    if (!app) {
        if (!secondTime) {
// window is not tracked yet, Wait until Mainloop has added it and is idle again
            Mainloop.idle_add(Lang.bind(this, function() {
                this._move(display, win, true);
                return false;
            }));
        }
        return;
    }

    // manipulate the window. (win.move, win.move_frame or win.resize)

} // end of _move




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]