2012-12-21 07:55:00 -05:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
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;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var BackgroundMenu = class BackgroundMenu extends PopupMenu.PopupMenu {
|
|
|
|
constructor(layoutManager) {
|
|
|
|
super(layoutManager.dummyCursor, 0, St.Side.TOP);
|
2012-12-21 07:55:00 -05:00
|
|
|
|
2013-02-20 13:43:13 -05:00
|
|
|
this.addSettingsAction(_("Change Background…"), 'gnome-background-panel.desktop');
|
2015-03-31 04:20:14 -04:00
|
|
|
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
this.addSettingsAction(_("Display Settings"), 'gnome-display-panel.desktop');
|
|
|
|
this.addSettingsAction(_("Settings"), 'gnome-control-center.desktop');
|
2012-12-21 07:55:00 -05: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 17:14:47 -05:00
|
|
|
layoutManager.uiGroup.add_actor(this.actor);
|
2012-12-21 07:55:00 -05:00
|
|
|
this.actor.hide();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2012-12-21 07:55:00 -05:00
|
|
|
|
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 17:14:47 -05:00
|
|
|
function addBackgroundMenu(actor, layoutManager) {
|
2013-02-19 20:18:14 -05:00
|
|
|
actor.reactive = true;
|
2013-02-15 04:56:34 -05:00
|
|
|
actor._backgroundMenu = new BackgroundMenu(layoutManager);
|
2012-12-21 07:55:00 -05:00
|
|
|
actor._backgroundManager = new PopupMenu.PopupMenuManager({ actor: actor });
|
|
|
|
actor._backgroundManager.addMenu(actor._backgroundMenu);
|
|
|
|
|
2014-07-22 06:34:56 -04:00
|
|
|
function openMenu(x, y) {
|
2014-04-11 10:12:52 -04:00
|
|
|
Main.layoutManager.setDummyCursorGeometry(x, y, 0, 0);
|
2013-02-18 15:51:48 -05:00
|
|
|
actor._backgroundMenu.open(BoxPointer.PopupAnimation.NONE);
|
2012-12-21 07:55:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let clickAction = new Clutter.ClickAction();
|
2017-10-30 20:38:18 -04:00
|
|
|
clickAction.connect('long-press', (action, actor, state) => {
|
2012-12-21 07:55:00 -05:00
|
|
|
if (state == Clutter.LongPressState.QUERY)
|
2014-07-22 06:34:56 -04:00
|
|
|
return ((action.get_button() == 0 ||
|
|
|
|
action.get_button() == 1) &&
|
|
|
|
!actor._backgroundMenu.isOpen);
|
2013-04-23 16:39:29 -04:00
|
|
|
if (state == Clutter.LongPressState.ACTIVATE) {
|
2014-07-22 06:34:56 -04:00
|
|
|
let [x, y] = action.get_coords();
|
|
|
|
openMenu(x, y);
|
2013-04-23 16:39:29 -04:00
|
|
|
actor._backgroundManager.ignoreRelease();
|
|
|
|
}
|
2012-12-21 07:55:00 -05:00
|
|
|
return true;
|
|
|
|
});
|
2017-10-30 20:38:18 -04:00
|
|
|
clickAction.connect('clicked', action => {
|
2014-07-22 06:34:56 -04:00
|
|
|
if (action.get_button() == 3) {
|
|
|
|
let [x, y] = action.get_coords();
|
|
|
|
openMenu(x, y);
|
|
|
|
}
|
2012-12-21 07:55:00 -05:00
|
|
|
});
|
|
|
|
actor.add_action(clickAction);
|
2013-04-01 23:57:55 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let grabOpBeginId = global.display.connect('grab-op-begin', () => {
|
2014-06-25 11:53:37 -04:00
|
|
|
clickAction.release();
|
|
|
|
});
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
actor.connect('destroy', () => {
|
2013-02-15 04:56:34 -05:00
|
|
|
actor._backgroundMenu.destroy();
|
|
|
|
actor._backgroundMenu = null;
|
|
|
|
actor._backgroundManager = null;
|
2014-06-25 11:53:37 -04:00
|
|
|
global.display.disconnect(grabOpBeginId);
|
2013-02-15 04:56:34 -05:00
|
|
|
});
|
2012-12-21 07:55:00 -05:00
|
|
|
}
|