2012-12-21 12:55:00 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import St from 'gi://St';
|
2012-12-21 12:55:00 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import * as BoxPointer from './boxpointer.js';
|
|
|
|
import * as PopupMenu from './popupMenu.js';
|
2012-12-21 12:55:00 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import * as Main from './main.js';
|
|
|
|
|
|
|
|
export class BackgroundMenu extends PopupMenu.PopupMenu {
|
2017-10-31 01:19:44 +00:00
|
|
|
constructor(layoutManager) {
|
|
|
|
super(layoutManager.dummyCursor, 0, St.Side.TOP);
|
2012-12-21 12:55:00 +00:00
|
|
|
|
2023-08-06 22:34:20 +00:00
|
|
|
this.addSettingsAction(_('Change Background…'), 'gnome-background-panel.desktop');
|
2015-03-31 08:20:14 +00:00
|
|
|
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2023-08-06 22:34:20 +00:00
|
|
|
this.addSettingsAction(_('Display Settings'), 'gnome-display-panel.desktop');
|
2022-01-21 13:24:02 +00:00
|
|
|
this.addSettingsAction(_('Settings'), 'org.gnome.Settings.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();
|
|
|
|
}
|
2023-07-10 09:53:00 +00:00
|
|
|
}
|
2012-12-21 12:55:00 +00:00
|
|
|
|
2023-07-30 12:56:59 +00:00
|
|
|
/**
|
|
|
|
* @param {Meta.BackgroundActor} actor
|
|
|
|
* @param {import('./layout.js').LayoutManager} layoutManager
|
|
|
|
*/
|
2023-07-10 09:53:00 +00:00
|
|
|
export function addBackgroundMenu(actor, layoutManager) {
|
2013-02-20 01:18:14 +00:00
|
|
|
actor.reactive = true;
|
2013-02-15 09:56:34 +00:00
|
|
|
actor._backgroundMenu = new BackgroundMenu(layoutManager);
|
2019-04-09 23:23:59 +00:00
|
|
|
actor._backgroundManager = new PopupMenu.PopupMenuManager(actor);
|
2012-12-21 12:55:00 +00:00
|
|
|
actor._backgroundManager.addMenu(actor._backgroundMenu);
|
|
|
|
|
2014-07-22 10:34:56 +00:00
|
|
|
function openMenu(x, y) {
|
2014-04-11 14:12:52 +00:00
|
|
|
Main.layoutManager.setDummyCursorGeometry(x, y, 0, 0);
|
2019-09-11 20:00:39 +00:00
|
|
|
actor._backgroundMenu.open(BoxPointer.PopupAnimation.FULL);
|
2012-12-21 12:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let clickAction = new Clutter.ClickAction();
|
2019-08-20 00:20:08 +00:00
|
|
|
clickAction.connect('long-press', (action, theActor, state) => {
|
2023-08-07 00:51:19 +00:00
|
|
|
if (state === Clutter.LongPressState.QUERY) {
|
|
|
|
return (action.get_button() === 0 ||
|
|
|
|
action.get_button() === 1) &&
|
2019-08-19 19:38:51 +00:00
|
|
|
!actor._backgroundMenu.isOpen;
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2023-08-07 00:51:19 +00:00
|
|
|
if (state === Clutter.LongPressState.ACTIVATE) {
|
2014-07-22 10:34:56 +00:00
|
|
|
let [x, y] = action.get_coords();
|
|
|
|
openMenu(x, y);
|
2013-04-23 20:39:29 +00:00
|
|
|
actor._backgroundManager.ignoreRelease();
|
|
|
|
}
|
2012-12-21 12:55:00 +00:00
|
|
|
return true;
|
|
|
|
});
|
2017-10-31 00:38:18 +00:00
|
|
|
clickAction.connect('clicked', action => {
|
2023-08-07 00:51:19 +00:00
|
|
|
if (action.get_button() === 3) {
|
2014-07-22 10:34:56 +00:00
|
|
|
let [x, y] = action.get_coords();
|
|
|
|
openMenu(x, y);
|
|
|
|
}
|
2012-12-21 12:55:00 +00:00
|
|
|
});
|
|
|
|
actor.add_action(clickAction);
|
2013-04-02 03:57:55 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
actor.connect('destroy', () => {
|
2013-02-15 09:56:34 +00:00
|
|
|
actor._backgroundMenu.destroy();
|
|
|
|
actor._backgroundMenu = null;
|
|
|
|
actor._backgroundManager = null;
|
|
|
|
});
|
2012-12-21 12:55:00 +00:00
|
|
|
}
|