diff options
author | Aylur <[email protected]> | 2024-09-21 19:06:08 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-09-21 19:07:29 +0200 |
commit | ad8d3409fec4d7d4fd728f364a139947ff1185e3 (patch) | |
tree | 3e4ac867c3e1f543fec2f045a18b9d86c990a94f /examples | |
parent | a819c41afcdde7b4bbe0ecf04dc8a84c87cc3c75 (diff) |
fix(Variable): remove explicit run_dispose
let gc collect them
Diffstat (limited to 'examples')
-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 |
5 files changed, 185 insertions, 0 deletions
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(); + } +} |