Skip to content

Commit

Permalink
panel-tweaks@anaximeno: Version 0.1.2 (linuxmint#6413)
Browse files Browse the repository at this point in the history
* Round values to avoid floating point errors while setting style values
* Update tweak style unset constant name
* Small update in settings ordering
  • Loading branch information
anaximeno authored Sep 12, 2024
1 parent 402e9dd commit bf0b6ab
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var UUID = "panel-tweaks@anaximeno";
var STYLE_UNSET_KEY = "##unset##";
var STYLE_TWEAK_UNSET_KEY = "##tweak-unset##";
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
'use strict';

const { STYLE_UNSET_KEY } = require("./constants.js");
const { STYLE_TWEAK_UNSET_KEY } = require("./constants.js");

function basicStylesDecoder(stylesText) {
let stylesObject = {};
Expand All @@ -40,8 +40,13 @@ function basicStylesEncoder(stylesObject) {

if (stylesObject)
for (let [key, value] of Object.entries(stylesObject))
if (value && value !== STYLE_UNSET_KEY)
if (value && value !== STYLE_TWEAK_UNSET_KEY)
stylesEncoded += `${key}: ${value}; `;

return stylesEncoded.trimEnd();
}

function round(value, nplaces = 0) {
let multDiv = 10 ** nplaces;
return Math.round(value * multDiv) / multDiv;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,42 @@
"description": "Tweak Panel Shadow",
"default": false
},
"panel-shadow-x-axis-shift": {
"panel-shadow-color": {
"type": "colorchooser",
"description": "Panel Shadow Color",
"dependency": "enable-panel-shadow-tweak",
"default": "#010101"
},
"panel-shadow-bluriness": {
"type": "spinbutton",
"units": "px",
"dependency": "enable-panel-shadow-tweak",
"description": "Shadow X-Axis Shift",
"description": "Shadow Bluriness",
"default": 0.0,
"min": -10.0,
"max": 10.0,
"min": 0.0,
"max": 16.0,
"step": 0.05
},
"panel-shadow-y-axis-shift": {
"panel-shadow-x-axis-shift": {
"type": "spinbutton",
"units": "px",
"dependency": "enable-panel-shadow-tweak",
"description": "Shadow Y-Axis Shift",
"description": "Shadow X-Axis Shift",
"default": 0.0,
"min": -10.0,
"max": 10.0,
"step": 0.05
},
"panel-shadow-bluriness": {
"panel-shadow-y-axis-shift": {
"type": "spinbutton",
"units": "px",
"dependency": "enable-panel-shadow-tweak",
"description": "Shadow Bluriness",
"description": "Shadow Y-Axis Shift",
"default": 0.0,
"min": 0.0,
"max": 16.0,
"min": -10.0,
"max": 10.0,
"step": 0.05
},
"panel-shadow-color": {
"type": "colorchooser",
"description": "Panel Shadow Color",
"dependency": "enable-panel-shadow-tweak",
"default": "#010101"
},
"enable-panel-border-tweak": {
"type": "switch",
"description": "Tweak Panel Border",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
'use strict';

const Params = imports.misc.params;
const { basicStylesEncoder, basicStylesDecoder } = require("./helpers.js");
const { STYLE_UNSET_KEY } = require("./constants.js");
const { basicStylesEncoder, basicStylesDecoder, round } = require("./helpers.js");
const { STYLE_TWEAK_UNSET_KEY } = require("./constants.js");


var PanelTweakController = class PanelTweakController {
Expand All @@ -30,12 +30,14 @@ var PanelTweakController = class PanelTweakController {
this.enablerKey = enablerKey;

if (enablerKey) {
this.settings.bind(enablerKey, enablerKey.replaceAll('-', '_'), this.on_enabler_switched.bind(this));
this.settings.bind(
this.enablerKey,
this.enablerKey.replaceAll('-', '_'),
this.on_enabler_switched.bind(this),
);
}

if (this.enabled) {
this.start();
}
if (this.enabled) this.start();
}

get values() {
Expand Down Expand Up @@ -72,8 +74,13 @@ var PanelTweakController = class PanelTweakController {
}

start() {
for (const key of this.keys)
this.settings.bind(key, key.replaceAll('-', '_'), this.on_changed.bind(this));
for (const key of this.keys) {
this.settings.bind(
key,
key.replaceAll('-', '_'),
this.on_changed.bind(this),
);
}
this.on_changed();
}

Expand All @@ -88,10 +95,6 @@ var PanelTweakController = class PanelTweakController {


var PanelColorTweakController = class PanelColorTweakController extends PanelTweakController {
constructor(applet, settings, key, enablerKey) {
super(applet, settings, key, enablerKey);
}

on_changed() {
let [value] = this.values;
this.set_panel_style({
Expand All @@ -103,44 +106,36 @@ var PanelColorTweakController = class PanelColorTweakController extends PanelTwe

finalize() {
this.set_panel_style({
"background-color": STYLE_UNSET_KEY,
"background-gradient-end": STYLE_UNSET_KEY,
"background-gradient-start": STYLE_UNSET_KEY,
"background-color": STYLE_TWEAK_UNSET_KEY,
"background-gradient-end": STYLE_TWEAK_UNSET_KEY,
"background-gradient-start": STYLE_TWEAK_UNSET_KEY,
});
}
}

var PanelShadowTweakController = class PanelShadowTweakController extends PanelTweakController {
constructor(applet, settings, key, enablerKey) {
super(applet, settings, key, enablerKey);
}

on_changed() {
let values = this.valuesKeysMapped;
let x = values["panel-shadow-x-axis-shift"];
let y = values["panel-shadow-y-axis-shift"];
let bluriness = values["panel-shadow-bluriness"];
let x = round(values["panel-shadow-x-axis-shift"], 2);
let y = round(values["panel-shadow-y-axis-shift"], 2);
let bluriness = round(values["panel-shadow-bluriness"], 2);
let color = values["panel-shadow-color"];
let shadow = `${x}px ${y}px ${bluriness}px ${color}`;
this.set_panel_style({ "box-shadow": shadow });
}

finalize() {
this.set_panel_style({ "box-shadow": STYLE_UNSET_KEY });
this.set_panel_style({ "box-shadow": STYLE_TWEAK_UNSET_KEY });
}
}

var PanelBorderTweakController = class PanelBorderTweakController extends PanelTweakController {
constructor(applet, settings, key, enablerKey) {
super(applet, settings, key, enablerKey);
}

on_changed() {
let values = this.valuesKeysMapped;
let top = values["panel-border-top-thickness"];
let right = values["panel-border-right-thickness"];
let bottom = values["panel-border-bottom-thickness"];
let left = values["panel-border-left-thickness"];
let top = round(values["panel-border-top-thickness"], 2);
let right = round(values["panel-border-right-thickness"], 2);
let bottom = round(values["panel-border-bottom-thickness"], 2);
let left = round(values["panel-border-left-thickness"], 2);
let color = values["panel-border-color"];
this.set_panel_style({
"border-top": `${top}px`,
Expand All @@ -153,11 +148,11 @@ var PanelBorderTweakController = class PanelBorderTweakController extends PanelT

finalize() {
this.set_panel_style({
"border-top": STYLE_UNSET_KEY,
"border-right": STYLE_UNSET_KEY,
"border-bottom": STYLE_UNSET_KEY,
"border-left": STYLE_UNSET_KEY,
"border-color": STYLE_UNSET_KEY,
"border-top": STYLE_TWEAK_UNSET_KEY,
"border-right": STYLE_TWEAK_UNSET_KEY,
"border-bottom": STYLE_TWEAK_UNSET_KEY,
"border-left": STYLE_TWEAK_UNSET_KEY,
"border-color": STYLE_TWEAK_UNSET_KEY,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.1",
"version": "0.1.2",
"uuid": "panel-tweaks@anaximeno",
"name": "Cinnamon Panel Tweaker",
"multiversion": true,
Expand Down

0 comments on commit bf0b6ab

Please sign in to comment.