introduce space key modifier
Pointer movement is ignored when the `space` key is held. To ensure [Screenshot Tool](https://extensions.gnome.org/extension/1112/screenshot-tool/) extension compatibility, we need a way to let the third extension select the screenshot area with pointer but without leaving drawing mode and without drawing. As a side effect, it allows to insert straight line segments in free drawing (after releasing the key). Fixes issue #20
This commit is contained in:
parent
5e8cb0ea1f
commit
1e03967fbf
10
README.md
10
README.md
|
|
@ -25,3 +25,13 @@ Install :
|
||||||
5. Enable the extension in Gnome-tweak-tool
|
5. Enable the extension in Gnome-tweak-tool
|
||||||
6. `Super + Alt + D` to test
|
6. `Super + Alt + D` to test
|
||||||
7. [https://framagit.org/abakkk/DrawOnYourScreen/issues](https://framagit.org/abakkk/DrawOnYourScreen/issues) to say it doesn't work
|
7. [https://framagit.org/abakkk/DrawOnYourScreen/issues](https://framagit.org/abakkk/DrawOnYourScreen/issues) to say it doesn't work
|
||||||
|
|
||||||
|
|
||||||
|
Details :
|
||||||
|
---------
|
||||||
|
|
||||||
|
* Screenshot Tool extension:
|
||||||
|
|
||||||
|
|
||||||
|
[Screenshot Tool](https://extensions.gnome.org/extension/1112/screenshot-tool/) is a convenient extension to “create, copy, store and upload screenshots”. To use it while drawing mode is active, toggle the area selection mode thanks to the Screenshot Tool shortcut (`Super + F11` by default, see its preferences) and **hold** the `space` key when selecting the area with pointer to avoid drawing.
|
||||||
|
|
||||||
|
|
|
||||||
32
draw.js
32
draw.js
|
|
@ -213,6 +213,9 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_onButtonPressed: function(actor, event) {
|
_onButtonPressed: function(actor, event) {
|
||||||
|
if (this.spaceKeyPressed)
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
|
||||||
let button = event.get_button();
|
let button = event.get_button();
|
||||||
let [x, y] = event.get_coords();
|
let [x, y] = event.get_coords();
|
||||||
let shiftPressed = event.has_shift_modifier();
|
let shiftPressed = event.has_shift_modifier();
|
||||||
|
|
@ -250,6 +253,20 @@ var DrawingArea = new Lang.Class({
|
||||||
return Clutter.EVENT_STOP;
|
return Clutter.EVENT_STOP;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_onStageKeyPressed: function(actor, event) {
|
||||||
|
if (event.get_key_symbol() == Clutter.KEY_space)
|
||||||
|
this.spaceKeyPressed = true;
|
||||||
|
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
},
|
||||||
|
|
||||||
|
_onStageKeyReleased: function(actor, event) {
|
||||||
|
if (event.get_key_symbol() == Clutter.KEY_space)
|
||||||
|
this.spaceKeyPressed = false;
|
||||||
|
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
},
|
||||||
|
|
||||||
_onKeyPressed: function(actor, event) {
|
_onKeyPressed: function(actor, event) {
|
||||||
if (event.get_key_symbol() == Clutter.Escape) {
|
if (event.get_key_symbol() == Clutter.Escape) {
|
||||||
this.emit('stop-drawing');
|
this.emit('stop-drawing');
|
||||||
|
|
@ -332,6 +349,9 @@ var DrawingArea = new Lang.Class({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.motionHandler = this.connect('motion-event', (actor, event) => {
|
this.motionHandler = this.connect('motion-event', (actor, event) => {
|
||||||
|
if (this.spaceKeyPressed)
|
||||||
|
return;
|
||||||
|
|
||||||
let coords = event.get_coords();
|
let coords = event.get_coords();
|
||||||
let [s, x, y] = this.transform_stage_point(coords[0], coords[1]);
|
let [s, x, y] = this.transform_stage_point(coords[0], coords[1]);
|
||||||
if (!s)
|
if (!s)
|
||||||
|
|
@ -579,7 +599,9 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
enterDrawingMode: function() {
|
enterDrawingMode: function() {
|
||||||
this.keyPressedHandler = this.connect('key-press-event', this._onKeyPressed.bind(this));
|
this.stageKeyPressedHandler = global.stage.connect('key-press-event', this._onStageKeyPressed.bind(this));
|
||||||
|
this.stageKeyReleasedHandler = global.stage.connect('key-release-event', this._onStageKeyReleased.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));
|
||||||
this._onKeyboardPopupMenuHandler = this.connect('popup-menu', this._onKeyboardPopupMenu.bind(this));
|
this._onKeyboardPopupMenuHandler = this.connect('popup-menu', this._onKeyboardPopupMenu.bind(this));
|
||||||
this.scrollHandler = this.connect('scroll-event', this._onScroll.bind(this));
|
this.scrollHandler = this.connect('scroll-event', this._onScroll.bind(this));
|
||||||
|
|
@ -588,6 +610,14 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
leaveDrawingMode: function(save) {
|
leaveDrawingMode: function(save) {
|
||||||
|
if (this.stageKeyPressedHandler) {
|
||||||
|
global.stage.disconnect(this.stageKeyPressedHandler);
|
||||||
|
this.stageKeyPressedHandler = null;
|
||||||
|
}
|
||||||
|
if (this.stageKeyReleasedHandler) {
|
||||||
|
global.stage.disconnect(this.stageKeyReleasedHandler);
|
||||||
|
this.stageKeyReleasedHandler = null;
|
||||||
|
}
|
||||||
if (this.keyPressedHandler) {
|
if (this.keyPressedHandler) {
|
||||||
this.disconnect(this.keyPressedHandler);
|
this.disconnect(this.keyPressedHandler);
|
||||||
this.keyPressedHandler = null;
|
this.keyPressedHandler = null;
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,12 @@ msgstr ""
|
||||||
msgid "Shift key held"
|
msgid "Shift key held"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Ignore pointer movement"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Space key held"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgid "Leave"
|
msgid "Leave"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
||||||
1
prefs.js
1
prefs.js
|
|
@ -83,6 +83,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: "Ignore pointer movement", shortcut: "Space key held" },
|
||||||
{ desc: "Leave", shortcut: "Escape key" }
|
{ desc: "Leave", shortcut: "Escape key" }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue