import GLib from "gi://GLib"; import Gio from "gi://Gio"; import Meta from "gi://Meta"; import St from "gi://St"; import Shell from "gi://Shell"; import * as Main from "resource:///org/gnome/shell/ui/main.js"; import { Extension } from "resource:///org/gnome/shell/extensions/extension.js"; import { SystemIndicator, QuickMenuToggle } from "resource:///org/gnome/shell/ui/quickSettings.js"; import GObject from "gi://GObject"; import { Button as PanelMenuButton } from "resource:///org/gnome/shell/ui/panelMenu.js"; const MyIndicator = GObject.registerClass( class MyIndicator extends SystemIndicator { _indicator: any; _settings?: Gio.Settings; constructor(extensioObject: Extension) { super(); this._indicator = this._addIndicator(); this._indicator.icon_name = "selection-mode-symbolic"; this._settings = extensioObject.getSettings(); this._settings!.bind("float", this._indicator, "active", Gio.SettingsBindFlags.DEFAULT); this.quickSettingsItems.push(this._indicator); } } ); const ExampleToggle = GObject.registerClass( class ExampleToggle extends QuickMenuToggle { _settings: Gio.Settings; constructor(extensionObject: Extension) { super({ title: "Float", subtitle: "Floating Window", iconName: "selection-mode-symbolic", toggleMode: true, }); this._settings = extensionObject.getSettings(); this._settings.bind("float", this, "checked", Gio.SettingsBindFlags.DEFAULT); } } ); export default class MyExtension extends Extension { _button?: PanelMenuButton; indicator?: SystemIndicator; settings?: Gio.Settings; enable() { const icon = new St.Icon({ icon_name: "face-laugh-symbolic", style_class: "system-status-icon", }); this._button = new PanelMenuButton(0.0, this.metadata.name, false); this._button.add_child(icon); this.settings = this.getSettings(); this._button.connect("button-press-event", () => this.toggleFloat()); this._button.connect("touch-event", () => this.toggleFloat()); // this._button.addChild(); // this.indicator = new MyIndicator(this); // this.indicator.quickSettingsItems.push(new ExampleToggle(this)); // Main.panel.statusArea.quickSettings.addExternalIndicator(this.indicator); Main.panel.addToStatusArea(this.uuid, this._button); } toggleFloat() { let bool = this.getSettings().get_boolean("float"); console.log(bool); this.getSettings().set_boolean("float", !bool); } disable() { this._button?.destroy(); this._button = undefined; // this.indicator?.quickSettingsItems.forEach((item) => item.destroy()); // this.indicator?.destroy(); // this.indicator = undefined; } }