diff options
-rw-r--r-- | core/gjs/src/variable.ts | 1 | ||||
-rw-r--r-- | core/lua/astal/variable.lua | 3 | ||||
-rw-r--r-- | core/src/widget/box.vala | 7 | ||||
-rw-r--r-- | core/src/widget/stack.vala | 7 | ||||
-rw-r--r-- | examples/js/simple-bar/widget/Bar.tsx | 2 | ||||
-rw-r--r-- | examples/lua/simple-bar/widget/Bar.lua | 2 | ||||
-rw-r--r-- | examples/vala/simple-bar/app.vala | 14 | ||||
-rw-r--r-- | examples/vala/simple-bar/flake.lock | 62 | ||||
-rw-r--r-- | examples/vala/simple-bar/flake.nix | 36 | ||||
-rw-r--r-- | examples/vala/simple-bar/meson.build | 23 | ||||
-rw-r--r-- | examples/vala/simple-bar/widget/Bar.vala | 50 |
11 files changed, 195 insertions, 12 deletions
diff --git a/core/gjs/src/variable.ts b/core/gjs/src/variable.ts index 84f8cc5..8739ef6 100644 --- a/core/gjs/src/variable.ts +++ b/core/gjs/src/variable.ts @@ -101,7 +101,6 @@ class VariableWrapper<T> extends Function { drop() { this.variable.emit("dropped") - idle(() => this.variable.run_dispose()) } onDropped(callback: () => void) { diff --git a/core/lua/astal/variable.lua b/core/lua/astal/variable.lua index da2e894..377b448 100644 --- a/core/lua/astal/variable.lua +++ b/core/lua/astal/variable.lua @@ -124,9 +124,6 @@ end function Variable:drop() self.variable.emit_dropped() - Astal.Time.idle(GObject.Closure(function() - self.variable.run_dispose() - end)) end ---@param callback function diff --git a/core/src/widget/box.vala b/core/src/widget/box.vala index 0e069e0..0008fd4 100644 --- a/core/src/widget/box.vala +++ b/core/src/widget/box.vala @@ -42,10 +42,11 @@ public class Box : Gtk.Box { private void _set_children(List<weak Gtk.Widget> arr) { foreach(var child in get_children()) { - remove(child); - - if (!no_implicit_destroy && arr.find(child).length() == 0) + if (!no_implicit_destroy && arr.find(child).length() == 0) { child.destroy(); + } else { + remove(child); + } } foreach(var child in arr) diff --git a/core/src/widget/stack.vala b/core/src/widget/stack.vala index 020e716..00adf7f 100644 --- a/core/src/widget/stack.vala +++ b/core/src/widget/stack.vala @@ -16,10 +16,11 @@ public class Astal.Stack : Gtk.Stack { private void _set_children(List<weak Gtk.Widget> arr) { foreach(var child in get_children()) { - remove(child); - - if (!no_implicit_destroy && arr.find(child).length() == 0) + if (!no_implicit_destroy && arr.find(child).length() == 0) { child.destroy(); + } else { + remove(child); + } } var i = 0; diff --git a/examples/js/simple-bar/widget/Bar.tsx b/examples/js/simple-bar/widget/Bar.tsx index 19e1133..644e835 100644 --- a/examples/js/simple-bar/widget/Bar.tsx +++ b/examples/js/simple-bar/widget/Bar.tsx @@ -56,7 +56,7 @@ function BatteryLevel() { return <box className="Battery" visible={bind(bat, "isPresent")}> - <icon icon={bind(bat, "iconName")} /> + <icon icon={bind(bat, "batteryIconName")} /> <label label={bind(bat, "percentage").as(p => `${Math.floor(p * 100)} %` )} /> diff --git a/examples/lua/simple-bar/widget/Bar.lua b/examples/lua/simple-bar/widget/Bar.lua index 56cb060..d44db2d 100644 --- a/examples/lua/simple-bar/widget/Bar.lua +++ b/examples/lua/simple-bar/widget/Bar.lua @@ -97,7 +97,7 @@ local function BatteryLevel() class_name = "Battery", visible = bind(bat, "is-present"), Widget.Icon({ - icon = bind(bat, "icon-name"), + icon = bind(bat, "battery-icon-name"), }), Widget.Label({ label = bind(bat, "percentage"):as(function(p) diff --git a/examples/vala/simple-bar/app.vala b/examples/vala/simple-bar/app.vala new file mode 100644 index 0000000..ccd3957 --- /dev/null +++ b/examples/vala/simple-bar/app.vala @@ -0,0 +1,14 @@ +class Application : Astal.Application { + Application() { + + } + + public override void activate () { + this.add_window(new Bar()); + } + + public static int main() { + var app = new Application(); + return app.run(null); + } +} diff --git a/examples/vala/simple-bar/flake.lock b/examples/vala/simple-bar/flake.lock new file mode 100644 index 0000000..34fb84f --- /dev/null +++ b/examples/vala/simple-bar/flake.lock @@ -0,0 +1,62 @@ +{ + "nodes": { + "astal": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1726702968, + "narHash": "sha256-kRS/WZzwBiVgfBVz0HTRl4FnmUEHDIRp0962rrFtvk8=", + "owner": "aylur", + "repo": "astal", + "rev": "a819c41afcdde7b4bbe0ecf04dc8a84c87cc3c75", + "type": "github" + }, + "original": { + "owner": "aylur", + "repo": "astal", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716293225, + "narHash": "sha256-pU9ViBVE3XYb70xZx+jK6SEVphvt7xMTbm6yDIF4xPs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3eaeaeb6b1e08a016380c279f8846e0bd8808916", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1726463316, + "narHash": "sha256-gI9kkaH0ZjakJOKrdjaI/VbaMEo9qBbSUl93DnU7f4c=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "99dc8785f6a0adac95f5e2ab05cc2e1bf666d172", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "astal": "astal", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/vala/simple-bar/flake.nix b/examples/vala/simple-bar/flake.nix new file mode 100644 index 0000000..9b977a2 --- /dev/null +++ b/examples/vala/simple-bar/flake.nix @@ -0,0 +1,36 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + astal.url = "github:aylur/astal"; + }; + + outputs = { + self, + nixpkgs, + astal, + }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.${system} = { + default = pkgs.stdenv.mkDerivation { + pname = "simple-bar"; + version = "git"; + src = ./.; + + nativeBuildInputs = [ + pkgs.meson + pkgs.ninja + pkgs.pkg-config + pkgs.vala + pkgs.gobject-introspection + ]; + + buildInputs = [ + astal.packages.${system}.default + astal.packages.${system}.battery + ]; + }; + }; + }; +} diff --git a/examples/vala/simple-bar/meson.build b/examples/vala/simple-bar/meson.build new file mode 100644 index 0000000..960ce0d --- /dev/null +++ b/examples/vala/simple-bar/meson.build @@ -0,0 +1,23 @@ +project('simple-bar', 'vala', 'c') + +sources = files( + 'widget/Bar.vala', + 'app.vala', +) + +pkgconfig_deps = [ + dependency('glib-2.0'), + dependency('gobject-2.0'), + dependency('gtk+-3.0'), + dependency('astal-0.1'), + dependency('astal-battery-0.1'), +] + +# needed for GLib.Math +deps = pkgconfig_deps + meson.get_compiler('c').find_library('m') + +executable( + 'simple-bar', + sources, + dependencies: deps, +) diff --git a/examples/vala/simple-bar/widget/Bar.vala b/examples/vala/simple-bar/widget/Bar.vala new file mode 100644 index 0000000..4d42f9c --- /dev/null +++ b/examples/vala/simple-bar/widget/Bar.vala @@ -0,0 +1,50 @@ +class Battery : Gtk.Box { + Astal.Icon icon = new Astal.Icon(); + Astal.Label label = new Astal.Label(); + + public Battery() { + add(icon); + add(label); + + var bat = AstalBattery.get_default(); + bat.bind_property("battery-icon-name", icon, "icon", BindingFlags.SYNC_CREATE); + bat.bind_property("percentage", label, "label", BindingFlags.SYNC_CREATE, (_, src, ref trgt) => { + var p = Math.floor(src.get_double() * 100); + trgt.set_string(@"$p%"); + return true; + }); + } +} + +class Clock : Astal.Label { + string format; + Astal.Time interval; + + void sync() { + label = new DateTime.now_local().format(format); + } + + public Clock(string format = "%H:%M - %A %e.") { + this.format = format; + interval = Astal.Time.interval(1000, null); + interval.now.connect(sync); + destroy.connect(interval.cancel); + } +} + +class Left : Gtk.Box { + public Left() { + add(new Clock()); + add(new Battery()); + } +} + +class Bar : Astal.Window { + public Bar() { + add(new Astal.CenterBox() { + start_widget = new Left() + }); + + show_all(); + } +} |