From 8671a9e5027646b38adba9e81ebff315f4143533 Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 09:22:37 +0200 Subject: [PATCH 1/6] GS 3.34 compatibility * PanelMenu.Button actor * PopupMenu.PopupBaseMenuItem, PopupMenu.PopupSwitchMenuItem and PopupMenu.PopupSeparatorMenuItem actor * Slider.Slider actor and 'value-changed' signal * PopupMenu.PopupMenuManager init params * 'org.gnome.settings-daemon.plugins.media-keys' setting values : string -> array of strings --- draw.js | 44 +++++++++++++++++++++++++++++++------------- extension.js | 10 +++++++--- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/draw.js b/draw.js index 4a2dae4..9c634d4 100644 --- a/draw.js +++ b/draw.js @@ -33,6 +33,7 @@ const Signals = imports.signals; const St = imports.gi.St; const BoxPointer = imports.ui.boxpointer; +const Config = imports.misc.config; const Main = imports.ui.main; const PopupMenu = imports.ui.popupMenu; const Slider = imports.ui.slider; @@ -46,6 +47,8 @@ const ExtensionJs = Extension.imports.extension; const Prefs = Extension.imports.prefs; const _ = imports.gettext.domain(Extension.metadata["gettext-domain"]).gettext; +const GS_VERSION = Config.PACKAGE_VERSION; + const FILL_ICON_PATH = Extension.dir.get_child('icons').get_child('fill-symbolic.svg').get_path(); const STROKE_ICON_PATH = Extension.dir.get_child('icons').get_child('stroke-symbolic.svg').get_path(); const LINEJOIN_ICON_PATH = Extension.dir.get_child('icons').get_child('linejoin-symbolic.svg').get_path(); @@ -919,6 +922,8 @@ var DrawingHelper = new Lang.Class({ this.vbox.add(hbox); continue; } + if (!settings.get_strv(settingKey)[0]) + continue; let [keyval, mods] = Gtk.accelerator_parse(settings.get_strv(settingKey)[0]); hbox.add(new St.Label({ text: _(Prefs.GLOBAL_KEYBINDINGS[settingKey]) })); hbox.add(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods) }), { expand: true }); @@ -946,6 +951,8 @@ var DrawingHelper = new Lang.Class({ continue; } let hbox = new St.BoxLayout({ vertical: false }); + if (!settings.get_strv(settingKey)[0]) + continue; let [keyval, mods] = Gtk.accelerator_parse(settings.get_strv(settingKey)[0]); hbox.add(new St.Label({ text: _(Prefs.INTERNAL_KEYBINDINGS[settingKey]) })); hbox.add(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods) }), { expand: true }); @@ -958,8 +965,9 @@ var DrawingHelper = new Lang.Class({ for (let settingKey in MEDIA_KEYS_KEYS) { if (!mediaKeysSettings.settings_schema.has_key(settingKey)) - return; - let [keyval, mods] = Gtk.accelerator_parse(mediaKeysSettings.get_string(settingKey)); + continue; + let shortcut = GS_VERSION < '3.33.0' ? mediaKeysSettings.get_string(settingKey) : mediaKeysSettings.get_strv(settingKey)[0]; + let [keyval, mods] = Gtk.accelerator_parse(shortcut); let hbox = new St.BoxLayout({ vertical: false }); hbox.add(new St.Label({ text: _(MEDIA_KEYS_KEYS[settingKey]) })); hbox.add(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods) }), { expand: true }); @@ -1005,7 +1013,7 @@ var DrawingMenu = new Lang.Class({ this.area = area; let side = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL ? St.Side.RIGHT : St.Side.LEFT; this.menu = new PopupMenu.PopupMenu(Main.layoutManager.dummyCursor, 0.25, side); - this.menuManager = new PopupMenu.PopupMenuManager({ actor: this.area }); + this.menuManager = new PopupMenu.PopupMenuManager(GS_VERSION < '3.33.0' ? { actor: this.area } : this.area); this.menuManager.addMenu(this.menu); Main.layoutManager.uiGroup.add_actor(this.menu.actor); @@ -1022,7 +1030,6 @@ var DrawingMenu = new Lang.Class({ this.linecapIcon = new Gio.FileIcon({ file: Gio.File.new_for_path(LINECAP_ICON_PATH) }); this.fullLineIcon = new Gio.FileIcon({ file: Gio.File.new_for_path(FULL_LINE_ICON_PATH) }); this.dashedLineIcon = new Gio.FileIcon({ file: Gio.File.new_for_path(DASHED_LINE_ICON_PATH) }); - }, disable: function() { @@ -1125,9 +1132,10 @@ var DrawingMenu = new Lang.Class({ _addSwitchItem: function(menu, label, iconFalse, iconTrue, target, targetProperty) { let item = new PopupMenu.PopupSwitchMenuItem(label, target[targetProperty]); + let itemActor = GS_VERSION < '3.33.0' ? item.actor : item; item.icon = new St.Icon({ style_class: 'popup-menu-icon' }); - item.actor.insert_child_at_index(item.icon, 1); + itemActor.insert_child_at_index(item.icon, 1); item.icon.set_gicon(target[targetProperty] ? iconTrue : iconFalse); item.connect('toggled', (item, state) => { @@ -1146,17 +1154,26 @@ var DrawingMenu = new Lang.Class({ _addSliderItem: function(menu, target, targetProperty) { let item = new PopupMenu.PopupBaseMenuItem({ activate: false }); + let itemActor = GS_VERSION < '3.33.0' ? item.actor : item; let label = new St.Label({ text: target[targetProperty] + " " + _("px"), style_class: 'draw-on-your-screen-menu-slider-label' }); let slider = new Slider.Slider(target[targetProperty] / 50); + let sliderActor = GS_VERSION < '3.33.0' ? slider.actor : slider; - slider.connect('value-changed', (slider, value, property) => { - target[targetProperty] = Math.max(Math.round(value * 50), 1); - label.set_text(target[targetProperty] + " px"); - }); + if (GS_VERSION < '3.33.0') { + slider.connect('value-changed', (slider, value, property) => { + target[targetProperty] = Math.max(Math.round(value * 50), 1); + label.set_text(target[targetProperty] + " px"); + }); + } else { + slider.connect('notify::value', () => { + target[targetProperty] = Math.max(Math.round(slider.value * 50), 1); + label.set_text(target[targetProperty] + " px"); + }); + } - item.actor.add(slider.actor, { expand: true }); - item.actor.add(label); - item.actor.connect('key-press-event', slider.onKeyPressEvent.bind(slider)); + itemActor.add(sliderActor, { expand: true }); + itemActor.add(label); + itemActor.connect('key-press-event', slider.onKeyPressEvent.bind(slider)); menu.addMenuItem(item); }, @@ -1222,7 +1239,8 @@ var DrawingMenu = new Lang.Class({ _addSeparator: function(menu) { let separator = new PopupMenu.PopupSeparatorMenuItem(' '); - separator.actor.add_style_class_name('draw-on-your-screen-menu-separator'); + let separatorActor = GS_VERSION < '3.33.0' ? separator.actor : separator; + separatorActor.add_style_class_name('draw-on-your-screen-menu-separator'); menu.addMenuItem(separator); } }); diff --git a/extension.js b/extension.js index e928394..2767def 100644 --- a/extension.js +++ b/extension.js @@ -26,6 +26,7 @@ const Meta = imports.gi.Meta; const Shell = imports.gi.Shell; const St = imports.gi.St; +const Config = imports.misc.config; const Main = imports.ui.main; const OsdWindow = imports.ui.osdWindow; const PanelMenu = imports.ui.panelMenu; @@ -35,6 +36,8 @@ const Convenience = Extension.imports.convenience; const Draw = Extension.imports.draw; const _ = imports.gettext.domain(Extension.metadata["gettext-domain"]).gettext; +const GS_VERSION = Config.PACKAGE_VERSION; + // DRAWING_ACTION_MODE is a custom Shell.ActionMode var DRAWING_ACTION_MODE = Math.pow(2,14); @@ -378,16 +381,17 @@ var DrawingIndicator = new Lang.Class({ _init: function() { let [menuAlignment, dontCreateMenu] = [0, true]; this.button = new PanelMenu.Button(menuAlignment, "Drawing Indicator", dontCreateMenu); + this.buttonActor = GS_VERSION < '3.33.0' ? this.button.actor: this.button; Main.panel.addToStatusArea('draw-on-your-screen-indicator', this.button); this.icon = new St.Icon({ icon_name: 'applications-graphics-symbolic', style_class: 'system-status-icon screencast-indicator' }); - this.button.actor.add_child(this.icon); - this.button.actor.visible = false; + this.buttonActor.add_child(this.icon); + this.buttonActor.visible = false; }, sync: function(visible) { - this.button.actor.visible = visible; + this.buttonActor.visible = visible; }, disable: function() { From 7d9bb459b404526aaf49955617f8408cbad4ff26 Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 09:39:17 +0200 Subject: [PATCH 2/6] Create drawing menu on demand --- draw.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/draw.js b/draw.js index 9c634d4..77291cd 100644 --- a/draw.js +++ b/draw.js @@ -80,7 +80,6 @@ var DrawingArea = new Lang.Class({ this.settings = Convenience.getSettings(); this.emitter = new DrawingAreaEmitter(); this.monitor = monitor; - this.menu = new DrawingMenu(this); this.helper = helper; this.elements = []; @@ -98,6 +97,12 @@ var DrawingArea = new Lang.Class({ this._loadJson(); }, + get menu() { + if (!this._menu) + this._menu = new DrawingMenu(this); + return this._menu; + }, + _redisplay: function() { // force area to emit 'repaint' this.queue_repaint(); From 52ca619294af927f021d5e8e7379baf8b7e7c3c7 Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 13:26:08 +0200 Subject: [PATCH 3/6] 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); + }); + } } }, From 99369f0d42f92871bb6041ec3811586fbc5d5e83 Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 13:32:41 +0200 Subject: [PATCH 4/6] minor, .pot comments --- locale/draw-on-your-screen.pot | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index 4e519b4..e579156 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -17,11 +17,18 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -# add your name here, for example: -# "Aïssata\n" -# "Ali\n" -# "" -# It will be displayed in About page +# Add your name here, for example: +# (add "\n" as separator if there is many translators) +# msgid "Translators" +# msgstr "Me" +# or, with mail: +# msgid "Translators" +# msgstr "Me" +# or, with page: +# msgid "Translators" +# msgstr "Me" +# else keep it empty. +# It will be displayed in about page msgid "Translators" msgstr "" From e9445ca2c906aa525c62d0624e49901107f778ca Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 13:33:41 +0200 Subject: [PATCH 5/6] version -> 4.1 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 60aef69..a4ef64a 100644 --- a/metadata.json +++ b/metadata.json @@ -1,7 +1,7 @@ { "name": "Draw On You Screen", "description": "Start drawing with Super+Alt+D and save your beautiful work by taking a screenshot", - "version": 4, + "version": 4.1, "uuid": "drawOnYourScreen@abakkk.framagit.org", "url": "https://framagit.org/abakkk/DrawOnYourScreen", "settings-schema": "org.gnome.shell.extensions.draw-on-your-screen", From 3f2fb189c750054fa0affae7049e160fda59874c Mon Sep 17 00:00:00 2001 From: abakkk Date: Fri, 11 Oct 2019 14:21:04 +0200 Subject: [PATCH 6/6] minor, readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b3408f..8eb7998 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ Features : * Basic shapes (rectangle, circle, ellipse, line, curve, text, free) * Smooth stroke -* Drawing on desktop and persistence +* Draw over applications +* Keep drawings on desktop background with persistence (notes, children's art ...) * Multi-monitor support * Export to SVG