diff --git a/draw.js b/draw.js index f48b6c5..b54dfa4 100644 --- a/draw.js +++ b/draw.js @@ -29,7 +29,6 @@ const Gtk = imports.gi.Gtk; const Lang = imports.lang; const Mainloop = imports.mainloop; const Shell = imports.gi.Shell; -const Signals = imports.signals; const St = imports.gi.St; const BoxPointer = imports.ui.boxpointer; @@ -71,6 +70,8 @@ var FontFamilyNames = { 0: 'Default', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospac var DrawingArea = new Lang.Class({ Name: 'DrawOnYourScreenDrawingArea', Extends: St.DrawingArea, + Signals: { 'show-osd': { param_types: [GObject.TYPE_STRING, GObject.TYPE_DOUBLE] }, + 'stop-drawing': {} }, _init: function(params, monitor, helper, loadJson) { this.parent({ style_class: 'draw-on-your-screen', name: params && params.name ? params.name : ""}); @@ -78,7 +79,6 @@ var DrawingArea = new Lang.Class({ this.connect('repaint', this._repaint.bind(this)); this.settings = Convenience.getSettings(); - this.emitter = new DrawingAreaEmitter(); this.monitor = monitor; this.helper = helper; @@ -212,7 +212,7 @@ var DrawingArea = new Lang.Class({ _onKeyPressed: function(actor, event) { if (event.get_key_symbol() == Clutter.Escape) { - this.emitter.emit('stop-drawing'); + this.emit('stop-drawing'); return Clutter.EVENT_STOP; } else if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.WRITING) { @@ -322,7 +322,7 @@ var DrawingArea = new Lang.Class({ if (this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.DRAWING) { this.currentElement.state = TextState.WRITING; this.currentElement.text = ''; - this.emitter.emit('show-osd', _("Type your text\nand press Enter"), null); + this.emit('show-osd', _("Type your text\nand press Enter"), -1); this._updateCursorTimeout(); this.textHasCursor = true; this._redisplay(); @@ -468,38 +468,38 @@ var DrawingArea = new Lang.Class({ this.currentElement.color = this.currentColor.to_string(); this._redisplay(); } - this.emitter.emit('show-osd', `${this.currentColor.to_string()}`, null); + this.emit('show-osd', `${this.currentColor.to_string()}`, -1); }, selectShape: function(shape) { this.currentShape = shape; - this.emitter.emit('show-osd', _(ShapeNames[shape]), null); + this.emit('show-osd', _(ShapeNames[shape]), -1); this.updatePointerCursor(); }, toggleFill: function() { this.fill = !this.fill; - this.emitter.emit('show-osd', this.fill ? _("Fill") : _("Stroke"), null); + this.emit('show-osd', this.fill ? _("Fill") : _("Stroke"), -1); }, toggleDash: function() { this.dashedLine = !this.dashedLine; - this.emitter.emit('show-osd', this.dashedLine ? _("Dashed line") : _("Full line"), null); + this.emit('show-osd', this.dashedLine ? _("Dashed line") : _("Full line"), -1); }, incrementLineWidth: function(increment) { this.currentLineWidth = Math.max(this.currentLineWidth + increment, 0); - this.emitter.emit('show-osd', this.currentLineWidth + " " + _("px"), 2 * this.currentLineWidth); + this.emit('show-osd', this.currentLineWidth + " " + _("px"), 2 * this.currentLineWidth); }, toggleLineJoin: function() { this.currentLineJoin = this.currentLineJoin == 2 ? 0 : this.currentLineJoin + 1; - this.emitter.emit('show-osd', _(LineJoinNames[this.currentLineJoin]), null); + this.emit('show-osd', _(LineJoinNames[this.currentLineJoin]), -1); }, toggleLineCap: function() { this.currentLineCap = this.currentLineCap == 2 ? 0 : this.currentLineCap + 1; - this.emitter.emit('show-osd', _(LineCapNames[this.currentLineCap]), null); + this.emit('show-osd', _(LineCapNames[this.currentLineCap]), -1); }, toggleFontWeight: function() { @@ -508,7 +508,7 @@ var DrawingArea = new Lang.Class({ this.currentElement.font.weight = this.currentFontWeight; this._redisplay(); } - this.emitter.emit('show-osd', `${_(FontWeightNames[this.currentFontWeight])}`, null); + this.emit('show-osd', `${_(FontWeightNames[this.currentFontWeight])}`, -1); }, toggleFontStyle: function() { @@ -517,7 +517,7 @@ var DrawingArea = new Lang.Class({ this.currentElement.font.style = this.currentFontStyle; this._redisplay(); } - this.emitter.emit('show-osd', `${_(FontStyleNames[this.currentFontStyle])}`, null); + this.emit('show-osd', `${_(FontStyleNames[this.currentFontStyle])}`, -1); }, toggleFontFamily: function() { @@ -527,7 +527,7 @@ var DrawingArea = new Lang.Class({ this.currentElement.font.family = currentFontFamily; this._redisplay(); } - this.emitter.emit('show-osd', `${_(currentFontFamily)}`, null); + this.emit('show-osd', `${_(currentFontFamily)}`, -1); }, toggleHelp: function() { @@ -671,15 +671,6 @@ var DrawingArea = new Lang.Class({ } }); -var DrawingAreaEmitter = new Lang.Class({ - Name: 'DrawingAreaEmitter', - - _init: function() { - } -}); -Signals.addSignalMethods(DrawingAreaEmitter.prototype); - - // DrawingElement represents a "brushstroke". // It can be converted into a cairo path as well as a svg element. // See DrawingArea._startDrawing() to know its params. diff --git a/extension.js b/extension.js index f84769f..7b09d71 100644 --- a/extension.js +++ b/extension.js @@ -148,8 +148,8 @@ var AreaManager = new Lang.Class({ container.set_position(monitor.x, monitor.y); container.set_size(monitor.width, monitor.height); area.set_size(monitor.width, monitor.height); - area.emitter.stopDrawingHandler = area.emitter.connect('stop-drawing', this.toggleDrawing.bind(this)); - area.emitter.showOsdHandler = area.emitter.connect('show-osd', this.showOsd.bind(this)); + area.stopDrawingHandler = area.connect('stop-drawing', this.toggleDrawing.bind(this)); + area.showOsdHandler = area.connect('show-osd', this.showOsd.bind(this)); this.areas.push(area); } }, @@ -313,11 +313,17 @@ var AreaManager = new Lang.Class({ this.indicator.sync(this.activeArea != null); }, + // use level -1 to set no level (null) showOsd: function(emitter, label, level, maxLevel) { if (this.osdDisabled) return; let activeIndex = this.areas.indexOf(this.activeArea); if (activeIndex != -1) { + if (level == -1) + level = null; + else if (level > 100) + maxLevel = 2; + // GS 3.32- : bar from 0 to 100 // GS 3.34+ : bar from 0 to 1 if (level && GS_VERSION > '3.33.0') @@ -341,8 +347,8 @@ var AreaManager = new Lang.Class({ let area = this.areas[i]; let container = area.get_parent(); container.get_parent().remove_actor(container); - area.emitter.disconnect(area.emitter.stopDrawingHandler); - area.emitter.disconnect(area.emitter.showOsdHandler); + area.disconnect(area.stopDrawingHandler); + area.disconnect(area.showOsdHandler); area.disable(); container.destroy(); }