Files
.gitlab
.gitlab-ci
.settings
data
docs
js
dbusServices
gdm
misc
perf
portalHelper
ui
components
status
accessibility.js
bluetooth.js
brightness.js
dwellClick.js
keyboard.js
location.js
network.js
nightLight.js
power.js
remoteAccess.js
rfkill.js
screencast.js
system.js
thunderbolt.js
volume.js
accessDialog.js
altTab.js
animation.js
appDisplay.js
appFavorites.js
audioDeviceSelection.js
background.js
backgroundMenu.js
barLevel.js
boxpointer.js
calendar.js
checkBox.js
closeDialog.js
ctrlAltTab.js
dash.js
dateMenu.js
dialog.js
dnd.js
edgeDragAction.js
endSessionDialog.js
environment.js
extensionDownloader.js
extensionSystem.js
focusCaretTracker.js
grabHelper.js
ibusCandidatePopup.js
iconGrid.js
inhibitShortcutsDialog.js
kbdA11yDialog.js
keyboard.js
layout.js
lightbox.js
locatePointer.js
lookingGlass.js
magnifier.js
magnifierDBus.js
main.js
messageList.js
messageTray.js
modalDialog.js
mpris.js
notificationDaemon.js
osdMonitorLabeler.js
osdWindow.js
overview.js
overviewControls.js
padOsd.js
pageIndicators.js
panel.js
panelMenu.js
pointerA11yTimeout.js
pointerWatcher.js
popupMenu.js
remoteSearch.js
ripples.js
runDialog.js
screenShield.js
screencast.js
screenshot.js
scripting.js
search.js
sessionMode.js
shellDBus.js
shellEntry.js
shellMountOperation.js
slider.js
swipeTracker.js
switchMonitor.js
switcherPopup.js
unlockDialog.js
userWidget.js
viewSelector.js
windowAttentionHandler.js
windowManager.js
windowMenu.js
workspace.js
workspaceSwitcherPopup.js
workspaceThumbnail.js
workspacesView.js
xdndHandler.js
js-resources.gresource.xml
meson.build
portal-resources.gresource.xml
lint
man
meson
po
src
subprojects
tests
tools
.eslintrc.yml
.gitignore
.gitlab-ci.yml
.gitmodules
COPYING
HACKING.md
NEWS
README.md
config.h.meson
gnome-shell.doap
meson.build
meson_options.txt
gnome-shell/js/ui/status/system.js
Florian Müllner a205f4e249 status/system: Fix session submenu visibility
Commit 147a743d8d moved the suspend and power-off actions into
the submenu that contains the log-out and switch-user actions,
but did not update the submenu visibility logic to account for
the additional actions.

As a result, the submenu is hidden when log-out and switch-user
are unavailable (like on the login screen), even if suspend and
power-off are enabled.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/2169
2020-02-04 14:40:44 +00:00

172 lines
6.8 KiB
JavaScript

// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported Indicator */
const { GObject, Shell, St } = imports.gi;
const BoxPointer = imports.ui.boxpointer;
const SystemActions = imports.misc.systemActions;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
var Indicator = GObject.registerClass(
class Indicator extends PanelMenu.SystemIndicator {
_init() {
super._init();
this._systemActions = new SystemActions.getDefault();
this._createSubMenu();
this._loginScreenItem.connect('notify::visible',
() => this._updateSessionSubMenu());
this._logoutItem.connect('notify::visible',
() => this._updateSessionSubMenu());
this._suspendItem.connect('notify::visible',
() => this._updateSessionSubMenu());
this._powerOffItem.connect('notify::visible',
() => this._updateSessionSubMenu());
// Whether shutdown is available or not depends on both lockdown
// settings (disable-log-out) and Polkit policy - the latter doesn't
// notify, so we update the menu item each time the menu opens or
// the lockdown setting changes, which should be close enough.
this.menu.connect('open-state-changed', (menu, open) => {
if (!open)
return;
this._systemActions.forceUpdate();
});
this._updateSessionSubMenu();
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
this._sessionUpdated();
}
_sessionUpdated() {
this._settingsItem.visible = Main.sessionMode.allowSettings;
}
_updateSessionSubMenu() {
this._sessionSubMenu.visible =
this._loginScreenItem.visible ||
this._logoutItem.visible ||
this._suspendItem.visible ||
this._powerOffItem.visible;
}
_createSubMenu() {
let bindFlags = GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;
let item;
item = new PopupMenu.PopupImageMenuItem(
this._systemActions.getName('lock-orientation'),
this._systemActions.orientation_lock_icon);
item.connect('activate', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
this._systemActions.activateLockOrientation();
});
this.menu.addMenuItem(item);
this._orientationLockItem = item;
this._systemActions.bind_property('can-lock-orientation',
this._orientationLockItem,
'visible',
bindFlags);
this._systemActions.connect('notify::orientation-lock-icon', () => {
let iconName = this._systemActions.orientation_lock_icon;
let labelText = this._systemActions.getName("lock-orientation");
this._orientationLockItem.setIcon(iconName);
this._orientationLockItem.label.text = labelText;
});
let app = this._settingsApp = Shell.AppSystem.get_default().lookup_app(
'gnome-control-center.desktop'
);
if (app) {
let [icon, name] = [app.app_info.get_icon().names[0],
app.get_name()];
item = new PopupMenu.PopupImageMenuItem(name, icon);
item.connect('activate', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
Main.overview.hide();
this._settingsApp.activate();
});
this.menu.addMenuItem(item);
this._settingsItem = item;
} else {
log('Missing required core component Settings, expect trouble…');
this._settingsItem = new St.Widget();
}
item = new PopupMenu.PopupImageMenuItem(_('Lock'), 'changes-prevent-symbolic');
item.connect('activate', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
this._systemActions.activateLockScreen();
});
this.menu.addMenuItem(item);
this._lockScreenItem = item;
this._systemActions.bind_property('can-lock-screen',
this._lockScreenItem,
'visible',
bindFlags);
this._sessionSubMenu = new PopupMenu.PopupSubMenuMenuItem(
_('Power Off / Log Out'), true);
this._sessionSubMenu.icon.icon_name = 'system-shutdown-symbolic';
item = new PopupMenu.PopupMenuItem(_("Log Out"));
item.connect('activate', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
this._systemActions.activateLogout();
});
this._sessionSubMenu.menu.addMenuItem(item);
this._logoutItem = item;
this._systemActions.bind_property('can-logout',
this._logoutItem,
'visible',
bindFlags);
item = new PopupMenu.PopupMenuItem(_("Switch User…"));
item.connect('activate', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
this._systemActions.activateSwitchUser();
});
this._sessionSubMenu.menu.addMenuItem(item);
this._loginScreenItem = item;
this._systemActions.bind_property('can-switch-user',
this._loginScreenItem,
'visible',
bindFlags);
this._sessionSubMenu.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
item = new PopupMenu.PopupMenuItem(_("Suspend"));
item.connect('activate', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
this._systemActions.activateSuspend();
});
this._sessionSubMenu.menu.addMenuItem(item);
this._suspendItem = item;
this._systemActions.bind_property('can-suspend',
this._suspendItem,
'visible',
bindFlags);
item = new PopupMenu.PopupMenuItem(_("Power Off…"));
item.connect('activate', () => {
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
this._systemActions.activatePowerOff();
});
this._sessionSubMenu.menu.addMenuItem(item);
this._powerOffItem = item;
this._systemActions.bind_property('can-power-off',
this._powerOffItem,
'visible',
bindFlags);
this.menu.addMenuItem(this._sessionSubMenu);
}
});