From c4621119b32b4ff1b963d4cd7ee4be250f8e731b Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Mon, 13 Aug 2012 19:04:03 +0200 Subject: [PATCH] AccessibilityMenu: hide when not needed Tie the menu visibility to having at least one a11y feature enabled. https://bugzilla.gnome.org/show_bug.cgi?id=681528 --- js/ui/panel.js | 1 + js/ui/sessionMode.js | 4 +-- js/ui/status/accessibility.js | 47 ++++++++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/js/ui/panel.js b/js/ui/panel.js index 3bcc4ba1a..7153abdff 100644 --- a/js/ui/panel.js +++ b/js/ui/panel.js @@ -919,6 +919,7 @@ const PANEL_ITEM_IMPLEMENTATIONS = { 'appMenu': AppMenuButton, 'dateMenu': imports.ui.dateMenu.DateMenuButton, 'a11y': imports.ui.status.accessibility.ATIndicator, + 'a11yGreeter': imports.ui.status.accessibility.ATGreeterIndicator, 'volume': imports.ui.status.volume.Indicator, 'battery': imports.ui.status.power.Indicator, 'lockScreen': imports.ui.status.lockScreenMenu.Indicator, diff --git a/js/ui/sessionMode.js b/js/ui/sessionMode.js index f802dbd29..e926ba2e7 100644 --- a/js/ui/sessionMode.js +++ b/js/ui/sessionMode.js @@ -47,7 +47,7 @@ const _modes = { panel: { left: ['logo'], center: ['dateMenu'], - right: ['a11y', 'display', 'keyboard', + right: ['a11yGreeter', 'display', 'keyboard', 'volume', 'battery', 'powerMenu'] }, panelStyle: 'login-screen' @@ -84,7 +84,7 @@ const _modes = { panel: { left: [], center: ['dateMenu'], - right: ['a11y', 'keyboard', 'volume'] + right: ['a11yGreeter', 'keyboard', 'volume'] } }, diff --git a/js/ui/status/accessibility.js b/js/ui/status/accessibility.js index 804b7d2f3..479a15a70 100644 --- a/js/ui/status/accessibility.js +++ b/js/ui/status/accessibility.js @@ -2,6 +2,7 @@ const Gio = imports.gi.Gio; const Lang = imports.lang; +const Mainloop = imports.mainloop; const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; @@ -69,6 +70,25 @@ const ATIndicator = new Lang.Class({ this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this.menu.addSettingsAction(_("Universal Access Settings"), 'gnome-universal-access-panel.desktop'); + + this._syncMenuVisibility(); + }, + + _syncMenuVisibility: function() { + this._syncMenuVisibilityIdle = 0; + + let items = this.menu._getMenuItems(); + + this.actor.visible = items.some(function(f) { return !!f.state; }); + + return false; + }, + + _queueSyncMenuVisibility: function() { + if (this._syncMenuVisibilityIdle) + return; + + this._syncMenuVisbilityIdle = Mainloop.idle_add(Lang.bind(this, this._syncMenuVisibility)); }, _buildItemExtended: function(string, initial_value, writable, on_set) { @@ -90,9 +110,11 @@ const ATIndicator = new Lang.Class({ function(enabled) { return settings.set_boolean(key, enabled); }); - settings.connect('changed::'+key, function() { + settings.connect('changed::'+key, Lang.bind(this, function() { widget.setToggleState(settings.get_boolean(key)); - }); + + this._queueSyncMenuVisibility(); + })); return widget; }, @@ -124,7 +146,7 @@ const ATIndicator = new Lang.Class({ wmSettings.reset(KEY_WM_THEME); } }); - interfaceSettings.connect('changed::' + KEY_GTK_THEME, function() { + interfaceSettings.connect('changed::' + KEY_GTK_THEME, Lang.bind(this, function() { let value = interfaceSettings.get_string(KEY_GTK_THEME); if (value == HIGH_CONTRAST_THEME) { highContrast.setToggleState(true); @@ -132,7 +154,9 @@ const ATIndicator = new Lang.Class({ highContrast.setToggleState(false); gtkTheme = value; } - }); + + this._queueSyncMenuVisibility(); + })); interfaceSettings.connect('changed::' + KEY_ICON_THEME, function() { let value = interfaceSettings.get_string(KEY_ICON_THEME); if (value != HIGH_CONTRAST_THEME) @@ -161,11 +185,22 @@ const ATIndicator = new Lang.Class({ else settings.reset(KEY_TEXT_SCALING_FACTOR); }); - settings.connect('changed::' + KEY_TEXT_SCALING_FACTOR, function() { + settings.connect('changed::' + KEY_TEXT_SCALING_FACTOR, Lang.bind(this, function() { let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR); let active = (factor > 1.0); widget.setToggleState(active); - }); + + this._queueSyncMenuVisibility(); + })); return widget; } }); + +const ATGreeterIndicator = new Lang.Class({ + Name: 'ATGreeterIndicator', + Extends: ATIndicator, + + // Override visibility handling to be always visible + _syncMenuVisibility: function() { }, + _queueSyncMenuVisibility: function() { } +});