This commit is contained in:
davedatum
2019-10-26 23:53:38 +01:00
parent e7adc8779e
commit 2f34697860
417 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
Copyright (c) 2011-2012, Giovanni Campagna <scampa.giovanni@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the GNOME nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
/**
* initTranslations:
* @domain: (optional): the gettext domain to use
*
* Initialize Gettext to load translations from extensionsdir/locale.
* If @domain is not provided, it will be taken from metadata['gettext-domain']
*/
function initTranslations(domain) {
let extension = ExtensionUtils.getCurrentExtension();
domain = domain || extension.metadata['gettext-domain'];
// check if this extension was built with "make zip-file", and thus
// has the locale files in a subfolder
// otherwise assume that extension has been installed in the
// same prefix as gnome-shell
let localeDir = extension.dir.get_child('locale');
if (localeDir.query_exists(null))
Gettext.bindtextdomain(domain, localeDir.get_path());
else
Gettext.bindtextdomain(domain, Config.LOCALEDIR);
}
/**
* getSettings:
* @schema: (optional): the GSettings schema id
*
* Builds and return a GSettings schema for @schema, using schema files
* in extensionsdir/schemas. If @schema is not provided, it is taken from
* metadata['settings-schema'].
*/
function getSettings(schema) {
let extension = ExtensionUtils.getCurrentExtension();
schema = schema || extension.metadata['settings-schema'];
const GioSSS = Gio.SettingsSchemaSource;
// check if this extension was built with "make zip-file", and thus
// has the schema files in a subfolder
// otherwise assume that extension has been installed in the
// same prefix as gnome-shell (and therefore schemas are available
// in the standard folders)
let schemaDir = extension.dir.get_child('schemas');
let schemaSource;
if (schemaDir.query_exists(null))
schemaSource = GioSSS.new_from_directory(schemaDir.get_path(),
GioSSS.get_default(),
false);
else
schemaSource = GioSSS.get_default();
let schemaObj = schemaSource.lookup(schema, true);
if (!schemaObj)
throw new Error('Schema ' + schema + ' could not be found for extension '
+ extension.metadata.uuid + '. Please check your installation.');
return new Gio.Settings({ settings_schema: schemaObj });
}

View File

@@ -0,0 +1,261 @@
// tweaks-system-menu - Put Gnome Tweaks in the system menu.
// Copyright (C) 2019 Philippe Troin (F-i-f on Github)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const Main = imports.ui.main;
const StatusSystem = imports.ui.status.system;
const Shell = imports.gi.Shell;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Logger = Me.imports.logger;
const TweaksSystemMenuActionButton = class TweaksSystemMenuActionButton {
constructor(extension, appName) {
this._extension = extension;
this._appName = appName;
this._app = null;
this._action = null;
this._signalConnection = null;
}
_log_debug(msg) {
this._extension._logger.log_debug('TweaksSystemMenuActionButton('
+ this._appName + '): '+msg);
}
enable() {
this._log_debug('enable()');
this._app = Shell.AppSystem.get_default().lookup_app(this._appName);
this._action = this._extension._systemMenu
._createActionButton(this._app.app_info.get_icon().names[0],
this._app.get_name());
this._signalConnection = this._action.connect('clicked',
this._on_clicked.bind(this));
}
disable(destroy) {
this._log_debug('disable(' + destroy +')');
this._action.disconnect(this._signalConnection);
if (destroy)
this._action.destroy()
this._app = null;
this._action = null;
this._signalConnection = null;
}
setVisible(visible) {
this._action.visible = visible;
}
getAction() {
return this._action;
}
_on_clicked() {
this._log_debug('_on_clicked()');
this._extension._systemMenu.menu.itemActivated();
Main.overview.hide();
this._app.activate();
}
};
const TweaksSystemMenuExtension = class TweaksSystemMenuExtension {
constructor() {
this._logger = null;
this._settings = null;
this._debugSettingChangedConnection = null;
this._buttonsMergeSettingChangeConnection = null;
this._positionSettingChangedConnection = null;
this._systemMenu = null;
this._systemActionsActor = null;
this._tweaksButton = null;
this._settingsButton = null;
this._settingsSwitcher = null;
this._actorToPosition = null;
this._openStateChangedConnectionId = null;
}
_findSystemAction(action) {
let systemActions = this._systemActionsActor.get_children();
for (let i=0; i < systemActions.length; ++i) {
if (systemActions[i] == action) {
this._logger.log_debug('_findSystemAction('+action+') = '+i);
return i;
}
}
this._logger.log_debug('_findSystemAction('+action+') = <null>');
return null;
}
enable() {
this._logger = new Logger.Logger('Tweaks-System-Menu');
this._settings = Convenience.getSettings();
this._on_debug_change();
this._logger.log_debug('enable()');
this._debugSettingChangedConnection = this._settings.connect('changed::debug',
this._on_debug_change.bind(this));
this._buttonsMergeSettingChangeConnection = this._settings.connect('changed::merge-with-settings',
this._on_buttons_merge_change.bind(this));
this._positionSettingChangedConnection = this._settings.connect('changed::position',
this._on_position_change.bind(this));
this._systemMenu = Main.panel.statusArea.aggregateMenu._system;
if (this._systemMenu.buttonGroup !== undefined && this._systemMenu.buttonGroup.actor !== undefined) {
// Gnome-Shell 3.33.90+
this._systemActionsActor = this._systemMenu.buttonGroup.actor;
} else {
// Gnome-Shell 3.32-
this._systemActionsActor = this._systemMenu._actionsItem.actor;
}
this._showButton();
this._openStateChangedConnectionId = this._systemMenu.menu.connect('open-state-changed',
this._on_open_state_changed.bind(this));
this._logger.log_debug('extension enabled');
}
disable() {
this._logger.log_debug('disable()');
this._systemMenu.menu.disconnect(this._openStateChangedConnectionId);
this._openStateChangedConnectionId = null;
this._hideButton();
this._systemMenu = null;
this._systemActionsActor = null;
this._settings.disconnect(this._debugSettingChangedConnection);
this._debugSettingChangedConnection = null;
this._settings.disconnect(this._buttonsMergeSettingChangeConnection);
this._buttonsMergeSettingChangeConnection = null;
this._settings.disconnect(this._positionSettingChangedConnection);
this._positionSettingChangedConnection = null;
this._settings = null;
this._logger.log_debug('extension disabled');
this._logger = null;
}
_showButton() {
this._logger.log_debug('_showButton()');
this._tweaksButton = new TweaksSystemMenuActionButton(this, 'org.gnome.tweaks.desktop');
this._tweaksButton.enable();
if (this._settings.get_boolean('merge-with-settings')) {
this._settingsButton = new TweaksSystemMenuActionButton(this, 'gnome-control-center.desktop');
this._settingsButton.enable();
this._settingsSwitcher = new StatusSystem.AltSwitcher(this._settingsButton.getAction(),
this._tweaksButton.getAction());
this._systemActionsActor.add(this._settingsSwitcher.actor,
{expand:true, x_fill:false});
this._actorToPosition = this._settingsSwitcher.actor;
this._systemMenu._settingsAction.visible = false;
} else {
this._systemActionsActor.add(this._tweaksButton.getAction(),
{expand: true, x_fill: false});
this._actorToPosition = this._tweaksButton.getAction();
}
this._on_position_change();
}
_hideButton() {
this._logger.log_debug('_hideButton()');
this._systemActionsActor.remove_child(this._actorToPosition);
this._actorToPosition = null;
this._tweaksButton.disable(!this._areButtonsMerged());
this._tweaksButton = null;
if (this._areButtonsMerged()) {
this._settingsButton.disable(false);
this._settingsButton = null;
this._settingsSwitcher.actor.destroy();
this._settingsSwitcher = null;
this._systemMenu._settingsAction.visible = true;
}
}
_areButtonsMerged() {
return this._settingsSwitcher != null;
}
_on_debug_change() {
this._logger.set_debug(this._settings.get_boolean('debug'));
this._logger.log_debug('debug = '+this._logger.get_debug());
}
_on_buttons_merge_change() {
let buttonsShouldMerge = this._settings.get_boolean('merge-with-settings');
this._logger.log_debug('_on_buttons_merge_change(): merge='+buttonsShouldMerge);
if ( ( buttonsShouldMerge && ! this._areButtonsMerged())
|| ( ! buttonsShouldMerge && this._areButtonsMerged())) {
this._hideButton();
this._showButton();
}
}
_on_position_change() {
let position = this._settings.get_int('position');
this._logger.log_debug('_on_position_change(): settings position=' + position);
if (position == -1) {
position = this._findSystemAction(this._systemMenu._settingsAction)+1;
this._logger.log_debug('_on_position_change(): automatic position=' + position);
}
let n_children = this._systemActionsActor.get_n_children();
if (position >= n_children) {
position = n_children-1;
this._logger.log_debug('_on_position_change(): adjusting position='
+ position + ' with '+n_children+' elements');
}
this._systemActionsActor.set_child_at_index(this._actorToPosition, position);
}
_on_open_state_changed(menu, open) {
this._logger.log_debug('_on_open_state_changed()');
if (!open)
return;
this._tweaksButton.setVisible(true);
if (this._settingsButton != null)
this._settingsButton.setVisible(true);
}
};
function init() {
return new TweaksSystemMenuExtension();
}

