2012-12-21 07:55:00 -05:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported addBackgroundMenu */
|
2012-12-21 07:55:00 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, St } = imports.gi;
|
2012-12-21 07:55:00 -05:00
|
|
|
|
|
|
|
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');
|
2022-01-21 08:24:02 -05:00
|
|
|
this.addSettingsAction(_('Settings'), 'org.gnome.Settings.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);
|
2019-04-09 19:23:59 -04:00
|
|
|
actor._backgroundManager = new PopupMenu.PopupMenuManager(actor);
|
2012-12-21 07:55:00 -05:00
|
|
|
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);
|
2019-09-11 16:00:39 -04:00
|
|
|
actor._backgroundMenu.open(BoxPointer.PopupAnimation.FULL);
|
2012-12-21 07:55:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let clickAction = new Clutter.ClickAction();
|
2019-08-19 20:20:08 -04:00
|
|
|
clickAction.connect('long-press', (action, theActor, state) => {
|
2019-08-19 20:51:42 -04:00
|
|
|
if (state == Clutter.LongPressState.QUERY) {
|
2019-08-19 15:38:51 -04:00
|
|
|
return (action.get_button() == 0 ||
|
2014-07-22 06:34:56 -04:00
|
|
|
action.get_button() == 1) &&
|
2019-08-19 15:38:51 -04:00
|
|
|
!actor._backgroundMenu.isOpen;
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
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
|
|
|
|
2021-08-15 18:36:59 -04:00
|
|
|
global.display.connectObject('grab-op-begin',
|
|
|
|
() => clickAction.release(), actor);
|
2014-06-25 11:53:37 -04:00
|
|
|
|
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;
|
|
|
|
});
|
2012-12-21 07:55:00 -05:00
|
|
|
}
|