From f979ebcb1a43ca120cb595909f724f813fcdece3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 27 Jan 2022 10:48:59 +0100 Subject: [PATCH] remoteAccess: Hide indicator after a timeout In order to make very short screen capture sessions more visible, let the indicator remain visible, but a bit greyed out, for some seconds. This makes it more obvious something was just capturing the screen. Part-of: --- js/ui/status/remoteAccess.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/js/ui/status/remoteAccess.js b/js/ui/status/remoteAccess.js index 992215ad3..a3dfd652c 100644 --- a/js/ui/status/remoteAccess.js +++ b/js/ui/status/remoteAccess.js @@ -7,6 +7,9 @@ const Main = imports.ui.main; const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; +// Minimum amount of time the shared indicator is visible (in micro seconds) +const MIN_SHARED_INDICATOR_VISIBLE_TIME_US = 5 * GLib.TIME_SPAN_SECOND; + var RemoteAccessApplet = GObject.registerClass( class RemoteAccessApplet extends PanelMenu.SystemIndicator { _init() { @@ -32,6 +35,7 @@ class RemoteAccessApplet extends PanelMenu.SystemIndicator { return; this._sharedIndicator = this._addIndicator(); + this._sharedIndicator.visible = false; this._sharedIndicator.icon_name = 'screen-shared-symbolic'; this._sharedIndicator.add_style_class_name('remote-access-indicator'); @@ -69,12 +73,41 @@ class RemoteAccessApplet extends PanelMenu.SystemIndicator { return recordingHandles.length > 0; } + _hideSharedIndicator() { + this._sharedIndicator.visible = false; + delete this._hideSharedIndicatorId; + return GLib.SOURCE_REMOVE; + } + _sync() { + if (this._hideSharedIndicatorId) { + GLib.source_remove(this._hideSharedIndicatorId); + delete this._hideSharedIndicatorId; + } + if (this._isScreenShared()) { + if (!this._sharedIndicator.visible) + this._visibleTimeUs = GLib.get_monotonic_time(); this._sharedIndicator.visible = true; this._sharedItem.visible = true; } else { - this._sharedIndicator.visible = false; + if (this._sharedIndicator.visible) { + const currentTimeUs = GLib.get_monotonic_time(); + const timeSinceVisibleUs = currentTimeUs - this._visibleTimeUs; + + if (timeSinceVisibleUs >= MIN_SHARED_INDICATOR_VISIBLE_TIME_US) { + this._hideSharedIndicator(); + } else { + const timeUntilHideUs = + MIN_SHARED_INDICATOR_VISIBLE_TIME_US - timeSinceVisibleUs; + this._hideSharedIndicatorId = + GLib.timeout_add( + GLib.PRIORITY_DEFAULT, + timeUntilHideUs / GLib.TIME_SPAN_MILLISECOND, + this._hideSharedIndicator.bind(this)); + } + } + this._sharedItem.visible = false; }