Skip to content

Commit

Permalink
clean indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Jul 11, 2021
1 parent c35ff1a commit 5c686cf
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 76 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ Then, enable the extension in the system preferences (gnome tweaks or whatever).
## Screenshot

![Screenshot](http://i.imgur.com/uJPgGkD.png)
<!--TODO mettre un truc à jour-->

51 changes: 26 additions & 25 deletions move-osd-windows@maestroschan.fr/extension.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// gpl v3

const Main = imports.ui.main;
const OsdWindow = imports.ui.osdWindow;

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

//------------------------------------------------

function init() {
Convenience.initTranslations();
Convenience.initTranslations();
}

//------------------------------------------------
//------------------------------------------------------------------------------

function injectToFunction(parent, name, func) {
let origin = parent[name];
Expand All @@ -34,37 +34,38 @@ function removeInjection(object, injection, name) {

let injections=[];

//---------------------------------------------
//------------------------------------------------------------------------------

function enable() {

let _settings = Convenience.getSettings('org.gnome.shell.extensions.move-osd-windows');

injections['show'] = injectToFunction(OsdWindow.OsdWindow.prototype, 'show', function(){

if ( _settings.get_boolean('hide') ){
this.actor.visible = false;
} else {
this.actor.visible = true;
let monitor = Main.layoutManager.monitors[this._monitorIndex];
let h_percent = _settings.get_int('horizontal');
let v_percent = _settings.get_int('vertical');

this._box.translation_x = h_percent * monitor.width / 100;
this._box.translation_y = v_percent * monitor.height / 100;
let settings = Convenience.getSettings('org.gnome.shell.extensions.move-osd-windows');

injections['show'] = injectToFunction(
OsdWindow.OsdWindow.prototype,
'show',
function() {
if(settings.get_boolean('hide')) {
this.actor.visible = false;
} else {
this.actor.visible = true;
let monitor = Main.layoutManager.monitors[this._monitorIndex];
let h_percent = settings.get_int('horizontal');
let v_percent = settings.get_int('vertical');

this._box.translation_x = h_percent * monitor.width / 100;
this._box.translation_y = v_percent * monitor.height / 100;
}
}
});
);
}

function disable() {

let arrayOSD = Main.osdWindowManager._osdWindows;
for (let i = 0; i < arrayOSD.length; i++) {

for(let i = 0; i < arrayOSD.length; i++) {
arrayOSD[i]._relayout();
arrayOSD[i]._box.translation_x = 0;
}

removeInjection(OsdWindow.OsdWindow.prototype, injections, 'show');
}

111 changes: 61 additions & 50 deletions move-osd-windows@maestroschan.fr/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,98 +10,109 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;

//-----------------------------------------------

function init() {
Convenience.initTranslations();
}

//-----------------------------------------------
//------------------------------------------------------------------------------

const OSDSettingsWidget = new GObject.Class({
Name: 'OSD.Prefs.Widget',
GTypeName: 'OSDPrefsWidget',
Extends: Gtk.Box,
Name: 'OSD.Prefs.Widget',
GTypeName: 'OSDPrefsWidget',
Extends: Gtk.Box,

_init: function(params) {
_init: function(params) {
this.parent(params);
this.margin = 30;
this.spacing = 25;
this.fill = true;
this.set_orientation(Gtk.Orientation.VERTICAL);
this.margin = 30;
this.spacing = 25;
this.fill = true;
this.set_orientation(Gtk.Orientation.VERTICAL);

this.SETTINGS = Convenience.getSettings('org.gnome.shell.extensions.move-osd-windows');

let labelHorizontalPercentage = _("Horizontal position (percentage) :");

let horizontalPercentage = new Gtk.SpinButton();
horizontalPercentage.set_sensitive(true);
horizontalPercentage.set_range(-60, 60);
horizontalPercentage.set_sensitive(true);
horizontalPercentage.set_range(-60, 60);
horizontalPercentage.set_value(0);
horizontalPercentage.set_value(this.SETTINGS.get_int('horizontal'));
horizontalPercentage.set_increments(1, 2);
horizontalPercentage.connect('value-changed', Lang.bind(this, function(w){
horizontalPercentage.set_value(this.SETTINGS.get_int('horizontal'));
horizontalPercentage.set_increments(1, 2);

horizontalPercentage.connect('value-changed', Lang.bind(this, function(w) {
var value = w.get_value_as_int();
this.SETTINGS.set_int('horizontal', value);
}));

let hBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 15 });
hBox.pack_start(new Gtk.Label({ label: labelHorizontalPercentage, use_markup: true, halign: Gtk.Align.START }), false, false, 0);
hBox.pack_start(new Gtk.Label({
label: labelHorizontalPercentage,
use_markup: true,
halign: Gtk.Align.START
}), false, false, 0);
hBox.pack_end(horizontalPercentage, false, false, 0);
this.add(hBox);
//-------------------------------------------------------

//----------------------------------------------------------------------

let labelVerticalPercentage = _("Vertical position (percentage) :");

let verticalPercentage = new Gtk.SpinButton();
verticalPercentage.set_sensitive(true);
verticalPercentage.set_range(-110, 110);
verticalPercentage.set_sensitive(true);
verticalPercentage.set_range(-110, 110);
verticalPercentage.set_value(70);
verticalPercentage.set_value(this.SETTINGS.get_int('vertical'));
verticalPercentage.set_increments(1, 2);
verticalPercentage.connect('value-changed', Lang.bind(this, function(w){
verticalPercentage.set_increments(1, 2);

verticalPercentage.connect('value-changed', Lang.bind(this, function(w) {
var value = w.get_value_as_int();
this.SETTINGS.set_int('vertical', value);
}));

let vBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 15 });
vBox.pack_start(new Gtk.Label({ label: labelVerticalPercentage, use_markup: true, halign: Gtk.Align.START }), false, false, 0);
vBox.pack_start(new Gtk.Label({
label: labelVerticalPercentage,
use_markup: true,
halign: Gtk.Align.START
}), false, false, 0);
vBox.pack_end(verticalPercentage, false, false, 0);
this.add(vBox);
//-------------------------------------------------------

//----------------------------------------------------------------------

let labelHide = _("Hide totally OSD windows :");

let HideSwitch = new Gtk.Switch();
HideSwitch.set_state(false);
HideSwitch.set_state(false);
HideSwitch.set_state(this.SETTINGS.get_boolean('hide'));

HideSwitch.connect('notify::active', Lang.bind(this, function(widget) {
if (widget.active) {
this.SETTINGS.set_boolean('hide', true);
} else {
this.SETTINGS.set_boolean('hide', false);
}
}));

let hideBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 15 });
hideBox.pack_start(new Gtk.Label({ label: labelHide, use_markup: true, halign: Gtk.Align.START }), false, false, 0);
hideBox.pack_start(new Gtk.Label({
label: labelHide,
use_markup: true,
halign: Gtk.Align.START
}), false, false, 0);
hideBox.pack_end(HideSwitch, false, false, 0);
this.add(hideBox);
}
});

//-----------------------------------------------
//------------------------------------------------------------------------------

//I guess this is like the "enable" in extension.js : something called each
//time he user try to access the settings' window
function init() {
Convenience.initTranslations();
}

// This is like the "enable" in extension.js : something called each time the
// user tries to access the settings' window
function buildPrefsWidget() {
let widget = new OSDSettingsWidget();
widget.show_all();
let widget = new OSDSettingsWidget();
widget.show_all();

return widget;
return widget;
}

0 comments on commit 5c686cf

Please sign in to comment.