diff options
53 files changed, 953 insertions, 1124 deletions
diff --git a/docs/guide/getting-started/installation.md b/docs/guide/getting-started/installation.md index fa7863e..e32b6a9 100644 --- a/docs/guide/getting-started/installation.md +++ b/docs/guide/getting-started/installation.md @@ -1,11 +1,5 @@ # Installation -## Nix - -maintainer: [@Aylur](https://github.com/Aylur) - -Read more about it on the [nix page](./nix#astal) - ## Arch maintainer: [@kotontrion](https://github.com/kotontrion) @@ -22,7 +16,13 @@ yay -S libastal-meta ::: -## Bulding libastal from source +## Nix + +maintainer: [@Aylur](https://github.com/Aylur) + +Read more about it on the [nix page](./nix#astal) + +## Bulding From Source 1. Install the following dependencies diff --git a/docs/guide/getting-started/nix.md b/docs/guide/getting-started/nix.md index 1e0572e..6bc5d9b 100644 --- a/docs/guide/getting-started/nix.md +++ b/docs/guide/getting-started/nix.md @@ -5,13 +5,15 @@ next: --- # Nix -## Astal - Using Astal on Nix will require you to package your project. +## TypeScript + +Using [AGS](https://aylur.github.io/ags/) as the bundler. + :::code-group -```nix [<i class="devicon-lua-plain"></i> Lua] +```nix [<i class="devicon-nixos-plain"></i> flake.nix] { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; @@ -19,80 +21,49 @@ Using Astal on Nix will require you to package your project. url = "github:aylur/astal"; inputs.nixpkgs.follows = "nixpkgs"; }; + ags = { + url = "github:aylur/ags"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { self, nixpkgs, astal }: let + outputs = { self, nixpkgs, astal, ags }: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; in { - packages.${system}.default = astal.lib.mkLuaPackage { - inherit pkgs; - src = ./path/to/project; # should contain init.lua - - # add extra glib packages or binaries - extraPackages = [ - astal.packages.${system}.battery - pkgs.dart-sass + packages.${system}. default = pkgs.stdenvNoCC.mkDerivation rec { + name = "my-shell"; + src = ./.; + + nativeBuildInputs = [ + ags.packages.${system}.default + pkgs.wrapGAppsHook + pkgs.gobject-introspection ]; - }; - }; -} -``` -```nix [<i class="devicon-python-plain"></i> Python] -# Not documented yet -``` - -```nix [<i class="devicon-vala-plain"></i> Vala] -# keep in mind that this is just the nix derivation -# and you still have to use some build tool like meson -{ - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/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 { - name = "my-shell"; - src = ./.; - - nativeBuildInputs = with pkgs; [ - meson - ninja - pkg-config - vala - gobject-introspection - ]; + buildInputs = with astal.packages.${system}; [ + astal3 + io + # any other package + ]; - # add extra packages - buildInputs = [ - astal.packages.${system}.astal - ]; - }; + installPhase = '' + mkdir -p $out/bin + ags bundle app.ts $out/bin/${name} + ''; }; }; } ``` -```nix [<i class="devicon-typescript-plain"></i> TypeScript] -# The usage of AGS (read below) is recommended -# Usage without AGS is not yet documented -``` - ::: -## AGS - -The recommended way to use [AGS](../typescript/first-widgets#first-widgets) on NixOS is through the home-manager module. - -Example content of a `flake.nix` file that contains your `homeConfigurations`. +:::tip +You can use any other bundler too like `esbuild` +which is what `ags` uses under the hood. +::: -<!--TODO: remove v2 after merge--> +## Lua :::code-group @@ -100,28 +71,26 @@ Example content of a `flake.nix` file that contains your `homeConfigurations`. { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - home-manager = { - url = "github:nix-community/home-manager"; + astal = { + url = "github:aylur/astal"; inputs.nixpkgs.follows = "nixpkgs"; }; - - # add ags https://github.com/Aylur/ags/pull/504 - ags.url = "github:aylur/ags/v2"; }; - outputs = { home-manager, nixpkgs, ... }@inputs: - let + outputs = { self, nixpkgs, astal }: let system = "x86_64-linux"; - in - { - homeConfigurations."${username}" = home-manager.lib.homeManagerConfiguration { - pkgs = import nixpkgs { inherit system; }; - - # pass inputs as specialArgs - extraSpecialArgs = { inherit inputs; }; + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.${system}.default = astal.lib.mkLuaPackage { + inherit pkgs; + name = "my-shell"; # how to name the executable + src = ./path/to/project; # should contain init.lua - # import your home.nix - modules = [ ./home-manager/home.nix ]; + # add extra glib packages or binaries + extraPackages = [ + astal.packages.${system}.battery + pkgs.dart-sass + ]; }; }; } @@ -129,65 +98,58 @@ Example content of a `flake.nix` file that contains your `homeConfigurations`. ::: -Example content of `home.nix` file +## Python :::code-group -```nix [<i class="devicon-nixos-plain"></i> home.nix] -{ inputs, pkgs, ... }: -{ - # add the home manager module - imports = [ inputs.ags.homeManagerModules.default ]; - - programs.ags = { - enable = true; - configDir = ../ags; - - # additional packages to add to gjs's runtime - extraPackages = with pkgs; [ - inputs.ags.packages.${pkgs.system}.battery - fzf - ]; - }; -} +```nix [<i class="devicon-nixos-plain"></i> flake.nix] +# Not documented yet ``` ::: -AGS by default only includes the core `astal3/astal4` and `astal-io` libraries. -If you want to include any other [library](../libraries/references) you have to add them to `extraPackages`. -You can also add binaries which will be added to the gjs runtime. - -:::warning -The `configDir` option symlinks the given path to `~/.config/ags`. -If you already have your source code there leave it as `null`. -::: +## Vala -The AGS flake does not expose the `astal` cli to the home environment, you have to do that yourself if you want: +Keep in mind that this is just the nix derivation +and you still have to use some build tool like meson. :::code-group -```nix [<i class="devicon-nixos-plain"></i> home.nix] -home.packages = [ inputs.ags.packages.${pkgs.system}.io ]; -``` - -```sh [<i class="devicon-bash-plain"></i> sh] -astal --help -``` - -::: - -Same applies to the `extraPackages` option, it does not expose the passed packages to the home environment. -To make astal cli tools available to home environments, you have to add them yourself: - -:::code-group +```nix [<i class="devicon-nixos-plain"></i> flake.nix] +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + astal = { + url = "github:aylur/astal"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; -```nix [<i class="devicon-nixos-plain"></i> home.nix] -home.packages = [ inputs.ags.packages.${pkgs.system}.notifd ]; -``` + outputs = { self, nixpkgs, astal }: let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.${system}.default = pkgs.stdenv.mkDerivation { + name = "my-shell"; + src = ./.; + + nativeBuildInputs = with pkgs; [ + meson + ninja + pkg-config + vala + gobject-introspection + ]; -```sh [<i class="devicon-bash-plain"></i> sh] -astal-notifd --help + buildInputs = [ + astal.packages.${system}.io + astal.packages.${system}.astal3 + astal.packages.${system}.battery + # add extra packages + ]; + }; + }; +} ``` ::: diff --git a/docs/guide/libraries/apps.md b/docs/guide/libraries/apps.md index 1871d18..f1748db 100644 --- a/docs/guide/libraries/apps.md +++ b/docs/guide/libraries/apps.md @@ -3,40 +3,6 @@ Library and CLI tool for querying and launching applications that have a corresponding `.desktop` file. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac libjson-glib-dev gobject-introspection -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/apps -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Apps reference](https://aylur.github.io/libastal/apps). @@ -106,3 +72,37 @@ foreach (var app in apps.fuzzy_query("firefox")) { ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac libjson-glib-dev gobject-introspection +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/apps +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/auth.md b/docs/guide/libraries/auth.md index d5f0a49..b52e38a 100644 --- a/docs/guide/libraries/auth.md +++ b/docs/guide/libraries/auth.md @@ -2,51 +2,6 @@ Library and CLI tool for authentication using [pam](https://github.com/linux-pam/linux-pam). -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson pam gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson pam-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -# Not yet documented -``` - -::: - -::: warning On NixOS you have to add `astal-auth` to `security.pam`. -::: code-group - -```nix [configuration.nix] -{ - security.pam.services.astal-auth = {} -} -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/auth -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Auth reference](https://aylur.github.io/libastal/auth). @@ -105,3 +60,48 @@ end) ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson pam gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson pam-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +# Not yet documented +``` + +::: + +::: warning On NixOS you have to add `astal-auth` to `security.pam`. +::: code-group + +```nix [configuration.nix] +{ + security.pam.services.astal-auth = {} +} +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/auth +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/battery.md b/docs/guide/libraries/battery.md index 56f955c..7e6fe24 100644 --- a/docs/guide/libraries/battery.md +++ b/docs/guide/libraries/battery.md @@ -2,45 +2,6 @@ Library and CLI tool for monitoring [upowerd](https://upower.freedesktop.org/) devices. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac libjson-glib-dev gobject-introspection -``` - -::: - -::: info -Although UPower is not a direct build dependency, -it should be self-explanatory that the daemon is required to be available at runtime. -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/battery -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Battery reference](https://aylur.github.io/libastal/battery). @@ -84,3 +45,42 @@ print(battery.percentage) ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac libjson-glib-dev gobject-introspection +``` + +::: + +::: info +Although UPower is not a direct build dependency, +it should be self-explanatory that the daemon is required to be available at runtime. +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/battery +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/bluetooth.md b/docs/guide/libraries/bluetooth.md index 03ac9c9..9a3e5b8 100644 --- a/docs/guide/libraries/bluetooth.md +++ b/docs/guide/libraries/bluetooth.md @@ -2,45 +2,6 @@ Library for monitoring [bluez](https://www.bluez.org/) over dbus. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac gobject-introspection -``` - -::: - -::: info -Although bluez is not a direct build dependency, -it should be self-explanatory that the daemon is required to be available at runtime. -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/bluetooth -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Bluetooth reference](https://aylur.github.io/libastal/bluetooth). @@ -91,3 +52,42 @@ end ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac gobject-introspection +``` + +::: + +::: info +Although bluez is not a direct build dependency, +it should be self-explanatory that the daemon is required to be available at runtime. +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/bluetooth +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/cava.md b/docs/guide/libraries/cava.md index e695e16..60b2824 100644 --- a/docs/guide/libraries/cava.md +++ b/docs/guide/libraries/cava.md @@ -2,6 +2,46 @@ Audio visualizer using [cava](https://github.com/karlstav/cava). +## Usage + +You can browse the [Cava reference](https://aylur.github.io/libastal/cava). + +### CLI + +There is no CLI for this library, use the one provided by cava. + +```sh +cava +``` + +### Library + +:::code-group + +```js [<i class="devicon-javascript-plain"></i> JavaScript] +import Cava from "gi://AstalCava" + +const cava = Cava.get_default() + +cava.connect("notify::values", () => { + print(cava.get_values()) +}) +``` + +```py [<i class="devicon-python-plain"></i> Python] +# Not yet documented +``` + +```lua [<i class="devicon-lua-plain"></i> Lua] +-- Not yet documented +``` + +```vala [<i class="devicon-vala-plain"></i> Vala] +// Not yet documented +``` + +::: + ## Installation 1. install dependencies @@ -49,43 +89,3 @@ meson setup --prefix /usr build ``` ::: - -## Usage - -You can browse the [Cava reference](https://aylur.github.io/libastal/cava). - -### CLI - -There is no CLI for this library, use the one provided by cava. - -```sh -cava -``` - -### Library - -:::code-group - -```js [<i class="devicon-javascript-plain"></i> JavaScript] -import Cava from "gi://AstalCava" - -const cava = Cava.get_default() - -cava.connect("notify::values", () => { - print(cava.get_values()) -}) -``` - -```py [<i class="devicon-python-plain"></i> Python] -# Not yet documented -``` - -```lua [<i class="devicon-lua-plain"></i> Lua] --- Not yet documented -``` - -```vala [<i class="devicon-vala-plain"></i> Vala] -// Not yet documented -``` - -::: diff --git a/docs/guide/libraries/greet.md b/docs/guide/libraries/greet.md index f0cd012..47f98b9 100644 --- a/docs/guide/libraries/greet.md +++ b/docs/guide/libraries/greet.md @@ -2,45 +2,6 @@ Library and CLI tool for sending requests to [greetd](https://sr.ht/~kennylevinsen/greetd/). -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac libjson-glib-dev gobject-introspection -``` - -::: - -::: info -Although `greetd` is not a direct build dependency, -it should be self-explanatory that the daemon is required to be available at runtime. -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/greet -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Greet reference](https://aylur.github.io/libastal/greet). @@ -92,3 +53,42 @@ try { ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac libjson-glib-dev gobject-introspection +``` + +::: + +::: info +Although `greetd` is not a direct build dependency, +it should be self-explanatory that the daemon is required to be available at runtime. +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/greet +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/hyprland.md b/docs/guide/libraries/hyprland.md index 94a398f..82d9e9d 100644 --- a/docs/guide/libraries/hyprland.md +++ b/docs/guide/libraries/hyprland.md @@ -2,40 +2,6 @@ Library and CLI tool for monitoring the [Hyprland socket](https://wiki.hyprland.org/IPC/). -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac libjson-glib-dev gobject-introspection -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/hyprland -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Hyprland reference](https://aylur.github.io/libastal/hyprland). @@ -84,3 +50,37 @@ end ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac libjson-glib-dev gobject-introspection +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/hyprland +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/mpris.md b/docs/guide/libraries/mpris.md index 30f3d13..c2283cc 100644 --- a/docs/guide/libraries/mpris.md +++ b/docs/guide/libraries/mpris.md @@ -6,52 +6,6 @@ exposing an mpris interface through dbus. An alternative for [playerctl](https://github.com/altdesktop/playerctl) that better integrates with astal. -:::warning -In order for network cover art urls to be cached (spotify for example) -make sure `gvfs` is enabled. - -:::code-group - -```nix [<i class="devicon-nixos-plain"></i> configuration.nix] -services.gvfs.enable = true; -``` - -::: - -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala gvfs json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc gvfs json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac gvfs libjson-glib-dev gobject-introspection -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/mpris -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Mpris reference](https://aylur.github.io/libastal/mpris). @@ -99,3 +53,49 @@ end ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala gvfs json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc gvfs json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac gvfs libjson-glib-dev gobject-introspection +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/mpris +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` + +:::warning +In order for network cover art urls to be cached (spotify for example) +make sure `gvfs` is enabled. + +:::code-group + +```nix [<i class="devicon-nixos-plain"></i> configuration.nix] +services.gvfs.enable = true; +``` + +::: diff --git a/docs/guide/libraries/network.md b/docs/guide/libraries/network.md index 21c7b10..79a217c 100644 --- a/docs/guide/libraries/network.md +++ b/docs/guide/libraries/network.md @@ -2,40 +2,6 @@ Wrapper library over [networkmanager](https://networkmanager.dev/) to better integrate with Astal. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala libnm gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc NetworkManager-libnm-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac libnm-dev gobject-introspection -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/network -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Network reference](https://aylur.github.io/libastal/network). @@ -81,3 +47,37 @@ print(network.wifi.ssid) ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala libnm gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc NetworkManager-libnm-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac libnm-dev gobject-introspection +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/network +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/notifd.md b/docs/guide/libraries/notifd.md index 4208700..1d61099 100644 --- a/docs/guide/libraries/notifd.md +++ b/docs/guide/libraries/notifd.md @@ -6,40 +6,6 @@ A [notification daemon](https://specifications.freedesktop.org/notification-spec The first instantiation of the [Notifd](https://aylur.github.io/libastal/notifd/class.Notifd.html) class will become the daemon and every subsequent instantiation will queue up to act as the daemon and will act as a client in the meantime. This means this library can be used throughout multiple processes. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala gdk-pixbuf2 json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc gdk-pixbuf2-devel json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac libgdk-pixbuf-2.0-dev libjson-glib-dev gobject-introspection -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/notifd -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Notifd reference](https://aylur.github.io/libastal/notifd). @@ -93,3 +59,37 @@ end ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala gdk-pixbuf2 json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc gdk-pixbuf2-devel json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac libgdk-pixbuf-2.0-dev libjson-glib-dev gobject-introspection +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/notifd +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/powerprofiles.md b/docs/guide/libraries/powerprofiles.md index bdafcde..b42d7c6 100644 --- a/docs/guide/libraries/powerprofiles.md +++ b/docs/guide/libraries/powerprofiles.md @@ -2,45 +2,6 @@ Library and CLI tool for monitoring [upowerd](https://upower.freedesktop.org/) powerprofiles. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson valac libjson-glib-dev gobject-introspection -``` - -::: - -::: info -Although UPower is not a direct build dependency, -it should be self-explanatory that the daemon is required to be available at runtime. -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/powerprofiles -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [PowerProfiles reference](https://aylur.github.io/libastal/powerprofiles). @@ -84,3 +45,42 @@ print(powerprofiles.active_profile) ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson valac libjson-glib-dev gobject-introspection +``` + +::: + +::: info +Although UPower is not a direct build dependency, +it should be self-explanatory that the daemon is required to be available at runtime. +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/powerprofiles +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/references.md b/docs/guide/libraries/references.md index 3a85d73..f8ab4d8 100644 --- a/docs/guide/libraries/references.md +++ b/docs/guide/libraries/references.md @@ -33,6 +33,8 @@ Reading their documentation will vary depending on the language they are used in - [Auth](https://aylur.github.io/libastal/auth): Authentication library using PAM - [Battery](https://aylur.github.io/libastal/battery): DBus proxy library for upower daemon - [Bluetooth](https://aylur.github.io/libastal/bluetooth): Library to control bluez over dbus +- [Cava](https://aylur.github.io/libastal/cava): Audio visualizer library using cava +- [Greet](https://aylur.github.io/libastal/greet): Library and CLI tool for sending requests to greetd - [Hyprland](https://aylur.github.io/libastal/hyprland): Library and cli tool for Hyprland IPC socket - [Mpris](https://aylur.github.io/libastal/mpris): Library and cli tool for controlling media players - [Network](https://aylur.github.io/libastal/network): NetworkManager wrapper library diff --git a/docs/guide/libraries/river.md b/docs/guide/libraries/river.md index 299aa8c..dc1c71e 100644 --- a/docs/guide/libraries/river.md +++ b/docs/guide/libraries/river.md @@ -2,40 +2,6 @@ Library and CLI tool for monitoring the [River Wayland Compositor](https://isaacfreund.com/software/river/). -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson json-glib gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson gcc json-glib-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson libjson-glib-dev gobject-introspection -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/river -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [River reference](https://aylur.github.io/libastal/river). @@ -84,3 +50,37 @@ end ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson json-glib gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson gcc json-glib-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson libjson-glib-dev gobject-introspection +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/river +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/tray.md b/docs/guide/libraries/tray.md index b5cccc7..43b3aa6 100644 --- a/docs/guide/libraries/tray.md +++ b/docs/guide/libraries/tray.md @@ -2,40 +2,6 @@ Library for managing the systemtray by implementing the [StatusNotifierItem](https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/) protocol. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson gtk3 gobject-introspection libdbusmenu-gtk3 -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson gcc gtk3-devel libdbusmenu-gtk3 gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install meson libgtk-3-dev libdbusmenu-gtk3-dev gobject-introspection -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/tray -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Tray reference](https://aylur.github.io/libastal/tray). @@ -84,3 +50,37 @@ end ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson gtk3 gobject-introspection libdbusmenu-gtk3 +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson gcc gtk3-devel libdbusmenu-gtk3-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +sudo apt install meson libgtk-3-dev libdbusmenu-gtk3-dev gobject-introspection +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/tray +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/libraries/wireplumber.md b/docs/guide/libraries/wireplumber.md index c06161e..d6faea1 100644 --- a/docs/guide/libraries/wireplumber.md +++ b/docs/guide/libraries/wireplumber.md @@ -2,40 +2,6 @@ Wrapper library over [wireplumber](https://pipewire.pages.freedesktop.org/wireplumber/) to better integrate with Astal. -## Installation - -1. install dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu meson vala wireplumber gobject-introspection -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install meson vala valadoc wireplumber-devel gobject-introspection-devel -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -# Not yet documented -``` - -::: - -2. clone repo - -```sh -git clone https://github.com/aylur/astal.git -cd astal/lib/wireplumber -``` - -3. install - -```sh -meson setup --prefix /usr build -meson install -C build -``` - ## Usage You can browse the [Wireplumber reference](https://aylur.github.io/libastal/wireplumber). @@ -81,3 +47,37 @@ print(audio.default_speaker.volume) ``` ::: + +## Installation + +1. install dependencies + +:::code-group + +```sh [<i class="devicon-archlinux-plain"></i> Arch] +sudo pacman -Syu meson vala wireplumber gobject-introspection +``` + +```sh [<i class="devicon-fedora-plain"></i> Fedora] +sudo dnf install meson vala valadoc wireplumber-devel gobject-introspection-devel +``` + +```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] +# Not yet documented +``` + +::: + +2. clone repo + +```sh +git clone https://github.com/aylur/astal.git +cd astal/lib/wireplumber +``` + +3. install + +```sh +meson setup --prefix /usr build +meson install -C build +``` diff --git a/docs/guide/lua/first-widgets.md b/docs/guide/lua/first-widgets.md index efc1c4f..70cfe0c 100644 --- a/docs/guide/lua/first-widgets.md +++ b/docs/guide/lua/first-widgets.md @@ -13,8 +13,7 @@ local App = require("astal.gtk3.app") App:start({ main = function() -- you will instantiate Widgets here - -- or setup anything else if you need - print("hi") + -- and setup anything else if you need end }) ``` @@ -22,7 +21,7 @@ App:start({ ::: Then run `lua init.lua` in the terminal, and that's it! -Now you have an instance running with Lua. +Now you have an Astal instance running written in Lua. ## Root of every shell component: Window diff --git a/docs/guide/lua/theming.md b/docs/guide/lua/theming.md index 502e8e9..4f556fc 100644 --- a/docs/guide/lua/theming.md +++ b/docs/guide/lua/theming.md @@ -39,7 +39,7 @@ App:start({ ::: :::warning -When using relative paths, so for example `./style.css` keep in mind that they +When using relative paths, for example `./style.css` keep in mind that they will be relative to the current working directory. ::: diff --git a/docs/guide/typescript/cli-app.md b/docs/guide/typescript/cli-app.md index 85b117c..9b299aa 100644 --- a/docs/guide/typescript/cli-app.md +++ b/docs/guide/typescript/cli-app.md @@ -6,7 +6,6 @@ Depending on gtk version import paths will differ ```ts import { App } from "astal/gtk3" - import { App } from "astal/gtk4" ``` @@ -53,20 +52,11 @@ App.start({ }) ``` -:::code-group - -```sh [astal] +```sh astal say hi # hi cli ``` -```sh [ags] -ags request "say hi" -# hi cli -``` - -::: - If you want to run arbitrary JavaScript from CLI, you can use `App.eval` which will evaluate the passed string as the body of an `async` function. @@ -102,7 +92,7 @@ In order for Astal to know about your windows, you have to register them. You can do this by specifying a **unique** `name` and calling `App.add_window` ```tsx {4} -import { App } from "astal" +import { App } from "astal/gtk3" function Bar() { return <window name="Bar" setup={self => App.add_window(self)}> @@ -114,7 +104,7 @@ function Bar() { You can also invoke `App.add_window` by simply passing the `App` to the `application` prop. ```tsx {4} -import { App } from "astal" +import { App } from "astal/gtk3" function Bar() { return <window name="Bar" application={App}> @@ -128,24 +118,13 @@ When assigning the `application` prop make sure `name` comes before. Props are set sequentially and if name is applied after application it won't work. ::: -:::code-group - ```sh [astal] astal -t Bar ``` -```sh [ags] -ags toggle Bar -``` - -::: - -## Bundled scripts - -The produced scripts when bundling can run as the main instance -and a "client" instance. +## Client -The first time you execute your bundled script the `main` function gets called. +The first time you execute your script the `main` function gets called. While that instance is running any subsequent execution of the script will call the `client` function. diff --git a/docs/guide/typescript/faq.md b/docs/guide/typescript/faq.md index 48c802c..a151099 100644 --- a/docs/guide/typescript/faq.md +++ b/docs/guide/typescript/faq.md @@ -7,7 +7,7 @@ the same as the compositor. Instead use the `gdkmonitor` property which expects a `Gdk.Monitor` object. ```tsx -import { App } from "astal" +import { App } from "astal/gtk3" function Bar(gdkmonitor) { return <window gdkmonitor={gdkmonitor} /> @@ -162,7 +162,7 @@ export default function Bar(gdkmonitor: Gdk.Monitor) { :::code-group ```ts [app.ts] -import { Gdk, Gtk } from "astal" +import { Gdk, Gtk } from "astal/gtk3" import Bar from "./Bar" function main() { diff --git a/docs/guide/typescript/first-widgets.md b/docs/guide/typescript/first-widgets.md index 96a1275..a467382 100644 --- a/docs/guide/typescript/first-widgets.md +++ b/docs/guide/typescript/first-widgets.md @@ -2,41 +2,26 @@ ## Getting Started -Start by initializing a project +Start by importing the singleton +[Astal.Application](https://aylur.github.io/libastal/astal3/class.Application.html) instance. -```sh -ags init -``` +:::code-group -then run `ags run` in the terminal +```ts [app.ts] +import { App } from "astal/gtk3" -```sh -ags run +App.start({ + main() { + // you will instantiate Widgets here + // and setup anything else if you need + } +}) ``` -:::details Usage without AGS -🚧 Not yet documented. 🚧 -::: - -That's it! You have now a custom written bar using Gtk. - -:::tip -AGS will transpile every `.ts`, `.jsx` and `.tsx` files into regular JavaScript, then -it will bundle everything into a single JavaScript file which then GJS can execute. ::: -The AGS init command will generate the following files - -```txt -. -├── @girs/ # generated types -├── widget/ -│ └── Bar.tsx -├── app.ts # entry proint -├── env.d.ts # additional types -├── style.css -└── tsconfig.json # needed by LSPs -``` +After your [bundle step](./installation.md) run `gjs -m app.js`, and that's it! +Now you have an Astal instance running written in TypeScript. ## Root of every shell component: Window diff --git a/docs/guide/typescript/installation.md b/docs/guide/typescript/installation.md index e0f1bd5..0c19325 100644 --- a/docs/guide/typescript/installation.md +++ b/docs/guide/typescript/installation.md @@ -1,89 +1,19 @@ # Installation -It is recommended to use [AGS](https://github.com/aylur/ags) +It is recommended to use [AGS](https://aylur.github.io/ags/) to scaffold and run projects in TypeScript. It lets you - generate TypeScript types using [ts-for-gir](https://github.com/gjsify/ts-for-gir) -- generate a tsconfig which is used by LSPs -- bundle your TypeScript and JavaScript code using [esbuild](https://esbuild.github.io/). +- generate a tsconfig which is used by LSPs to provide intellisense +- bundle your TypeScript and JavaScript code using [esbuild](https://esbuild.github.io/) :::details Trivia AGS is the predecessor of Astal, which was written purely in TypeScript and so only supported -JavaScript/TypeScript. Now it serves as a scaffolding tool for Astal+TypeScript+JSX projects. +JavaScript/TypeScript. Now it serves as a scaffolding tool for Astal+TypeScript projects. ::: -## Nix - -maintainer: [@Aylur](https://github.com/Aylur) - -Read more about it on the [nix page](../getting-started/nix#ags) - -You can try without installing. - -<!--TODO: remove v2 after merge--> -```sh -nix run github:aylur/ags/v2#agsFull -- --help -``` - -## From source - -1. [Install Astal](../getting-started/installation.md) if you have not already - -2. Install the Astal GJS package - -```sh -git clone https://github.com/aylur/astal /tmp/astal -cd /tmp/astal/lang/gjs -meson setup --prefix /usr build -meson install -C build -``` - -:::tip -You might be wondering why it is recommended to install a JavaScript -package on the system instead of installing it as a node module. -It is solely to keep it in **sync** with the core `astal-io` and `astal3`/`astal4` package. -::: - -3. Install the following dependencies - -:::code-group - -```sh [<i class="devicon-archlinux-plain"></i> Arch] -sudo pacman -Syu go npm gjs -``` - -```sh [<i class="devicon-fedora-plain"></i> Fedora] -sudo dnf install golang npm gjs -``` - -```sh [<i class="devicon-ubuntu-plain"></i> Ubuntu] -sudo apt install golang-go npm gjs -``` - -::: - -3. Clone the repo and Install - -<!--TODO: remove v2 after merge--> -```sh -git clone https://github.com/aylur/ags.git /tmp/ags -cd /tmp/ags -git checkout v2 # https://github.com/Aylur/ags/pull/504 -go install -``` - -:::tip -`go install` installs the `ags` binary to `$GOPATH/bin` so make sure its in your `$PATH`. -You can move it to another directory if you like. For example - -```sh -sudo mv $GOPATH/bin/ags /usr/bin/ags -``` - -::: - -## Without AGS +## Setting up a project 🚧 Setting up a dev environment without AGS is not yet documented. 🚧 diff --git a/docs/guide/typescript/theming.md b/docs/guide/typescript/theming.md index 10a3981..5944c4e 100644 --- a/docs/guide/typescript/theming.md +++ b/docs/guide/typescript/theming.md @@ -23,28 +23,24 @@ You can pass a path to a file or css as a string in `App.start` :::code-group ```ts [app.ts] -import style from "inline:./style.css" - -const inlineCssInCode = ` -window { - background-color: transparent; -} +const inlineCss = ` + window { + background-color: transparent; + } ` App.start({ - css: "./style.css", - css: style, - css: `${SRC}/style.css'`, css: inlineCss, + css: "./style.css", + css: "/path/to/style.css", }) ``` ::: -:::info -When using AGS the global `SRC` will point to the directory `app.ts` is in. -AGS will set the current working directory to `--config`, so `./style.css` also works. -If you are not using AGS you should inline import CSS instead. +:::warning +When using relative paths, for example `./style.css` keep in mind that they +will be relative to the current working directory. ::: ## Css Property on Widgets @@ -90,20 +86,11 @@ You can reset stylesheets with `App.resetCss` If you are not sure about the widget hierarchy or any CSS selector, you can use the [GTK inspector](https://wiki.gnome.org/Projects/GTK/Inspector) -::: code-group - -```sh [astal] +```sh # to bring up the inspector run astal --inspector ``` -```sh [ags] -# to bring up the inspector run -ags --inspector -``` - -::: - ## Using SCSS Gtk's CSS only supports a subset of what the web offers. @@ -126,54 +113,22 @@ npm install -g sass # not packaged on Ubuntu ::: -Importing `scss` files will simply return transpiled css. - :::code-group ```ts [app.ts] -import style from "./style.scss" +import { exec } from "astal/process" + +exec("sass", "./style.scss", "/tmp/style.css") App.start({ - css: style, + css: "/tmp/style.css", main() {}, }) ``` ::: -:::details Without AGS -AGS uses a plugin to transpile scss files before importing them. -If you are not using AGS, you can use a plugin for your chosen bundler. -::: - :::tip -If you for example want to set scss varibles from JS, -You can inline import, compose, and transpile yourself. - -```ts [app.ts] -import style1 from "inline:./style1.scss" -import style2 from "inline:./style2.scss" - -const tmpscss = "/tmp/style.scss" -const target = "/tmp/style.css" - -writeFile(tmpscss, ` - $var1: red; - $var1: blue; - ${style1} - ${style1} -`) - -exec(`sass ${tmpscss} ${target}`) - -App.start({ - css: target, -}) - -``` - -::: - -:::info -If you want other preprocessors support builtin open an Issue. +You could also transpile scss into css using a bundler +and simply passing the path of the resulting css file to `css`. ::: diff --git a/docs/package.json b/docs/package.json index fea7e8f..ad76c9a 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,5 +1,5 @@ { - "name": "docs", + "name": "astal-docs", "type": "module", "devDependencies": { "@eslint/js": "^9.12.0", diff --git a/examples/js/applauncher/widget/Applauncher.scss b/examples/js/applauncher/widget/Applauncher.scss index 86c5e87..ae2453d 100644 --- a/examples/js/applauncher/widget/Applauncher.scss +++ b/examples/js/applauncher/widget/Applauncher.scss @@ -41,5 +41,19 @@ window#launcher { color: gtkalpha($fg-color, .8); } } + + box.not-found { + padding: 1rem; + + icon { + font-size: 6em; + color: gtkalpha($fg-color, .7); + } + + label { + color: gtkalpha($fg-color, .9); + font-size: 1.2em; + } + } } } diff --git a/examples/js/applauncher/widget/Applauncher.tsx b/examples/js/applauncher/widget/Applauncher.tsx index d92b5e3..c7bac68 100644 --- a/examples/js/applauncher/widget/Applauncher.tsx +++ b/examples/js/applauncher/widget/Applauncher.tsx @@ -4,8 +4,14 @@ import { Variable } from "astal" const MAX_ITEMS = 8 +function hide() { + App.get_window("launcher")!.hide() +} + function AppButton({ app }: { app: Apps.Application }) { - return <button className="AppButton" onClicked={() => app.launch()}> + return <button + className="AppButton" + onClicked={() => { hide(); app.launch() }}> <box> <icon icon={app.iconName} /> <box valign={Gtk.Align.CENTER} vertical> @@ -27,12 +33,14 @@ function AppButton({ app }: { app: Apps.Application }) { } export default function Applauncher() { + const { CENTER } = Gtk.Align const apps = new Apps.Apps() - const list = Variable(apps.get_list().slice(0, MAX_ITEMS)) - const hide = () => App.get_window("launcher")!.hide() - function search(text: string) { - list.set(apps.fuzzy_query(text).slice(0, MAX_ITEMS)) + const text = Variable("") + const list = text(text => apps.fuzzy_query(text).slice(0, MAX_ITEMS)) + const onEnter = () => { + apps.fuzzy_query(text.get())?.[0].launch() + hide() } return <window @@ -41,7 +49,7 @@ export default function Applauncher() { exclusivity={Astal.Exclusivity.IGNORE} keymode={Astal.Keymode.ON_DEMAND} application={App} - onShow={() => list.set(apps.get_list().slice(0, MAX_ITEMS))} + onShow={() => text.set("")} onKeyPressEvent={function (self, event: Gdk.Event) { if (event.get_keyval()[1] === Gdk.KEY_Escape) self.hide() @@ -53,16 +61,22 @@ export default function Applauncher() { <box widthRequest={500} className="Applauncher" vertical> <entry placeholderText="Search" - onChanged={({ text }) => search(text)} + text={text()} + onChanged={self => text.set(self.text)} + onActivate={onEnter} /> <box spacing={6} vertical> - {list(list => list.map(app => ( + {list.as(list => list.map(app => ( <AppButton app={app} /> )))} </box> - <box visible={list(l => l.length === 0)}> + <box + halign={CENTER} + className="not-found" + vertical + visible={list.as(l => l.length === 0)}> <icon icon="system-search-symbolic" /> - No match found + <label label="No match found" /> </box> </box> <eventbox expand onClick={hide} /> diff --git a/examples/js/simple-bar/README.md b/examples/js/simple-bar/README.md index 6488d14..f92b20e 100644 --- a/examples/js/simple-bar/README.md +++ b/examples/js/simple-bar/README.md @@ -4,7 +4,6 @@ A simple bar for Hyprland using -- [Audio library](https://aylur.github.io/astal/guide/libraries/audio). - [Battery library](https://aylur.github.io/astal/guide/libraries/battery). - [Hyprland library](https://aylur.github.io/astal/guide/libraries/hyprland). - [Mpris library](https://aylur.github.io/astal/guide/libraries/mpris). diff --git a/examples/lua/simple-bar/README.md b/examples/lua/simple-bar/README.md index bcc6bba..48cc27c 100644 --- a/examples/lua/simple-bar/README.md +++ b/examples/lua/simple-bar/README.md @@ -4,7 +4,6 @@ A simple bar for Hyprland using -- [Audio library](https://aylur.github.io/astal/guide/libraries/audio). - [Battery library](https://aylur.github.io/astal/guide/libraries/battery). - [Hyprland library](https://aylur.github.io/astal/guide/libraries/hyprland). - [Mpris library](https://aylur.github.io/astal/guide/libraries/mpris). diff --git a/examples/py/simple-bar/README.md b/examples/py/simple-bar/README.md index bcc6bba..48cc27c 100644 --- a/examples/py/simple-bar/README.md +++ b/examples/py/simple-bar/README.md @@ -4,7 +4,6 @@ A simple bar for Hyprland using -- [Audio library](https://aylur.github.io/astal/guide/libraries/audio). - [Battery library](https://aylur.github.io/astal/guide/libraries/battery). - [Hyprland library](https://aylur.github.io/astal/guide/libraries/hyprland). - [Mpris library](https://aylur.github.io/astal/guide/libraries/mpris). diff --git a/examples/vala/simple-bar/README.md b/examples/vala/simple-bar/README.md index bcc6bba..48cc27c 100644 --- a/examples/vala/simple-bar/README.md +++ b/examples/vala/simple-bar/README.md @@ -4,7 +4,6 @@ A simple bar for Hyprland using -- [Audio library](https://aylur.github.io/astal/guide/libraries/audio). - [Battery library](https://aylur.github.io/astal/guide/libraries/battery). - [Hyprland library](https://aylur.github.io/astal/guide/libraries/hyprland). - [Mpris library](https://aylur.github.io/astal/guide/libraries/mpris). diff --git a/lang/gjs/meson.build b/lang/gjs/meson.build index 7134dc0..f4272ee 100644 --- a/lang/gjs/meson.build +++ b/lang/gjs/meson.build @@ -21,3 +21,12 @@ install_data( install_subdir('src/gtk3', install_dir: dest) install_subdir('src/gtk4', install_dir: dest) + +import('pkgconfig').generate( + description: 'Astal GJS pacakge', + name: meson.project_name(), + install_dir: get_option('libdir') / 'pkgconfig', + variables: { + 'srcdir': dest, + }, +) diff --git a/lang/gjs/package.json b/lang/gjs/package.json index da88d90..43a7702 100644 --- a/lang/gjs/package.json +++ b/lang/gjs/package.json @@ -4,7 +4,7 @@ "description": "Building blocks for building linux desktop shell", "type": "module", "author": "Aylur", - "license": "GPL", + "license": "LGPL-2.1", "repository": { "type": "git", "url": "https://github.com/aylur/astal.git", diff --git a/lang/gjs/src/gobject.ts b/lang/gjs/src/gobject.ts index 59dd62a..b744cfb 100644 --- a/lang/gjs/src/gobject.ts +++ b/lang/gjs/src/gobject.ts @@ -51,6 +51,8 @@ export function register(options: MetaInfo = {}) { Properties: { ...cls[meta]?.Properties }, ...options, }, cls) + + delete cls[meta] } } @@ -124,7 +126,9 @@ export function signal( } } else { - target.constructor[meta].Signals[name] = declaration + target.constructor[meta].Signals[name] = declaration || { + param_types: [], + } } if (!desc) { diff --git a/lang/gjs/src/gtk3/astalify.ts b/lang/gjs/src/gtk3/astalify.ts index b9dd36f..b758976 100644 --- a/lang/gjs/src/gtk3/astalify.ts +++ b/lang/gjs/src/gtk3/astalify.ts @@ -43,7 +43,7 @@ function setProp(obj: any, prop: string, value: any) { export default function astalify< C extends { new(...args: any[]): Gtk.Widget }, ->(cls: C) { +>(cls: C, clsName = cls.name) { class Widget extends cls { get css(): string { return Astal.widget_get_css(this) } set css(css: string) { Astal.widget_set_css(this, css) } @@ -236,7 +236,7 @@ export default function astalify< } GObject.registerClass({ - GTypeName: `Astal_${cls.name}`, + GTypeName: `Astal_${clsName}`, Properties: { "class-name": GObject.ParamSpec.string( "class-name", "", "", GObject.ParamFlags.READWRITE, "", @@ -259,7 +259,7 @@ export default function astalify< return Widget } -type BindableProps<T> = { +export type BindableProps<T> = { [K in keyof T]: Binding<T[K]> | T[K]; } diff --git a/lang/gjs/src/gtk3/index.ts b/lang/gjs/src/gtk3/index.ts index cfafbda..ff641af 100644 --- a/lang/gjs/src/gtk3/index.ts +++ b/lang/gjs/src/gtk3/index.ts @@ -1,9 +1,9 @@ import Astal from "gi://Astal?version=3.0" import Gtk from "gi://Gtk?version=3.0" import Gdk from "gi://Gdk?version=3.0" -import astalify, { type ConstructProps } from "./astalify.js" +import astalify, { type ConstructProps, type BindableProps } from "./astalify.js" export { Astal, Gtk, Gdk } export { default as App } from "./app.js" -export { astalify, ConstructProps } +export { astalify, ConstructProps, BindableProps } export * as Widget from "./widget.js" diff --git a/lang/lua/astal-dev-1.rockspec b/lang/lua/astal-dev-1.rockspec index 3970672..d8ee9be 100644 --- a/lang/lua/astal-dev-1.rockspec +++ b/lang/lua/astal-dev-1.rockspec @@ -8,7 +8,7 @@ source = { description = { summary = "lua bindings for libastal.", homepage = "https://aylur.github.io/astal/", - license = "GPL-3", + license = "LGPL-2.1", } dependencies = { diff --git a/lang/lua/astal/binding.lua b/lang/lua/astal/binding.lua index 2944ec4..dd2df7f 100644 --- a/lang/lua/astal/binding.lua +++ b/lang/lua/astal/binding.lua @@ -2,12 +2,14 @@ local lgi = require("lgi") local GObject = lgi.require("GObject", "2.0") ---@class Binding ----@field emitter table|Variable +---@field emitter table | Variable | userdata ---@field property? string ---@field transform_fn function +---@overload fun(emitter: table | userdata, property?: string): Binding local Binding = {} +Binding.__index = Binding ----@param emitter table +---@param emitter table | Variable | userdata ---@param property? string ---@return Binding function Binding.new(emitter, property) @@ -28,14 +30,15 @@ function Binding:__tostring() return str .. ">" end +---@return any function Binding:get() if self.property ~= nil and GObject.Object:is_type_of(self.emitter) then return self.transform_fn(self.emitter[self.property]) - end - if type(self.emitter.get) == "function" then + elseif type(self.emitter.get) == "function" then return self.transform_fn(self.emitter:get()) + else + error("can not get: Not a GObject or a Variable " + self) end - error("can not get: Not a GObject or a Variable " + self) end ---@param transform fun(value: any): any @@ -58,14 +61,17 @@ function Binding:subscribe(callback) return function() GObject.signal_handler_disconnect(self.emitter, id) end - end - if type(self.emitter.subscribe) == "function" then + elseif type(self.emitter.subscribe) == "function" then return self.emitter:subscribe(function() callback(self:get()) end) + else + error("can not subscribe: Not a GObject or a Variable " + self) end - error("can not subscribe: Not a GObject or a Variable " + self) end -Binding.__index = Binding -return Binding +return setmetatable(Binding, { + __call = function(_, emitter, prop) + return Binding.new(emitter, prop) + end, +}) diff --git a/lang/lua/astal/gtk3/app.lua b/lang/lua/astal/gtk3/app.lua index 7895f69..58564ce 100644 --- a/lang/lua/astal/gtk3/app.lua +++ b/lang/lua/astal/gtk3/app.lua @@ -25,29 +25,26 @@ end local app = AstalLua() ---@class StartConfig ----@field icons? string ----@field instance_name? string ----@field gtk_theme? string ----@field icon_theme? string ----@field cursor_theme? string ----@field css? string ----@field hold? boolean ----@field request_handler? fun(msg: string, response: fun(res: any)) ----@field main? fun(...): unknown ----@field client? fun(message: fun(msg: string): string, ...): unknown +---@field icons string? +---@field instance_name string? +---@field gtk_theme string? +---@field icon_theme string? +---@field cursor_theme string? +---@field css string? +---@field hold boolean? +---@field request_handler fun(msg: string, response: fun(res: any)): nil +---@field main fun(...): nil +---@field client fun(message: fun(msg: string): string, ...): nil ----@param config StartConfig | nil +---@param config? StartConfig function Astal.Application:start(config) - if config == nil then - config = {} - end + config = config or {} - if config.client == nil then - config.client = function() + config.client = config.client + or function() print('Astal instance "' .. app.instance_name .. '" is already running') os.exit(1) end - end if config.hold == nil then config.hold = true @@ -61,17 +58,11 @@ function Astal.Application:start(config) if config.icons then self:add_icons(config.icons) end - if config.instance_name then - self.instance_name = config.instance_name - end - if config.gtk_theme then - self.gtk_theme = config.gtk_theme - end - if config.icon_theme then - self.icon_theme = config.icon_theme - end - if config.cursor_theme then - self.cursor_theme = config.cursor_theme + + for _, key in ipairs({ "instance_name", "gtk_theme", "icon_theme", "cursor_theme" }) do + if config[key] then + self[key] = config[key] + end end app.on_activate = function() diff --git a/lang/lua/astal/gtk3/astalify.lua b/lang/lua/astal/gtk3/astalify.lua index 211a1d4..95faa2c 100644 --- a/lang/lua/astal/gtk3/astalify.lua +++ b/lang/lua/astal/gtk3/astalify.lua @@ -163,9 +163,7 @@ return function(ctor) end return function(tbl) - if tbl == nil then - tbl = {} - end + tbl = tbl or {} local bindings = {} local setup = tbl.setup diff --git a/lang/lua/astal/gtk3/widget.lua b/lang/lua/astal/gtk3/widget.lua index 3286c26..adcb65f 100644 --- a/lang/lua/astal/gtk3/widget.lua +++ b/lang/lua/astal/gtk3/widget.lua @@ -3,6 +3,7 @@ local Astal = lgi.require("Astal", "3.0") local Gtk = lgi.require("Gtk", "3.0") local astalify = require("astal.gtk3.astalify") +---@overload fun(ctor: any): function local Widget = { astalify = astalify, Box = astalify(Astal.Box), diff --git a/lang/lua/astal/init.lua b/lang/lua/astal/init.lua index 5630ba4..190994a 100644 --- a/lang/lua/astal/init.lua +++ b/lang/lua/astal/init.lua @@ -7,6 +7,7 @@ local Binding = require("astal.binding") local File = require("astal.file") local Process = require("astal.process") local Time = require("astal.time") +---@type Variable | fun(v: any): Variable local Variable = require("astal.variable") return { diff --git a/lang/lua/astal/variable.lua b/lang/lua/astal/variable.lua index 2305a71..ad59a3f 100644 --- a/lang/lua/astal/variable.lua +++ b/lang/lua/astal/variable.lua @@ -17,6 +17,7 @@ local Process = require("astal.process") ---@field private poll_fn? function ---@field private watch_transform? fun(next: any, prev: any): any ---@field private watch_exec? string[] | string +---@overload fun(transform?: fun(v: any): any): Binding local Variable = {} Variable.__index = Variable @@ -24,23 +25,23 @@ Variable.__index = Variable ---@return Variable function Variable.new(value) local v = Astal.VariableBase() - local variable = setmetatable({ - variable = v, - _value = value, - }, Variable) + local variable = setmetatable({ variable = v, _value = value }, Variable) + v.on_dropped = function() variable:stop_watch() variable:stop_poll() end + v.on_error = function(_, err) if variable.err_handler then variable.err_handler(err) end end + return variable end ----@param transform? fun(v: any): any +---@param transform? fun(v: any): any ---@return Binding function Variable:__call(transform) if type(transform) == "nil" then @@ -54,10 +55,13 @@ function Variable:__tostring() return "Variable<" .. tostring(self:get()) .. ">" end +---@return any function Variable:get() return self._value end +---@param value any +---@return nil function Variable:set(value) if value ~= self:get() then self._value = value @@ -107,7 +111,6 @@ function Variable:start_watch() end) end - function Variable:stop_poll() if self:is_polling() then self._poll.cancel() @@ -122,7 +125,6 @@ function Variable:stop_watch() self._watch = nil end - function Variable:drop() self.variable.emit_dropped() end @@ -180,8 +182,9 @@ end ---@param exec string | string[] ---@param transform? fun(next: any, prev: any): any +---@return Variable function Variable:watch(exec, transform) - transform = transform or function (next) + transform = transform or function(next) return next end @@ -240,7 +243,7 @@ function Variable.derive(deps, transform) for i, var in ipairs(deps) do if getmetatable(var) == Variable then - deps[i] = Binding.new(var) + deps[i] = var() end end @@ -249,7 +252,7 @@ function Variable.derive(deps, transform) for i, binding in ipairs(deps) do params[i] = binding:get() end - return transform(table.unpack(params), 1, #deps) + return transform(table.unpack(params, 1, #deps)) end local var = Variable.new(update()) @@ -272,4 +275,4 @@ return setmetatable(Variable, { __call = function(_, v) return Variable.new(v) end, -})
\ No newline at end of file +}) diff --git a/lib/astal/gtk4/gir.py b/lib/astal/gtk4/gir.py index 9ef680f..16a3a64 100644..120000 --- a/lib/astal/gtk4/gir.py +++ b/lib/astal/gtk4/gir.py @@ -1,58 +1 @@ -""" -Vala's generated gir does not contain comments, -so we use valadoc to generate them. However, they are formatted -for valadoc and not gi-docgen so we need to fix it. -""" - -import xml.etree.ElementTree as ET -import html -import sys -import subprocess - - -def fix_gir(name: str, gir: str, out: str): - namespaces = { - "": "http://www.gtk.org/introspection/core/1.0", - "c": "http://www.gtk.org/introspection/c/1.0", - "glib": "http://www.gtk.org/introspection/glib/1.0", - } - for prefix, uri in namespaces.items(): - ET.register_namespace(prefix, uri) - - tree = ET.parse(gir) - root = tree.getroot() - - for doc in root.findall(".//doc", namespaces): - if doc.text: - doc.text = ( - html.unescape(doc.text).replace("<para>", "").replace("</para>", "") - ) - - if (inc := root.find("c:include", namespaces)) is not None: - inc.set("name", f"{name}.h") - else: - print("no c:include tag found", file=sys.stderr) - exit(1) - - tree.write(out, encoding="utf-8", xml_declaration=True) - - -def valadoc(name: str, gir: str, args: list[str]): - cmd = ["valadoc", "-o", "docs", "--package-name", name, "--gir", gir, *args] - try: - subprocess.run(cmd, check=True, text=True, capture_output=True) - except subprocess.CalledProcessError as e: - print(e.stderr, file=sys.stderr) - exit(1) - - -if __name__ == "__main__": - name = sys.argv[1] - in_out = sys.argv[2].split(":") - args = sys.argv[3:] - - gir = in_out[0] - out = in_out[1] if len(in_out) > 1 else gir - - valadoc(name, gir, args) - fix_gir(name, gir, out) +../../gir.py
\ No newline at end of file diff --git a/lib/astal/io/gir.py b/lib/astal/io/gir.py index 9ef680f..16a3a64 100644..120000 --- a/lib/astal/io/gir.py +++ b/lib/astal/io/gir.py @@ -1,58 +1 @@ -""" -Vala's generated gir does not contain comments, -so we use valadoc to generate them. However, they are formatted -for valadoc and not gi-docgen so we need to fix it. -""" - -import xml.etree.ElementTree as ET -import html -import sys -import subprocess - - -def fix_gir(name: str, gir: str, out: str): - namespaces = { - "": "http://www.gtk.org/introspection/core/1.0", - "c": "http://www.gtk.org/introspection/c/1.0", - "glib": "http://www.gtk.org/introspection/glib/1.0", - } - for prefix, uri in namespaces.items(): - ET.register_namespace(prefix, uri) - - tree = ET.parse(gir) - root = tree.getroot() - - for doc in root.findall(".//doc", namespaces): - if doc.text: - doc.text = ( - html.unescape(doc.text).replace("<para>", "").replace("</para>", "") - ) - - if (inc := root.find("c:include", namespaces)) is not None: - inc.set("name", f"{name}.h") - else: - print("no c:include tag found", file=sys.stderr) - exit(1) - - tree.write(out, encoding="utf-8", xml_declaration=True) - - -def valadoc(name: str, gir: str, args: list[str]): - cmd = ["valadoc", "-o", "docs", "--package-name", name, "--gir", gir, *args] - try: - subprocess.run(cmd, check=True, text=True, capture_output=True) - except subprocess.CalledProcessError as e: - print(e.stderr, file=sys.stderr) - exit(1) - - -if __name__ == "__main__": - name = sys.argv[1] - in_out = sys.argv[2].split(":") - args = sys.argv[3:] - - gir = in_out[0] - out = in_out[1] if len(in_out) > 1 else gir - - valadoc(name, gir, args) - fix_gir(name, gir, out) +../../gir.py
\ No newline at end of file @@ -9,6 +9,7 @@ import html import sys import subprocess import re +import os # valac fails on gi-docgen compliant markdown @@ -47,7 +48,7 @@ def fix_gir(name: str, gir: str, out: str): def valadoc(name: str, gir: str, args: list[str]): - cmd = ["valadoc", "-o", "docs", "--package-name", name, "--gir", gir, *args] + cmd = [os.getenv("VALADOC", "valadoc"), "-o", "docs", "--package-name", name, "--gir", gir, *args] try: subprocess.run(cmd, check=True, text=True, capture_output=True) except subprocess.CalledProcessError as e: diff --git a/lib/hyprland/monitor.vala b/lib/hyprland/monitor.vala index d7b8028..6c46142 100644 --- a/lib/hyprland/monitor.vala +++ b/lib/hyprland/monitor.vala @@ -1,5 +1,4 @@ -namespace AstalHyprland { -public class Monitor : Object { +public class AstalHyprland.Monitor : Object { public signal void removed (); public int id { get; private set; } @@ -20,6 +19,7 @@ public class Monitor : Object { public int reserved_left { get; private set; } public int reserved_right { get; private set; } public double scale { get; private set; } + public Transform transform { get; private set; } public bool focused { get; private set; } public bool dpms_status { get; private set; } public bool vrr { get; private set; } @@ -43,6 +43,7 @@ public class Monitor : Object { x = (int)obj.get_int_member("x"); y = (int)obj.get_int_member("y"); scale = obj.get_double_member("scale"); + transform = (Transform)obj.get_int_member("transform"); focused = obj.get_boolean_member("focused"); dpms_status = obj.get_boolean_member("dpmsStatus"); vrr = obj.get_boolean_member("vrr"); @@ -67,5 +68,22 @@ public class Monitor : Object { public void focus() { Hyprland.get_default().dispatch("focusmonitor", id.to_string()); } -} + + public enum Transform { + NORMAL = 0, + /** rotate by 90° counter clockwise */ + ROTATE_90_DEG = 1, + /** rotate by 180° */ + ROTATE_180_DEG = 2, + /** rotate by 270° counter clockwise */ + ROTATE_270_DEG = 3, + /** mirror both axis */ + FLIPPED = 4, + /** flip and rotate by 90° */ + FLIPPED_ROTATE_90_DEG = 5, + /** flip and rotate by 180° */ + FLIPPED_ROTATE_180_DEG = 6, + /** flip and rotate by 270° */ + FLIPPED_ROTATE_270_DEG = 7, + } } diff --git a/lib/network/network.vala b/lib/network/network.vala index fb7efa0..96e19c8 100644 --- a/lib/network/network.vala +++ b/lib/network/network.vala @@ -149,19 +149,19 @@ public enum AstalNetwork.Connectivity { // alias for NM.DeviceState public enum AstalNetwork.DeviceState { - UNKNOWN, - UNMANAGED, - UNAVAILABLE, - DISCONNECTED, - PREPARE, - CONFIG, - NEED_AUTH, - IP_CONFIG, - IP_CHECK, - SECONDARIES, - ACTIVATED, - DEACTIVATING, - FAILED; + UNKNOWN = 0, + UNMANAGED = 10, + UNAVAILABLE = 20, + DISCONNECTED = 30, + PREPARE = 40, + CONFIG = 50, + NEED_AUTH = 60, + IP_CONFIG = 70, + IP_CHECK = 80, + SECONDARIES = 90, + ACTIVATED = 100, + DEACTIVATING = 110, + FAILED = 120; public string to_string() { switch (this) { diff --git a/lib/powerprofiles/cli.vala b/lib/powerprofiles/cli.vala index 7be01d2..1e5cc70 100644 --- a/lib/powerprofiles/cli.vala +++ b/lib/powerprofiles/cli.vala @@ -56,16 +56,16 @@ int main(string[] argv) { if (daemonize) { var loop = new MainLoop(); - stdout.printf("%s\n", profiles.to_json_string()); + stdout.printf("%s\n", to_json_string(profiles)); stdout.flush(); profiles.notify.connect(() => { - stdout.printf("%s\n", profiles.to_json_string()); + stdout.printf("%s\n", to_json_string(profiles)); stdout.flush(); }); profiles.profile_released.connect(() => { - stdout.printf("%s\n", profiles.to_json_string()); + stdout.printf("%s\n", to_json_string(profiles)); stdout.flush(); }); @@ -73,8 +73,49 @@ int main(string[] argv) { } if (set == null && !daemonize) { - stdout.printf("%s\n", profiles.to_json_string()); + stdout.printf("%s\n", to_json_string(profiles)); } return 0; } + +string to_json_string(AstalPowerProfiles.PowerProfiles profiles) { + var acts = new Json.Builder().begin_array(); + foreach (var action in profiles.actions) { + acts.add_string_value(action); + } + + var active_holds = new Json.Builder().begin_array(); + foreach (var action in profiles.active_profile_holds) { + active_holds.add_value(new Json.Builder() + .begin_object() + .set_member_name("application_id").add_string_value(action.application_id) + .set_member_name("profile").add_string_value(action.profile) + .set_member_name("reason").add_string_value(action.reason) + .end_object() + .get_root()); + } + + var profs = new Json.Builder().begin_array(); + foreach (var prof in profiles.profiles) { + profs.add_value(new Json.Builder() + .begin_object() + .set_member_name("profie").add_string_value(prof.profile) + .set_member_name("driver").add_string_value(prof.driver) + .set_member_name("cpu_driver").add_string_value(prof.cpu_driver) + .set_member_name("platform_driver").add_string_value(prof.platform_driver) + .end_object() + .get_root()); + } + + return Json.to_string(new Json.Builder() + .begin_object() + .set_member_name("active_profile").add_string_value(profiles.active_profile) + .set_member_name("icon_name").add_string_value(profiles.icon_name) + .set_member_name("performance_degraded").add_string_value(profiles.performance_degraded) + .set_member_name("actions").add_value(acts.end_array().get_root()) + .set_member_name("active_profile_holds").add_value(active_holds.end_array().get_root()) + .set_member_name("profiles").add_value(profs.end_array().get_root()) + .end_object() + .get_root(), false); +} diff --git a/lib/powerprofiles/gir.py b/lib/powerprofiles/gir.py new file mode 120000 index 0000000..b5b4f1d --- /dev/null +++ b/lib/powerprofiles/gir.py @@ -0,0 +1 @@ +../gir.py
\ No newline at end of file diff --git a/lib/powerprofiles/meson.build b/lib/powerprofiles/meson.build index d0fe78f..cd8cc2b 100644 --- a/lib/powerprofiles/meson.build +++ b/lib/powerprofiles/meson.build @@ -39,32 +39,38 @@ deps = [ dependency('json-glib-1.0'), ] -sources = [ - config, +sources = [config] + files( 'power-profiles.vala', -] +) if get_option('lib') lib = library( meson.project_name(), sources, dependencies: deps, + vala_args: ['--vapi-comments'], vala_header: meson.project_name() + '.h', vala_vapi: meson.project_name() + '-' + api_version + '.vapi', - vala_gir: gir, version: meson.project_version(), install: true, - install_dir: [true, true, true, true], + install_dir: [true, true, true], ) - import('pkgconfig').generate( - lib, - name: meson.project_name(), - filebase: meson.project_name() + '-' + api_version, - version: meson.project_version(), - subdirs: meson.project_name(), - requires: deps, - install_dir: get_option('libdir') / 'pkgconfig', + pkgs = [] + foreach dep : deps + pkgs += ['--pkg=' + dep.name()] + endforeach + + gir_tgt = custom_target( + gir, + command: [find_program('python3'), files('gir.py'), meson.project_name(), gir] + + pkgs + + sources, + input: sources, + depends: lib, + output: gir, + install: true, + install_dir: get_option('datadir') / 'gir-1.0', ) custom_target( @@ -77,10 +83,20 @@ if get_option('lib') ], input: lib, output: typelib, - depends: lib, + depends: [lib, gir_tgt], install: true, install_dir: get_option('libdir') / 'girepository-1.0', ) + + import('pkgconfig').generate( + lib, + name: meson.project_name(), + filebase: meson.project_name() + '-' + api_version, + version: meson.project_version(), + subdirs: meson.project_name(), + requires: deps, + install_dir: get_option('libdir') / 'pkgconfig', + ) endif if get_option('cli') diff --git a/lib/powerprofiles/power-profiles.vala b/lib/powerprofiles/power-profiles.vala index ab98505..a104d2e 100644 --- a/lib/powerprofiles/power-profiles.vala +++ b/lib/powerprofiles/power-profiles.vala @@ -16,11 +16,17 @@ private interface IPowerProfiles : DBusProxy { } public PowerProfiles get_default() { + /** Gets the default singleton PowerProfiles instance. */ return PowerProfiles.get_default(); } +/** + * Client for [[https://freedesktop-team.pages.debian.net/power-profiles-daemon/gdbus-org.freedesktop.UPower.PowerProfiles.html|PowerProfiles]]. + */ public class PowerProfiles : Object { private static PowerProfiles instance; + + /** Gets the default singleton PowerProfiles instance. */ public static PowerProfiles get_default() { if (instance == null) instance = new PowerProfiles(); @@ -52,19 +58,34 @@ public class PowerProfiles : Object { } } + /** + * The type of the currently active profile. + * It might change automatically if a profile is held, + * using the [[email protected]_profile] method. + */ public string active_profile { owned get { return proxy.active_profile; } set { proxy.active_profile = value; } } + /** + * Return a named icon based [[email protected]:active_profile]. + */ public string icon_name { owned get { return @"power-profile-$active_profile-symbolic"; } } + /** + * List of the "actions" implemented in the running daemon. + * This can used to figure out whether particular functionality is available in the daemon. + */ public string[] actions { owned get { return proxy.actions.copy(); } } + /** + * List of dictionaries representing the current profile holds. + */ public Hold[] active_profile_holds { owned get { Hold[] holds = new Hold[proxy.active_profile_holds.length]; @@ -80,14 +101,21 @@ public class PowerProfiles : Object { } } + /** + * This will be set if the performance power profile is running in degraded mode, + * with the value being used to identify the reason for that degradation. + * Possible values are: + * - "lap-detected" (the computer is sitting on the user's lap) + * - "high-operating-temperature" (the computer is close to overheating) + * - "" (the empty string, if not performance is not degraded) + */ public string performance_degraded { owned get { return proxy.performance_degraded; } } - public string performance_inhibited { - owned get { return proxy.performance_degraded; } - } - + /** + * List of each profile. + */ public Profile[] profiles { owned get { Profile[] profs = new Profile[proxy.profiles.length]; @@ -104,12 +132,31 @@ public class PowerProfiles : Object { } } + /** + * The version of the power-profiles-daemon software. + */ public string version { owned get { return proxy.version; } } + /** + * Emitted when the profile is released because + * [[email protected]:active_profile] was manually changed. + * This will only be emitted to the process that originally called + * [[email protected]_profile]. + */ public signal void profile_released (uint cookie); + /** + * This forces the passed profile (either 'power-saver' or 'performance') + * to be activated until either the caller quits, + * [[email protected]_profile] is called, + * or the [[email protected]:active_profile] is changed by the user. + * When conflicting profiles are requested to be held, + * the 'power-saver' profile will be activated in preference to the 'performance' profile. + * Those holds will be automatically cancelled if the user manually switches to another profile, + * and the [[email protected]::profile_released] signal will be emitted. + */ public int hold_profile(string profile, string reason, string application_id) { try { return (int)proxy.hold_profile(profile, reason, application_id); @@ -119,6 +166,9 @@ public class PowerProfiles : Object { } } + /** + * This removes the hold that was set on a profile. + */ public void release_profile(uint cookie) { try { proxy.release_profile(cookie); @@ -126,54 +176,21 @@ public class PowerProfiles : Object { critical(error.message); } } - - public string to_json_string() { - var acts = new Json.Builder().begin_array(); - foreach (var action in actions) { - acts.add_string_value(action); - } - - var active_holds = new Json.Builder().begin_array(); - foreach (var action in active_profile_holds) { - active_holds.add_value(new Json.Builder() - .begin_object() - .set_member_name("application_id").add_string_value(action.application_id) - .set_member_name("profile").add_string_value(action.profile) - .set_member_name("reason").add_string_value(action.reason) - .end_object() - .get_root()); - } - - var profs = new Json.Builder().begin_array(); - foreach (var prof in profiles) { - profs.add_value(new Json.Builder() - .begin_object() - .set_member_name("profie").add_string_value(prof.profile) - .set_member_name("driver").add_string_value(prof.driver) - .set_member_name("cpu_driver").add_string_value(prof.cpu_driver) - .set_member_name("platform_driver").add_string_value(prof.platform_driver) - .end_object() - .get_root()); - } - - return Json.to_string(new Json.Builder() - .begin_object() - .set_member_name("active_profile").add_string_value(active_profile) - .set_member_name("icon_name").add_string_value(icon_name) - .set_member_name("performance_degraded").add_string_value(performance_degraded) - .set_member_name("performance_inhibited").add_string_value(performance_inhibited) - .set_member_name("actions").add_value(acts.end_array().get_root()) - .set_member_name("active_profile_holds").add_value(active_holds.end_array().get_root()) - .set_member_name("profiles").add_value(profs.end_array().get_root()) - .end_object() - .get_root(), false); - } } public struct Profile { + /** + * Will be one of: + * - "power-saver" (battery saving profile) + * - "balanced" (the default profile) + * - "performance" (a profile that does not care about noise or battery consumption) + */ public string profile; public string cpu_driver; public string platform_driver; + /** + * Identifies the power-profiles-daemon backend code used to implement the profile. + */ public string driver; } diff --git a/lib/tray/meson.build b/lib/tray/meson.build index cb7ab30..139cfb1 100644 --- a/lib/tray/meson.build +++ b/lib/tray/meson.build @@ -54,7 +54,7 @@ if get_option('lib') vala_args: ['--vapi-comments'], version: meson.project_version(), install: true, - install_dir: [true, true, true], + install_dir: [true, true, true] ) pkgs = [] |