1
// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
2
// Start apps on custom workspaces
4
const Glib = imports.gi.GLib;
5
const Gio = imports.gi.Gio;
6
const Lang = imports.lang;
7
const Mainloop = imports.mainloop;
8
const Meta = imports.gi.Meta;
9
const Shell = imports.gi.Shell;
10
const St = imports.gi.St;
12
const Main = imports.ui.main;
14
// list of applications and workspace pairs
15
// format: "desktop-file-id.desktop:<num>"
16
const APPLICATIONS = [ ];
18
function WindowMover() {
22
WindowMover.prototype = {
24
this._windowTracker = Shell.WindowTracker.get_default();
26
let display = global.screen.get_display();
27
// Connect after so the handler from ShellWindowTracker has already run
28
this._windowCreatedId = display.connect_after('window-created', Lang.bind(this, this._findAndMove));
32
if (this._windowCreatedId) {
33
global.screen.get_display().disconnect(this._windowCreatedId);
34
this._windowCreatedId = 0;
38
_ensureAtLeastWorkspaces: function(num, window) {
39
for (let j = global.screen.n_workspaces; j <= num; j++) {
40
window.change_workspace_by_index(j-1, false, global.get_current_time());
41
global.screen.append_new_workspace(false, 0);
45
_findAndMove: function(display, window, noRecurse) {
46
if (!this._windowTracker.is_window_interesting(window))
49
let spaces = APPLICATIONS;
51
let app = this._windowTracker.get_window_app(window);
54
// window is not tracked yet
55
Mainloop.idle_add(Lang.bind(this, function() {
56
this._findAndMove(display, window, true);
60
log ('Cannot find application for window');
63
let app_id = app.get_id();
64
for ( let j = 0 ; j < spaces.length; j++ ) {
65
let apps_to_space = spaces[j].split(":");
66
// Match application id
67
if (apps_to_space[0] == app_id) {
68
let workspace_num = parseInt(apps_to_space[1]) - 1;
70
if (workspace_num >= global.screen.n_workspaces)
71
this._ensureAtLeastWorkspaces(workspace_num, window);
73
window.change_workspace_by_index(workspace_num, false, global.get_current_time());
79
let prevCheckWorkspaces;
82
function init(extensionMeta) {
87
prevCheckWorkspaces = Main._checkWorkspaces;
88
Main._checkWorkspaces = function() {
90
let emptyWorkspaces = new Array(Main._workspaces.length);
92
for (i = 0; i < Main._workspaces.length; i++) {
93
let lastRemoved = Main._workspaces[i]._lastRemovedWindow;
95
(lastRemoved.get_window_type() == Meta.WindowType.SPLASHSCREEN ||
96
lastRemoved.get_window_type() == Meta.WindowType.DIALOG ||
97
lastRemoved.get_window_type() == Meta.WindowType.MODAL_DIALOG))
98
emptyWorkspaces[i] = false;
100
emptyWorkspaces[i] = true;
104
let windows = global.get_window_actors();
105
for (i = 0; i < windows.length; i++) {
106
let win = windows[i];
108
if (win.get_meta_window().is_on_all_workspaces())
111
let workspaceIndex = win.get_workspace();
112
emptyWorkspaces[workspaceIndex] = false;
115
// If we don't have an empty workspace at the end, add one
116
if (!emptyWorkspaces[emptyWorkspaces.length -1]) {
117
global.screen.append_new_workspace(false, global.get_current_time());
118
emptyWorkspaces.push(false);
121
let activeWorkspaceIndex = global.screen.get_active_workspace_index();
122
let activeIsLast = activeWorkspaceIndex == global.screen.n_workspaces - 2;
123
let removingTrailWorkspaces = (emptyWorkspaces[activeWorkspaceIndex] &&
125
// Don't enter the overview when removing multiple empty workspaces at startup
126
let showOverview = (removingTrailWorkspaces &&
127
!emptyWorkspaces.every(function(x) { return x; }));
129
if (removingTrailWorkspaces) {
130
// "Merge" the empty workspace we are removing with the one at the end
131
Main.wm.blockAnimations();
134
// Delete other empty workspaces; do it from the end to avoid index changes
135
for (i = emptyWorkspaces.length - 2; i >= 0; i--) {
136
if (emptyWorkspaces[i])
137
global.screen.remove_workspace(Main._workspaces[i], global.get_current_time());
142
if (removingTrailWorkspaces) {
143
global.screen.get_workspace_by_index(global.screen.n_workspaces - 1).activate(global.get_current_time());
145
Main.wm.unblockAnimations();
147
if (!Main.overview.visible && showOverview)
148
Main.overview.show();
151
Main._checkWorkspacesId = 0;
156
winMover = new WindowMover();
160
Main._checkWorkspaces = prevCheckWorkspaces;