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:
parent
72292c41f6
commit
da52cfa260
14
draw.js
14
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]`;
|
||||
|
|
|
|||
47
extension.js
47
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();
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
8
prefs.js
8
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: "<small>" + _("Draw On Your Screen becomes Draw On Your Desktop") + "</small>" });
|
||||
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: "<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);
|
||||
persistentLabel2.get_style_context().add_class("dim-label");
|
||||
persistentLabelBox.pack_start(persistentLabel1, true, true, 0);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -6,7 +6,7 @@
|
|||
<summary>smoothed stroke</summary>
|
||||
<description>smoothed stroke</description>
|
||||
</key>
|
||||
<key type="b" name="move-drawing-on-desktop">
|
||||
<key type="b" name="drawing-on-desktop">
|
||||
<default>false</default>
|
||||
<summary>move drawing on desktop</summary>
|
||||
<description>move drawing on desktop</description>
|
||||
|
|
|
|||
Loading…
Reference in New Issue