Drawing is hidden by default when leaving drawing mode

It doesn't stay on top of windows because of problems with "desktop"
extensions.
This commit is contained in:
abakkk 2019-03-12 00:29:14 +01:00
parent 72292c41f6
commit da52cfa260
6 changed files with 45 additions and 32 deletions

14
draw.js
View File

@ -171,7 +171,7 @@ var DrawingArea = new Lang.Class({
_onKeyPressed: function(actor, event) { _onKeyPressed: function(actor, event) {
if (event.get_key_symbol() == Clutter.Escape) { if (event.get_key_symbol() == Clutter.Escape) {
this.emitter.emit('stop-drawing', true); this.emitter.emit('stop-drawing');
return Clutter.EVENT_STOP; return Clutter.EVENT_STOP;
} else if (this.currentElement && this.currentElement.shape == Shapes.TEXT) { } else if (this.currentElement && this.currentElement.shape == Shapes.TEXT) {
@ -464,10 +464,6 @@ var DrawingArea = new Lang.Class({
this.helper.showHelp(); this.helper.showHelp();
}, },
get isEmpty() {
return this.elements.length == 0;
},
enterDrawingMode: function() { enterDrawingMode: function() {
this.keyPressedHandler = this.connect('key-press-event', this._onKeyPressed.bind(this)); this.keyPressedHandler = this.connect('key-press-event', this._onKeyPressed.bind(this));
this.buttonPressedHandler = this.connect('button-press-event', this._onButtonPressed.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._redisplay();
this.get_parent().set_background_color(null); this.get_parent().set_background_color(null);
if (save) if (save)
this._saveAsJson(); this.saveAsJson();
}, },
saveAsSvg: function() { saveAsSvg: function() {
@ -544,7 +540,7 @@ var DrawingArea = new Lang.Class({
} }
}, },
_saveAsJson: function() { saveAsJson: function() {
let filename = `DrawOnYourScreen.json`; let filename = `DrawOnYourScreen.json`;
let dir = GLib.get_user_data_dir(); let dir = GLib.get_user_data_dir();
let path = GLib.build_filenamev([dir, filename]); let path = GLib.build_filenamev([dir, filename]);
@ -556,6 +552,10 @@ var DrawingArea = new Lang.Class({
oldContents = imports.byteArray.toString(oldContents); 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);" // 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 // 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]`; let contents = `[\n ` + new Array(...this.elements.map(element => JSON.stringify(element))).join(`,\n\n `) + `\n]`;

View File

@ -75,6 +75,9 @@ var AreaManager = new Lang.Class({
this.updateAreas(); this.updateAreas();
this.monitorChangedHandler = Main.layoutManager.connect('monitors-changed', this.updateAreas.bind(this)); 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) { if (Extension.stylesheet) {
this.stylesheetMonitor = Extension.stylesheet.monitor(Gio.FileMonitorFlags.NONE, null); this.stylesheetMonitor = Extension.stylesheet.monitor(Gio.FileMonitorFlags.NONE, null);
this.stylesheetChangedHandler = this.stylesheetMonitor.connect('changed', (monitor, file, otherFile, eventType) => { 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() { updateAreas: function() {
if (this.activeArea) if (this.activeArea)
this.toggleDrawing(); this.toggleDrawing();
@ -103,16 +118,13 @@ var AreaManager = new Lang.Class({
container.add_child(area); container.add_child(area);
container.add_child(helper); 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); Main.layoutManager._backgroundGroup.insert_child_above(container, Main.layoutManager._bgManagers[i].backgroundActor);
else if (!this.settings.get_boolean("drawing-on-desktop"))
Main.uiGroup.insert_child_above(container, global.window_group); container.hide();
container.set_position(monitor.x, monitor.y); container.set_position(monitor.x, monitor.y);
container.set_size(monitor.width, monitor.height); container.set_size(monitor.width, monitor.height);
area.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.stopDrawingHandler = area.emitter.connect('stop-drawing', this.toggleDrawing.bind(this));
area.emitter.showOsdHandler = area.emitter.connect('show-osd', this.showOsd.bind(this)); area.emitter.showOsdHandler = area.emitter.connect('show-osd', this.showOsd.bind(this));
this.areas.push(area); this.areas.push(area);
@ -183,10 +195,8 @@ var AreaManager = new Lang.Class({
}, },
eraseDrawing: function() { 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].erase();
this.areas[i].get_parent().hide();
}
}, },
togglePanelAndDockOpacity: function() { togglePanelAndDockOpacity: function() {
@ -223,12 +233,11 @@ var AreaManager = new Lang.Class({
} }
}, },
toggleDrawing: function(emitter, hide) { toggleDrawing: function() {
if (this.activeArea) { if (this.activeArea) {
let activeIndex = this.areas.indexOf(this.activeArea); let activeIndex = this.areas.indexOf(this.activeArea);
let activeContainer = this.activeArea.get_parent(); let activeContainer = this.activeArea.get_parent();
let save = activeIndex == Main.layoutManager.primaryIndex && this.settings.get_boolean('persistent-drawing'); let save = activeIndex == Main.layoutManager.primaryIndex && this.settings.get_boolean('persistent-drawing');
hide = hide || this.activeArea.isEmpty;
if (this.hiddenList) if (this.hiddenList)
this.togglePanelAndDockOpacity(); this.togglePanelAndDockOpacity();
@ -240,12 +249,8 @@ var AreaManager = new Lang.Class({
this.activeArea = null; this.activeArea = null;
activeContainer.get_parent().remove_actor(activeContainer); 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); Main.layoutManager._backgroundGroup.insert_child_above(activeContainer, Main.layoutManager._bgManagers[activeIndex].backgroundActor);
else if (!this.settings.get_boolean("drawing-on-desktop"))
Main.uiGroup.insert_child_above(activeContainer, global.window_group);
if (hide)
activeContainer.hide(); activeContainer.hide();
// check display or screen (API changes) // check display or screen (API changes)
@ -313,6 +318,14 @@ var AreaManager = new Lang.Class({
Main.layoutManager.disconnect(this.monitorChangedHandler); Main.layoutManager.disconnect(this.monitorChangedHandler);
this.monitorChangedHandler = null; 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) if (this.activeArea)
this.toggleDrawing(); this.toggleDrawing();

View File

@ -201,7 +201,7 @@ msgstr ""
msgid "Shift key held" msgid "Shift key held"
msgstr "" msgstr ""
msgid "Leave and hide the drawing" msgid "Leave"
msgstr "" msgstr ""
msgid "Escape key" msgid "Escape key"
@ -217,7 +217,7 @@ msgstr ""
msgid "Global" msgid "Global"
msgstr "" msgstr ""
msgid "Move drawing on the desktop when leaving drawing mode" msgid "Drawing on the desktop"
msgstr "" msgstr ""
msgid "Draw On Your Screen becomes Draw On Your Desktop" msgid "Draw On Your Screen becomes Draw On Your Desktop"
@ -226,7 +226,7 @@ msgstr ""
msgid "Persistent" msgid "Persistent"
msgstr "" msgstr ""
msgid "Persistent drawing through restart" msgid "Persistent drawing through session restart"
msgstr "" msgstr ""
msgid "Internal" msgid "Internal"

View File

@ -78,7 +78,7 @@ var OTHER_SHORTCUTS = [
{ desc: "Increment/decrement line width", shortcut: "Scroll" }, { desc: "Increment/decrement line width", shortcut: "Scroll" },
{ desc: "Select color", shortcut: "Ctrl+1...9" }, { desc: "Select color", shortcut: "Ctrl+1...9" },
{ desc: "Select eraser", shortcut: "Shift key held" }, { desc: "Select eraser", shortcut: "Shift key held" },
{ desc: "Leave and hide the drawing", shortcut: "Escape key" } { desc: "Leave", shortcut: "Escape key" }
]; ];
function init() { function init() {
@ -128,14 +128,14 @@ const PrefsPage = new GObject.Class({
let desktopBox = new Gtk.Box({ margin: MARGIN }); let desktopBox = new Gtk.Box({ margin: MARGIN });
let desktopLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL }); 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: "<small>" + _("Draw On Your Screen becomes Draw On Your Desktop") + "</small>" }); let desktopLabel2 = new Gtk.Label({ use_markup: true, halign: 1, label: "<small>" + _("Draw On Your Screen becomes Draw On Your Desktop") + "</small>" });
desktopLabel1.set_halign(1); desktopLabel1.set_halign(1);
desktopLabel2.get_style_context().add_class("dim-label"); desktopLabel2.get_style_context().add_class("dim-label");
desktopLabelBox.pack_start(desktopLabel1, true, true, 0); desktopLabelBox.pack_start(desktopLabel1, true, true, 0);
desktopLabelBox.pack_start(desktopLabel2, true, true, 0); desktopLabelBox.pack_start(desktopLabel2, true, true, 0);
let desktopSwitch = new Gtk.Switch({valign: 3}); 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(desktopLabelBox, true, true, 4);
desktopBox.pack_start(desktopSwitch, false, false, 4); desktopBox.pack_start(desktopSwitch, false, false, 4);
listBox.add(desktopBox); listBox.add(desktopBox);
@ -143,7 +143,7 @@ const PrefsPage = new GObject.Class({
let persistentBox = new Gtk.Box({ margin: MARGIN }); let persistentBox = new Gtk.Box({ margin: MARGIN });
let persistentLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL }); let persistentLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
let persistentLabel1 = new Gtk.Label({label: _("Persistent")}); let persistentLabel1 = new Gtk.Label({label: _("Persistent")});
let persistentLabel2 = new Gtk.Label({ use_markup: true, halign: 1, label: "<small>" + _("Persistent drawing through restart") + "</small>" }); let persistentLabel2 = new Gtk.Label({ use_markup: true, halign: 1, label: "<small>" + _("Persistent drawing through session restart") + "</small>" });
persistentLabel1.set_halign(1); persistentLabel1.set_halign(1);
persistentLabel2.get_style_context().add_class("dim-label"); persistentLabel2.get_style_context().add_class("dim-label");
persistentLabelBox.pack_start(persistentLabel1, true, true, 0); persistentLabelBox.pack_start(persistentLabel1, true, true, 0);

Binary file not shown.

View File

@ -6,7 +6,7 @@
<summary>smoothed stroke</summary> <summary>smoothed stroke</summary>
<description>smoothed stroke</description> <description>smoothed stroke</description>
</key> </key>
<key type="b" name="move-drawing-on-desktop"> <key type="b" name="drawing-on-desktop">
<default>false</default> <default>false</default>
<summary>move drawing on desktop</summary> <summary>move drawing on desktop</summary>
<description>move drawing on desktop</description> <description>move drawing on desktop</description>