~mterry/ubuntu/natty/gnome-shell/wip

« back to all changes in this revision

Viewing changes to js/ui/main.js

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-10-12 22:44:00 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091012224400-k91p42yvou07i525
Tags: 2.28.0-0ubuntu1
* New upstream version
* debian/control:
  - updated build requirement
* debian/patches/80_git_change_fix_alt_tab_ressource_usage.patch:
  - git change to fix ressources not being freed on alt-tab

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
 
3
3
const Clutter = imports.gi.Clutter;
 
4
const DBus = imports.dbus;
4
5
const Gdk = imports.gi.Gdk;
5
6
const Gio = imports.gi.Gio;
6
7
const GLib = imports.gi.GLib;
9
10
const Meta = imports.gi.Meta;
10
11
const Shell = imports.gi.Shell;
11
12
const Signals = imports.signals;
 
13
const St = imports.gi.St;
12
14
 
13
15
const Chrome = imports.ui.chrome;
 
16
const Environment = imports.ui.environment;
14
17
const Overview = imports.ui.overview;
15
18
const Panel = imports.ui.panel;
16
19
const RunDialog = imports.ui.runDialog;
17
20
const LookingGlass = imports.ui.lookingGlass;
 
21
const ShellDBus = imports.ui.shellDBus;
18
22
const Sidebar = imports.ui.sidebar;
19
 
const Tweener = imports.ui.tweener;
20
23
const WindowManager = imports.ui.windowManager;
21
24
 
22
25
const DEFAULT_BACKGROUND_COLOR = new Clutter.Color();
30
33
let lookingGlass = null;
31
34
let wm = null;
32
35
let recorder = null;
 
36
let shellDBusService = null;
33
37
let modalCount = 0;
34
38
let modalActorFocusStack = [];
35
39
 
42
46
    Gio.DesktopAppInfo.set_desktop_env("GNOME");
43
47
 
44
48
    global.grab_dbus_service();
 
49
    shellDBusService = new ShellDBus.GnomeShell();
 
50
    // Force a connection now; dbus.js will do this internally
 
51
    // if we use its name acquisition stuff but we aren't right
 
52
    // now; to do so we'd need to convert from its async calls
 
53
    // back into sync ones.
 
54
    DBus.session.flush();
45
55
 
46
 
    Tweener.init();
 
56
    Environment.init();
47
57
 
48
58
    // Ensure ShellAppMonitor is initialized; this will
49
59
    // also initialize ShellAppSystem first.  ShellAppSystem
66
76
    for (let i = 0; i < children.length; i++)
67
77
        children[i].destroy();
68
78
 
 
79
    let themeContext = St.ThemeContext.get_for_stage (global.stage);
 
80
    let stylesheetPath = global.datadir + "/theme/gnome-shell.css";
 
81
    let theme = new St.Theme ({ application_stylesheet: stylesheetPath });
 
82
    themeContext.set_theme (theme);
 
83
 
69
84
    global.connect('panel-run-dialog', function(panel) {
70
85
        // Make sure not more than one run dialog is shown.
71
86
        getRunDialog().open();
72
87
    });
 
88
    let shellwm = global.window_manager;
 
89
    shellwm.takeover_keybinding("panel_main_menu");
 
90
    shellwm.connect("keybinding::panel_main_menu", function () {
 
91
        overview.toggle();
 
92
    });
 
93
    shellwm.takeover_keybinding("panel_run_dialog");
 
94
    shellwm.connect("keybinding::panel_run_dialog", function () {
 
95
       getRunDialog().open();
 
96
    });
73
97
 
74
98
    overview = new Overview.Overview();
75
99
    chrome = new Chrome.Chrome();
103
127
}
104
128
 
105
129
function _relayout() {
106
 
    panel.actor.set_size(global.screen_width, Panel.PANEL_HEIGHT);
 
130
    let primary = global.get_primary_monitor();
 
131
    panel.actor.set_position(primary.x, primary.y);
 
132
    panel.actor.set_size(primary.width, Panel.PANEL_HEIGHT);
107
133
    overview.relayout();
108
134
}
109
135
 
175
201
                overview.hide();
176
202
 
177
203
            return true;
178
 
        } else if (symbol == Clutter.F2 && (event.get_state() & Clutter.ModifierType.MOD1_MASK)) {
 
204
        } else if (symbol == Clutter.F2 && (Shell.get_event_state(event) & Clutter.ModifierType.MOD1_MASK)) {
179
205
            getRunDialog().open();
180
206
        }
181
207
    }
205
231
 * Next, record the current Clutter keyboard focus on a stack.  If the modal stack
