Re: missing workflows with gnome-shell



Il giorno mer, 23/02/2011 alle 10.28 +0100, Thomas Bouffon ha scritto: 
> 
> Actually you can override the Main._checkWorkspaces function. I
> modified it so that it only removes the last workspaces if there are
> more than one. Thus if the first workspace is empty but the 2nd one is
> not, the 1st won't be deleted.
> I also modified _ensureAtLeastWorkspaces to move the window to the new
> workspace created, so that new workspaces are not collected if there
> are more than 2.
> This workflow suits my needs, at least (I generally use 4 Desktops and
> put Firefox on the 3rd, which now guarantees me the 4 desktops.)
> I renamed extension.js to extension.txt and attached it here.
> Any remarks are welcome !
> 
> Cheers,
> Thomas

Woah, awesome!

Didn't know that you can override the GS's main cycle, this is plain
wonderful :), I do not have to maintain my sick branch anymore. I tried
your modded extension but it fails inside ensureAtLeastWorkspace saying
that window.change_workspace_by_index() is not a function. I think that
"window" is not defined there (I might be wrong, I am in clear
difficulty with javascript variables management, used to old C++ where
you declare everything).

I've changed the extension to something that seems to work for me. I've
also changed the Main behaviour, marking as not empty all the workspaces
before the last one that contains a window, instead of breaking the
delete cycle. The extension is enclosed in the mail, any feedback is
welcomed :)

Cheers,
Alessandro


// Start apps on custom workspaces

const Glib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Shell = imports.gi.Shell;
const St = imports.gi.St;

const Main = imports.ui.main;

const SETTINGS_SCHEMA = 'org.gnome.shell.extensions.auto-move-windows';
const SETTINGS_KEY = 'application-list';

function WindowMover() {
    this._init();
}

WindowMover.prototype = {
    _init: function() {
	this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
	this._windowTracker = Shell.WindowTracker.get_default();

	let display = global.screen.get_display();
	// Connect after so the handler from ShellWindowTracker has already run
	display.connect_after('window-created', Lang.bind(this, this._findAndMove));
    },

    _ensureAtLeastWorkspaces: function(num, window) {
        for (let j = global.screen.n_workspaces; j <= num; j++) {
	    window.change_workspace_by_index(j - 1, false, global.get_current_time());
            global.screen.append_new_workspace(false, 0);
        }
    },

    _findAndMove: function(display, window, noRecurse) {
	if (!this._windowTracker.is_window_interesting(window))
	    return;

	let spaces = this._settings.get_strv(SETTINGS_KEY);

	let app = this._windowTracker.get_window_app(window);
	if (!app) {
	    if (!noRecurse) {
		// window is not tracked yet
		Mainloop.idle_add(Lang.bind(this, function() {
		    this._findAndMove(display, window, true);
		    return false;
		}));
	    } else
		log ('Cannot find application for window');
	    return;
	}
	let app_id = app.get_id();
        for ( let j = 0 ; j < spaces.length; j++ ) {
            let apps_to_space = spaces[j].split(":");
            // Match application id
            if (apps_to_space[0] == app_id) {
		let workspace_num = parseInt(apps_to_space[1]) - 1;
		this._ensureAtLeastWorkspaces(workspace_num, window);

		window.change_workspace_by_index(workspace_num, false, global.get_current_time());
            }
        }
    }
}

function main(extensionMeta) {
    Main._checkWorkspaces=function(){
        let i;
        let emptyWorkspaces = [];

        for (i = 0; i < Main._workspaces.length; i++)
            emptyWorkspaces[i] = true;

        let windows = global.get_window_actors();
        for (i = 0; i < windows.length; i++) {
            let win = windows[i];

            if (win.get_meta_window().is_on_all_workspaces())
              continue;

            let workspaceIndex = win.get_workspace();
	    for (j = 0; j <= workspaceIndex; j++)
                emptyWorkspaces[j] = false;
        }

        // If we don't have an empty workspace at the end, add one
        if (!emptyWorkspaces[emptyWorkspaces.length -1]) {
            global.screen.append_new_workspace(false, global.get_current_time());
            emptyWorkspaces.push(false);
        }

        // Delete other empty workspaces; do it from the end to avoid index changes
        for (i = emptyWorkspaces.length - 2; i >= 0; i--) {
            if (emptyWorkspaces[i]) 
                global.screen.remove_workspace(Main._workspaces[i], global.get_current_time());
        }
        Main._checkWorkspacesId = 0;
        return false;
    };

    new WindowMover();
}


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