diff --git a/draw.js b/draw.js index 5a6cfe7..2f1d793 100644 --- a/draw.js +++ b/draw.js @@ -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); diff --git a/extension.js b/extension.js index d497aae..31d2a54 100644 --- a/extension.js +++ b/extension.js @@ -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 = _("Press %s for help").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(); diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index e96e603..03ff099 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -163,6 +163,9 @@ msgstr "" msgid "Erase all drawings" msgstr "" +msgid "Toggle modeless/modal" +msgstr "" + #: INTERNAL_KEYBINDINGS msgid "Undo last brushstroke" diff --git a/prefs.js b/prefs.js index 5e5c947..b08a7aa 100644 --- a/prefs.js +++ b/prefs.js @@ -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 = { diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index 409cec5..fda9879 100644 Binary files a/schemas/gschemas.compiled and b/schemas/gschemas.compiled differ diff --git a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml index 3dd963c..38c9300 100644 --- a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml +++ b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml @@ -31,6 +31,11 @@ erase drawing erase drawing + + ["<Primary><Alt><Super>d"] + toggle modeless/modal + toggle modeless/modal + ["<Primary>z"] undo