toggle modeless / modal

Keybinding to ungrab keyboard and mouse while drawing remains at the top.
To be aware that this create some problems with the shell (DnD #1 and maybe more ?).

related to #6, #9, #20, #24, #33
This commit is contained in:
abakkk 2020-06-21 01:08:45 +02:00
parent 3c14f72f56
commit 98832cec72
6 changed files with 79 additions and 33 deletions

View File

@ -691,6 +691,11 @@ var DrawingArea = new Lang.Class({
this.setPointerCursor('MOVE_OR_RESIZE_WINDOW');
},
initPointerCursor: function() {
this.currentPointerCursorName = null;
this.updatePointerCursor();
},
_stopTextCursorTimeout: function() {
if (this.textCursorTimeoutId) {
GLib.source_remove(this.textCursorTimeoutId);

View File

@ -86,6 +86,12 @@ var AreaManager = new Lang.Class({
Shell.ActionMode.ALL,
this.eraseDrawing.bind(this));
Main.wm.addKeybinding('toggle-modal',
this.settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.ALL,
this.toggleModal.bind(this));
this.updateAreas();
this.monitorChangedHandler = Main.layoutManager.connect('monitors-changed', this.updateAreas.bind(this));
@ -306,53 +312,78 @@ var AreaManager = new Lang.Class({
}
},
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');
if (this.hiddenList)
this.togglePanelAndDockOpacity();
setCursor('DEFAULT');
if (!this.osdDisabled)
this.showOsd(null, this.leaveGicon, _("Leaving drawing mode"));
Main.popModal(this.activeArea);
this.removeInternalKeybindings();
this.activeArea.reactive = false;
this.activeArea.leaveDrawingMode(save);
this.activeArea = null;
activeContainer.get_parent().remove_actor(activeContainer);
toggleContainer: function() {
if (!this.activeArea)
return;
let activeContainer = this.activeArea.get_parent();
let activeIndex = this.areas.indexOf(this.activeArea);
if (activeContainer.get_parent() == Main.uiGroup) {
Main.uiGroup.remove_actor(activeContainer);
Main.layoutManager._backgroundGroup.insert_child_above(activeContainer, Main.layoutManager._bgManagers[activeIndex].backgroundActor);
if (!this.settings.get_boolean("drawing-on-desktop"))
activeContainer.hide();
} else {
// avoid to deal with Meta changes (global.display/global.screen)
let currentIndex = Main.layoutManager.monitors.indexOf(Main.layoutManager.currentMonitor);
let activeContainer = this.areas[currentIndex].get_parent();
activeContainer.get_parent().remove_actor(activeContainer);
Main.layoutManager._backgroundGroup.remove_actor(activeContainer);
Main.uiGroup.add_child(activeContainer);
}
},
toggleModal: function() {
if (!this.activeArea)
return;
if (Main.actionMode & DRAWING_ACTION_MODE) {
Main.popModal(this.activeArea);
setCursor('DEFAULT');
this.activeArea.reactive = false;
this.removeInternalKeybindings();
} else {
// add Shell.ActionMode.NORMAL to keep system keybindings enabled (e.g. Alt + F2 ...)
if (!Main.pushModal(this.areas[currentIndex], { actionMode: DRAWING_ACTION_MODE | Shell.ActionMode.NORMAL }))
return;
this.activeArea = this.areas[currentIndex];
if (!Main.pushModal(this.activeArea, { actionMode: DRAWING_ACTION_MODE | Shell.ActionMode.NORMAL }))
return false;
this.addInternalKeybindings();
this.activeArea.reactive = true;
this.activeArea.enterDrawingMode();
this.activeArea.initPointerCursor();
}
return true;
},
toggleDrawing: function() {
if (this.activeArea) {
let activeIndex = this.areas.indexOf(this.activeArea);
let save = activeIndex == Main.layoutManager.primaryIndex && this.settings.get_boolean('persistent-drawing');
setCursor('POINTING_HAND');
this.showOsd(null, this.leaveGicon, _("Leaving drawing mode"));
this.activeArea.leaveDrawingMode(save);
if (this.hiddenList)
this.togglePanelAndDockOpacity();
if (Main.actionMode & DRAWING_ACTION_MODE)
this.toggleModal();
this.toggleContainer();
this.activeArea = null;
} else {
// avoid to deal with Meta changes (global.display/global.screen)
let currentIndex = Main.layoutManager.monitors.indexOf(Main.layoutManager.currentMonitor);
this.activeArea = this.areas[currentIndex];
this.toggleContainer();
if (!this.toggleModal()) {
this.toggleContainer();
this.activeArea = null;
return;
}
this.activeArea.enterDrawingMode();
this.osdDisabled = this.settings.get_boolean('osd-disabled');
let label = _("<small>Press <i>%s</i> for help</small>").format(this.activeArea.helper.helpKeyLabel) + "\n\n" + _("Entering drawing mode");
this.showOsd(null, this.enterGicon, label, null, null, true);
}
if (this.indicator)
this.indicator.sync(this.activeArea != null);
this.indicator.sync(Boolean(this.activeArea));
},
// Use level -1 to set no level through a signal.
@ -482,6 +513,7 @@ var AreaManager = new Lang.Class({
this.toggleDrawing();
Main.wm.removeKeybinding('toggle-drawing');
Main.wm.removeKeybinding('erase-drawing');
Main.wm.removeKeybinding('toggle-modal');
this.removeAreas();
if (this.indicator)
this.indicator.disable();

View File

@ -163,6 +163,9 @@ msgstr ""
msgid "Erase all drawings"
msgstr ""
msgid "Toggle modeless/modal"
msgstr ""
#: INTERNAL_KEYBINDINGS
msgid "Undo last brushstroke"

View File

@ -37,7 +37,8 @@ const MARGIN = 10;
var GLOBAL_KEYBINDINGS = {
'toggle-drawing': "Enter/leave drawing mode",
'erase-drawing': "Erase all drawings"
'erase-drawing': "Erase all drawings",
'toggle-modal': "Toggle modeless/modal"
};
var INTERNAL_KEYBINDINGS = {

Binary file not shown.

View File

@ -31,6 +31,11 @@
<summary>erase drawing</summary>
<description>erase drawing</description>
</key>
<key type="as" name="toggle-modal">
<default>["&lt;Primary&gt;&lt;Alt&gt;&lt;Super&gt;d"]</default>
<summary>toggle modeless/modal</summary>
<description>toggle modeless/modal</description>
</key>
<key type="as" name="undo">
<default>["&lt;Primary&gt;z"]</default>
<summary>undo</summary>