status/system: Add screenshot item

We got a shiny new screenshot UI last cycle, but only relatively
obscure ways of launching it: Keyboard shortcut or overview search.

The new quick settings provides us with a natural place to expose
the functionality more prominently, and at the same time reduce
the emptiness of the top row, in particular on systems without a
battery and when locked.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2439>
This commit is contained in:
Florian Müllner 2022-08-21 18:23:06 +02:00 committed by Marge Bot
parent 6db6db8a6b
commit 1e9749a782

View File

@ -1,11 +1,12 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported Indicator */ /* exported Indicator */
const {Atk, Clutter, Gio, GObject, Shell, St, UPowerGlib: UPower} = imports.gi; const {Atk, Clutter, Gio, GLib, GObject, Meta, Shell, St, UPowerGlib: UPower} = imports.gi;
const SystemActions = imports.misc.systemActions; const SystemActions = imports.misc.systemActions;
const Main = imports.ui.main; const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu; const PopupMenu = imports.ui.popupMenu;
const {PopupAnimation} = imports.ui.boxpointer;
const {QuickSettingsItem, QuickToggle, SystemIndicator} = imports.ui.quickSettings; const {QuickSettingsItem, QuickToggle, SystemIndicator} = imports.ui.quickSettings;
const {loadInterfaceXML} = imports.misc.fileUtils; const {loadInterfaceXML} = imports.misc.fileUtils;
@ -93,6 +94,27 @@ const PowerToggle = GObject.registerClass({
} }
}); });
const ScreenshotItem = GObject.registerClass(
class ScreenshotItem extends QuickSettingsItem {
_init() {
super._init({
style_class: 'icon-button',
can_focus: true,
icon_name: 'camera-photo-symbolic',
visible: !Main.sessionMode.isGreeter,
});
this.connect('clicked', () => {
const topMenu = Main.panel.statusArea.quickSettings.menu;
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
Main.screenshotUI.open().catch(logError);
return GLib.SOURCE_REMOVE;
});
topMenu.close(PopupAnimation.NONE);
});
}
});
const SettingsItem = GObject.registerClass( const SettingsItem = GObject.registerClass(
class SettingsItem extends QuickSettingsItem { class SettingsItem extends QuickSettingsItem {
_init() { _init() {
@ -242,6 +264,9 @@ class SystemItem extends QuickSettingsItem {
GObject.BindingFlags.SYNC_CREATE); GObject.BindingFlags.SYNC_CREATE);
this.child.add_child(this._laptopSpacer); this.child.add_child(this._laptopSpacer);
const screenshotItem = new ScreenshotItem();
this.child.add_child(screenshotItem);
const settingsItem = new SettingsItem(); const settingsItem = new SettingsItem();
this.child.add_child(settingsItem); this.child.add_child(settingsItem);