From 98832cec72fc0558d150e0717457dc6ddfb1ae1c Mon Sep 17 00:00:00 2001 From: abakkk Date: Sun, 21 Jun 2020 01:08:45 +0200 Subject: [PATCH] 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 --- draw.js | 5 + extension.js | 96 ++++++++++++------ locale/draw-on-your-screen.pot | 3 + prefs.js | 3 +- schemas/gschemas.compiled | Bin 4140 -> 4192 bytes ...extensions.draw-on-your-screen.gschema.xml | 5 + 6 files changed, 79 insertions(+), 33 deletions(-) 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 409cec50e7908f645d9e0283b5b710d2f03ceeb1..fda9879c7f963d5e881c849b17159b30b433f063 100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