View File

@@ -0,0 +1,53 @@
// meson-gse - Library for gnome-shell extensions
// Copyright (C) 2019 Philippe Troin (F-i-f on Github)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
var Logger = class MesonGseLogger {
constructor(title) {
this._first_log = true;
this._title = title;
this._debug = false;
}
get_version() {
return Me.metadata['version']+' / git '+Me.metadata['vcs_revision'];
}
log(text) {
if (this._first_log) {
this._first_log = false;
this.log('version '+this.get_version());
}
global.log(''+this._title+': '+text);
}
log_debug(text) {
if (this._debug) {
this.log(text);
}
}
set_debug(debug) {
this._debug = debug;
}
get_debug() {
return this._debug;
}
};

View File

@@ -0,0 +1,18 @@
{
"_generated": "Generated by SweetTooth, do not edit",
"description": "Put Gnome Tweaks in the System menu. Optionally, collapse Settings and Tweaks into a single button.",
"gettext-domain": "tweaks-system-menu",
"name": "Tweaks in System Menu",
"settings-schema": "org.gnome.shell.extensions.tweaks-system-menu",
"shell-version": [
"3.28",
"3.30",
"3.34",
"3.32",
"3.33.90"
],
"url": "https://github.com/F-i-f/tweaks-system-menu",
"uuid": "tweaks-system-menu@extensions.gnome-shell.fifi.org",
"vcs_revision": "v8-0-g38a53c2",
"version": 8
}

View File

