2012-12-21 12:55:00 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
|
|
|
const BackgroundMenu = new Lang.Class({
|
|
|
|
Name: 'BackgroundMenu',
|
|
|
|
Extends: PopupMenu.PopupMenu,
|
|
|
|
|
layout: Fix several issues with the background management code
If monitor-changed fires at startup, it will destroy all of the
backgrounds, but since this._isStartup is true, won't recreate any
of them. Additionally, since _bgManagers is indexed by monitor index,
if the primary index is not 0, it could become a sparse array (e.g.
[undefined, undefined, primaryBackground]), and our for loop will
crash trying to access properties of undefined.
Fix both of these issues by always creating background managers for
every monitor, hiding them on startup but only showing them after
the startup animation is complete.
One thing we need to watch out for is that while LayoutManager is
constructing, Main.uiGroup / Main.layoutManager will be undefined,
so addBackgroundMenu will fail. Fix this by passing down the uiGroup
to the background menu code.
https://bugzilla.gnome.org/show_bug.cgi?id=709313
2013-11-07 22:14:47 +00:00
|
|
|
_init: function(source, layoutManager) {
|
2012-12-21 12:55:00 +00:00
|
|
|
this.parent(source, 0, St.Side.TOP);
|
|
|
|
|
2013-02-20 18:43:13 +00:00
|
|
|
this.addSettingsAction(_("Settings"), 'gnome-control-center.desktop');
|
2012-12-21 12:55:00 +00:00
|
|
|
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2013-02-20 18:43:13 +00:00
|
|
|
this.addSettingsAction(_("Change Background…"), 'gnome-background-panel.desktop');
|
2012-12-21 12:55:00 +00:00
|
|
|
|
|
|
|
this.actor.add_style_class_name('background-menu');
|
|
|
|
|
layout: Fix several issues with the background management code
If monitor-changed fires at startup, it will destroy all of the
backgrounds, but since this._isStartup is true, won't recreate any
of them. Additionally, since _bgManagers is indexed by monitor index,
if the primary index is not 0, it could become a sparse array (e.g.
[undefined, undefined, primaryBackground]), and our for loop will
crash trying to access properties of undefined.
Fix both of these issues by always creating background managers for
every monitor, hiding them on startup but only showing them after
the startup animation is complete.
One thing we need to watch out for is that while LayoutManager is
constructing, Main.uiGroup / Main.layoutManager will be undefined,
so addBackgroundMenu will fail. Fix this by passing down the uiGroup
to the background menu code.
https://bugzilla.gnome.org/show_bug.cgi?id=709313
2013-11-07 22:14:47 +00:00
|
|
|
layoutManager.uiGroup.add_actor(this.actor);
|
2012-12-21 12:55:00 +00:00
|
|
|
this.actor.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
layout: Fix several issues with the background management code
If monitor-changed fires at startup, it will destroy all of the
backgrounds, but since this._isStartup is true, won't recreate any
of them. Additionally, since _bgManagers is indexed by monitor index,
if the primary index is not 0, it could become a sparse array (e.g.
[undefined, undefined, primaryBackground]), and our for loop will
crash trying to access properties of undefined.
Fix both of these issues by always creating background managers for
every monitor, hiding them on startup but only showing them after
the startup animation is complete.
One thing we need to watch out for is that while LayoutManager is
constructing, Main.uiGroup / Main.layoutManager will be undefined,
so addBackgroundMenu will fail. Fix this by passing down the uiGroup
to the background menu code.
https://bugzilla.gnome.org/show_bug.cgi?id=709313
2013-11-07 22:14:47 +00:00
|
|
|
function addBackgroundMenu(actor, layoutManager) {
|
2012-12-21 12:55:00 +00:00
|
|
|
let cursor = new St.Bin({ opacity: 0 });
|
layout: Fix several issues with the background management code
If monitor-changed fires at startup, it will destroy all of the
backgrounds, but since this._isStartup is true, won't recreate any
of them. Additionally, since _bgManagers is indexed by monitor index,
if the primary index is not 0, it could become a sparse array (e.g.
[undefined, undefined, primaryBackground]), and our for loop will
crash trying to access properties of undefined.
Fix both of these issues by always creating background managers for
every monitor, hiding them on startup but only showing them after
the startup animation is complete.
One thing we need to watch out for is that while LayoutManager is
constructing, Main.uiGroup / Main.layoutManager will be undefined,
so addBackgroundMenu will fail. Fix this by passing down the uiGroup
to the background menu code.
https://bugzilla.gnome.org/show_bug.cgi?id=709313
2013-11-07 22:14:47 +00:00
|
|
|
layoutManager.uiGroup.add_actor(cursor);
|
2012-12-21 12:55:00 +00:00
|
|
|
|
2013-02-20 01:18:14 +00:00
|
|
|
actor.reactive = true;
|
layout: Fix several issues with the background management code
If monitor-changed fires at startup, it will destroy all of the
backgrounds, but since this._isStartup is true, won't recreate any
of them. Additionally, since _bgManagers is indexed by monitor index,
if the primary index is not 0, it could become a sparse array (e.g.
[undefined, undefined, primaryBackground]), and our for loop will
crash trying to access properties of undefined.
Fix both of these issues by always creating background managers for
every monitor, hiding them on startup but only showing them after
the startup animation is complete.
One thing we need to watch out for is that while LayoutManager is
constructing, Main.uiGroup / Main.layoutManager will be undefined,
so addBackgroundMenu will fail. Fix this by passing down the uiGroup
to the background menu code.
https://bugzilla.gnome.org/show_bug.cgi?id=709313
2013-11-07 22:14:47 +00:00
|
|
|
actor._backgroundMenu = new BackgroundMenu(cursor, layoutManager);
|
2012-12-21 12:55:00 +00:00
|
|
|
actor._backgroundManager = new PopupMenu.PopupMenuManager({ actor: actor });
|
|
|
|
actor._backgroundManager.addMenu(actor._backgroundMenu);
|
|
|
|
|
|
|
|
function openMenu() {
|
|
|
|
let [x, y] = global.get_pointer();
|
|
|
|
cursor.set_position(x, y);
|
2013-02-18 20:51:48 +00:00
|
|
|
actor._backgroundMenu.open(BoxPointer.PopupAnimation.NONE);
|
2012-12-21 12:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let clickAction = new Clutter.ClickAction();
|
|
|
|
clickAction.connect('long-press', function(action, actor, state) {
|
|
|
|
if (state == Clutter.LongPressState.QUERY)
|
|
|
|
return action.get_button() == 1 && !actor._backgroundMenu.isOpen;
|
2013-04-23 20:39:29 +00:00
|
|
|
if (state == Clutter.LongPressState.ACTIVATE) {
|
2012-12-21 12:55:00 +00:00
|
|
|
openMenu();
|
2013-04-23 20:39:29 +00:00
|
|
|
actor._backgroundManager.ignoreRelease();
|
|
|
|
}
|
2012-12-21 12:55:00 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
clickAction.connect('clicked', function(action) {
|
|
|
|
if (action.get_button() == 3)
|
|
|
|
openMenu();
|
|
|
|
});
|
|
|
|
actor.add_action(clickAction);
|
2013-04-02 03:57:55 +00:00
|
|
|
|
|
|
|
actor.connect('destroy', function() {
|
|
|
|
actor._backgroundMenu.destroy();
|
|
|
|
actor._backgroundMenu = null;
|
|
|
|
actor._backgroundManager = null;
|
2013-04-04 20:37:13 +00:00
|
|
|
|
|
|
|
cursor.destroy();
|
2013-04-02 03:57:55 +00:00
|
|
|
});
|
2012-12-21 12:55:00 +00:00
|
|
|
}
|