Skip to content

Commit

Permalink
Add a preference window !
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDG2 committed Oct 28, 2014
1 parent ca964ae commit 7b5fb10
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 13 deletions.
93 changes: 93 additions & 0 deletions [email protected]/convenience.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
Copyright (c) 2011-2012, Giovanni Campagna <[email protected]>
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 });
}

66 changes: 54 additions & 12 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,59 @@

const Main = imports.ui.main;
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;


/* Debug tool */
const St = imports.gi.St;
const Mainloop = imports.mainloop;

function _showMessage(msg) {
let label = new St.Label({ style_class: 'debug-label', text: msg });
let monitor = Main.layoutManager.primaryMonitor;
global.stage.add_actor(label);
label.set_position(Math.floor (monitor.width / 2 - label.width / 2), Math.floor(monitor.height / 2 - label.height / 2));
Mainloop.timeout_add(3000, function () { label.destroy(); });
}

//const panelModification = "gradient";
const panelModification = "transparency";

const PanelTransparencyManager = new Lang.Class({
Name: 'PanelTransparencyManager',

_init: function(panel) {
_init: function(panel, style) {
this._panel = panel;
this._style = style || 'transparency';
this._isTransp= true;
},

updateStyle: function(newStyle) {
let retransp = false;
if(this._isTransp) {
this.setSolid();
retransp = true;
}
this._style = newStyle;
if(retransp) this.setTransparent();
},

setTransparent: function() {
// Add transparency
this._panel.actor.add_style_class_name('panel-' + panelModification);
this._panel._leftCorner.actor.add_style_class_name('corner-' + panelModification);
this._panel._rightCorner.actor.add_style_class_name('corner-' + panelModification);
//_showMessage("Style used : " + this._style);
this._isTransp = true;
this._panel.actor.add_style_class_name('panel-' + this._style);
this._panel._leftCorner.actor.add_style_class_name('corner-' + this._style);
this._panel._rightCorner.actor.add_style_class_name('corner-' + this._style);
},

setSolid: function() {
// Restore opacity
this._panel.actor.remove_style_class_name('panel-' + panelModification);
this._panel._leftCorner.actor.remove_style_class_name('corner-' + panelModification);
this._panel._rightCorner.actor.remove_style_class_name('corner-' + panelModification);
//_showMessage("Style used : solid");
this._isTransp = false;
this._panel.actor.remove_style_class_name('panel-' + this._style);
this._panel._leftCorner.actor.remove_style_class_name('corner-' + this._style);
this._panel._rightCorner.actor.remove_style_class_name('corner-' + this._style);
}
});

Expand Down Expand Up @@ -154,7 +184,8 @@ const WorkspaceManager = new Lang.Class({
const GlobalManager = new Lang.Class({
Name: 'WorkspaceList',

_init: function(transparencyManager) {
_init: function(transparencyManager, settings) {
this._settings = settings;
this._transparencyManager = transparencyManager;
this._currentWorkspace = new WorkspaceManager(transparencyManager, global.screen.get_active_workspace());
this._currentWorkspace.updatePanelTransparency();
Expand All @@ -163,6 +194,8 @@ const GlobalManager = new Lang.Class({
this._notifyShowOverviewId = Main.overview.connect('showing', Lang.bind(this, this._showOverview));
this._notifyHideOverviewId = Main.overview.connect('hiding', Lang.bind(this, this._hideOverview));
this._overviewOpen = false;

this._notifySettingsId = this._settings.connect('changed', Lang.bind(this, this._settingsUpdate))
},

_switchWorkspace: function(winManager, previousWkId, newWkId) {
Expand All @@ -189,6 +222,13 @@ const GlobalManager = new Lang.Class({
global.window_manager.disconnect(this._notifySwitchId);
Main.overview.disconnect(this._notifyShowOverviewId);
Main.overview.disconnect(this._notifyHideOverviewId);
this._settings.disconnect(this._notifySettingsId);
},

_settingsUpdate: function() {
//_showMessage('New style value ' + this._settings.get_string('style'));
this._transparencyManager.updateStyle(this._settings.get_string('style'));
this._currentWorkspace.updatePanelTransparency();
}
});

Expand All @@ -198,6 +238,7 @@ const GlobalManager = new Lang.Class({
*/
let topPanelTransparencyManager;
let globalManager;
let preferences;

/*
* Extensions standard functions
Expand All @@ -206,8 +247,9 @@ function init() {
}

function enable() {
topPanelTransparencyManager = new PanelTransparencyManager(Main.panel);
workspaceManager = new GlobalManager(topPanelTransparencyManager);
preferences = Convenience.getSettings();
topPanelTransparencyManager = new PanelTransparencyManager(Main.panel, preferences.get_string('style'));
workspaceManager = new GlobalManager(topPanelTransparencyManager, preferences);
}

function disable() {
Expand Down
5 changes: 4 additions & 1 deletion [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
"description": "Dynamic top bar for Gnome Shell",
"name": "Dynamic Top Bar",
"shell-version": [
"3.10",
"3.12",
"3.14"
],
"extension-id": "dynamic-top-bar",
"settings-schema": "org.gnome.shell.extensions.dynamic-top-bar",
"url": "http://github.com/AMDG2/GnomeShell_DynamicTopBar",
"uuid": "[email protected]",
"version": 7
"version": 8
}
89 changes: 89 additions & 0 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@


const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;

const PrefWindow = new GObject.Class({
Name: 'PrefWindow',
GTypeName: 'PrefWindow',
Extends: Gtk.Grid,

_init: function(params) {
this.parent(params);
this.margin = 12;
this.row_spacing = this.column_spacing = 6;

this._settings = Convenience.getSettings();

this.set_orientation(Gtk.Orientation.VERTICAL);

this.add(new Gtk.Label({
label: '<b>Tranparency style</b>',
use_markup: true,
halign: Gtk.Align.START
}));

this._styleList = new Gtk.ListStore();
this._styleList.set_column_types([
GObject.TYPE_STRING
]);

this._styleList.set(
this._styleList.append(),
[0],
['transparency']
);

this._styleList.set(
this._styleList.append(),
[0],
['gradient']
);

let rendererText = new Gtk.CellRendererText();

this._comboBox = new Gtk.ComboBox({
model: this._styleList
});

this._comboBox.pack_start (rendererText, false);
this._comboBox.add_attribute (rendererText, "text", 0);

if(this._settings.get_string('style') == 'transparency')
this._comboBox.set_active(0);
else
this._comboBox.set_active(1);

this.add(this._comboBox);

//this._settings.bind('style', this._comboBox, 'text', Gio.SettingsBindFlags.DEFAULT);
this._comboBox.connect ('changed', Lang.bind (this, this._styleChanged));
},

_styleChanged: function() {
let selection = this._comboBox.get_active();
log('New selection : ' + selection);
if(selection == 0)
this._settings.set_string('style', 'transparency');
else
this._settings.set_string('style', 'gradient');
}
});

function init() {

}

function buildPrefsWidget() {
let prefWindow = new PrefWindow();
prefWindow.show_all();

return prefWindow;
}
Binary file added [email protected]/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<schemalist gettext-domain="dynamic-top-bar">
<enum id="org.gnome.shell.extensions.dynamic-top-bar.style">
<value value="0" nick="transparency"/>
<value value="1" nick="gradient"/>
</enum>
<schema
id="org.gnome.shell.extensions.dynamic-top-bar"
path="/org/gnome/shell/extensions/dynamic-top-bar/">
<key name="style" enum="org.gnome.shell.extensions.dynamic-top-bar.style">
<default>'transparency'</default>
<summary>Choose the top bar transparency style : gradient or full transparency</summary>
</key>
</schema>
</schemalist>
9 changes: 9 additions & 0 deletions [email protected]/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@
background-color: transparent;
-panel-corner-radius: 0;
}

.debug-label {
font-size: 36px;
font-weight: bold;
color: #ffffff;
background-color: rgba(10,10,10,0.7);
border-radius: 5px;
padding: 15px;
}

0 comments on commit 7b5fb10

Please sign in to comment.