@@ -0,0 +1,161 @@
// Tweaks-system-menu - Put Gnome Tweaks in the system menu.
// Copyright (C) 2019 Philippe Troin (F-i-f on Github)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
const _ = Gettext.gettext;
const Logger = Me.imports.logger;
const TweaksSystemMenuSettings = GObject.registerClass(class TweaksSystemMenuSettings extends Gtk.Grid {
setup() {
this.margin_top = 12;
this.margin_bottom = this.margin_top;
this.margin_left = 48;
this.margin_right = this.margin_left;
this.row_spacing = 6;
this.column_spacing = this.row_spacing;
this.orientation = Gtk.Orientation.VERTICAL;
this._settings = Convenience.getSettings();
this._logger = new Logger.Logger('Tweaks-System-Menu/prefs');
this._logger.set_debug(this._settings.get_boolean('debug'));
let ypos = 1;
let descr;
this.title_label = new Gtk.Label({
use_markup: true,
label: '<span size="large" weight="heavy">'
+_('Tweaks in System Menu')+'</span>',
hexpand: true,
halign: Gtk.Align.CENTER
});
this.attach(this.title_label, 1, ypos, 2, 1);
ypos += 1;
this.version_label = new Gtk.Label({
use_markup: true,
label: '<span size="small">'+_('Version')
+ ' ' + this._logger.get_version() + '</span>',
hexpand: true,
halign: Gtk.Align.CENTER,
});
this.attach(this.version_label, 1, ypos, 2, 1);
ypos += 1;
this.link_label = new Gtk.Label({
use_markup: true,
label: '<span size="small"><a href="'+Me.metadata.url+'">'
+ Me.metadata.url + '</a></span>',
hexpand: true,
halign: Gtk.Align.CENTER,
margin_bottom: this.margin_bottom
});
this.attach(this.link_label, 1, ypos, 2, 1);
ypos += 1;
descr = _(this._settings.settings_schema.get_key('merge-with-settings')
.get_description());
this.merge_ws_label = new Gtk.Label({
label: _("Merge both Settings and Tweaks:"),
halign: Gtk.Align.START
});
this.merge_ws_label.set_tooltip_text(descr);
this.merge_ws_control = new Gtk.Switch({
halign: Gtk.Align.END
});
this.merge_ws_control.set_tooltip_text(descr);
this.merge_ws_label.set_tooltip_text(descr);
this.attach(this.merge_ws_label, 1, ypos, 1, 1);
this.attach(this.merge_ws_control, 2, ypos, 1, 1);
this._settings.bind('merge-with-settings', this.merge_ws_control,
'active', Gio.SettingsBindFlags.DEFAULT);
ypos += 1;
let sschema = this._settings.settings_schema.get_key('position');
descr = _(sschema.get_description());
this.position_label = new Gtk.Label({
label: _("Button position:"),
halign: Gtk.Align.START
});
this.position_label.set_tooltip_text(descr);
let position_range = sschema.get_range().deep_unpack()[1].deep_unpack()
this.position_control = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: position_range[0],
upper: position_range[1],
step_increment: 1
}),
halign: Gtk.Align.END
});
this.position_control.set_tooltip_text(descr);
this.attach(this.position_label, 1, ypos, 1, 1);
this.attach(this.position_control, 2, ypos, 1, 1);
this._settings.bind('position', this.position_control,
'value', Gio.SettingsBindFlags.DEFAULT);
ypos += 1;
descr = _(this._settings.settings_schema.get_key('debug').get_description());
this.debug_label = new Gtk.Label({label: _("Debug:"), halign: Gtk.Align.START});
this.debug_label.set_tooltip_text(descr);
this.debug_control = new Gtk.Switch({halign: Gtk.Align.END});
this.debug_control.set_tooltip_text(descr);
this.attach(this.debug_label, 1, ypos, 1, 1);
this.attach(this.debug_control, 2, ypos, 1, 1);
this._settings.bind('debug', this.debug_control, 'active', Gio.SettingsBindFlags.DEFAULT);
ypos += 1;
this.copyright_label = new Gtk.Label({
use_markup: true,
label: '<span size="small">'
+ _('Copyright © 2019 Philippe Troin (<a href="https://github.com/F-i-f">F-i-f</a> on GitHub)')
+ '</span>',
hexpand: true,
halign: Gtk.Align.CENTER,
margin_top: this.margin_bottom
});
this.attach(this.copyright_label, 1, ypos, 2, 1);
ypos += 1;
}
});
function init() {
Convenience.initTranslations();
}
function buildPrefsWidget() {
let widget = new TweaksSystemMenuSettings();
widget.setup();
widget.show_all();
return widget;
}

View File

@@ -0,0 +1,28 @@
<schemalist gettext-domain="tweaks-system-menu">
<schema id="org.gnome.shell.extensions.tweaks-system-menu" path="/org/gnome/shell/extensions/tweaks-system-menu/">
<key name="merge-with-settings" type="b">
<default>false</default>
<summary>Merge both Settings and Tweaks into a single button.</summary>
<description>When enabled, both Settings and Tweaks share a
single button: the Settings button is visible when the system
menu opens, and Tweaks can be shown by pressing the "Alt" key or
by long clicking on the button. When disabled, Tweaks uses its
own, different button.</description>
</key>
<key name="position" type="i">
<default>-1</default>
<range min="-1" max="99"/>
<summary>Position of the button.</summary>
<description>If set to -1, the button position is automatic:
the merged button replaces the Settings button, and if the
buttons are not merged, Tweaks will show up to the right of the
Settings button. If set to zero or more, the actual button
position on the system menu.</description>
</key>
<key name="debug" type="b">
<default>false</default>
<summary>Debugging.</summary>
<description>Enable debugging for the extension.</description>
</key>
</schema>
</schemalist>