From da52cfa26038b2c369509be8fb7ad6f672fae5de Mon Sep 17 00:00:00 2001 From: abakkk Date: Tue, 12 Mar 2019 00:29:14 +0100 Subject: [PATCH] Drawing is hidden by default when leaving drawing mode It doesn't stay on top of windows because of problems with "desktop" extensions. --- draw.js | 14 +++--- extension.js | 47 +++++++++++------- locale/draw-on-your-screen.pot | 6 +-- prefs.js | 8 +-- schemas/gschemas.compiled | Bin 3088 -> 3080 bytes ...extensions.draw-on-your-screen.gschema.xml | 2 +- 6 files changed, 45 insertions(+), 32 deletions(-) diff --git a/draw.js b/draw.js index f9c20b7..28669f6 100644 --- a/draw.js +++ b/draw.js @@ -171,7 +171,7 @@ var DrawingArea = new Lang.Class({ _onKeyPressed: function(actor, event) { if (event.get_key_symbol() == Clutter.Escape) { - this.emitter.emit('stop-drawing', true); + this.emitter.emit('stop-drawing'); return Clutter.EVENT_STOP; } else if (this.currentElement && this.currentElement.shape == Shapes.TEXT) { @@ -464,10 +464,6 @@ var DrawingArea = new Lang.Class({ this.helper.showHelp(); }, - get isEmpty() { - return this.elements.length == 0; - }, - enterDrawingMode: function() { this.keyPressedHandler = this.connect('key-press-event', this._onKeyPressed.bind(this)); this.buttonPressedHandler = this.connect('button-press-event', this._onButtonPressed.bind(this)); @@ -507,7 +503,7 @@ var DrawingArea = new Lang.Class({ this._redisplay(); this.get_parent().set_background_color(null); if (save) - this._saveAsJson(); + this.saveAsJson(); }, saveAsSvg: function() { @@ -544,7 +540,7 @@ var DrawingArea = new Lang.Class({ } }, - _saveAsJson: function() { + saveAsJson: function() { let filename = `DrawOnYourScreen.json`; let dir = GLib.get_user_data_dir(); let path = GLib.build_filenamev([dir, filename]); @@ -556,6 +552,10 @@ var DrawingArea = new Lang.Class({ oldContents = imports.byteArray.toString(oldContents); } + // do not create a file to write just an empty array + if (!oldContents && this.elements.length == 0) + return; + // do not use "content = JSON.stringify(this.elements, null, 2);", neither "content = JSON.stringify(this.elements);" // because of compromise between disk usage and human readability let contents = `[\n ` + new Array(...this.elements.map(element => JSON.stringify(element))).join(`,\n\n `) + `\n]`; diff --git a/extension.js b/extension.js index db9fcab..552864c 100644 --- a/extension.js +++ b/extension.js @@ -75,6 +75,9 @@ var AreaManager = new Lang.Class({ this.updateAreas(); this.monitorChangedHandler = Main.layoutManager.connect('monitors-changed', this.updateAreas.bind(this)); + this.desktopSettingHandler = this.settings.connect('changed::drawing-on-desktop', this.onDesktopSettingChanged.bind(this)); + this.persistentSettingHandler = this.settings.connect('changed::persistent-drawing', this.onPersistentSettingChanged.bind(this)); + if (Extension.stylesheet) { this.stylesheetMonitor = Extension.stylesheet.monitor(Gio.FileMonitorFlags.NONE, null); this.stylesheetChangedHandler = this.stylesheetMonitor.connect('changed', (monitor, file, otherFile, eventType) => { @@ -87,6 +90,18 @@ var AreaManager = new Lang.Class({ } }, + onDesktopSettingChanged: function() { + if (this.settings.get_boolean("drawing-on-desktop")) + this.areas.forEach(area => area.get_parent().show()); + else + this.areas.forEach(area => area.get_parent().hide()); + }, + + onPersistentSettingChanged: function() { + if (this.settings.get_boolean('persistent-drawing')) + this.areas[Main.layoutManager.primaryIndex].saveAsJson(); + }, + updateAreas: function() { if (this.activeArea) this.toggleDrawing(); @@ -103,16 +118,13 @@ var AreaManager = new Lang.Class({ container.add_child(area); container.add_child(helper); - if (this.settings.get_boolean("move-drawing-on-desktop")) - Main.layoutManager._backgroundGroup.insert_child_above(container, Main.layoutManager._bgManagers[i].backgroundActor); - else - Main.uiGroup.insert_child_above(container, global.window_group); + Main.layoutManager._backgroundGroup.insert_child_above(container, Main.layoutManager._bgManagers[i].backgroundActor); + if (!this.settings.get_boolean("drawing-on-desktop")) + container.hide(); container.set_position(monitor.x, monitor.y); container.set_size(monitor.width, monitor.height); area.set_size(monitor.width, monitor.height); - if (area.isEmpty) - container.hide(); area.emitter.stopDrawingHandler = area.emitter.connect('stop-drawing', this.toggleDrawing.bind(this)); area.emitter.showOsdHandler = area.emitter.connect('show-osd', this.showOsd.bind(this)); this.areas.push(area); @@ -183,10 +195,8 @@ var AreaManager = new Lang.Class({ }, eraseDrawing: function() { - for (let i = 0; i < this.areas.length; i++) { + for (let i = 0; i < this.areas.length; i++) this.areas[i].erase(); - this.areas[i].get_parent().hide(); - } }, togglePanelAndDockOpacity: function() { @@ -223,12 +233,11 @@ var AreaManager = new Lang.Class({ } }, - toggleDrawing: function(emitter, hide) { + toggleDrawing: function() { if (this.activeArea) { let activeIndex = this.areas.indexOf(this.activeArea); let activeContainer = this.activeArea.get_parent(); let save = activeIndex == Main.layoutManager.primaryIndex && this.settings.get_boolean('persistent-drawing'); - hide = hide || this.activeArea.isEmpty; if (this.hiddenList) this.togglePanelAndDockOpacity(); @@ -240,12 +249,8 @@ var AreaManager = new Lang.Class({ this.activeArea = null; activeContainer.get_parent().remove_actor(activeContainer); - if (this.settings.get_boolean("move-drawing-on-desktop")) - Main.layoutManager._backgroundGroup.insert_child_above(activeContainer, Main.layoutManager._bgManagers[activeIndex].backgroundActor); - else - Main.uiGroup.insert_child_above(activeContainer, global.window_group); - - if (hide) + Main.layoutManager._backgroundGroup.insert_child_above(activeContainer, Main.layoutManager._bgManagers[activeIndex].backgroundActor); + if (!this.settings.get_boolean("drawing-on-desktop")) activeContainer.hide(); // check display or screen (API changes) @@ -313,6 +318,14 @@ var AreaManager = new Lang.Class({ Main.layoutManager.disconnect(this.monitorChangedHandler); this.monitorChangedHandler = null; } + if (this.desktopSettingHandler) { + this.settings.disconnect(this.desktopSettingHandler); + this.desktopSettingHandler = null; + } + if (this.persistentSettingHandler) { + this.settings.disconnect(this.persistentSettingHandler); + this.persistentSettingHandler = null; + } if (this.activeArea) this.toggleDrawing(); diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index 009c315..a1ab2ec 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -201,7 +201,7 @@ msgstr "" msgid "Shift key held" msgstr "" -msgid "Leave and hide the drawing" +msgid "Leave" msgstr "" msgid "Escape key" @@ -217,7 +217,7 @@ msgstr "" msgid "Global" msgstr "" -msgid "Move drawing on the desktop when leaving drawing mode" +msgid "Drawing on the desktop" msgstr "" msgid "Draw On Your Screen becomes Draw On Your Desktop" @@ -226,7 +226,7 @@ msgstr "" msgid "Persistent" msgstr "" -msgid "Persistent drawing through restart" +msgid "Persistent drawing through session restart" msgstr "" msgid "Internal" diff --git a/prefs.js b/prefs.js index 7089bba..adca46c 100644 --- a/prefs.js +++ b/prefs.js @@ -78,7 +78,7 @@ var OTHER_SHORTCUTS = [ { desc: "Increment/decrement line width", shortcut: "Scroll" }, { desc: "Select color", shortcut: "Ctrl+1...9" }, { desc: "Select eraser", shortcut: "Shift key held" }, - { desc: "Leave and hide the drawing", shortcut: "Escape key" } + { desc: "Leave", shortcut: "Escape key" } ]; function init() { @@ -128,14 +128,14 @@ const PrefsPage = new GObject.Class({ let desktopBox = new Gtk.Box({ margin: MARGIN }); let desktopLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL }); - let desktopLabel1 = new Gtk.Label({label: _("Move drawing on the desktop when leaving drawing mode")}); + let desktopLabel1 = new Gtk.Label({label: _("Drawing on the desktop")}); let desktopLabel2 = new Gtk.Label({ use_markup: true, halign: 1, label: "" + _("Draw On Your Screen becomes Draw On Your Desktop") + "" }); desktopLabel1.set_halign(1); desktopLabel2.get_style_context().add_class("dim-label"); desktopLabelBox.pack_start(desktopLabel1, true, true, 0); desktopLabelBox.pack_start(desktopLabel2, true, true, 0); let desktopSwitch = new Gtk.Switch({valign: 3}); - this.settings.bind("move-drawing-on-desktop", desktopSwitch, "active", 0); + this.settings.bind("drawing-on-desktop", desktopSwitch, "active", 0); desktopBox.pack_start(desktopLabelBox, true, true, 4); desktopBox.pack_start(desktopSwitch, false, false, 4); listBox.add(desktopBox); @@ -143,7 +143,7 @@ const PrefsPage = new GObject.Class({ let persistentBox = new Gtk.Box({ margin: MARGIN }); let persistentLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL }); let persistentLabel1 = new Gtk.Label({label: _("Persistent")}); - let persistentLabel2 = new Gtk.Label({ use_markup: true, halign: 1, label: "" + _("Persistent drawing through restart") + "" }); + let persistentLabel2 = new Gtk.Label({ use_markup: true, halign: 1, label: "" + _("Persistent drawing through session restart") + "" }); persistentLabel1.set_halign(1); persistentLabel2.get_style_context().add_class("dim-label"); persistentLabelBox.pack_start(persistentLabel1, true, true, 0); diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index a0f2bb139b3b31cc557b0443ac9d4271972ccb93..dfce124bc6d9c4dd8dc2e7db0ed13bc53f71b76d 100644 GIT binary patch delta 513 zcmXw$y-Pw-7{-sH*!5;<PFmmDz9uX^Y6AMW`W%zygUYUPV%`T&1ut`&fdaj5{O| zR0u&!1V%U%v^EG05&Z!zE#lBnQ$4TLfgjIve&?KbxVL26wUvS5s88~nu)W|I>tsu;hI{~x+mUVZ)J^cu$am0u-3yVY-U0uGb6H3ht}CZm#&azQO-seZ%Wjpss^&A~jV`Kc#JbMmLU}Un>xLJN5L3kE zWF{fV86hU+7V~lzXS96LVM!5l(*F%|>NR($MvSLwA0Kn)19g*!5~^LjI#hS<4OFBKjFxf*f)P%!m-WiuiNO#IQf92!f)FI~Xk{ zg0o>XH8`{y1QCs`EmF~tQ@vkw;NgA0=bUdkN7kaXIHTuu3@5;JNaOi@)nvnH|Hp}R zH8{nAve3R6+1F#NaE$3$j@6O(;QjeHNS=BR{0s68B!kOSyS0qDfnjsZPo8=& z{3vn))B=ePdFmGU5ON8GE^e#vGOt=FT%K&T=}iZoc8xq^UeMgx<$rLftKo-{i=cED ztkZkyX82X)AyE5kTJqHU;IEL^;49^k$W!Oxo5)9SDui3`zQ4hMi&w}G;INgqX@R;5 z{u{|PIQ6X3dz>Xeid1-Zgm<*>Hw%}TLYQWT<6Ix9pYsdzGvUB<@eGVxR-lb?*rpW1}H$6LB! Ismoothed stroke smoothed stroke - + false move drawing on desktop move drawing on desktop