From 52ca619294af927f021d5e8e7379baf8b7e7c3c7 Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 13:26:08 +0200 Subject: [PATCH] Fix lineWidth * GS 3.34 compatibility for barLevel, see for example status/volume.js StreamSlider.getLevel(): * 3.32 : "return 100 * this._stream.volume / this._control.get_vol_max_norm();" * 3.34 : "return this._stream.volume / this._control.get_vol_max_norm();" * allow 0 px lineWidth because stroke lines cannot have color with some transparency * use warning color in OSD and drawing menu when lineWidth is 0 px --- draw.js | 16 ++++++++++++---- extension.js | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/draw.js b/draw.js index 77291cd..cbdd8fa 100644 --- a/draw.js +++ b/draw.js @@ -466,8 +466,8 @@ var DrawingArea = new Lang.Class({ }, incrementLineWidth: function(increment) { - this.currentLineWidth = Math.max(this.currentLineWidth + increment, 1); - this.emitter.emit('show-osd', this.currentLineWidth + " " + _("px"), this.currentLineWidth); + this.currentLineWidth = Math.max(this.currentLineWidth + increment, 0); + this.emitter.emit('show-osd', this.currentLineWidth + " " + _("px"), 2 * this.currentLineWidth); }, toggleLineJoin: function() { @@ -1166,13 +1166,21 @@ var DrawingMenu = new Lang.Class({ if (GS_VERSION < '3.33.0') { slider.connect('value-changed', (slider, value, property) => { - target[targetProperty] = Math.max(Math.round(value * 50), 1); + target[targetProperty] = Math.max(Math.round(value * 50), 0); label.set_text(target[targetProperty] + " px"); + if (target[targetProperty] === 0) + label.add_style_class_name(ExtensionJs.WARNING_COLOR_STYLE_CLASS_NAME); + else + label.remove_style_class_name(ExtensionJs.WARNING_COLOR_STYLE_CLASS_NAME); }); } else { slider.connect('notify::value', () => { - target[targetProperty] = Math.max(Math.round(slider.value * 50), 1); + target[targetProperty] = Math.max(Math.round(slider.value * 50), 0); label.set_text(target[targetProperty] + " px"); + if (target[targetProperty] === 0) + label.add_style_class_name(ExtensionJs.WARNING_COLOR_STYLE_CLASS_NAME); + else + label.remove_style_class_name(ExtensionJs.WARNING_COLOR_STYLE_CLASS_NAME); }); } diff --git a/extension.js b/extension.js index 2767def..325f5f3 100644 --- a/extension.js +++ b/extension.js @@ -40,6 +40,8 @@ const GS_VERSION = Config.PACKAGE_VERSION; // DRAWING_ACTION_MODE is a custom Shell.ActionMode var DRAWING_ACTION_MODE = Math.pow(2,14); +// use 'login-dialog-message-warning' class in order to get GS theme warning color (default: #f57900) +var WARNING_COLOR_STYLE_CLASS_NAME = 'login-dialog-message-warning'; let manager; @@ -325,8 +327,21 @@ var AreaManager = new Lang.Class({ return; let activeIndex = this.areas.indexOf(this.activeArea); if (activeIndex != -1) { + // GS 3.32- : bar from 0 to 100 + // GS 3.34+ : bar from 0 to 1 + if (level && GS_VERSION > '3.33.0') + level = level / 100; Main.osdWindowManager.show(activeIndex, this.enterGicon, label, level, maxLevel); Main.osdWindowManager._osdWindows[activeIndex]._label.get_clutter_text().set_use_markup(true); + + if (level === 0) { + Main.osdWindowManager._osdWindows[activeIndex]._label.add_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME); + // the same label is shared by all GS OSD so the style must be removed after being used + let osdLabelChangedHandler = Main.osdWindowManager._osdWindows[activeIndex]._label.connect('notify::text', () => { + Main.osdWindowManager._osdWindows[activeIndex]._label.remove_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME); + Main.osdWindowManager._osdWindows[activeIndex]._label.disconnect(osdLabelChangedHandler); + }); + } } },