[gnome-shell-extensions/wip/rstrode/heads-up-display: 2/62] Add top-icons extension
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions/wip/rstrode/heads-up-display: 2/62] Add top-icons extension
- Date: Thu, 26 Aug 2021 19:31:29 +0000 (UTC)
commit 66321f53be453c64e06345bdf119115c860cb978
Author: Florian Müllner <fmuellner gnome org>
Date: Wed May 20 17:44:50 2015 +0200
Add top-icons extension
extensions/top-icons/extension.js | 96 +++++++++++++++++++++++++++++++++++
extensions/top-icons/meson.build | 5 ++
extensions/top-icons/metadata.json.in | 10 ++++
extensions/top-icons/stylesheet.css | 1 +
meson.build | 1 +
5 files changed, 113 insertions(+)
---
diff --git a/extensions/top-icons/extension.js b/extensions/top-icons/extension.js
new file mode 100644
index 0000000..a8eec13
--- /dev/null
+++ b/extensions/top-icons/extension.js
@@ -0,0 +1,96 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+/* exported init */
+
+const { Clutter, Shell, St } = imports.gi;
+const Main = imports.ui.main;
+const PanelMenu = imports.ui.panelMenu;
+const System = imports.system;
+
+const PANEL_ICON_SIZE = 16;
+
+const STANDARD_TRAY_ICON_IMPLEMENTATIONS = [
+ 'bluetooth-applet',
+ 'gnome-sound-applet',
+ 'nm-applet',
+ 'gnome-power-manager',
+ 'keyboard',
+ 'a11y-keyboard',
+ 'kbd-scrolllock',
+ 'kbd-numlock',
+ 'kbd-capslock',
+ 'ibus-ui-gtk'
+];
+
+class SysTray {
+ constructor() {
+ this._icons = [];
+ this._tray = null;
+ }
+
+ _onTrayIconAdded(o, icon) {
+ let wmClass = icon.wm_class ? icon.wm_class.toLowerCase() : '';
+ if (STANDARD_TRAY_ICON_IMPLEMENTATIONS.includes(wmClass))
+ return;
+
+ let button = new PanelMenu.Button(0.5, null, true);
+
+ let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
+ let iconSize = PANEL_ICON_SIZE * scaleFactor;
+
+ icon.set({
+ width: iconSize,
+ height: iconSize,
+ x_align: Clutter.ActorAlign.CENTER,
+ y_align: Clutter.ActorAlign.CENTER
+ });
+
+ let iconBin = new St.Widget({
+ layout_manager: new Clutter.BinLayout()
+ });
+ iconBin.add_actor(icon);
+ button.add_actor(iconBin);
+
+ this._icons.push(icon);
+
+ button.connect('button-release-event', (actor, event) => {
+ icon.click(event);
+ });
+ button.connect('key-press-event', (actor, event) => {
+ icon.click(event);
+ });
+
+ icon.connect('destroy', () => {
+ button.destroy();
+ });
+
+ let role = wmClass || `${icon}`;
+ Main.panel.addToStatusArea(role, button);
+ }
+
+ _onTrayIconRemoved(o, icon) {
+ let parent = icon.get_parent();
+ parent.destroy();
+ this._icons.splice(this._icons.indexOf(icon), 1);
+ }
+
+ enable() {
+ this._tray = new Shell.TrayManager();
+ this._tray.connect('tray-icon-added',
+ this._onTrayIconAdded.bind(this));
+ this._tray.connect('tray-icon-removed',
+ this._onTrayIconRemoved.bind(this));
+ this._tray.manage_screen(Main.panel.actor);
+ }
+
+ disable() {
+ this._icons.forEach(icon => icon.get_parent().destroy());
+ this._icons = [];
+
+ this._tray = null;
+ System.gc(); // force finalizing tray to unmanage screen
+ }
+}
+
+function init() {
+ return new SysTray();
+}
diff --git a/extensions/top-icons/meson.build b/extensions/top-icons/meson.build
new file mode 100644
index 0000000..48504f6
--- /dev/null
+++ b/extensions/top-icons/meson.build
@@ -0,0 +1,5 @@
+extension_data += configure_file(
+ input: metadata_name + '.in',
+ output: metadata_name,
+ configuration: metadata_conf
+)
diff --git a/extensions/top-icons/metadata.json.in b/extensions/top-icons/metadata.json.in
new file mode 100644
index 0000000..f1e2436
--- /dev/null
+++ b/extensions/top-icons/metadata.json.in
@@ -0,0 +1,10 @@
+{
+"extension-id": "@extension_id@",
+"uuid": "@uuid@",
+"settings-schema": "@gschemaname@",
+"gettext-domain": "@gettext_domain@",
+"name": "Top Icons",
+"description": "Shows legacy tray icons on top",
+"shell-version": [ "@shell_current@" ],
+"url": "http://94.247.144.115/repo/topicons/"
+}
diff --git a/extensions/top-icons/stylesheet.css b/extensions/top-icons/stylesheet.css
new file mode 100644
index 0000000..25134b6
--- /dev/null
+++ b/extensions/top-icons/stylesheet.css
@@ -0,0 +1 @@
+/* This extensions requires no special styling */
diff --git a/meson.build b/meson.build
index b987f2d..6050c32 100644
--- a/meson.build
+++ b/meson.build
@@ -50,6 +50,7 @@ all_extensions = default_extensions
all_extensions += [
'auto-move-windows',
'native-window-placement',
+ 'top-icons',
'user-theme'
]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]