206
232
 * returns to this actor, reset the focus to the actor which was focused
207
233
 * at the time pushModal() was invoked.
 
234
 *
 
235
 * Returns: true iff we successfully acquired a grab or already had one
208
236
 */
209
237
function pushModal(actor) {
210
 
    let timestamp = global.screen.get_display().get_current_time();
 
238
    if (modalCount == 0) {
 
239
        if (!global.begin_modal(currentTime())) {
 
240
            log("pushModal: invocation of begin_modal failed");
 
241
            return false;
 
242
        }
 
243
    }
 
244
 
 
245
    global.set_stage_input_mode(Shell.StageInputMode.FULLSCREEN);
211
246
 
212
247
    modalCount += 1;
213
248
    actor.connect('destroy', function() {
225
260
    }
226
261
    modalActorFocusStack.push([actor, curFocus]);
227
262
 
228
 
    if (modalCount > 1)
229
 
        return;
230
 
 
231
 
    if (!global.begin_modal(timestamp)) {
232
 
        log("pushModal: invocation of begin_modal failed");
233
 
        return;
234
 
    }
235
 
    global.set_stage_input_mode(Shell.StageInputMode.FULLSCREEN);
 
263
    return true;
236
264
}
237
265
 
238
266
/**
244
272
 * previous focus at the time when pushModal() was invoked.
245
273
 */
246
274
function popModal(actor) {
247
 
    let timestamp = global.screen.get_display().get_current_time();
248
 
 
249
275
    modalCount -= 1;
250
276
    let focusIndex = _findModal(actor);
251
277
    if (focusIndex >= 0) {
263
289
    if (modalCount > 0)
264
290
        return;
265
291
 
266
 
    global.end_modal(timestamp);
 
292
    global.end_modal(currentTime());
267
293
    global.set_stage_input_mode(Shell.StageInputMode.NORMAL);
268
294
}
269
295
 
283
309
}
284
310
 
285
311
function createAppLaunchContext() {
286
 
    let screen = global.screen;
287
 
    let display = screen.get_display();
288
 
 
289
312
    let context = new Gdk.AppLaunchContext();
290
 
    context.set_timestamp(display.get_current_time());
 
313
    context.set_timestamp(currentTime());
291
314
 
292
315
    // Make sure that the app is opened on the current workspace even if
293
316
    // the user switches before it starts
294
 
    context.set_desktop(screen.get_active_workspace_index());
 
317
    context.set_desktop(global.screen.get_active_workspace_index());
295
318
 
296
319
    return context;
297
320
}
 
321
 
 
322
/**
 
323
 * currentTime:
 
324
 *
 
325
 * Gets the current X server time from the current Clutter, Gdk, or X
 
326
 * event. If called from outside an event handler, this may return
 
327
 * %Clutter.CURRENT_TIME (aka 0), or it may return a slightly
 
328
 * out-of-date timestamp.
 
329
 */
 
330
function currentTime() {
 
331
    // meta_display_get_current_time() will return the correct time
 
332
    // when handling an X or Gdk event, but will return CurrentTime
 
333
    // from some Clutter event callbacks.
 
334
    //
 
335
    // clutter_get_current_event_time() will return the correct time
 
336
    // from a Clutter event callback, but may return an out-of-date
 
337
    // timestamp if called at other times.
 
338
    //
 
339
    // So we try meta_display_get_current_time() first, since we
 
340
    // can recognize a "wrong" answer from that, and then fall back
 
341
    // to clutter_get_current_event_time().
 
342
 
 
343
    let time = global.screen.get_display().get_current_time();
 
344
    if (time != Clutter.CURRENT_TIME)
 
345
        return time;
 
346
 
 
347
    return Clutter.get_current_event_time();
 
348
}
 
349
 
 
350
/**
 
351
 * activateWindow:
 
352
 * @window: the Meta.Window to activate
 
353
 * @time: (optional) current event time
 
354
 *
 
355
 * Activates @window, switching to its workspace first if necessary
 
356
 */
 
357
function activateWindow(window, time) {
 
358
    let activeWorkspaceNum = global.screen.get_active_workspace_index();
 
359
    let windowWorkspaceNum = window.get_workspace().index();
 
360
 
 
361
    if (!time)
 
362
        time = currentTime();
 
363
 
 
364
    if (windowWorkspaceNum != activeWorkspaceNum) {
 
365
        let workspace = global.screen.get_workspace_by_index(windowWorkspaceNum);
 
366
        workspace.activate_with_focus(window, time);
 
367
    } else {
 
368
        window.activate(time);
 
369
    }
 
370
}