diff --git a/draw.js b/draw.js
index cbdd8fa..20b8b05 100644
--- a/draw.js
+++ b/draw.js
@@ -29,7 +29,6 @@ const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Shell = imports.gi.Shell;
-const Signals = imports.signals;
const St = imports.gi.St;
const BoxPointer = imports.ui.boxpointer;
@@ -71,6 +70,8 @@ var FontFamilyNames = { 0: 'Default', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospac
var DrawingArea = new Lang.Class({
Name: 'DrawOnYourScreenDrawingArea',
Extends: St.DrawingArea,
+ Signals: { 'show-osd': { param_types: [GObject.TYPE_STRING, GObject.TYPE_DOUBLE] },
+ 'stop-drawing': {} },
_init: function(params, monitor, helper, loadJson) {
this.parent({ style_class: 'draw-on-your-screen', name: params && params.name ? params.name : ""});
@@ -78,7 +79,6 @@ var DrawingArea = new Lang.Class({
this.connect('repaint', this._repaint.bind(this));
this.settings = Convenience.getSettings();
- this.emitter = new DrawingAreaEmitter();
this.monitor = monitor;
this.helper = helper;
@@ -212,7 +212,7 @@ var DrawingArea = new Lang.Class({
_onKeyPressed: function(actor, event) {
if (event.get_key_symbol() == Clutter.Escape) {
- this.emitter.emit('stop-drawing');
+ this.emit('stop-drawing');
return Clutter.EVENT_STOP;
} else if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.WRITING) {
@@ -231,6 +231,9 @@ var DrawingArea = new Lang.Class({
// stop writing
// Clutter.KEY_Return is "Enter" and 65421 is KP_Enter
this._stopWriting();
+ } else if (event.has_control_modifier()){
+ // it's a shortcut, do not write text
+ return Clutter.EVENT_PROPAGATE;
} else {
let unicode = event.get_key_unicode();
this.currentElement.text += unicode;
@@ -319,10 +322,11 @@ var DrawingArea = new Lang.Class({
if (this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.DRAWING) {
this.currentElement.state = TextState.WRITING;
this.currentElement.text = '';
- this.emitter.emit('show-osd', _("Type your text\nand press Enter"), null);
+ this.emit('show-osd', _("Type your text\nand press Enter"), -1);
this._updateCursorTimeout();
this.textHasCursor = true;
this._redisplay();
+ this.updatePointerCursor();
return;
}
@@ -331,6 +335,7 @@ var DrawingArea = new Lang.Class({
this.currentElement = null;
this._redisplay();
+ this.updatePointerCursor();
},
_updateDrawing: function(x, y, controlPressed) {
@@ -346,7 +351,9 @@ var DrawingArea = new Lang.Class({
this.currentElement.transformLine(x, y);
else
this.currentElement.points[1] = [x, y];
+
this._redisplay();
+ this.updatePointerCursor(controlPressed);
},
_stopWriting: function() {
@@ -357,6 +364,20 @@ var DrawingArea = new Lang.Class({
this._redisplay();
},
+ setPointerCursor: function(pointerCursorName) {
+ if (!this.currentPointerCursorName || this.currentPointerCursorName != pointerCursorName) {
+ this.currentPointerCursorName = pointerCursorName;
+ ExtensionJs.setCursor(pointerCursorName);
+ }
+ },
+
+ updatePointerCursor: function(controlPressed) {
+ if (!this.currentElement || (this.currentElement.shape == Shapes.TEXT && this.currentElement.state == TextState.WRITING))
+ this.setPointerCursor(this.currentShape == Shapes.NONE ? 'POINTING_HAND' : 'CROSSHAIR');
+ else if (this.currentElement.shape != Shapes.NONE && controlPressed)
+ this.setPointerCursor('MOVE_OR_RESIZE_WINDOW');
+ },
+
_stopCursorTimeout: function() {
if (this.cursorTimeoutId) {
Mainloop.source_remove(this.cursorTimeoutId);
@@ -447,37 +468,38 @@ var DrawingArea = new Lang.Class({
this.currentElement.color = this.currentColor.to_string();
this._redisplay();
}
- this.emitter.emit('show-osd', `${this.currentColor.to_string()}`, null);
+ this.emit('show-osd', `${this.currentColor.to_string()}`, -1);
},
selectShape: function(shape) {
this.currentShape = shape;
- this.emitter.emit('show-osd', _(ShapeNames[shape]), null);
+ this.emit('show-osd', _(ShapeNames[shape]), -1);
+ this.updatePointerCursor();
},
toggleFill: function() {
this.fill = !this.fill;
- this.emitter.emit('show-osd', this.fill ? _("Fill") : _("Stroke"), null);
+ this.emit('show-osd', this.fill ? _("Fill") : _("Stroke"), -1);
},
toggleDash: function() {
this.dashedLine = !this.dashedLine;
- this.emitter.emit('show-osd', this.dashedLine ? _("Dashed line") : _("Full line"), null);
+ this.emit('show-osd', this.dashedLine ? _("Dashed line") : _("Full line"), -1);
},
incrementLineWidth: function(increment) {
this.currentLineWidth = Math.max(this.currentLineWidth + increment, 0);
- this.emitter.emit('show-osd', this.currentLineWidth + " " + _("px"), 2 * this.currentLineWidth);
+ this.emit('show-osd', this.currentLineWidth + " " + _("px"), 2 * this.currentLineWidth);
},
toggleLineJoin: function() {
this.currentLineJoin = this.currentLineJoin == 2 ? 0 : this.currentLineJoin + 1;
- this.emitter.emit('show-osd', _(LineJoinNames[this.currentLineJoin]), null);
+ this.emit('show-osd', _(LineJoinNames[this.currentLineJoin]), -1);
},
toggleLineCap: function() {
this.currentLineCap = this.currentLineCap == 2 ? 0 : this.currentLineCap + 1;
- this.emitter.emit('show-osd', _(LineCapNames[this.currentLineCap]), null);
+ this.emit('show-osd', _(LineCapNames[this.currentLineCap]), -1);
},
toggleFontWeight: function() {
@@ -486,7 +508,7 @@ var DrawingArea = new Lang.Class({
this.currentElement.font.weight = this.currentFontWeight;
this._redisplay();
}
- this.emitter.emit('show-osd', `${_(FontWeightNames[this.currentFontWeight])}`, null);
+ this.emit('show-osd', `${_(FontWeightNames[this.currentFontWeight])}`, -1);
},
toggleFontStyle: function() {
@@ -495,7 +517,7 @@ var DrawingArea = new Lang.Class({
this.currentElement.font.style = this.currentFontStyle;
this._redisplay();
}
- this.emitter.emit('show-osd', `${_(FontStyleNames[this.currentFontStyle])}`, null);
+ this.emit('show-osd', `${_(FontStyleNames[this.currentFontStyle])}`, -1);
},
toggleFontFamily: function() {
@@ -505,7 +527,7 @@ var DrawingArea = new Lang.Class({
this.currentElement.font.family = currentFontFamily;
this._redisplay();
}
- this.emitter.emit('show-osd', `${_(currentFontFamily)}`, null);
+ this.emit('show-osd', `${_(currentFontFamily)}`, -1);
},
toggleHelp: function() {
@@ -649,15 +671,6 @@ var DrawingArea = new Lang.Class({
}
});
-var DrawingAreaEmitter = new Lang.Class({
- Name: 'DrawingAreaEmitter',
-
- _init: function() {
- }
-});
-Signals.addSignalMethods(DrawingAreaEmitter.prototype);
-
-
// DrawingElement represents a "brushstroke".
// It can be converted into a cairo path as well as a svg element.
// See DrawingArea._startDrawing() to know its params.
@@ -1044,9 +1057,13 @@ var DrawingMenu = new Lang.Class({
},
_onMenuOpenStateChanged: function(menu, open) {
- if (!open)
+ if (open) {
+ this.area.setPointerCursor('DEFAULT');
+ } else {
+ this.area.updatePointerCursor();
// actionMode has changed, set previous actionMode in order to keep internal shortcuts working
Main.actionMode = ExtensionJs.DRAWING_ACTION_MODE | Shell.ActionMode.NORMAL;
+ }
},
popup: function() {
@@ -1213,9 +1230,10 @@ var DrawingMenu = new Lang.Class({
else
text = _(obj[i]);
+ let iCaptured = i;
let subItem = item.menu.addAction(text, () => {
- item.label.set_text(_(obj[i]));
- target[targetProperty] = i;
+ item.label.set_text(_(obj[iCaptured]));
+ target[targetProperty] = iCaptured;
if (callback)
callback();
});
@@ -1239,8 +1257,9 @@ var DrawingMenu = new Lang.Class({
Mainloop.timeout_add(0, () => {
for (let i = 1; i < this.area.colors.length; i++) {
let text = `${this.area.colors[i].to_string()}`;
+ let iCaptured = i;
let colorItem = item.menu.addAction(text, () => {
- this.area.currentColor = this.area.colors[i];
+ this.area.currentColor = this.area.colors[iCaptured];
item.icon.set_style(`color:${this.area.currentColor.to_string().slice(0, 7)};`);
});
colorItem.label.get_clutter_text().set_use_markup(true);
diff --git a/extension.js b/extension.js
index 325f5f3..5e712e2 100644
--- a/extension.js
+++ b/extension.js
@@ -43,7 +43,7 @@ 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;
+var manager;
function init() {
Convenience.initTranslations();
@@ -148,8 +148,8 @@ var AreaManager = new Lang.Class({
container.set_position(monitor.x, monitor.y);
container.set_size(monitor.width, monitor.height);
area.set_size(monitor.width, monitor.height);
- 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.stopDrawingHandler = area.connect('stop-drawing', this.toggleDrawing.bind(this));
+ area.showOsdHandler = area.connect('show-osd', this.showOsd.bind(this));
this.areas.push(area);
}
},
@@ -193,11 +193,12 @@ var AreaManager = new Lang.Class({
}
for (let i = 1; i < 10; i++) {
+ let iCaptured = i;
Main.wm.addKeybinding('select-color' + i,
this.settings,
Meta.KeyBindingFlags.NONE,
DRAWING_ACTION_MODE,
- () => this.activeArea.selectColor(i));
+ () => this.activeArea.selectColor(iCaptured));
}
},
@@ -279,11 +280,7 @@ var AreaManager = new Lang.Class({
if (!this.settings.get_boolean("drawing-on-desktop"))
activeContainer.hide();
- // check display or screen (API changes)
- if (global.display.set_cursor)
- global.display.set_cursor(Meta.Cursor.DEFAULT);
- else if (global.screen && global.screen.set_cursor)
- global.screen.set_cursor(Meta.Cursor.DEFAULT);
+ setCursor('DEFAULT');
if (!this.osdDisabled)
Main.osdWindowManager.show(activeIndex, this.leaveGicon, _("Leaving drawing mode"), null);
} else {
@@ -302,19 +299,14 @@ var AreaManager = new Lang.Class({
this.activeArea.reactive = true;
this.activeArea.enterDrawingMode();
- // check display or screen (API changes)
- if (global.display.set_cursor)
- global.display.set_cursor(Meta.Cursor.POINTING_HAND);
- else if (global.screen && global.screen.set_cursor)
- global.screen.set_cursor(Meta.Cursor.POINTING_HAND);
-
+ setCursor('POINTING_HAND');
this.osdDisabled = this.settings.get_boolean('osd-disabled');
if (!this.osdDisabled) {
// increase OSD display time
let hideTimeoutSave = OsdWindow.HIDE_TIMEOUT;
- OsdWindow.HIDE_TIMEOUT = 2000;
+ try { OsdWindow.HIDE_TIMEOUT = 2000; } catch(e) { /* HIDE_TIMEOUT is not exported with 'var' */ }
Main.osdWindowManager.show(currentIndex, this.enterGicon, _("Press Ctrl + F1 for help") + "\n\n" + _("Entering drawing mode"), null);
- OsdWindow.HIDE_TIMEOUT = hideTimeoutSave;
+ try { OsdWindow.HIDE_TIMEOUT = hideTimeoutSave; } catch(e) {}
}
}
@@ -322,11 +314,17 @@ var AreaManager = new Lang.Class({
this.indicator.sync(this.activeArea != null);
},
+ // use level -1 to set no level (null)
showOsd: function(emitter, label, level, maxLevel) {
if (this.osdDisabled)
return;
let activeIndex = this.areas.indexOf(this.activeArea);
if (activeIndex != -1) {
+ if (level == -1)
+ level = null;
+ else if (level > 100)
+ maxLevel = 2;
+
// GS 3.32- : bar from 0 to 100
// GS 3.34+ : bar from 0 to 1
if (level && GS_VERSION > '3.33.0')
@@ -350,8 +348,8 @@ var AreaManager = new Lang.Class({
let area = this.areas[i];
let container = area.get_parent();
container.get_parent().remove_actor(container);
- area.emitter.disconnect(area.emitter.stopDrawingHandler);
- area.emitter.disconnect(area.emitter.showOsdHandler);
+ area.disconnect(area.stopDrawingHandler);
+ area.disconnect(area.showOsdHandler);
area.disable();
container.destroy();
}
@@ -414,4 +412,12 @@ var DrawingIndicator = new Lang.Class({
}
});
+function setCursor(cursorName) {
+ // check display or screen (API changes)
+ if (global.display.set_cursor)
+ global.display.set_cursor(Meta.Cursor[cursorName]);
+ else if (global.screen && global.screen.set_cursor)
+ global.screen.set_cursor(Meta.Cursor[cursorName]);
+}
+
diff --git a/metadata.json b/metadata.json
index a4ef64a..b612103 100644
--- a/metadata.json
+++ b/metadata.json
@@ -1,15 +1,17 @@
{
"name": "Draw On You Screen",
"description": "Start drawing with Super+Alt+D and save your beautiful work by taking a screenshot",
- "version": 4.1,
"uuid": "drawOnYourScreen@abakkk.framagit.org",
"url": "https://framagit.org/abakkk/DrawOnYourScreen",
"settings-schema": "org.gnome.shell.extensions.draw-on-your-screen",
"gettext-domain": "draw-on-your-screen",
"shell-version": [
+ "3.24",
"3.26",
"3.28",
"3.30",
- "3.32"
- ]
+ "3.32",
+ "3.34"
+ ],
+ "version": 5
}
diff --git a/prefs.js b/prefs.js
index 222dc3c..e35e294 100644
--- a/prefs.js
+++ b/prefs.js
@@ -88,12 +88,6 @@ function init() {
Convenience.initTranslations();
}
-function buildPrefsWidget() {
- let prefsPage = new PrefsPage();
- prefsPage.show_all();
- return prefsPage;
-}
-
function buildPrefsWidget() {
let topStack = new TopStack();
let switcher = new Gtk.StackSwitcher({halign: Gtk.Align.CENTER, visible: true, stack: topStack});