~ubuntu-branches/ubuntu/vivid/gnome-shell-extensions/vivid-proposed

« back to all changes in this revision

Viewing changes to .pc/02-Revert-all-remove-all-GSettings-usage.patch/extensions/auto-move-windows/extension.js

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Josselin Mouette, Michael Biebl
  • Date: 2012-02-11 23:28:53 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120211232853-mc92yae3sgemtz7l
Tags: 3.2.3-1
[ Josselin Mouette ]
* gnome-shell-extensions.gsettings-override: enable the alternative 
  status menu by default. Closes: #648112.
* Use ${gnome:Version} to generate strict dependencies, it’s very 
  unlikely that extensions remain compatible after a major upgrade.

[ Michael Biebl ]
* Upload to unstable.

[ Josselin Mouette ]
* 01_status-menu_disable_accounts.patch: new patch. Drop the unusable
  advertisement for Google. It is already available in the control 
  center anyway.

[ Michael Biebl ]
* New upstream release.
* Drop patches which have been merged upstream:
  - debian/patches/upstream/*
  - debian/patches/fix-*
* Refresh 01_status-menu_disable_accounts.patch.
* Add 02-Revert-all-remove-all-GSettings-usage.patch: Use GSettings since we
  install the extensions system-wide.
* Use dh-autoreconf to generate the build system.
* Add 03-Revert-Remove-all-references-to-localedir-from-metad.patch: Use
  locales from system-wide location.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
 
2
// Start apps on custom workspaces
 
3
 
 
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;
 
11
 
 
12
const Main = imports.ui.main;
 
13
 
 
14
// list of applications and workspace pairs
 
15
// format: "desktop-file-id.desktop:<num>"
 
16
const APPLICATIONS = [ ];
 
17
 
 
18
function WindowMover() {
 
19
    this._init();
 
20
}
 
21
 
 
22
WindowMover.prototype = {
 
23
    _init: function() {
 
24
        this._windowTracker = Shell.WindowTracker.get_default();
 
25
 
 
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));
 
29
    },
 
30
 
 
31
    destroy: function() {
 
32
        if (this._windowCreatedId) {
 
33
            global.screen.get_display().disconnect(this._windowCreatedId);
 
34
            this._windowCreatedId = 0;
 
35
        }
 
36
    },
 
37
 
 
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);
 
42
        }
 
43
    },
 
44
 
 
45
    _findAndMove: function(display, window, noRecurse) {
 
46
        if (!this._windowTracker.is_window_interesting(window))
 
47
            return;
 
48
 
 
49
        let spaces = APPLICATIONS;
 
50
 
 
51
        let app = this._windowTracker.get_window_app(window);
 
52
        if (!app) {
 
53
            if (!noRecurse) {
 
54
                // window is not tracked yet
 
55
                Mainloop.idle_add(Lang.bind(this, function() {
 
56
                    this._findAndMove(display, window, true);
 
57
                    return false;
 
58
                }));
 
59
            } else
 
60
                log ('Cannot find application for window');
 
61
            return;
 
62
        }
 
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;
 
69
 
 
70
                if (workspace_num >= global.screen.n_workspaces)
 
71
                    this._ensureAtLeastWorkspaces(workspace_num, window);
 
72
 
 
73
                window.change_workspace_by_index(workspace_num, false, global.get_current_time());
 
74
            }
 
75
        }
 
76
    }
 
77
}
 
78
 
 
79
let prevCheckWorkspaces;
 
80
let winMover;
 
81
 
 
82
function init(extensionMeta) {
 
83
    // do nothing here
 
84
}
 
85
 
 
86
function enable() {
 
87
    prevCheckWorkspaces = Main._checkWorkspaces;
 
88
    Main._checkWorkspaces = function() {
 
89
        let i;
 
90
        let emptyWorkspaces = new Array(Main._workspaces.length);
 
91
 
 
92
        for (i = 0; i < Main._workspaces.length; i++) {
 
93
            let lastRemoved = Main._workspaces[i]._lastRemovedWindow;
 
94
            if (lastRemoved &&
 
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;
 
99
            else
 
100
                emptyWorkspaces[i] = true;
 
101
        }
 
102
 
 
103
 
 
104
        let windows = global.get_window_actors();
 
105
        for (i = 0; i < windows.length; i++) {
 
106
            let win = windows[i];
 
107
 
 
108
            if (win.get_meta_window().is_on_all_workspaces())
 
109
                continue;
 
110
 
 
111
            let workspaceIndex = win.get_workspace();
 
112
            emptyWorkspaces[workspaceIndex] = false;
 
113
        }
 
114
 
 
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);
 
119
        }
 
120
 
 
121
        let activeWorkspaceIndex = global.screen.get_active_workspace_index();
 
122
        let activeIsLast = activeWorkspaceIndex == global.screen.n_workspaces - 2;
 
123
        let removingTrailWorkspaces = (emptyWorkspaces[activeWorkspaceIndex] &&
 
124
                                        activeIsLast);
 
125
        // Don't enter the overview when removing multiple empty workspaces at startup
 
126
        let showOverview  = (removingTrailWorkspaces &&
 
127
                             !emptyWorkspaces.every(function(x) { return x; }));
 
128
 
 
129
        if (removingTrailWorkspaces) {
 
130
            // "Merge" the empty workspace we are removing with the one at the end
 
131
            Main.wm.blockAnimations();
 
132
        }
 
133
 
 
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());
 
138
            else
 
139
                break;
 
140
        }
 
141
 
 
142
        if (removingTrailWorkspaces) {
 
143
            global.screen.get_workspace_by_index(global.screen.n_workspaces - 1).activate(global.get_current_time());
 
144
 
 
145
            Main.wm.unblockAnimations();
 
146
 
 
147
            if (!Main.overview.visible && showOverview)
 
148
                Main.overview.show();
 
149
        }
 
150
 
 
151
        Main._checkWorkspacesId = 0;
 
152
        return false;
 
153
 
 
154
    };
 
155
 
 
156
    winMover = new WindowMover();
 
157
}
 
158
 
 
159
function disable() {
 
160
    Main._checkWorkspaces = prevCheckWorkspaces;
 
161
    winMover.destroy();
 
162
}