Skip to content

Instantly share code, notes, and snippets.

@fmuellner
Last active August 23, 2017 21:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmuellner/e1aaec3169990fa7b7bd95da4e0a915a to your computer and use it in GitHub Desktop.
Save fmuellner/e1aaec3169990fa7b7bd95da4e0a915a to your computer and use it in GitHub Desktop.
Adjust topIcons extension to the legacy tray removal in GNOME 3.26
From 03b014746fa67bb76d73d9ff5274dce461fa413b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
Date: Sat, 19 Aug 2017 14:34:00 +0200
Subject: [PATCH 1/2] Adjust to tray removal in gnome-shell
GNOME 3.26 will no longer display status icons by default, so there is
no system tray we can take over. Take this case into account to avoid
errors, although this alone doesn't give us back status icons - we will
do that in a second step by starting to manage our own tray.
---
extension.js | 13 ++++++++-----
metadata.json | 3 ++-
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/extension.js b/extension.js
index bcd7639..813d44c 100644
--- a/extension.js
+++ b/extension.js
@@ -16,7 +16,7 @@ let trayAddedId = 0;
let trayRemovedId = 0;
let getSource = null;
let icons = [];
-let notificationDaemon;
+let notificationDaemon = null;
const PANEL_ICON_SIZE = 24;
@@ -25,18 +25,20 @@ function init() {
notificationDaemon = Main.legacyTray;
NotificationDaemon.STANDARD_TRAY_ICON_IMPLEMENTATIONS = imports.ui.legacyTray.STANDARD_TRAY_ICON_IMPLEMENTATIONS;
}
- else if (Main.notificationDaemon._fdoNotificationDaemon) {
+ else if (Main.notificationDaemon._fdoNotificationDaemon &&
+ Main.notificationDaemon._fdoNotificationDaemon._trayManager) {
notificationDaemon = Main.notificationDaemon._fdoNotificationDaemon;
getSource = Lang.bind(notificationDaemon, NotificationDaemon.FdoNotificationDaemon.prototype._getSource);
}
- else {
+ else if (Main.notificationDaemon._trayManager) {
notificationDaemon = Main.notificationDaemon;
getSource = Lang.bind(notificationDaemon, NotificationDaemon.NotificationDaemon.prototype._getSource);
}
}
function enable() {
- GLib.idle_add(GLib.PRIORITY_LOW, moveToTop);
+ if (notificationDaemon)
+ GLib.idle_add(GLib.PRIORITY_LOW, moveToTop);
}
function createSource (title, pid, ndata, sender, trayIcon) {
@@ -190,5 +192,6 @@ function moveToTray() {
}
function disable() {
- moveToTray();
+ if (notificationDaemon)
+ moveToTray();
}
diff --git a/metadata.json b/metadata.json
index 3e21a19..120ea7a 100644
--- a/metadata.json
+++ b/metadata.json
@@ -12,7 +12,8 @@
"3.13.4",
"3.16",
"3.18",
- "3.20"
+ "3.20",
+ "3.26"
],
"url": "",
"uuid": "topIcons@adel.gadllah@gmail.com",
--
2.13.3
From de9d3b340e046abc840e15633f91ae70c36b667d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
Date: Sat, 19 Aug 2017 21:17:18 +0200
Subject: [PATCH 2/2] Manage system tray ourselves on recent GNOME versions
Now that gnome-shell removed its legacy tray, we have to create our
own tray manager to monitor status icon additions and removals.
---
extension.js | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/extension.js b/extension.js
index 813d44c..953ea28 100644
--- a/extension.js
+++ b/extension.js
@@ -11,12 +11,14 @@ const PanelMenu = imports.ui.panelMenu;
const Meta = imports.gi.Meta;
const Mainloop = imports.mainloop;
const NotificationDaemon = imports.ui.notificationDaemon;
+const System = imports.system;
let trayAddedId = 0;
let trayRemovedId = 0;
let getSource = null;
let icons = [];
let notificationDaemon = null;
+let sysTray = null;
const PANEL_ICON_SIZE = 24;
@@ -34,11 +36,20 @@ function init() {
notificationDaemon = Main.notificationDaemon;
getSource = Lang.bind(notificationDaemon, NotificationDaemon.NotificationDaemon.prototype._getSource);
}
+ else {
+ NotificationDaemon.STANDARD_TRAY_ICON_IMPLEMENTATIONS = {
+ 'bluetooth-applet': 1, 'gnome-sound-applet': 1, 'nm-applet': 1,
+ 'gnome-power-manager': 1, 'keyboard': 1, 'a11y-keyboard': 1,
+ 'kbd-scrolllock': 1, 'kbd-numlock': 1, 'kbd-capslock': 1, 'ibus-ui-gtk': 1
+ };
+ }
}
function enable() {
if (notificationDaemon)
GLib.idle_add(GLib.PRIORITY_LOW, moveToTop);
+ else
+ createTray();
}
function createSource (title, pid, ndata, sender, trayIcon) {
@@ -119,6 +130,21 @@ function onTrayIconRemoved(o, icon) {
icons.splice(icons.indexOf(icon), 1);
}
+function createTray() {
+ sysTray = new Shell.TrayManager();
+ sysTray.connect('tray-icon-added', onTrayIconAdded);
+ sysTray.connect('tray-icon-removed', onTrayIconRemoved);
+ sysTray.manage_screen(global.screen, Main.panel.actor);
+}
+
+function destroyTray() {
+ icons.forEach(icon => { icon.get_parent().destroy(); });
+ icons = [];
+
+ sysTray = null;
+ System.gc(); // force finalizing tray to unmanage screen
+}
+
function moveToTop() {
notificationDaemon._trayManager.disconnect(notificationDaemon._trayIconAddedId);
notificationDaemon._trayManager.disconnect(notificationDaemon._trayIconRemovedId);
@@ -194,4 +220,6 @@ function moveToTray() {
function disable() {
if (notificationDaemon)
moveToTray();
+ else
+ destroyTray();
}
--
2.13.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment