From cb40739af7665c3bac86c498574b3ec897a87374 Mon Sep 17 00:00:00 2001 From: abakkk Date: Thu, 11 Mar 2021 09:20:39 +0100 Subject: [PATCH 1/6] override default handlers in prefs Use GJS GObject overrides. Not to matter whether the signal exists. --- prefs.js | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/prefs.js b/prefs.js index 2c93299..31cc9e4 100644 --- a/prefs.js +++ b/prefs.js @@ -612,7 +612,7 @@ const PrefRow = new GObject.Class({ } }); -const PixelSpinButton = new GObject.Class(Object.assign({ +const PixelSpinButton = new GObject.Class({ Name: `${UUID}-PixelSpinButton`, Extends: Gtk.SpinButton, Properties: { @@ -638,22 +638,24 @@ const PixelSpinButton = new GObject.Class(Object.assign({ this.adjustment.set_page_increment(step * 10); }, - vfunc_constructed() { - this.parent(); + on_output: function() { + this.text = _("%f px").format(Number(this.value).toFixed(2)); + return true; + }, + + // Prevent accidental scrolling (GTK 3). + on_scroll_event: function(event) { + if (this.has_focus) { + try { + GObject.signal_chain_from_overridden([this, event], false); + } catch(e) { } + + return Gdk.EVENT_STOP; + } - // No virtual functions with Gtk4 :/. - // Add 'px' unit. - this.connect('output', spinButton => { - this.text = _("%f px").format(Number(spinButton.value).toFixed(2)); - return true; - }); + return Gdk.EVENT_PROPAGATE; } -}, IS_GTK3 ? { - // Prevent accidental scrolling. - vfunc_scroll_event: function(event) { - return this.has_focus ? this.parent(event) : Gdk.EVENT_PROPAGATE; - } -} : {})); +}); // A color button that can be easily bound with a color string setting. const ColorStringButton = new GObject.Class({ @@ -676,20 +678,15 @@ const ColorStringButton = new GObject.Class({ this.set_rgba(newRgba); }, - vfunc_constructed() { - this.parent(); + on_color_set: function() { + let oldRgba = new Gdk.RGBA(); + oldRgba.parse(this.color_string); - // No virtual functions with Gtk4 :/. // Do nothing if the new color is equivalent to the old color (e.g. "black" and "rgb(0,0,0)"). - this.connect('color-set', colorButton => { - let oldRgba = new Gdk.RGBA(); - oldRgba.parse(colorButton.color_string); - - if (!this.rgba.equal(oldRgba)) { - this._color_string = colorButton.rgba.to_string(); - this.notify('color-string'); - } - }); + if (!this.rgba.equal(oldRgba)) { + this._color_string = this.rgba.to_string(); + this.notify('color-string'); + } } }); From 5ad5dfffd162b5bd40bb1433a45718c883383a21 Mon Sep 17 00:00:00 2001 From: abakkk Date: Thu, 11 Mar 2021 09:32:22 +0100 Subject: [PATCH 2/6] not to erase the text on Escape key pressed Related to #60. --- area.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/area.js b/area.js index f368a76..80ce3cf 100644 --- a/area.js +++ b/area.js @@ -845,9 +845,6 @@ var DrawingArea = new Lang.Class({ this.textEntry.clutterText.set_single_line_mode(false); this.textEntry.clutterText.set_activatable(false); - this.textEntry.clutterText.connect('activate', (clutterText) => { - this._stopWriting(); - }); let showCursorOnPositionChanged = true; this.textEntry.clutterText.connect('text-changed', clutterText => { @@ -868,7 +865,6 @@ var DrawingArea = new Lang.Class({ this.textEntry.clutterText.connect('key-press-event', (clutterText, event) => { if (event.get_key_symbol() == Clutter.KEY_Escape) { - this.currentElement.text = ""; this._stopWriting(); return Clutter.EVENT_STOP; } From 25e1f27ac9e79e84da0b6b14516c2f59d8853c24 Mon Sep 17 00:00:00 2001 From: abakkk Date: Sun, 4 Apr 2021 12:09:33 +0200 Subject: [PATCH 3/6] make helper not blocking --- helper.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/helper.js b/helper.js index 8616adb..e0eab8d 100644 --- a/helper.js +++ b/helper.js @@ -73,8 +73,13 @@ var DrawingHelper = new Lang.Class({ }, _updateHelpKeyLabel: function() { - let [keyval, mods] = Gtk.accelerator_parse(Me.internalShortcutSettings.get_strv('toggle-help')[0] || ''); - this._helpKeyLabel = Gtk.accelerator_get_label(keyval, mods); + try { + let [keyval, mods] = Gtk.accelerator_parse(Me.internalShortcutSettings.get_strv('toggle-help')[0] || ''); + this._helpKeyLabel = Gtk.accelerator_get_label(keyval, mods); + } catch(e) { + logError(e); + this._helpKeyLabel = " "; + } }, get helpKeyLabel() { @@ -172,10 +177,11 @@ var DrawingHelper = new Lang.Class({ this.set_position(Math.floor(this.monitor.width / 2 - this.width / 2), Math.floor(this.monitor.height / 2 - this.height / 2)); + // St.PolicyType: GS 3.32+ if (this.height == maxHeight) - this.vscrollbar_policy = Gtk.PolicyType.ALWAYS; + this.vscrollbar_policy = St.PolicyType ? St.PolicyType.ALWAYS : Gtk.PolicyType.ALWAYS; else - this.vscrollbar_policy = Gtk.PolicyType.NEVER; + this.vscrollbar_policy = St.PolicyType ? St.PolicyType.NEVER : Gtk.PolicyType.NEVER; if (Tweener) { Tweener.removeTweens(this); From 92b8bddb6b2021ed36181f7c9c8e8037171b514c Mon Sep 17 00:00:00 2001 From: abakkk Date: Mon, 26 Apr 2021 12:00:16 +0200 Subject: [PATCH 4/6] simplify prefs getChildrenOf GTK4 widgets are iterable. --- prefs.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/prefs.js b/prefs.js index 31cc9e4..a0db58f 100644 --- a/prefs.js +++ b/prefs.js @@ -65,19 +65,10 @@ const setAccessibleDescription = function(widget, description) { }; const getChildrenOf = function(widget) { - if (IS_GTK3) { + if (IS_GTK3) return widget.get_children(); - } else { - let listModel = widget.observe_children(); - let i = 0; - let children = []; - let child; - while (!!(child = listModel.get_item(i))) { - children.push(child); - i++; - } - return children; - } + else + return [...widget]; }; function init() { From 996a035017de11f69349da341cf8be3c840b692e Mon Sep 17 00:00:00 2001 From: abakkk Date: Mon, 26 Apr 2021 14:30:36 +0200 Subject: [PATCH 5/6] update "How to draw an arrow" media in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1741896..774f8b7 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Then save your beautiful work by taking a screenshot. Intersect two lines and curve the second thanks to the `Ctrl` key. - ![How to draw an arrow](https://framagit.org/abakkk/DrawOnYourScreen/uploads/af8f96d33cfeff49bb922a1ef9f4a4ce/arrow-screencast.webm) + ![How to draw an arrow](https://framagit.org/abakkk/DrawOnYourScreen/-/raw/media/arrow.webm) * Duplicate an element: From d716a398dce3f3213a08e219d2727190b9d4ecbf Mon Sep 17 00:00:00 2001 From: abakkk Date: Mon, 26 Apr 2021 14:31:16 +0200 Subject: [PATCH 6/6] version -> 11.1 --- NEWS | 5 +++++ metadata.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 5b82320..7d8db4b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +v11.1 - April 2021 +================== + +* Not to erase the text when pressing "Escape" #60 + v11 - February 2021 =================== diff --git a/metadata.json b/metadata.json index 1272b75..c346f90 100644 --- a/metadata.json +++ b/metadata.json @@ -19,5 +19,5 @@ "3.38", "40" ], - "version": 11 + "version": 11.1 }