ADD: working button to control boolean float

This commit is contained in:
2024-07-01 00:30:33 +01:00
parent 48c0f82593
commit a391b6a835
8 changed files with 100 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
NAME=floarbar
NAME=floatbar
DOMAIN=tomtroeger.de
.PHONY: all pack install clean
@@ -27,4 +27,11 @@ install: $(NAME).zip
@mv dist ~/.local/share/gnome-shell/extensions/$(NAME)@$(DOMAIN)
clean:
@rm -rf dist node_modules $(NAME).zip
@rm -rf dist node_modules $(NAME).zip
test:
@dbus-run-session -- gnome-shell --nested --wayland
full:
@make install
@make test

1
ambient.d.ts vendored
View File

@@ -2,3 +2,4 @@ import "@girs/gjs";
import "@girs/gjs/dom";
import "@girs/gnome-shell/ambient";
import "@girs/gnome-shell/extensions/global";
import "@girs/gnome-shell/ui/";

View File

@@ -1,20 +1,86 @@
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 {
gsettings?: Gio.Settings;
animationsEnabled: boolean = true;
_button?: PanelMenuButton;
indicator?: SystemIndicator;
settings?: Gio.Settings;
enable() {
this.gsettings = this.getSettings();
this.animationsEnabled = this.gsettings!.get_value("padding-inner").deepUnpack() ?? 8;
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.gsettings = undefined;
this._button?.destroy();
this._button = undefined;
// this.indicator?.quickSettingsItems.forEach((item) => item.destroy());
// this.indicator?.destroy();
// this.indicator = undefined;
}
}

BIN
floatbar.zip Normal file

Binary file not shown.

View File

@@ -22,7 +22,7 @@ export default class GnomeRectanglePreferences extends ExtensionPreferences {
const animationEnabled = new Adw.SwitchRow({
title: _("Enabled"),
subtitle: _("Wether to animate windows"),
subtitle: _("Floating Window"),
});
animationGroup.add(animationEnabled);
@@ -45,7 +45,7 @@ export default class GnomeRectanglePreferences extends ExtensionPreferences {
window.add(page);
this._settings!.bind("animate", animationEnabled, "active", Gio.SettingsBindFlags.DEFAULT);
this._settings!.bind("float", animationEnabled, "active", Gio.SettingsBindFlags.DEFAULT);
this._settings!.bind("padding-inner", paddingInner, "value", Gio.SettingsBindFlags.DEFAULT);
}
}

BIN
schemas/gschemas.compiled Normal file

Binary file not shown.

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema id="org.gnome.shell.extensions.my-extension" path="/org/gnome/shell/extensions/my-extension/">
<key name="padding-inner" type="i">
<default>8</default>
<summary>Inner padding</summary>
<description>Padding between windows</description>
</key>
<key name="float" type="b">
<default>true</default>
<summary>Floating</summary>
<description>Whether the topbar floats or not</description>
</key>
</schema>
</schemalist>

View File

@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"module": "ES2022",
"moduleResolution": "Bundler",
"outDir": "./dist",
"sourceMap": false,
"strict": true,