From d2c285154b94a34add3b42d240972d50cb06c6c4 Mon Sep 17 00:00:00 2001 From: abakkk Date: Thu, 28 Mar 2019 22:01:39 +0100 Subject: [PATCH] add panel indicator and prefs to disable osd notifications and indicator --- draw.js | 2 +- extension.js | 68 +++++++++++++++--- locale/draw-on-your-screen.pot | 6 ++ prefs.js | 30 ++++++-- schemas/gschemas.compiled | Bin 3140 -> 3256 bytes ...extensions.draw-on-your-screen.gschema.xml | 10 +++ 6 files changed, 103 insertions(+), 13 deletions(-) diff --git a/draw.js b/draw.js index de707c5..cca7194 100644 --- a/draw.js +++ b/draw.js @@ -506,7 +506,6 @@ var DrawingArea = new Lang.Class({ this.buttonPressedHandler = this.connect('button-press-event', this._onButtonPressed.bind(this)); this._onKeyboardPopupMenuHandler = this.connect('popup-menu', this._onKeyboardPopupMenu.bind(this)); this.scrollHandler = this.connect('scroll-event', this._onScroll.bind(this)); - this.selectShape(Shapes.NONE); this.get_parent().set_background_color(this.hasBackground ? this.activeBackgroundColor : null); this._updateStyle(); }, @@ -542,6 +541,7 @@ var DrawingArea = new Lang.Class({ this.currentElement = null; this._stopCursorTimeout(); + this.currentShape = Shapes.NONE; this.dashedLine = false; this.fill = false; this._redisplay(); diff --git a/extension.js b/extension.js index 176c37d..e928394 100644 --- a/extension.js +++ b/extension.js @@ -25,8 +25,11 @@ const Lang = imports.lang; const Meta = imports.gi.Meta; const Shell = imports.gi.Shell; const St = imports.gi.St; + const Main = imports.ui.main; const OsdWindow = imports.ui.osdWindow; +const PanelMenu = imports.ui.panelMenu; + const Extension = imports.misc.extensionUtils.getCurrentExtension(); const Convenience = Extension.imports.convenience; const Draw = Extension.imports.draw; @@ -78,6 +81,9 @@ var AreaManager = new Lang.Class({ this.updateAreas(); this.monitorChangedHandler = Main.layoutManager.connect('monitors-changed', this.updateAreas.bind(this)); + this.updateIndicator(); + this.indicatorSettingHandler = this.settings.connect('changed::indicator-disabled', this.updateIndicator.bind(this)); + this.desktopSettingHandler = this.settings.connect('changed::drawing-on-desktop', this.onDesktopSettingChanged.bind(this)); this.persistentSettingHandler = this.settings.connect('changed::persistent-drawing', this.onPersistentSettingChanged.bind(this)); @@ -105,6 +111,15 @@ var AreaManager = new Lang.Class({ this.areas[Main.layoutManager.primaryIndex].saveAsJson(); }, + updateIndicator: function() { + if (this.indicator) { + this.indicator.disable(); + this.indicator = null; + } + if (!this.settings.get_boolean('indicator-disabled')) + this.indicator = new DrawingIndicator(); + }, + updateAreas: function() { if (this.activeArea) this.toggleDrawing(); @@ -264,8 +279,8 @@ var AreaManager = new Lang.Class({ global.display.set_cursor(Meta.Cursor.DEFAULT); else if (global.screen && global.screen.set_cursor) global.screen.set_cursor(Meta.Cursor.DEFAULT); - - Main.osdWindowManager.show(activeIndex, this.leaveGicon, _("Leaving drawing mode"), null); + if (!this.osdDisabled) + Main.osdWindowManager.show(activeIndex, this.leaveGicon, _("Leaving drawing mode"), null); } else { // avoid to deal with Meta changes (global.display/global.screen) let currentIndex = Main.layoutManager.monitors.indexOf(Main.layoutManager.currentMonitor); @@ -287,16 +302,24 @@ var AreaManager = new Lang.Class({ global.display.set_cursor(Meta.Cursor.POINTING_HAND); else if (global.screen && global.screen.set_cursor) global.screen.set_cursor(Meta.Cursor.POINTING_HAND); - - // increase OSD display time - let hideTimeoutSave = OsdWindow.HIDE_TIMEOUT; - OsdWindow.HIDE_TIMEOUT = 2000; - Main.osdWindowManager.show(currentIndex, this.enterGicon, _("Press Ctrl + F1 for help") + "\n\n" + _("Entering drawing mode"), null); - OsdWindow.HIDE_TIMEOUT = hideTimeoutSave; + + this.osdDisabled = this.settings.get_boolean('osd-disabled'); + if (!this.osdDisabled) { + // increase OSD display time + let hideTimeoutSave = OsdWindow.HIDE_TIMEOUT; + OsdWindow.HIDE_TIMEOUT = 2000; + Main.osdWindowManager.show(currentIndex, this.enterGicon, _("Press Ctrl + F1 for help") + "\n\n" + _("Entering drawing mode"), null); + OsdWindow.HIDE_TIMEOUT = hideTimeoutSave; + } } + + if (this.indicator) + this.indicator.sync(this.activeArea != null); }, showOsd: function(emitter, label, level, maxLevel) { + if (this.osdDisabled) + return; let activeIndex = this.areas.indexOf(this.activeArea); if (activeIndex != -1) { Main.osdWindowManager.show(activeIndex, this.enterGicon, label, level, maxLevel); @@ -326,6 +349,10 @@ var AreaManager = new Lang.Class({ Main.layoutManager.disconnect(this.monitorChangedHandler); this.monitorChangedHandler = null; } + if (this.indicatorSettingHandler) { + this.settings.disconnect(this.indicatorSettingHandler); + this.indicatorSettingHandler = null; + } if (this.desktopSettingHandler) { this.settings.disconnect(this.desktopSettingHandler); this.desktopSettingHandler = null; @@ -340,6 +367,31 @@ var AreaManager = new Lang.Class({ Main.wm.removeKeybinding('toggle-drawing'); Main.wm.removeKeybinding('erase-drawing'); this.removeAreas(); + if (this.indicator) + this.indicator.disable(); + } +}); + +var DrawingIndicator = new Lang.Class({ + Name: 'DrawOnYourScreenIndicator', + + _init: function() { + let [menuAlignment, dontCreateMenu] = [0, true]; + this.button = new PanelMenu.Button(menuAlignment, "Drawing Indicator", dontCreateMenu); + Main.panel.addToStatusArea('draw-on-your-screen-indicator', this.button); + + this.icon = new St.Icon({ icon_name: 'applications-graphics-symbolic', + style_class: 'system-status-icon screencast-indicator' }); + this.button.actor.add_child(this.icon); + this.button.actor.visible = false; + }, + + sync: function(visible) { + this.button.actor.visible = visible; + }, + + disable: function() { + this.button.destroy(); } }); diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index eb1d9ae..eb936e2 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -277,6 +277,12 @@ msgstr "" msgid "Persistent drawing through session restart" msgstr "" +msgid "Disable on-screen notifications" +msgstr "" + +msgid "Disable panel indicator" +msgstr "" + msgid "Internal" msgstr "" diff --git a/prefs.js b/prefs.js index 890ec9d..ba791e0 100644 --- a/prefs.js +++ b/prefs.js @@ -109,7 +109,7 @@ function buildPrefsWidget() { return topStack; } -const TopStack = new GObject.Class({ +var TopStack = new GObject.Class({ Name: 'DrawOnYourScreenTopStack', GTypeName: 'DrawOnYourScreenTopStack', Extends: Gtk.Stack, @@ -123,7 +123,7 @@ const TopStack = new GObject.Class({ } }); -const AboutPage = new GObject.Class({ +var AboutPage = new GObject.Class({ Name: 'DrawOnYourScreenAboutPage', GTypeName: 'DrawOnYourScreenAboutPage', Extends: Gtk.ScrolledWindow, @@ -170,7 +170,7 @@ const AboutPage = new GObject.Class({ }); -const PrefsPage = new GObject.Class({ +var PrefsPage = new GObject.Class({ Name: 'DrawOnYourScreenPrefsPage', GTypeName: 'DrawOnYourScreenPrefsPage', Extends: Gtk.ScrolledWindow, @@ -226,6 +226,28 @@ const PrefsPage = new GObject.Class({ persistentBox.pack_start(persistentLabelBox, true, true, 4); persistentBox.pack_start(persistentSwitch, false, false, 4); listBox.add(persistentBox); + + let osdBox = new Gtk.Box({ margin: MARGIN }); + let osdLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL }); + let osdLabel1 = new Gtk.Label({label: _("Disable on-screen notifications")}); + osdLabel1.set_halign(1); + osdLabelBox.pack_start(osdLabel1, true, true, 0); + let osdSwitch = new Gtk.Switch({valign: 3}); + this.settings.bind("osd-disabled", osdSwitch, "active", 0); + osdBox.pack_start(osdLabelBox, true, true, 4); + osdBox.pack_start(osdSwitch, false, false, 4); + listBox.add(osdBox); + + let indicatorBox = new Gtk.Box({ margin: MARGIN }); + let indicatorLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL }); + let indicatorLabel1 = new Gtk.Label({label: _("Disable panel indicator")}); + indicatorLabel1.set_halign(1); + indicatorLabelBox.pack_start(indicatorLabel1, true, true, 0); + let indicatorSwitch = new Gtk.Switch({valign: 3}); + this.settings.bind("indicator-disabled", indicatorSwitch, "active", 0); + indicatorBox.pack_start(indicatorLabelBox, true, true, 4); + indicatorBox.pack_start(indicatorSwitch, false, false, 4); + listBox.add(indicatorBox); this.addSeparator(listBox); let internalTitleBox = new Gtk.Box({ margin: MARGIN }); @@ -313,7 +335,7 @@ const PrefsPage = new GObject.Class({ }); // this code comes from Sticky Notes View by Sam Bull, https://extensions.gnome.org/extension/568/notes/ -const KeybindingsWidget = new GObject.Class({ +var KeybindingsWidget = new GObject.Class({ Name: 'DrawOnYourScreenKeybindings.Widget', GTypeName: 'DrawOnYourScreenKeybindingsWidget', Extends: Gtk.Box, diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index 6645b28b84262d3cc1ca01aba32b9b08235c0a7f..329554d6b23e75f72fdb56ab41f68bcf99307d8f 100644 GIT binary patch literal 3256 zcmZu!U2GIp7#)ymp@8LA3RMe=Y{A*hQVOl96|_P{Ng#+pAE2{4cXx-*&MY&t{R0V6 z5;2MqeUKQ5H73FX2{i$t#z=iJ#Ds(=gy;h#nrNb=4?dU}#B*lv&d+u?IXNe1zq$9j z-@SA1oo%mZj-gqeB7e)kdn-CIQ+hMNvu=%blKEd!=~s?}2O1QmVTq#L!|%(vFqD^+ z3*fH++sP;MmR%G{w;)V2DMmbDxrS}IN!`(gRohZW?Xsh~Sw{$q&nk&0eNvSBz{LGP zBQOVO0@%fTU;(fQSRBDpXyPHDMPfPl;RqguCfb0Nz$%Hyz{KNquo~VPpdDB%u?}3t z_`szcO5oRGfik3wpeAnv%JQG?(x;ve{}lKf@#BeQ^r;uap9EhAj%;uJl|D87DR2`C z@a)K6*XUEvgTD;i1$=Pt_C@;CP4N4{uL94>cxuKMz{i1)zTGv!c^ zlRou>@UMVx0)4U_YPRz`xbXo+d0zU|em>wXV5{`0>Gy*Rz~H|ft!$rqA^fA@lfX6^ zPtEvo@FdVLeQNsGz*B&C=xQI^p=O;Mu`pVIsq63TqEF2_C&1mnygysNqfgCo^@Dc+ zFUa<(+5Q0dD6n1n)b!s6PXG<+FXpfv>ZS0nfN#==$#qZ7b^iJr{=h>fNui(E`M**r}ozacm`gCw?12YgFbZ|;uGL* z;QWr$hv`$#g1;HO7g*8qsqa(M9{?W&-cw(@%6Mwl=P39j@bSBc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1;QhBwUZb6w=h6o@fWHgPG7dH46v3|p!#CTT=ua)r5&RkO-dFvzv{SP`=fFP# zTN*!*{X@SoyU;0fTv z;}^5EQ`7%l@HwDv@-f+O)Xeh|_-kM;Yw^lUP5T0DOTe$6w8;HZbHCTYt2nDR|NJlg zsafZG@HSxGpH1J;PR(=g1ar1={?r3^0tlhq2XK~fvvt6B0Ih;EUY<{A-_mSa5500W zaULP8#<_zd)i{eD0$KsixCej)umj-1;M&UB#97t|Yy>#FIMbQ|Q(%x5gcIntOyNb5k}rysd{Lyz zFN#!!7ez|be3f_B#b*6r!WOZ-EtPjPr(N-Uc9rwl73Sj!Q}#)zUflzED;xAo;^bHc z70$yx4Toj(^F|RXm;Aj7>$XRpqyFt>@AhzA?$L5`d>@*^9}e6icf(I29WE+Qbme+> zxSla8bi>#E(Hy^3%Eu3%N6uz<)$UH0A`=HnKHvs_gihX~3Zu8LQw(e#4r$y12L z?=x~@sMj5HFg79uls(cB@k1URx}2yS@!M><3;oBTCsjt*}p6F7oOn@U7bGt57e4yOIv*=yNb)O@ZDkC$Qps;v?Mr#!N15!j((^-Ym`9O=!jCqqh!j`$oruSg zw=ioIEPDd0Mb^v4{Y=A;&m(Nqa!t(CNZS63BZh}=_JmQ&%L&h;;JQKnwmDSt6Zo!; zQOt0dW%4pd^O;m}Dit;AhyFTXhIy$|4KS2cAxi57@%#AqLystpersistent drawing persistent drawing + + false + disable OSD notifications + disable on-screen notifications + + + false + disable panel indicator + disable panel indicator + ["<Alt><Super>d"] toggle drawing