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
This commit is contained in:
abakkk 2019-10-11 13:26:08 +02:00
parent 7d9bb459b4
commit 52ca619294
2 changed files with 27 additions and 4 deletions

16
draw.js
View File

@ -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);
});
}

View File

@ -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);
});
}
}
},