Initial commit
This commit is contained in:
commit
1178d04d37
26 files changed
+6038
No files matched your search
@@ -0,0 +1,5 @@
|
||||
dist/
|
||||
result/
|
||||
.vitepress/cache/
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from "../vitepress.config"
|
||||
@@ -0,0 +1,5 @@
|
||||
import DefaultTheme from "vitepress/theme"
|
||||
import "../../vitepress.theme.css"
|
||||
import "devicon/devicon.min.css"
|
||||
|
||||
export default DefaultTheme
|
||||
@@ -0,0 +1,226 @@
|
||||
# App and CLI
|
||||
|
||||
`app` is a singleton **instance** of an
|
||||
[Gtk.Application](https://docs.gtk.org/gtk4/class.Application.html).
|
||||
|
||||
Depending on Gtk version import paths will differ
|
||||
|
||||
```ts
|
||||
import app from "astal/gtk3/app"
|
||||
import app from "astal/gtk4/app"
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> The `app` instance's DBus name is prefixed with `io.Astal`. If you are writing
|
||||
> a shell which is meant to be distributed you might want to avoid using `app`
|
||||
> and instead create a subclass of `Gtk.Application` or `Adw.Application` while
|
||||
> also following the
|
||||
> [packaging conventions](https://gjs.guide/guides/gtk/application-packaging.html).
|
||||
|
||||
::: details Example App implementation
|
||||
|
||||
```tsx
|
||||
import Astal from "gi://Astal?version=4.0"
|
||||
import Gio from "gi://Gio?version=2.0"
|
||||
import GObject from "gi://GObject?version=2.0"
|
||||
import Gtk from "gi://Gtk?version=4.0"
|
||||
import { programInvocationName, programArgs } from "system"
|
||||
import { createRoot } from "gnim"
|
||||
|
||||
class App extends Gtk.Application {
|
||||
static {
|
||||
GObject.registerClass(this)
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
applicationId: "my.awesome.app",
|
||||
flags: Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
|
||||
})
|
||||
}
|
||||
|
||||
vfunc_command_line(cmd: Gio.ApplicationCommandLine): number {
|
||||
const args: string[] = cmd.get_arguments()
|
||||
|
||||
if (cmd.isRemote) {
|
||||
console.log("invoked from remote instance")
|
||||
cmd.print_literal("hello from primary instance")
|
||||
cmd.done()
|
||||
} else {
|
||||
this.main(args)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
private main(args: string[]) {
|
||||
createRoot((dispose) => {
|
||||
this.connect("shutdown", dispose)
|
||||
|
||||
return (
|
||||
<Astal.Window name="bar" application={this}>
|
||||
<Gtk.CenterBox>
|
||||
<Gtk.Label $type="center" label="My Awesome Bar" />
|
||||
</Gtk.CenterBox>
|
||||
</Astal.Window>
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const app = new App()
|
||||
app.runAsync([programInvocationName, ...programArgs])
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## Entry point
|
||||
|
||||
You should generally avoid creating resources in the top level of modules and
|
||||
instead create everything in the scope of the `main` function. This is due to
|
||||
the possibility of running as a [client](./app-cli#clients) process.
|
||||
|
||||
:::code-group
|
||||
|
||||
```tsx [app.tsx]
|
||||
const globalInstance = SomeLibrary.get_default() // [!code --]
|
||||
|
||||
function Bar() {
|
||||
const globalInstance = SomeLibrary.get_default() // [!code ++]
|
||||
|
||||
return <></>
|
||||
}
|
||||
|
||||
app.start({
|
||||
main() {
|
||||
Bar()
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## Instance identifier
|
||||
|
||||
You can run multiple instances by defining a unique instance name.
|
||||
|
||||
```ts
|
||||
app.start({
|
||||
instanceName: "my-instance", // defaults to "ags"
|
||||
main() {},
|
||||
})
|
||||
```
|
||||
|
||||
## Messaging from CLI
|
||||
|
||||
If you want to interact with an instance from the CLI, you can do so by sending
|
||||
a request. A request is an argument array.
|
||||
|
||||
```ts
|
||||
app.start({
|
||||
requestHandler(argv: string[], response: (response: string) => void) {
|
||||
const [cmd, arg, ...rest] = argv
|
||||
if (cmd == "say") {
|
||||
return response(arg)
|
||||
}
|
||||
response("unknown command")
|
||||
},
|
||||
main() {},
|
||||
})
|
||||
```
|
||||
|
||||
The `response` function can be called once per request. `ags request` command
|
||||
will wait until a response is given at which point it will print it and exit.
|
||||
|
||||
```sh
|
||||
ags request say hi
|
||||
# hi
|
||||
```
|
||||
|
||||
A request handler can also be defined by connecting to the `request` signal.
|
||||
|
||||
```ts
|
||||
app.connect("reqeust", (app, [cmd, arg, ...rest], response) => {
|
||||
if (cmd === "say") {
|
||||
response(arg)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Toggling Windows by their name
|
||||
|
||||
In order for the application 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 {5}
|
||||
import app from "astal/gtk4/app"
|
||||
|
||||
function Bar() {
|
||||
return (
|
||||
<window name="Bar" $={(self) => app.add_window(self)}>
|
||||
<box />
|
||||
</window>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
You can also invoke `app.add_window()` by simply passing `app` to the
|
||||
`application` prop.
|
||||
|
||||
```tsx {5}
|
||||
import app from "astal/gtk4/app"
|
||||
|
||||
function Bar() {
|
||||
return (
|
||||
<window name="Bar" application={app}>
|
||||
<box />
|
||||
</window>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> 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.
|
||||
|
||||
Toggle the visibility of windows using the `ags` CLI.
|
||||
|
||||
```sh
|
||||
ags toggle Bar
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> In JavaScript you can get a window instance and toggle it using
|
||||
> `app.get_window()`
|
||||
>
|
||||
> ```ts
|
||||
> const bar = app.get_window("Bar")
|
||||
> if (bar) bar.visible = true
|
||||
> ```
|
||||
|
||||
## Clients
|
||||
|
||||
The first time you invoke `app.start()` (for example with `ags run`) the `main`
|
||||
block gets executed. While that instance is running any subsequent execution of
|
||||
the app will simply invoke a [request](#messaging-from-cli). For example running
|
||||
`ags run` again will be the equivalent of running `ags request`
|
||||
|
||||
:::code-group
|
||||
|
||||
```ts [app.ts]
|
||||
app.start({
|
||||
requestHandler(argv, response) {
|
||||
console.log("request", ...argv)
|
||||
response("hello from main instance")
|
||||
},
|
||||
main(...argv: string[]) {
|
||||
console.log(...argv)
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
@@ -0,0 +1,15 @@
|
||||
# Examples
|
||||
|
||||
## Gtk4
|
||||
|
||||
### [Simple Bar](https://github.com/Aylur/ags/tree/main/examples/gtk4/simple-bar)
|
||||
|
||||

|
||||
|
||||
### [Applauncher](https://github.com/Aylur/ags/tree/main/examples/gtk4/applauncher)
|
||||
|
||||

|
||||
|
||||
### [Notifications](https://github.com/Aylur/ags/tree/main/examples/gtk4/notifications)
|
||||
|
||||

|
||||
@@ -0,0 +1,327 @@
|
||||
# Frequently Asked Questions
|
||||
|
||||
## Standard Library
|
||||
|
||||
GJS does not include Node.js APIs you might be used to. You can find the
|
||||
alternative for most APIs in [GLib](https://docs.gtk.org/glib/) and
|
||||
[Gio](https://docs.gtk.org/gio/).
|
||||
|
||||
## Avoiding JSX
|
||||
|
||||
JSX syntax is entirely optional. Under the hood it is just syntactic sugar for
|
||||
[function composition](https://aylur.github.io/gnim/jsx#jsx-expressions-and-jsx-function).
|
||||
|
||||
```tsx
|
||||
function Bar() {
|
||||
// [!code --:5]
|
||||
return (
|
||||
<window name="Bar">
|
||||
<box />
|
||||
</window>
|
||||
)
|
||||
// [!code ++:4]
|
||||
return jsx(Astal.Window, {
|
||||
name: "Bar",
|
||||
children: [jsx(Gtk.Box, {})],
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> You can wrap Gtk/Astal widgets in a simple function to achieve the syntax used
|
||||
> in AGSv1:
|
||||
>
|
||||
> ```ts
|
||||
> import { CCProps, jsx } from "ags"
|
||||
> import { Gtk, Astal } from "ags/gtk4"
|
||||
>
|
||||
> const Box = (props: Partial<CCProps<Gtk.Box, Gtk.Box.ConstructorProps>>) =>
|
||||
> jsx(Gtk.Box, props)
|
||||
>
|
||||
> const Window = (
|
||||
> props: Partial<CCProps<Astal.Window, Astal.Window.ConstructorProps>>,
|
||||
> ) => jsx(Astal.Window, props)
|
||||
>
|
||||
> function Bar() {
|
||||
> return Window({
|
||||
> name: "Bar",
|
||||
> children: [Box({ children: ["Hello There"] })],
|
||||
> })
|
||||
> }
|
||||
> ```
|
||||
|
||||
## Monitor id does not match compositor
|
||||
|
||||
The monitor id property that windows expect is mapped by Gdk, which is not
|
||||
always the same as the compositor. Instead use the `gdkmonitor` property which
|
||||
expects a `Gdk.Monitor` object.
|
||||
|
||||
```tsx
|
||||
function Bar(gdkmonitor) {
|
||||
return <window gdkmonitor={gdkmonitor} />
|
||||
}
|
||||
|
||||
function main() {
|
||||
for (const monitor of app.get_monitors()) {
|
||||
if (monitor.model == "your-desired-model") {
|
||||
Bar(monitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Environment variables
|
||||
|
||||
JavaScript is **not** bash or other shell environments.
|
||||
|
||||
```ts
|
||||
const HOME = exec("echo $HOME") // does not work as you'd expect
|
||||
```
|
||||
|
||||
`exec` and `execAsync` runs the passed program as is, its **not** run in a shell
|
||||
environment, so the above example just passes `$HOME` as a string literal to the
|
||||
`echo` program.
|
||||
|
||||
:::danger Please don't do this
|
||||
|
||||
```ts
|
||||
const HOME = exec("bash -c 'echo $HOME'")
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
You can read environment variables using
|
||||
[GLib.getenv](https://gjs-docs.gnome.org/glib20~2.0/glib.getenv).
|
||||
|
||||
```ts
|
||||
import GLib from "gi://GLib"
|
||||
|
||||
const HOME = GLib.getenv("HOME")
|
||||
```
|
||||
|
||||
## Custom SVG symbolic icons
|
||||
|
||||
Put the svgs in a directory following the freedesktop spec, name them
|
||||
`<icon-name>-symbolic.svg` and use `app.add_icons()` or `icons` parameter in
|
||||
`app.start()`
|
||||
|
||||
```txt
|
||||
.
|
||||
├── icons
|
||||
│ └── hicolor
|
||||
│ └── scalable
|
||||
│ └── actions
|
||||
│ └── custom-symbolic.svg
|
||||
└── app.ts
|
||||
```
|
||||
|
||||
:::code-group
|
||||
|
||||
```ts [app.ts]
|
||||
app.start({
|
||||
icons: `${SRC}/icons`, // SRC will point to the root
|
||||
main() {
|
||||
new Gtk.Image({
|
||||
iconName: "custom-symbolic",
|
||||
})
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
> [!INFO]
|
||||
>
|
||||
> If there is a name clash with an icon from your current icon pack the icon
|
||||
> pack will take precedence
|
||||
|
||||
## Logging
|
||||
|
||||
The `console` API in GJS uses glib logging functions. If you just want to print
|
||||
some text as is to stdout use the globally available `print` function or
|
||||
`printerr` for stderr.
|
||||
|
||||
```ts
|
||||
print("print this line to stdout")
|
||||
printerr("print this line to stderr")
|
||||
```
|
||||
|
||||
## Auto create Window for each Monitor
|
||||
|
||||
You can use the `<For>` component to auto create/destroy a top-level widget
|
||||
automatically for each monitor.
|
||||
|
||||
```tsx [app.ts]
|
||||
import Gtk from "gi://Gtk"
|
||||
import Bar from "./Bar"
|
||||
import { For, This, createBinding } from "ags"
|
||||
|
||||
function main() {
|
||||
const monitors = createBinding(app, "monitors")
|
||||
|
||||
return (
|
||||
<For each={monitors}>
|
||||
{(monitor) => (
|
||||
<This this={app}>
|
||||
<window
|
||||
name="MyWindow"
|
||||
gdkmonitor={monitor}
|
||||
$={(self) => onCleanup(() => self.destroy())}
|
||||
/>
|
||||
{otherWindows}
|
||||
</This>
|
||||
)}
|
||||
</For>
|
||||
)
|
||||
}
|
||||
|
||||
app.start({ main })
|
||||
```
|
||||
|
||||
## Error: Can't convert non-null pointer to JS value
|
||||
|
||||
These happen when accessing list type properties. Gjs fails to correctly bind
|
||||
`List` and other array like types of Vala as a property.
|
||||
|
||||
```ts
|
||||
import Notifd from "gi://AstalNotifd"
|
||||
const notifd = Notifd.get_default()
|
||||
|
||||
notifd.notifications // [!code --]
|
||||
notifd.get_notifications() // [!code ++]
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> Open up an issue/PR to add an
|
||||
> [override](https://github.com/Aylur/ags/blob/main/lib/src/overrides.ts).
|
||||
|
||||
## How to create regular floating windows
|
||||
|
||||
Use `Gtk.Window`.
|
||||
|
||||
By default `Gtk.Window` is destroyed on close. To prevent this add a handler for
|
||||
`delete-event`.
|
||||
|
||||
```tsx {3-6}
|
||||
return (
|
||||
<Gtk.Window
|
||||
onDeleteEvent={(self) => {
|
||||
self.hide()
|
||||
return true
|
||||
}}
|
||||
>
|
||||
{child}
|
||||
</Gtk.Window>
|
||||
)
|
||||
```
|
||||
|
||||
## Is there a way to limit the width/height of a widget?
|
||||
|
||||
- Gtk3: Unfortunately not. You can set a minimum size with `min-width` and
|
||||
`min-heigth` css attributes, but you can not set max size.
|
||||
|
||||
- Gtk4: Yes, using custom layout managers. As a shortcut you can use
|
||||
[Adw.Clamp](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.7/class.Clamp.html)
|
||||
|
||||
## How do I register keybindings?
|
||||
|
||||
Only **focused** windows can capture events. To make a window focusable set its
|
||||
keymode.
|
||||
|
||||
::: code-group
|
||||
|
||||
```tsx [gtk3]
|
||||
<window
|
||||
keymode={Astal.Keymode.ON_DEMAND}
|
||||
onKeyPressEvent={(self, event: Gdk.Event) => {
|
||||
if (event.get_keyval()[1] === Gdk.KEY_Escape) {
|
||||
self.hide()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
```
|
||||
|
||||
```tsx [gtk4]
|
||||
<window keymode={Astal.Keymode.ON_DEMAND}>
|
||||
<Gtk.EventControllerKey
|
||||
onKeyPressed={({ widget }, keyval: number) => {
|
||||
if (keyval === Gdk.KEY_Escape) {
|
||||
widget.hide()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</window>
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> If you want global keybindings you have to use your compositor keybinding
|
||||
> settings. You can define a [request handler](./app-cli#messaging-from-cli) and
|
||||
> invoke it using a compositor keybinding.
|
||||
|
||||
## How to create a Popup
|
||||
|
||||
- Gtk4: simply use Gtk's builtin
|
||||
[Popover](https://docs.gtk.org/gtk4/class.Popover.html).
|
||||
|
||||
- Gtk3: you can create an
|
||||
[Astal.Window](https://aylur.github.io/libastal/astal3/class.Window.html)
|
||||
instance, position it and handle click events. Checkout
|
||||
[examples/gtk3/popover](https://github.com/Aylur/ags/tree/main/examples/gtk3/popover)
|
||||
|
||||
## Nested reactive values
|
||||
|
||||
You might want to access deeply nested objects reactively which you can do using
|
||||
the [`<With>`](https://aylur.github.io/gnim/jsx#dynamic-rendering) component or
|
||||
by using [`createBinding`](https://aylur.github.io/gnim/jsx#createbinding).
|
||||
|
||||
```ts
|
||||
interface Nested extends GObject.Object {
|
||||
value: string
|
||||
}
|
||||
|
||||
interface MyObject extends GObject.Object {
|
||||
nested: null | Nested
|
||||
}
|
||||
```
|
||||
|
||||
Using the `<With>` component you can conditionally access and bind nested
|
||||
objects.
|
||||
|
||||
```tsx
|
||||
function Component() {
|
||||
const nested: Accessor<Nested | null> = createBinding(object, "nested")
|
||||
|
||||
return (
|
||||
<With value={nested}>
|
||||
{(nested) =>
|
||||
nested && (
|
||||
<box>
|
||||
<label label={createBinding(nested, "value")} />
|
||||
</box>
|
||||
)
|
||||
}
|
||||
</With>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Using `createBinding` you can specify multiple properties which will be have as
|
||||
a "path" to the target property. Note that if any property in the path is
|
||||
nullable the result will be nullable.
|
||||
|
||||
```tsx
|
||||
function Component() {
|
||||
const value: Accessor<string | null> = createBinding(
|
||||
object,
|
||||
"nested",
|
||||
"value",
|
||||
)
|
||||
|
||||
return <label label={value((v) => v ?? "")} />
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,431 @@
|
||||
# First Widgets
|
||||
|
||||
On this page you will learn about the JSX syntax. To learn about it more in
|
||||
depth you can read the [Gnim docs](https://aylur.github.io/gnim/jsx.html).
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> `gnim` symbols is reexported from the `ags` module.
|
||||
|
||||
## Entry point of applications
|
||||
|
||||
Every application's entry point is an `app.start` invocation. `app` is a
|
||||
singleton instance of
|
||||
[Gtk.Application](https://docs.gtk.org/gtk4/class.Application.html).
|
||||
|
||||
```ts [<i class="devicon-typescript-plain"></i> app.ts]
|
||||
import app from "ags/gtk4/app"
|
||||
|
||||
app.start({
|
||||
main() {
|
||||
// you will instantiate Widgets here
|
||||
// and setup anything else if you need
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Root of every shell component: Window
|
||||
|
||||
Desktop Shells are composed of widgets. A widget is a piece of UI that has its
|
||||
own logic and style. A widget can be as small as a button or an entire bar. The
|
||||
top level - also known as a root - widget is always a
|
||||
[Window](https://aylur.github.io/libastal/astal4/class.Window.html).
|
||||
|
||||
```tsx [widget/Bar.tsx]
|
||||
function Bar(monitor = 0) {
|
||||
return (
|
||||
<window visible class="Bar" monitor={monitor}>
|
||||
<box>Content of the widget</box>
|
||||
</window>
|
||||
)
|
||||
}
|
||||
|
||||
app.start({
|
||||
main() {
|
||||
Bar(0)
|
||||
Bar(1) // instantiate for each monitor
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
> In Gtk4 unlike other widgets, window widgets are not visible by default. Don't
|
||||
> forget to explicitly make it `visible`.
|
||||
|
||||
## Creating and nesting widgets
|
||||
|
||||
Widgets are JavaScript functions which return `GObject.Object` (usually
|
||||
`Gtk.Widget`) instances by using JSX expressions.
|
||||
|
||||
:::code-group
|
||||
|
||||
```tsx [MyButton.tsx]
|
||||
function MyButton() {
|
||||
return (
|
||||
<button onClicked={(self) => console.log(self, "clicked")}>
|
||||
<label label="Click me!" />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
Now that you have declared `MyButton`, you can nest it into another component.
|
||||
|
||||
```tsx
|
||||
function MyBar() {
|
||||
return (
|
||||
<window visible>
|
||||
<box>
|
||||
Click The button
|
||||
<MyButton />
|
||||
</box>
|
||||
</window>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Notice that widgets you defined start with a capital letter `<MyButton />`.
|
||||
Lowercase tags are builtin [intrinsic](./intrinsics) widgets, while capital
|
||||
letter is for custom widgets.
|
||||
|
||||
## Displaying Data
|
||||
|
||||
JSX lets you put markup into JavaScript. Curly braces let you “escape back” into
|
||||
JavaScript so that you can embed some variable from your code and display it.
|
||||
|
||||
```tsx
|
||||
function MyWidget() {
|
||||
const label = "hello"
|
||||
|
||||
return <button>{label}</button>
|
||||
}
|
||||
```
|
||||
|
||||
You can also pass JavaScript to markup attributes
|
||||
|
||||
```tsx
|
||||
function MyWidget() {
|
||||
const label = "hello"
|
||||
|
||||
return <button label={label} />
|
||||
}
|
||||
```
|
||||
|
||||
## Conditional Rendering
|
||||
|
||||
You can use the same techniques as you use when writing regular JavaScript code.
|
||||
For example, you can use an if statement to conditionally include JSX:
|
||||
|
||||
```tsx
|
||||
function MyWidget() {
|
||||
let content
|
||||
|
||||
if (condition) {
|
||||
content = <True />
|
||||
} else {
|
||||
content = <False />
|
||||
}
|
||||
|
||||
return <box>{content}</box>
|
||||
}
|
||||
```
|
||||
|
||||
You can also inline a
|
||||
[conditional `?`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator)
|
||||
(ternary) expression.
|
||||
|
||||
```tsx
|
||||
function MyWidget() {
|
||||
return <box>{condition ? <True /> : <False />}</box>
|
||||
}
|
||||
```
|
||||
|
||||
When you don’t need the `else` branch, you can also use a shorter
|
||||
[logical && syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND#short-circuit_evaluation):
|
||||
|
||||
```tsx
|
||||
function MyWidget() {
|
||||
return <box>{condition && <True />}</box>
|
||||
}
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) values are
|
||||
> not rendered.
|
||||
|
||||
## Rendering lists
|
||||
|
||||
You can use
|
||||
[`for` loops](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for)
|
||||
or
|
||||
[array `map()` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
|
||||
|
||||
```tsx
|
||||
function MyWidget() {
|
||||
const labels = ["label1", "label2", "label3"]
|
||||
|
||||
return (
|
||||
<box>
|
||||
{labels.map((label) => (
|
||||
<label label={label} />
|
||||
))}
|
||||
</box>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
## Widget signal handlers
|
||||
|
||||
You can respond to events by declaring event handler functions inside your
|
||||
widget:
|
||||
|
||||
```tsx
|
||||
import Gtk from "gi://Gtk"
|
||||
|
||||
function MyButton() {
|
||||
function onClicked(self: Gtk.Button) {
|
||||
console.log(self, "was clicked")
|
||||
}
|
||||
|
||||
return <button onClicked={onClicked} />
|
||||
}
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> Using Gtk4, you can use
|
||||
> [EventControllers](https://docs.gtk.org/gtk4/class.EventController.html) for
|
||||
> more complex event handling.
|
||||
>
|
||||
> ```tsx
|
||||
> <box>
|
||||
> <Gtk.GestureClick
|
||||
> propagationPhase={Gtk.PropagationPhase.CAPTURE}
|
||||
> button={Gdk.BUTTON_PRIMARY}
|
||||
> onPressed={() => print("clicked with primary button")}
|
||||
> />
|
||||
> </box>
|
||||
> ```
|
||||
|
||||
## How properties are passed
|
||||
|
||||
Using JSX, a custom widget will always have a single object as its parameter.
|
||||
|
||||
```ts
|
||||
type Props = {
|
||||
myprop: string
|
||||
children?: JSX.Element | Array<JSX.Element>
|
||||
}
|
||||
|
||||
function MyWidget({ myprop, children }: Props) {
|
||||
//
|
||||
}
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> `JSX.Element` is an alias to `GObject.Object`
|
||||
|
||||
The `children` property is a special one which is used to pass the children
|
||||
given in the JSX expression.
|
||||
|
||||
```tsx
|
||||
// `children` prop of MyWidget is the box
|
||||
return (
|
||||
<MyWidget myprop="hello">
|
||||
<box />
|
||||
</MyWidget>
|
||||
)
|
||||
```
|
||||
|
||||
```tsx
|
||||
// `children` prop of MyWidget is [box, box]
|
||||
return (
|
||||
<MyWidget myprop="hello">
|
||||
<box />
|
||||
<box />
|
||||
</MyWidget>
|
||||
)
|
||||
```
|
||||
|
||||
## State management
|
||||
|
||||
State is managed using signals which are called
|
||||
[`Accessor`](https://aylur.github.io/gnim/jsx#state-management).
|
||||
|
||||
- with `createState` you can instantiate a writable reactive value
|
||||
- with `createBinding` you can hook into GObject properties.
|
||||
- with `createComputed` you can derive reactive values
|
||||
|
||||
:::code-group
|
||||
|
||||
```tsx [State example]
|
||||
import { createState, createComputed } from "ags"
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = createState(0)
|
||||
|
||||
function increment() {
|
||||
setCount((v) => v + 1)
|
||||
}
|
||||
|
||||
const label = createComputed(() => count().toString())
|
||||
|
||||
return (
|
||||
<box>
|
||||
<label label={label} />
|
||||
<button onClicked={increment}>Click to increment</button>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
```tsx [GObject example]
|
||||
import GObject, { register, property } from "ags/gobject"
|
||||
import { createBinding, createComputed } from "ags"
|
||||
|
||||
@register()
|
||||
class CounterStore extends GObject.Object {
|
||||
@property(Number) count = 0
|
||||
}
|
||||
|
||||
function Counter() {
|
||||
const counter = new CounterStore()
|
||||
|
||||
function increment() {
|
||||
counter.count += 1
|
||||
}
|
||||
|
||||
const count = createBinding(count, "count")
|
||||
const label = createComputed(() => count().toString())
|
||||
|
||||
return (
|
||||
<box>
|
||||
<label label={label} />
|
||||
<button onClicked={increment}>Click to increment</button>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
Notice how in the `createComputed` body `count` is called as a function to track
|
||||
it automatically as a dependency for the derived `label` property.
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> There is a shorthand for `createComputed`.
|
||||
>
|
||||
> ```ts
|
||||
> // these two lines mean and do the same thing
|
||||
> const label = createComputed(() => count().toString())
|
||||
> const label = count((c) => c.toString())
|
||||
> ```
|
||||
|
||||
## Integrating external programs
|
||||
|
||||
Other than the aforementioned functions to manage state, AGS provides ways to
|
||||
integrate CLI tools you might be already familiar with:
|
||||
[`createPoll`](./utilities#createpoll) which polls a program at each given
|
||||
interval and [`createSubprocess`](./utilities#createsubprocess) which launches a
|
||||
given program and monitors its standard output.
|
||||
|
||||
As an example let's say you want to use the `date` CLI command to get a
|
||||
formatted date.
|
||||
|
||||
```tsx
|
||||
const date = createPoll("", 1000, `bash -c "date +%H:%M"`)
|
||||
|
||||
return <label label={date} />
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> Running subprocesses are relatively expensive, so always prefer to use a
|
||||
> [library](./resources.html#astal-libraries) when available.
|
||||
|
||||
In reality you would use
|
||||
[`GLib.DateTime`](https://docs.gtk.org/glib/struct.DateTime.html) or
|
||||
JavaScript's
|
||||
[`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date).
|
||||
In newer version of GJS (1.85.2 >=) you can also use the new
|
||||
[`Temporal`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal)
|
||||
JavaScript builtin.
|
||||
|
||||
```tsx
|
||||
const date = createPoll("", 1000, () => new Date().toString())
|
||||
|
||||
return <label label={date} />
|
||||
```
|
||||
|
||||
> [!WARNING] Avoid polling when possible.
|
||||
>
|
||||
> Keep in mind that polling is generally considered bad practice. You should use
|
||||
> events and signals whenever possible which will only do operations when
|
||||
> necessary.
|
||||
|
||||
## Dynamic rendering
|
||||
|
||||
When you want to render based on a value, you can use the `<With>` component.
|
||||
|
||||
```tsx
|
||||
import { With, Accessor } from "ags"
|
||||
|
||||
let value: Accessor<{ member: string } | null>
|
||||
|
||||
return (
|
||||
<box>
|
||||
<With value={value}>
|
||||
{(value) => value && <label label={value.member} />}
|
||||
</With>
|
||||
</box>
|
||||
)
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> In most cases it is better to always render the component and set its
|
||||
> `visible` property instead. Use `<With>` in cases when you need to unpack a
|
||||
> nullable object or when you need to access nested values.
|
||||
|
||||
<!-- -->
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> When the value changes and the widget is re-rendered the previous one is
|
||||
> removed from the parent component and the new one is _appended_. Order of
|
||||
> widgets are _not_ kept so make sure to wrap `<With>` in a container to avoid
|
||||
> it. This is due to Gtk not having a generic API on containers to sort widgets.
|
||||
|
||||
## Dynamic list rendering
|
||||
|
||||
The `<For>` component let's you render based on an array dynamically. Each time
|
||||
the array changes it is compared with its previous state. Widgets for new items
|
||||
are inserted while widgets associated with removed items are removed.
|
||||
|
||||
```tsx
|
||||
import { For, Accessor } from "ags"
|
||||
|
||||
let list: Accessor<Array<any>>
|
||||
|
||||
return (
|
||||
<box>
|
||||
<For each={list}>
|
||||
{(item, index: Accessor<number>) => (
|
||||
<label label={index((i) => `${i}. ${item}`)} />
|
||||
)}
|
||||
</For>
|
||||
</box>
|
||||
)
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> Similarly to `<With>`, when the list changes and a new item is added it is
|
||||
> simply **appended** to the parent. Order of widgets are not kept so make sure
|
||||
> to wrap `<For>` in a container to avoid this.
|
||||
@@ -0,0 +1,62 @@
|
||||
# Installation
|
||||
|
||||
## Arch
|
||||
|
||||
maintainer: [@kotontrion](https://github.com/kotontrion)
|
||||
|
||||
```sh
|
||||
yay -S aylurs-gtk-shell-git
|
||||
```
|
||||
|
||||
## Nix
|
||||
|
||||
maintainer: [@Aylur](https://github.com/Aylur)
|
||||
|
||||
```sh
|
||||
nix shell github:aylur/ags
|
||||
```
|
||||
|
||||
Read more about running AGS on [Nix](./nix)
|
||||
|
||||
## From Source
|
||||
|
||||
1. Install these three
|
||||
[Astal packages](https://aylur.github.io/astal/guide/installation)
|
||||
|
||||
- astal-io
|
||||
- astal3
|
||||
- astal4
|
||||
|
||||
2. Install dependencies
|
||||
|
||||
:::code-group
|
||||
|
||||
```sh [<i class="devicon-archlinux-plain" /> Arch]
|
||||
sudo pacman -Syu \
|
||||
npm meson ninja go gobject-introspection \
|
||||
gtk3 gtk-layer-shell \
|
||||
gtk4 gtk4-layer-shell
|
||||
```
|
||||
|
||||
```sh [<i class="devicon-fedora-plain" /> Fedora]
|
||||
sudo dnf install \
|
||||
npm meson ninja golang gobject-introspection-devel \
|
||||
gtk3-devel gtk-layer-shell-devel \
|
||||
gtk4-devel gtk4-layer-shell-devel
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
3. Clone and install AGS
|
||||
|
||||
```sh
|
||||
git clone https://github.com/aylur/ags.git
|
||||
cd ags
|
||||
npm install
|
||||
meson setup build
|
||||
meson install -C build
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
> By default, meson installs to `/usr/local`.
|
||||
@@ -0,0 +1,436 @@
|
||||
# Builtin Intrinsic Elements
|
||||
|
||||
These are just Gtk widgets which can be used without explicitly importing. For
|
||||
example `<box />` and `<Gtk.Box />` are exactly the same thing.
|
||||
|
||||
## Gtk4
|
||||
|
||||
### box
|
||||
|
||||
[Gtk.Box](https://docs.gtk.org/gtk4/class.Box.html)
|
||||
|
||||
```tsx
|
||||
<box orientation={Gtk.Orientation.HORIZONTAL}>
|
||||
<Child />
|
||||
<Child />
|
||||
<Child />
|
||||
</box>
|
||||
```
|
||||
|
||||
### button
|
||||
|
||||
[Gtk.Button](https://docs.gtk.org/gtk4/class.Button.html)
|
||||
|
||||
```tsx
|
||||
<button onClicked={() => print("clicked")}>
|
||||
<Child />
|
||||
</button>
|
||||
```
|
||||
|
||||
### centerbox
|
||||
|
||||
[Gtk.CenterBox](https://docs.gtk.org/gtk4/class.CenterBox.html)
|
||||
|
||||
```tsx
|
||||
<centerbox orientation={Gtk.Orientation.HORIZONTAL}>
|
||||
<Child $type="start" />
|
||||
<Child $type="center" />
|
||||
<Child $type="end" />
|
||||
</centerbox>
|
||||
```
|
||||
|
||||
### drawingarea
|
||||
|
||||
[Gtk.DrawingArea](https://docs.gtk.org/gtk4/class.DrawingArea.html)
|
||||
|
||||
```tsx
|
||||
<drawingarea
|
||||
$={(self) =>
|
||||
self.set_draw_func((area, cr, width, height) => {
|
||||
//
|
||||
})
|
||||
}
|
||||
/>
|
||||
```
|
||||
|
||||
### entry
|
||||
|
||||
[Gtk.Entry](https://docs.gtk.org/gtk4/class.Entry.html)
|
||||
|
||||
```tsx
|
||||
<entry
|
||||
placeholderText="Start typing..."
|
||||
text=""
|
||||
onNotifyText={({ text }) => print(text)}
|
||||
/>
|
||||
```
|
||||
|
||||
### image
|
||||
|
||||
[Gtk.Image](https://docs.gtk.org/gtk4/class.Image.html)
|
||||
|
||||
```tsx
|
||||
<image
|
||||
file="/path/to/file.png"
|
||||
iconName="system-search-symbolic"
|
||||
pixelSize={16}
|
||||
/>
|
||||
```
|
||||
|
||||
### label
|
||||
|
||||
[Gtk.Label](https://docs.gtk.org/gtk4/class.Label.html)
|
||||
|
||||
```tsx
|
||||
<label
|
||||
label="<span foreground='blue'>text</span>"
|
||||
useMarkup
|
||||
wrap
|
||||
ellipsize={Pango.EllipsizeMode.END}
|
||||
/>
|
||||
```
|
||||
|
||||
### levelbar
|
||||
|
||||
[Gtk.LevelBar](https://docs.gtk.org/gtk4/class.LevelBar.html)
|
||||
|
||||
```tsx
|
||||
<levelbar
|
||||
orientation={Gtk.Orientation.HORIZONTAL}
|
||||
widthRequest={200}
|
||||
value={0.5}
|
||||
/>
|
||||
```
|
||||
|
||||
### menubutton
|
||||
|
||||
[Gtk.MenuButton](https://docs.gtk.org/gtk4/class.MenuButton.html)
|
||||
|
||||
```tsx
|
||||
<menubutton>
|
||||
button content
|
||||
<popover>popover content</popover>
|
||||
</menubutton>
|
||||
```
|
||||
|
||||
### overlay
|
||||
|
||||
[Gtk.Overlay](https://docs.gtk.org/gtk4/class.Overlay.html)
|
||||
|
||||
```tsx
|
||||
<overlay>
|
||||
<Child />
|
||||
<Child $type="overlay" />
|
||||
<Child $type="overlay" />
|
||||
</overlay>
|
||||
```
|
||||
|
||||
### revealer
|
||||
|
||||
[Gtk.Revealer](https://docs.gtk.org/gtk4/class.Revealer.html)
|
||||
|
||||
```tsx
|
||||
<revealer
|
||||
transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
|
||||
revealChild={true}
|
||||
onNotifyChildRevealed={() => print("animation finished")}
|
||||
>
|
||||
<Child />
|
||||
</revealer>
|
||||
```
|
||||
|
||||
### scrolledwindow
|
||||
|
||||
[Gtk.ScrolledWindow](https://docs.gtk.org/gtk4/class.ScrolledWindow.html)
|
||||
|
||||
```tsx
|
||||
<scrolledwindow maxContentHeight={500}>
|
||||
<Child />
|
||||
</scrolledwindow>
|
||||
```
|
||||
|
||||
### slider
|
||||
|
||||
[Astal.Slider](https://aylur.github.io/libastal/astal4/class.Slider.html)
|
||||
|
||||
```tsx
|
||||
<slider
|
||||
value={0.5}
|
||||
min={0}
|
||||
max={1}
|
||||
onChangeValue={({ value }) => print(value)}
|
||||
/>
|
||||
```
|
||||
|
||||
### stack
|
||||
|
||||
[Gtk.Stack](https://docs.gtk.org/gtk4/class.Stack.html)
|
||||
|
||||
```tsx
|
||||
<stack visibleChildName="child2">
|
||||
<Child $type="named" name="child1" />
|
||||
<Child $type="named" name="child2" />
|
||||
</stack>
|
||||
```
|
||||
|
||||
### switch
|
||||
|
||||
[Gtk.Switch](https://docs.gtk.org/gtk4/class.Switch.html)
|
||||
|
||||
```tsx
|
||||
<switch active={true} onNotifyActive={({ active }) => print(active)} />
|
||||
```
|
||||
|
||||
### togglebutton
|
||||
|
||||
[Gtk.ToggleButton](https://docs.gtk.org/gtk4/class.ToggleButton.html)
|
||||
|
||||
```tsx
|
||||
<togglebutton active={true} onToggled={({ active }) => print(active)} />
|
||||
```
|
||||
|
||||
### window
|
||||
|
||||
[Astal.Window](https://aylur.github.io/libastal/astal4/class.Window.html)
|
||||
|
||||
```tsx
|
||||
<window
|
||||
visible
|
||||
namespace="bar"
|
||||
class="Bar"
|
||||
monitor={0}
|
||||
exclusivity={Astal.Exclusivity.EXCLUSIVE}
|
||||
keymode={Astal.Keymode.ON_DEMAND}
|
||||
anchor={
|
||||
Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT
|
||||
}
|
||||
/>
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> In Gtk4 windows are invisible by default, so don't forget to pass `visible`.
|
||||
|
||||
## Gtk3
|
||||
|
||||
### box
|
||||
|
||||
[Gtk.Box](https://docs.gtk.org/gtk3/class.Box.html)
|
||||
|
||||
```tsx
|
||||
<box orientation={Gtk.Orientation.HORIZONTAL}>
|
||||
<Child />
|
||||
<Child />
|
||||
<Child />
|
||||
</box>
|
||||
```
|
||||
|
||||
### button
|
||||
|
||||
[Gtk.Button](https://docs.gtk.org/gtk3/class.Button.html)
|
||||
|
||||
```tsx
|
||||
<button onClicked={() => print("clicked")}>
|
||||
<Child />
|
||||
</button>
|
||||
```
|
||||
|
||||
### centerbox
|
||||
|
||||
[Astal.CenterBox](https://aylur.github.io/libastal/astal3/class.CenterBox.html)
|
||||
|
||||
```tsx
|
||||
<centerbox orientation={Gtk.Orientation.HORIZONTAL}>
|
||||
<Child $type="start" />
|
||||
<Child $type="center" />
|
||||
<Child $type="end" />
|
||||
</centerbox>
|
||||
```
|
||||
|
||||
### circularprogress
|
||||
|
||||
[Astal.CircularProgress](https://aylur.github.io/libastal/astal3/class.CircularProgress.html)
|
||||
|
||||
```tsx
|
||||
<circularprogress value={0.5} startAt={0.75} endAt={0.75}>
|
||||
<icon />
|
||||
</circularprogress>
|
||||
```
|
||||
|
||||
```css
|
||||
circularprogress {
|
||||
color: green;
|
||||
background-color: black;
|
||||
font-size: 6px;
|
||||
margin: 2px;
|
||||
min-width: 32px;
|
||||
}
|
||||
```
|
||||
|
||||
### drawingarea
|
||||
|
||||
[Gtk.DrawingArea](https://docs.gtk.org/gtk3/class.DrawingArea.html)
|
||||
|
||||
```tsx
|
||||
<drawingarea
|
||||
onDraw={(self, cr) => {
|
||||
//
|
||||
}}
|
||||
/>
|
||||
```
|
||||
|
||||
### entry
|
||||
|
||||
[Gtk.Entry](https://docs.gtk.org/gtk3/class.Entry.html)
|
||||
|
||||
```tsx
|
||||
<entry
|
||||
onChanged={({ text }) => print("text changed", text)}
|
||||
onActivate={({ text }) => print("enter", text)}
|
||||
/>
|
||||
```
|
||||
|
||||
### eventbox
|
||||
|
||||
[Astal.EventBox](https://aylur.github.io/libastal/astal3/class.EventBox.html)
|
||||
|
||||
```tsx
|
||||
<eventbox
|
||||
onClick={(_, event) => {
|
||||
print(event.modifier, event.button)
|
||||
}}
|
||||
/>
|
||||
```
|
||||
|
||||
### icon
|
||||
|
||||
[Astal.Icon](https://aylur.github.io/libastal/astal3/class.Icon.html)
|
||||
|
||||
```tsx
|
||||
<icon
|
||||
// named icon or path to a file
|
||||
icon="/path/to/file.png"
|
||||
icon="missing-symbolic"
|
||||
/>
|
||||
```
|
||||
|
||||
```css
|
||||
icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
```
|
||||
|
||||
### label
|
||||
|
||||
[Astal.Label](https://aylur.github.io/libastal/astal3/class.Label.html)
|
||||
|
||||
```tsx
|
||||
<label label="hello" maxWidthChars={16} wrap />
|
||||
```
|
||||
|
||||
### levelbar
|
||||
|
||||
[Astal.LevelBar](https://aylur.github.io/libastal/astal3/class.LevelBar.html)
|
||||
|
||||
```tsx
|
||||
<levelbar value={0.5} widthRequest={200} />
|
||||
```
|
||||
|
||||
### overlay
|
||||
|
||||
[Astal.Overlay](https://aylur.github.io/libastal/astal3/class.Overlay.html)
|
||||
|
||||
```tsx
|
||||
<overlay>
|
||||
<Child>child</Child>
|
||||
<Child>overlay 1</Child>
|
||||
</overlay>
|
||||
```
|
||||
|
||||
### revealer
|
||||
|
||||
[Gtk.Revealer](https://docs.gtk.org/gtk3/class.Revealer.html)
|
||||
|
||||
```tsx
|
||||
<revealer
|
||||
transitionType={Gtk.RevealerTransitionType.SLIDE_RIGHT}
|
||||
revealChild={true}
|
||||
onNotifyChildRevealed={() => print("animation finished")}
|
||||
>
|
||||
<Child />
|
||||
</revealer>
|
||||
```
|
||||
|
||||
### scrollable
|
||||
|
||||
[Astal.Scrollable](https://aylur.github.io/libastal/astal3/class.Scrollable.html)
|
||||
|
||||
```tsx
|
||||
<scrollable heightRequest={100}>
|
||||
<Child />
|
||||
</scrollable>
|
||||
```
|
||||
|
||||
### slider
|
||||
|
||||
[Astal.Slider](https://aylur.github.io/libastal/astal3/class.Slider.html)
|
||||
|
||||
```tsx
|
||||
<slider widthRequest={100} onDragged={({ value }) => print(value)} />
|
||||
```
|
||||
|
||||
### stack
|
||||
|
||||
[Astal.Stack](https://aylur.github.io/libastal/astal3/class.Stack.html)
|
||||
|
||||
```tsx
|
||||
<stack visibleChildName="child2">
|
||||
<Child name="child1" />
|
||||
<Child name="child2" />
|
||||
</stack>
|
||||
```
|
||||
|
||||
### switch
|
||||
|
||||
[Gtk.Switch](https://docs.gtk.org/gtk3/class.Switch.html)
|
||||
|
||||
```tsx
|
||||
<switch active={true} onNotifyActive={({ active }) => print(active)} />
|
||||
```
|
||||
|
||||
### overlay
|
||||
|
||||
[Astal.Overlay](https://aylur.github.io/libastal/astal3/class.Overlay.html)
|
||||
|
||||
```tsx
|
||||
<overlay>
|
||||
<Child>child</Child>
|
||||
<Child>overlay 1</Child>
|
||||
<Child>overlay 1</Child>
|
||||
</overlay>
|
||||
```
|
||||
|
||||
### togglebutton
|
||||
|
||||
[Gtk.ToggleButton](https://docs.gtk.org/gtk4/class.ToggleButton.html)
|
||||
|
||||
```tsx
|
||||
<togglebutton active={true} onToggled={({ active }) => print(active)} />
|
||||
```
|
||||
|
||||
### window
|
||||
|
||||
[Astal.Window](https://aylur.github.io/libastal/astal4/class.Window.html)
|
||||
|
||||
```tsx
|
||||
<window
|
||||
namespace="bar"
|
||||
class="Bar"
|
||||
monitor={0}
|
||||
exclusivity={Astal.Exclusivity.EXCLUSIVE}
|
||||
keymode={Astal.Keymode.ON_DEMAND}
|
||||
anchor={
|
||||
Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT
|
||||
}
|
||||
/>
|
||||
```
|
||||
@@ -0,0 +1,448 @@
|
||||
# Migration Guide
|
||||
|
||||
## From v2
|
||||
|
||||
### Import paths
|
||||
|
||||
`astal` namespace have been dropped. AGS is now using
|
||||
[Gnim](https://github.com/aylur/gnim) which is reexported from the `ags`
|
||||
namespace.
|
||||
|
||||
```ts
|
||||
// [!code --:2]
|
||||
import { App, Gtk } from "astal/gtk3"
|
||||
import { bind, Variable } from "astal/state"
|
||||
// [!code ++:3]
|
||||
import app from "ags/gtk3/app"
|
||||
import Gtk from "gi://Gtk?version=3.0"
|
||||
import { createBinding, createState } from "ags"
|
||||
```
|
||||
|
||||
### Subclassing
|
||||
|
||||
`astalify` has been removed, `jsx` function and JSX expressions handle
|
||||
everything. It is possible to use Gtk widgets directly without any prior setup.
|
||||
|
||||
```tsx
|
||||
// [!code --:2]
|
||||
const Calendar = astalify(Gtk.Calendar)
|
||||
const _ = <Calendar />
|
||||
// [!code ++:1]
|
||||
const _ = <Gtk.Calendar />
|
||||
```
|
||||
|
||||
If you still prefer to use regular JS functions instead of JSX, you can do
|
||||
|
||||
```ts
|
||||
import { CCProps } from "ags"
|
||||
import { Gtk } from "ags/gtk4"
|
||||
type BoxProps = Partial<CCProps<Gtk.Box, Gtk.Box.ConstructorProps>>
|
||||
const Box = (props: BoxProps) => jsx(Gtk.Box, props)
|
||||
|
||||
Box({
|
||||
orientation: state,
|
||||
children: [Box()],
|
||||
})
|
||||
```
|
||||
|
||||
### GObject decorators
|
||||
|
||||
They were updated to the stage 3 proposal. You can read more about them on the
|
||||
[Gnim](https://aylur.github.io/gnim/gobject.html) documentation.
|
||||
|
||||
```ts
|
||||
@register()
|
||||
class MyObj extends GObject.Object {
|
||||
@property(String) declare myProp: string // [!code --]
|
||||
@property(String) myProp = "" // [!code ++]
|
||||
|
||||
@property(String) // [!code --]
|
||||
@getter(String) // [!code ++]
|
||||
get myProp() {
|
||||
return ""
|
||||
}
|
||||
|
||||
@property(String) // [!code --]
|
||||
@setter(String) // [!code ++]
|
||||
set myProp(v: string) {
|
||||
//
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Make sure to also update `tsconfig.json`
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": false, // [!code ++]
|
||||
"target": "ES2020", // [!code ++]
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### Syntax changes
|
||||
|
||||
- `setup` -> `$`
|
||||
- `className` -> `class`
|
||||
|
||||
```tsx
|
||||
<button class="my-button" $={(self) => print("ref", self)} />
|
||||
```
|
||||
|
||||
### Variable
|
||||
|
||||
`Variable` has been removed in favor of `Accessor` and `createState`. You can
|
||||
read more about them on the
|
||||
[Gnim](https://aylur.github.io/gnim/jsx.html#state-management) documentation.
|
||||
|
||||
```tsx
|
||||
// [!code --:3]
|
||||
const v = Variable("")
|
||||
return <label label={v()} />
|
||||
v.set("new value")
|
||||
// [!code ++:3]
|
||||
const [v, setV] = createState("")
|
||||
return <label label={v} />
|
||||
setV("new value")
|
||||
```
|
||||
|
||||
Variable methods have a matching Accessor create functions
|
||||
|
||||
- `.poll`: [`createPoll`](./utilities.md#createpoll)
|
||||
- `.watch`: [`createSubprocess`](./utilities.md#createsubprocess)
|
||||
- `.observe`:
|
||||
[`createConnection`](https://aylur.github.io/gnim/jsx#createconnection)
|
||||
- `.derive`: [`createComputed`](https://aylur.github.io/gnim/jsx#createcomputed)
|
||||
|
||||
- `.drop`: Accessors cannot be explicitly cleaned up. Use the intended create
|
||||
functions which will be cleaned up automatically.
|
||||
|
||||
### Binding
|
||||
|
||||
`Binding` and `bind` has been removed but the API is identical with the only
|
||||
difference being that you need to use an Accessor creator function.
|
||||
|
||||
```tsx
|
||||
// [!code --:2]
|
||||
import { bind } from "astal"
|
||||
const v = bind(object, "prop")
|
||||
// [!code ++:2]
|
||||
import { createBinding } from "ags"
|
||||
const v = createBinding(object, "prop")
|
||||
return <label label={v((v) => `transformed ${v}`)} />
|
||||
```
|
||||
|
||||
### Dynamic rendering
|
||||
|
||||
Dynamic children rendering is done with `<With>` and `<For>` components.
|
||||
`children` prop can no longer take a `Binding`.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
const value: Binding<object>
|
||||
const list: Binding<Array<object>>
|
||||
|
||||
return (
|
||||
<box>
|
||||
{/* [!code --:3] */}
|
||||
{value.as((value) => (
|
||||
<></>
|
||||
))}
|
||||
{/* [!code ++:3] */}
|
||||
<With value={value}>
|
||||
{(value) => <></>}
|
||||
</With>
|
||||
{/* [!code --:3] */}
|
||||
{list.as(list => list.map(item => (
|
||||
<></>
|
||||
)))}
|
||||
{/* [!code ++:3] */}
|
||||
<For each={list}>
|
||||
{(item) => <></>}
|
||||
</For>
|
||||
</box>
|
||||
)
|
||||
```
|
||||
|
||||
## From v1
|
||||
|
||||
Ags was rewritten from scratch and unfortunately everything changed drastically,
|
||||
you will have to rewrite your projects from the ground up.
|
||||
|
||||
There were so many changes I'm unable to list everything, but these are some
|
||||
highlights.
|
||||
|
||||
### Entry Point
|
||||
|
||||
Instead of a fixed `~/.config/ags/config.js` entry you can name the main file
|
||||
anything and specify it as an arg to `ags run </path/to/entry>`.
|
||||
|
||||
If you wish to stick to having the source code in `~/.config/ags` then name the
|
||||
entry file `app.js`, `app.ts`, `app.jsx` or `app.tsx` which `ags run` will use
|
||||
by default.
|
||||
|
||||
The entry point in code changed from `App.config` to `app.start`
|
||||
|
||||
```js
|
||||
// [!code --:5]
|
||||
App.config({
|
||||
windows: [
|
||||
// window instances
|
||||
],
|
||||
})
|
||||
// [!code ++:7]
|
||||
import app from "astal/gtk4/app"
|
||||
|
||||
app.start({
|
||||
main() {
|
||||
// any initialization code
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
### Instantiating widgets
|
||||
|
||||
It is no longer recommended to create top level instances because scripts can
|
||||
run in
|
||||
[client mode](https://aylur.github.io/astal/guide/typescript/cli-app#client) and
|
||||
it is recommended to only execute code in either `main` or `client` blocks.
|
||||
|
||||
```js
|
||||
// [!code --:5]
|
||||
const win = Widget.Window()
|
||||
|
||||
App.config({
|
||||
windows: [win],
|
||||
})
|
||||
// [!code ++:5]
|
||||
app.main({
|
||||
main() {
|
||||
new Widget.Window()
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
### Templating
|
||||
|
||||
AGS now supports and recommends the usage of
|
||||
[JSX](./first-widgets#creating-and-nesting-widgets).
|
||||
|
||||
```jsx
|
||||
// [!code --:4]
|
||||
const _ = Widget.Box({
|
||||
vertical: true,
|
||||
children: [Widget.Label("hello")],
|
||||
})
|
||||
// [!code ++:5]
|
||||
const _ = (
|
||||
<box vertical>
|
||||
<label label="hello" />
|
||||
</box>
|
||||
)
|
||||
```
|
||||
|
||||
### Reactivity
|
||||
|
||||
`Variable` has been removed in favor of signals.
|
||||
|
||||
```jsx
|
||||
const label = Variable("hello") // [!code --:5]
|
||||
|
||||
Label({
|
||||
label: label.bind().as((hello) => `${hello} world`),
|
||||
})
|
||||
import { createState } from "ags" // [!code ++:6]
|
||||
const [label, setLabel] = createState("hello")
|
||||
return <label label={label((hello) => `${hello} world`)} />
|
||||
```
|
||||
|
||||
### Hooks
|
||||
|
||||
Widgets are no longer subclassed, added methods have been removed.
|
||||
|
||||
```jsx
|
||||
// [!code --:6]
|
||||
Widget.Button({
|
||||
setup: (self) => {
|
||||
self.on("signal-name", handler)
|
||||
self.hook(obj, handler, "changed")
|
||||
},
|
||||
})
|
||||
import { onCleanup } from "ags" // [!code ++:14]
|
||||
|
||||
function MyWidget() {
|
||||
const id = obj.connect("signal-name", callback)
|
||||
|
||||
onCleanup(() => {
|
||||
obj.disconnect(id)
|
||||
})
|
||||
|
||||
return <button onClicked={handler} />
|
||||
}
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> `.keybind` and `.poll` hooks have been removed. Polling should be done using
|
||||
> `createPoll`. Keybinds should be done using the intended Gtk APIs.
|
||||
|
||||
### Widgets
|
||||
|
||||
`JSX` handles everything, it is no longer needed to subclass widgets.
|
||||
|
||||
```jsx
|
||||
import Gtk from "gi://Gtk"
|
||||
const calendar = <Gtk.Calendar />
|
||||
```
|
||||
|
||||
### Globals
|
||||
|
||||
`App`, `Service`, `Utils`, `Widget`, `Variable` are no longer globally available
|
||||
|
||||
```js
|
||||
import app from "ags/gtk4/app"
|
||||
import * as fileUtils from "ags/file"
|
||||
import * as procUtils from "ags/process"
|
||||
import * as timeUtils from "ags/time"
|
||||
import { createBinding, createState } from "ags"
|
||||
```
|
||||
|
||||
### Services
|
||||
|
||||
These are no longer called `Service`. There is no longer a distinction between a
|
||||
`Service` and `GObject.Object` and there are no longer builtin Services.
|
||||
|
||||
These are now simply external
|
||||
[libraries](https://aylur.github.io/astal/guide/libraries/references#astal-libraries)
|
||||
that will have to be installed next to AGS. They are now implemented in Vala or
|
||||
C which makes it possible to also use them outside of AGS.
|
||||
|
||||
They work very similarly however.
|
||||
|
||||
```js
|
||||
// importing
|
||||
const battery = await Service.import("battery") // [!code --]
|
||||
import Battery from "gi://AstalBattery" // [!code ++:2]
|
||||
const battery = Battery.get_default()
|
||||
|
||||
// binding
|
||||
const b = battery.bind("percentage") // [!code --]
|
||||
import { createBinding } from "ags" // [!code ++:2]
|
||||
const b = createBinding(battery, "percentage")
|
||||
```
|
||||
|
||||
Creating custom "Services" now simply means creating a `GObject.Object`
|
||||
subclass.
|
||||
|
||||
```ts
|
||||
// [!code --:16]
|
||||
class MyService extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{
|
||||
"my-signal": ["float"],
|
||||
},
|
||||
{
|
||||
"my-value": ["float", "rw"],
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
get my_value(): number
|
||||
set my_value(v: number)
|
||||
}
|
||||
import GObject, { register, signal, property } from "ags/gobject" // [!code ++:9]
|
||||
|
||||
@register()
|
||||
class MyService extends GObject.Object {
|
||||
@property(Number) myValue = 0
|
||||
|
||||
@signal(Number)
|
||||
mySignal(n: number): void {}
|
||||
}
|
||||
```
|
||||
|
||||
### Utils
|
||||
|
||||
- File, Process and Time utility functions are available from their own
|
||||
[module](./utilities)
|
||||
|
||||
```js
|
||||
Utils.exec("command") // [!code --:4]
|
||||
Utils.readFile("file")
|
||||
Utils.timeout(1000, callback)
|
||||
Utils.fetch("url")
|
||||
import { exec } from "ags/process" // [!code ++:4]
|
||||
import { readFile } from "ags/file"
|
||||
import { timeout } from "ags/time"
|
||||
import { fetch } from "ags/fetch"
|
||||
```
|
||||
|
||||
- Icon lookup is has no alternative. Use `Gtk.IconTheme`.
|
||||
|
||||
- Authenticating have been moved to
|
||||
[AstalAuth](https://aylur.github.io/astal/guide/libraries/auth)
|
||||
|
||||
- Sending notifications will be available in
|
||||
[AstalNotifd](https://aylur.github.io/astal/guide/libraries/notifd). Until
|
||||
then see [#26](https://github.com/Aylur/astal/issues/26).
|
||||
|
||||
### CLI
|
||||
|
||||
To make windows toggleable through CLI you will have to now
|
||||
[pass the `app` instance to `Window`](./app-cli#toggling-windows-by-their-name)
|
||||
instances instead of passing an array of windows to `App.config`.
|
||||
|
||||
```js
|
||||
// [!code --:3]
|
||||
App.config({
|
||||
windows: [Widget.Window({ name: "window-name" })],
|
||||
})
|
||||
// [!code ++:5]
|
||||
app.start({
|
||||
main() {
|
||||
return <window name="window-name" application={app}></window>
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
`ags --run-js` have been removed in favor of
|
||||
[requests](./app-cli#messaging-from-cli).
|
||||
|
||||
```ts
|
||||
// [!code --:3]
|
||||
globalThis.myfunction = () => {
|
||||
print("hello")
|
||||
}
|
||||
// [!code ++:8]
|
||||
app.start({
|
||||
requestHandler(request: string, res: (response: any) => void) {
|
||||
if (request == "myfunction") {
|
||||
res("hello")
|
||||
}
|
||||
res("unknown command")
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
```sh
|
||||
ags -r "myfunction()" # [!code --]
|
||||
ags request myfunction # [!code ++]
|
||||
```
|
||||
|
||||
Instance name is now defined in code instead of cli of first launch
|
||||
|
||||
```js
|
||||
app.start({
|
||||
instanceName: "name",
|
||||
})
|
||||
```
|
||||
|
||||
```sh
|
||||
ags -i name # [!code --:2]
|
||||
ags -t window-name -i name
|
||||
ags run # [!code ++:2]
|
||||
ags toggle window-name -i name
|
||||
```
|
||||
@@ -0,0 +1,211 @@
|
||||
# Usage on NixOS
|
||||
|
||||
Initialize a directory using the template.
|
||||
|
||||
```sh
|
||||
nix flake init --template github:aylur/ags
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> If you are new to NixOS and are not yet familiar with flakes, derivations or
|
||||
> development shells the recommended way to use AGS is the
|
||||
> [home-manager](#using-home-manager) module.
|
||||
|
||||
## Bundle and DevShell
|
||||
|
||||
To build a derivation you can use the `ags bundle` command.
|
||||
|
||||
:::code-group
|
||||
|
||||
```nix [<i class="devicon-nixos-plain"></i> flake.nix]
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
|
||||
astal = {
|
||||
url = "github:aylur/astal";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
ags = {
|
||||
url = "github:aylur/ags";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.astal.follows = "astal";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, ags, astal }: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
packages.${system}.default = pkgs.stdenv.mkDerivation { # [!code focus:31]
|
||||
pname = "my-shell";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
wrapGAppsHook3
|
||||
gobject-introspection
|
||||
ags.packages.${system}.default
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
pkgs.glib
|
||||
pkgs.gjs
|
||||
astal.io
|
||||
astal.astal4
|
||||
# packages like astal.battery or pkgs.libsoup_4
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
ags bundle app.ts $out/bin/my-shell
|
||||
'';
|
||||
|
||||
preFixup = ''
|
||||
gappsWrapperArgs+=(
|
||||
--prefix PATH : ${pkgs.lib.makeBinPath ([
|
||||
# runtime executables
|
||||
])}
|
||||
)
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
While working on the project, it would make sense to use the `ags` cli instead
|
||||
of building it everytime with `nix`.
|
||||
|
||||
You could enter a shell with `agsFull` package which exposes AGS + every
|
||||
[Astal library](https://aylur.github.io/astal/guide/libraries/references#astal-libraries).
|
||||
|
||||
```sh
|
||||
nix shell github:aylur/ags#agsFull
|
||||
```
|
||||
|
||||
Or define a `devShell` and cherry pick packages.
|
||||
|
||||
:::code-group
|
||||
|
||||
```nix [<i class="devicon-nixos-plain"></i> flake.nix]
|
||||
{
|
||||
outputs = { self, nixpkgs, ags }: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
(ags.packages.${system}.default.override { # [!code focus:5]
|
||||
extraPackages = [
|
||||
# cherry pick packages
|
||||
];
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## Using home-manager
|
||||
|
||||
If you prefer the workflow of "configuring a program" instead of "using a
|
||||
library", you can use the home-manager module.
|
||||
|
||||
:::
|
||||
|
||||
Example content of `flake.nix`
|
||||
|
||||
:::code-group
|
||||
|
||||
```nix [<i class="devicon-nixos-plain"></i> flake.nix]
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
|
||||
home-manager = {
|
||||
url = "github:nix-community/home-manager";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
astal.url = "github:aylur/astal";
|
||||
|
||||
ags.url = "github:aylur/ags"; # [!code focus]
|
||||
};
|
||||
|
||||
outputs = { home-manager, nixpkgs, ... }@inputs:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
in
|
||||
{
|
||||
homeConfigurations."${username}" = home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
|
||||
# pass inputs as specialArgs # [!code focus:2]
|
||||
extraSpecialArgs = { inherit inputs; };
|
||||
|
||||
# import your home.nix # [!code focus:2]
|
||||
modules = [ ./home-manager/home.nix ];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
Example content of `home.nix` file
|
||||
|
||||
:::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;
|
||||
|
||||
# symlink to ~/.config/ags
|
||||
configDir = ../ags;
|
||||
|
||||
# additional packages and executables to add to gjs's runtime
|
||||
extraPackages = with pkgs; [
|
||||
inputs.astal.packages.${pkgs.system}.battery
|
||||
fzf
|
||||
];
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
The module only includes the core `astal3`, `astal4` and `astal-io` libraries.
|
||||
If you want to include any other
|
||||
[library](https://aylur.github.io/astal/guide/libraries/references#astal-libraries)
|
||||
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`.
|
||||
|
||||
## Using Astal CLI tools
|
||||
|
||||
The home-manager module does not expose Astal CLIs to the home environment, you
|
||||
have to do that yourself if you want:
|
||||
|
||||
:::code-group
|
||||
|
||||
```nix [<i class="devicon-nixos-plain"></i> home.nix]
|
||||
home.packages = [ inputs.astal.packages.${pkgs.system}.notifd ];
|
||||
```
|
||||
|
||||
```sh [<i class="devicon-bash-plain"></i> sh]
|
||||
astal-notifd --help
|
||||
```
|
||||
|
||||
:::
|
||||
@@ -0,0 +1,88 @@
|
||||
# Quick Start
|
||||
|
||||
It's as easy as a few lines to get a bar running on your screen.
|
||||
|
||||
## What will you be using
|
||||
|
||||
- [Gnome JavaScript (GJS)](https://gjs.guide/) is the JavaScript runtime
|
||||
- [Astal](https://aylur.github.io/astal/) is a suite of libraries which lets you
|
||||
query and interact with parts of your system
|
||||
- [Gnim](https://aylur.github.io/gnim/) is a library for GJS, which allows you
|
||||
to write widgets using JSX
|
||||
- [AGS](https://aylur.github.io/ags/) is a CLI tool which lets you skip setting
|
||||
up a dev environment and jump straight into writing your Desktop Shell in
|
||||
TypeScript
|
||||
|
||||
## Single file start
|
||||
|
||||
First create a file anywhere on your system.
|
||||
|
||||
::: code-group
|
||||
|
||||
```tsx [<i class="devicon-typescript-plain"></i> mybar.tsx]
|
||||
import app from "ags/gtk4/app"
|
||||
import { Astal } from "ags/gtk4"
|
||||
import { createPoll } from "ags/time"
|
||||
|
||||
app.start({
|
||||
main() {
|
||||
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor
|
||||
const clock = createPoll("", 1000, "date")
|
||||
|
||||
return (
|
||||
<window visible anchor={TOP | LEFT | RIGHT}>
|
||||
<label label={clock} />
|
||||
</window>
|
||||
)
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
And run it using the following command:
|
||||
|
||||
```sh
|
||||
ags run ./mybar.tsx
|
||||
```
|
||||
|
||||
Alternatively, you can add a shebang and make it executable
|
||||
|
||||
```ts [mybar.tsx]
|
||||
#!/usr/bin/env -S ags run
|
||||
import app from "ags/gtk4/app"
|
||||
|
||||
app.start({
|
||||
main() {
|
||||
// entry point
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
```sh
|
||||
chmod +x mybar.tsx
|
||||
./mybar.tsx
|
||||
```
|
||||
|
||||
To setup a TypeScript environment use the `types` command
|
||||
|
||||
```sh
|
||||
ags types -u -d /path/to/project/root
|
||||
```
|
||||
|
||||
## Using a template
|
||||
|
||||
It is recommended to start with a template which will setup files needed for
|
||||
TypeScript development environments.
|
||||
|
||||
You can get started using a template with this simple command
|
||||
|
||||
```sh
|
||||
ags init -d /path/to/project
|
||||
```
|
||||
|
||||
If you are on nix, there is also a flake template
|
||||
|
||||
```sh
|
||||
nix flake init --template github:aylur/ags
|
||||
```
|
||||
@@ -0,0 +1,44 @@
|
||||
# Resources
|
||||
|
||||
- [Gnim](https://aylur.github.io/gnim/): The base GJS library AGS is built on.
|
||||
Note that `gnim` modules are reexported from the `ags` namespace. For example
|
||||
the `gnim/gobject` module becomes `ags/gobject`.
|
||||
|
||||
<!--TODO: explain C notations for GJS-->
|
||||
|
||||
## GJS
|
||||
|
||||
- [gjs-docs.gnome.org](https://gjs-docs.gnome.org/): Library references
|
||||
annotated for GJS
|
||||
- [gjs.guide](https://gjs.guide/): GJS and GObject guide
|
||||
|
||||
## Astal Libraries
|
||||
|
||||
- [Apps](https://aylur.github.io/libastal/apps): Library and CLI tool for
|
||||
querying applications
|
||||
- [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
|
||||
- [Notifd](https://aylur.github.io/libastal/notifd): A notification daemon
|
||||
library and CLI tool
|
||||
- [PowerProfiles](https://aylur.github.io/libastal/powerprofiles): Library and
|
||||
CLI to control upowerd powerprofiles
|
||||
- [River](https://aylur.github.io/libastal/river): Library and CLI tool for
|
||||
getting status information of the river wayland compositor
|
||||
- [Tray](https://aylur.github.io/libastal/tray): A systemtray library and CLI
|
||||
tool
|
||||
- [WirePlumber](https://aylur.github.io/libastal/wireplumber): A library for
|
||||
audio control using wireplumber
|
||||
@@ -0,0 +1,92 @@
|
||||
# Theming
|
||||
|
||||
Since the widget toolkit is **GTK** theming is done with **CSS**.
|
||||
|
||||
- [CSS tutorial](https://www.w3schools.com/css/)
|
||||
- Gtk4
|
||||
- [GTK4 CSS Overview wiki](https://docs.gtk.org/gtk4/css-overview.html)
|
||||
- [GTK4 CSS Properties Overview wiki](https://docs.gtk.org/gtk4/css-properties.html)
|
||||
- Gtk3
|
||||
- [GTK3 CSS Overview wiki](https://docs.gtk.org/gtk3/css-overview.html)
|
||||
- [GTK3 CSS Properties Overview wiki](https://docs.gtk.org/gtk3/css-properties.html)
|
||||
|
||||
> [!WARNING] GTK is not the web
|
||||
>
|
||||
> While most features are implemented in GTK, you can't assume anything that
|
||||
> works on the web will work with GTK. Refer to the GTK docs to see what is
|
||||
> supported.
|
||||
|
||||
## Loading static stylesheets
|
||||
|
||||
You can import any `css` or `scss` file which will be inlined as a string which
|
||||
you can pass to the css property.
|
||||
|
||||
:::code-group
|
||||
|
||||
```ts [app.ts]
|
||||
import css from "./style.css"
|
||||
import scss from "./style.scss"
|
||||
|
||||
const inlineCss = `
|
||||
window {
|
||||
background-color: transparent;
|
||||
}
|
||||
`
|
||||
|
||||
app.start({
|
||||
css: css,
|
||||
css: scss,
|
||||
css: inlineCss,
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## Css Property on Widgets
|
||||
|
||||
You should always prefer to style using class names and stylesheets. But in
|
||||
those rare cases when you need apply a style based on a JavaScript value you can
|
||||
use the `css` property.
|
||||
|
||||
```tsx
|
||||
<box css="padding 1em; border: 1px solid red;" />
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> The `css` property of a widget will not cascade to its children. You should
|
||||
> generally avoid using `css` and instead use `class` and stylesheets.
|
||||
|
||||
## Apply Stylesheets at Runtime
|
||||
|
||||
You can apply additional styles at runtime.
|
||||
|
||||
```ts
|
||||
app.apply_css("/path/to/file.css")
|
||||
```
|
||||
|
||||
```ts
|
||||
app.apply_css(`
|
||||
window {
|
||||
background-color: transparent;
|
||||
}
|
||||
`)
|
||||
```
|
||||
|
||||
```ts
|
||||
app.reset_css() // reset if need
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> `apply_css()` will apply on top of other stylesheets applied before. You can
|
||||
> reset stylesheets with `reset_css()`
|
||||
|
||||
## Inspector
|
||||
|
||||
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)
|
||||
|
||||
```sh [ags]
|
||||
ags inspect
|
||||
```
|
||||
@@ -0,0 +1,294 @@
|
||||
# Utilities
|
||||
|
||||
AGS comes with some builtin utilities for common operations.
|
||||
|
||||
## File functions
|
||||
|
||||
### Reading files
|
||||
|
||||
```ts
|
||||
import { readFile, readFileAsync } from "ags/file"
|
||||
|
||||
function readFile(path: string): string
|
||||
function readFileAsync(path: string): Promise<string>
|
||||
```
|
||||
|
||||
### Writing files
|
||||
|
||||
```ts
|
||||
import { writeFile, writeFileAsync } from "ags/file"
|
||||
|
||||
function writeFile(path: string, content: string): void
|
||||
function writeFileAsync(path: string, content: string): Promise<void>
|
||||
```
|
||||
|
||||
### Monitoring files
|
||||
|
||||
If `path` is a directory it will be recursively monitored.
|
||||
|
||||
```ts
|
||||
import { monitorFile } from "ags/file"
|
||||
|
||||
function monitorFile(
|
||||
path: string,
|
||||
callback: (file: string, event: Gio.FileMonitorEvent) => void,
|
||||
): Gio.FileMonitor
|
||||
```
|
||||
|
||||
## Timeouts and Intervals
|
||||
|
||||
```ts
|
||||
import { interval, timeout, idle, createPoll } from "ags/time"
|
||||
```
|
||||
|
||||
You can use JavaScript native `setTimeout` or `setInterval` functions which
|
||||
return a [GLib.Source](https://docs.gtk.org/glib/struct.Source.html) instance.
|
||||
Alternatively you can use these functions provided by AGS, which return a
|
||||
`Timer` instance.
|
||||
|
||||
```ts
|
||||
class Timer extends GObject.Object {
|
||||
declare $signals: {
|
||||
now(): void
|
||||
cancelled(): void
|
||||
}
|
||||
|
||||
cancel(): void
|
||||
}
|
||||
```
|
||||
|
||||
### Interval
|
||||
|
||||
Will immediately execute the function and every `interval` millisecond.
|
||||
|
||||
```ts
|
||||
function interval(interval: number, callback?: () => void): Timer
|
||||
```
|
||||
|
||||
### Timeout
|
||||
|
||||
Will execute the `callback` after `timeout` millisecond.
|
||||
|
||||
```ts
|
||||
function timeout(timeout: number, callback?: () => void): Timer
|
||||
```
|
||||
|
||||
### Idle
|
||||
|
||||
Executes `callback` whenever there are no higher priority events pending.
|
||||
|
||||
```ts
|
||||
function idle(callback?: () => void): Timer
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```ts
|
||||
const timer = interval(1000, () => {
|
||||
console.log("optional callback")
|
||||
})
|
||||
|
||||
timer.connect("now", () => {
|
||||
console.log("tick")
|
||||
})
|
||||
|
||||
timer.connect("cancelled", () => {
|
||||
console.log("cancelled")
|
||||
})
|
||||
|
||||
timer.cancel()
|
||||
```
|
||||
|
||||
### createPoll
|
||||
|
||||
`createPoll` creates a signal that only polls when there is at least one
|
||||
subscriber.
|
||||
|
||||
```ts
|
||||
function createPoll(
|
||||
init: string,
|
||||
interval: number,
|
||||
exec: string | string[],
|
||||
): Accessor<string>
|
||||
|
||||
function createPoll<T>(
|
||||
init: T,
|
||||
interval: number,
|
||||
exec: string | string[],
|
||||
transform: (stdout: string, prev: T) => T,
|
||||
): Accessor<T>
|
||||
|
||||
function createPoll<T>(
|
||||
init: T,
|
||||
interval: number,
|
||||
fn: (prev: T) => T | Promise<T>,
|
||||
): Accessor<T>
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```tsx
|
||||
function Counter() {
|
||||
const counter = createPoll(0, 1000, (prev) => prev + 1)
|
||||
|
||||
return <label label={counter((c) => c.toString())} />
|
||||
}
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> Under the hood when passing a command as the third argument it uses
|
||||
> [`execAsync`](#subprocess) which runs the given programs as is. They are
|
||||
> **not** executed in a shell environment, they do **not** expand ENV variables
|
||||
> like `$HOME`, and they do **not** handle logical operators like `&&` and `||`.
|
||||
>
|
||||
> If you want bash, run them with bash.
|
||||
>
|
||||
> ```ts
|
||||
> createPoll("", 1000, "bash -c 'command $ENV_VAR && command'")
|
||||
> ```
|
||||
|
||||
## Process functions
|
||||
|
||||
Import from `ags/process`
|
||||
|
||||
```ts
|
||||
import { subprocess, exec, execAsync, createSubprocess } from "ags/process"
|
||||
```
|
||||
|
||||
### Subprocess
|
||||
|
||||
You can start a subprocess and run callback functions whenever it outputs to
|
||||
stdout or stderr. The returned `Process` instance has an `stdout` and `stderr`
|
||||
signal.
|
||||
|
||||
```ts
|
||||
class Process extends GObject.Object {
|
||||
declare $signals: {
|
||||
stdout(out: string): void
|
||||
stderr(err: string): void
|
||||
exit(code: number, signaled: boolean): void
|
||||
}
|
||||
|
||||
kill(): void
|
||||
write(str: string): void
|
||||
async writeAsync(str: string): Promise<void>
|
||||
}
|
||||
|
||||
function subprocess(args: {
|
||||
cmd: string | string[]
|
||||
out?: (stdout: string) => void
|
||||
err?: (stderr: string) => void
|
||||
}): Process
|
||||
|
||||
function subprocess(
|
||||
cmd: string | string[],
|
||||
onOut?: (stdout: string) => void,
|
||||
onErr?: (stderr: string) => void,
|
||||
): Process
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```ts
|
||||
const proc = subprocess(
|
||||
"some-command",
|
||||
(out) => console.log(out), // optional
|
||||
(err) => console.error(err), // optional
|
||||
)
|
||||
|
||||
// or with signals
|
||||
const proc = subprocess("some-command")
|
||||
proc.connect("stdout", (_, out) => console.log(out))
|
||||
proc.connect("stderr", (_, err) => console.error(err))
|
||||
```
|
||||
|
||||
### Executing external commands and scripts
|
||||
|
||||
```ts
|
||||
function exec(cmd: string | string[]): string
|
||||
function execAsync(cmd: string | string[]): Promise<string>
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> You should generally avoid `exec` and use its async variant `execAsync` as the
|
||||
> former will block IO, meaning the whole shell will freeze and will be
|
||||
> unresponsive until it returns.
|
||||
|
||||
Example:
|
||||
|
||||
```ts
|
||||
try {
|
||||
const out = exec("/path/to/script")
|
||||
console.log(out)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
execAsync(["bash", "-c", "/path/to/script.sh"])
|
||||
.then((out) => console.log(out))
|
||||
.catch((err) => console.error(err))
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> `subprocess`, `exec`, and `execAsync` executes the passed executable as is.
|
||||
> They are **not** executed in a shell environment, they do **not** expand ENV
|
||||
> variables like `$HOME`, and they do **not** handle logical operators like `&&`
|
||||
> and `||`.
|
||||
>
|
||||
> If you want bash, run them with bash.
|
||||
>
|
||||
> ```ts
|
||||
> exec(["bash", "-c", "command $ENV_VAR && command"])
|
||||
> exec("bash -c 'command $ENV_VAR' && command")
|
||||
> ```
|
||||
|
||||
### createSubprocess
|
||||
|
||||
`createSubprocess` creates a signal that starts a subprocess when the first
|
||||
subscriber appears and kills the subprocess when number of subscribers drop to
|
||||
zero.
|
||||
|
||||
```ts
|
||||
export function createSubprocess(
|
||||
init: string,
|
||||
exec: string | string[],
|
||||
): Accessor<string>
|
||||
|
||||
export function createSubprocess<T>(
|
||||
init: T,
|
||||
exec: string | string[],
|
||||
transform: (stdout: string, prev: T) => T,
|
||||
): Accessor<T>
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```tsx
|
||||
function Log() {
|
||||
const log = createSubprocess("", "journalctl -f")
|
||||
|
||||
return <label label={log} />
|
||||
}
|
||||
```
|
||||
|
||||
## Http requests
|
||||
|
||||
```ts
|
||||
import { fetch, URL } from "ags/fetch"
|
||||
|
||||
const url = new URL("https://some-site.com/api")
|
||||
url.searchParams.set("hello", "world")
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ hello: "world" }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
|
||||
const json = await res.json()
|
||||
```
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
---
|
||||
layout: home
|
||||
pageClass: home-page
|
||||
|
||||
hero:
|
||||
name: AGS
|
||||
text: A framework for crafting Wayland Desktop Shells
|
||||
image: https://aylur.github.io/astal/icon.svg
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Get Started
|
||||
link: /guide/install
|
||||
- theme: alt
|
||||
text: Resources
|
||||
link: /guide/resources
|
||||
|
||||
features:
|
||||
- title: Initialize projects
|
||||
details:
|
||||
With <code>ags init</code> you can initialize a project, which generates a
|
||||
basic template
|
||||
- title: Generate TypeScript types
|
||||
details:
|
||||
With <code>ags types</code> you can generate types from GObject based
|
||||
libraries
|
||||
- title: Bundle projects
|
||||
details:
|
||||
With <code>ags bundle</code> you can bundle your project into a single
|
||||
executable script
|
||||
- title: Run projects
|
||||
details:
|
||||
With <code>ags run</code> you can run projects without bundling them first
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
<article class="feature feature-3-2">
|
||||
<div class="feature-text">
|
||||
<h3>Use a familiar language</h3>
|
||||
|
||||
<span>
|
||||
AGS uses the world's most used langauge: <i>JavaScript/TypeScript</i>. The rendering
|
||||
library which let's you use an XML like syntax in JavaScript is inspired by web
|
||||
frameworks such as React and Solid.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="feature-code feature-row-1">
|
||||
|
||||
```tsx
|
||||
function Bar() {
|
||||
const [counter, setCounter] = createState(0)
|
||||
const date = createPoll("", 1000, `date "+%H:%M - %A %e."`)
|
||||
|
||||
return (
|
||||
<window visible anchor={TOP | LEFT | RIGHT}>
|
||||
<centerbox>
|
||||
<label $type="start" label={date} />
|
||||
<button $type="end" onClicked={() => setCounter((c) => c + 1)}>
|
||||
<label label={counter((c) => `clicked ${c} times`)} />
|
||||
</button>
|
||||
</centerbox>
|
||||
</window>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="feature feature-2-3">
|
||||
<div class="feature-text">
|
||||
<h3>Batteries included</h3>
|
||||
|
||||
<span>
|
||||
Most common operations and queries you want to do are available from <a href="https://aylur.github.io/astal/" target="_blank">Astal</a> libraries. With most of the backend code provided, all you have to worry about is building the UI.
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="feature-code">
|
||||
|
||||
```tsx
|
||||
function BatteryLabel() {
|
||||
const percentage = createBinding(Battery.get_default(), "percentage")
|
||||
return <label label={percentage((p) => `${Math.round(p * 100)}%`)} />
|
||||
}
|
||||
|
||||
function MediaPlayers() {
|
||||
const players = createBinding(Mpris.get_default(), "players")
|
||||
return (
|
||||
<For each={players}>
|
||||
{(player) => (
|
||||
<button
|
||||
label={createBinding(player, "title")}
|
||||
onClicked={() => player.play_pause()}
|
||||
/>
|
||||
)}
|
||||
</For>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="feature feature-3-2">
|
||||
<div class="feature-text">
|
||||
<h3>Styled with css</h3>
|
||||
|
||||
<span>
|
||||
GTK supports styling with CSS. AGS also provides support for <a href="https://sass-lang.com/" target="_blank">SASS</a>. Although it's only a subset of what you can do on the web, most things you'd want are supported, such as CSS variables, keyframes, transforms, and more.
|
||||
</span>
|
||||
|
||||
<div class="feature-gtk-css">
|
||||
<a href="https://docs.gtk.org/gtk4/css-properties.html" target="_blank">List of supported CSS features</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="feature-code feature-row-1">
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```css
|
||||
button {
|
||||
animation: wiggle 2s linear infinite;
|
||||
}
|
||||
@keyframes wiggle {
|
||||
0% { transform: rotateZ(0); }
|
||||
7% { transform: rotateZ(0); }
|
||||
15% { transform: rotateZ(-15deg); }
|
||||
20% { transform: rotateZ(10deg); }
|
||||
25% { transform: rotateZ(-10deg); }
|
||||
30% { transform: rotateZ(6deg); }
|
||||
35% { transform: rotateZ(-4deg); }
|
||||
40% { transform: rotateZ(0); }
|
||||
100% { transform: rotateZ(0); }
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
</article>
|
||||
|
||||
## Showcases
|
||||
|
||||
<div class="showcase">
|
||||
|
||||

|
||||
|
||||
<div class="showcase-title">
|
||||
|
||||
[Delta Shell](https://github.com/Sinomor/delta-shell) by Sinomor
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="showcase">
|
||||
|
||||

|
||||
|
||||
<div class="showcase-title">
|
||||
|
||||
[Epik Shell](https://github.com/ezerinz/epik-shell) by ezerinz
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="showcase">
|
||||
|
||||

|
||||
|
||||
<div class="showcase-title">
|
||||
|
||||
[colorshell](https://github.com/retrozinndev/colorshell) by retrozinndev
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="showcase">
|
||||
|
||||

|
||||
|
||||
<div class="showcase-title">
|
||||
|
||||
[OkPanel](https://github.com/JohnOberhauser/OkPanel) by John Oberhauser
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="showcase">
|
||||
|
||||

|
||||
|
||||
<div class="showcase-title">
|
||||
|
||||
[Marble Shell](https://github.com/Aylur/marble-shell) by Aylur
|
||||
|
||||
</div>
|
||||
</div>
|
||||
Generated
+2475
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "ags-docs",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"vitepress": "^1.5.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vitepress dev .",
|
||||
"build": "vitepress build .",
|
||||
"preview": "vitepress preview ."
|
||||
},
|
||||
"dependencies": {
|
||||
"devicon": "^2.16.0"
|
||||
},
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"singleQuote": false,
|
||||
"tabWidth": 2,
|
||||
"printWidth": 80,
|
||||
"proseWrap": "always"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { defineConfig } from "vitepress"
|
||||
|
||||
export default defineConfig({
|
||||
title: "AGS",
|
||||
description: "Documentation website of AGS",
|
||||
|
||||
outDir: "./dist",
|
||||
base: "/ags/",
|
||||
lastUpdated: true,
|
||||
|
||||
head: [
|
||||
["link", { rel: "icon", href: "https://aylur.github.io/astal/icon.svg" }],
|
||||
],
|
||||
|
||||
markdown: {
|
||||
languageAlias: {
|
||||
meson: "ruby",
|
||||
blp: "c", // TODO: find a better alternative
|
||||
},
|
||||
},
|
||||
|
||||
themeConfig: {
|
||||
outline: "deep",
|
||||
|
||||
footer: {
|
||||
message: "Released under the GPL v3.0 License",
|
||||
copyright: "Logo is created by VDawg",
|
||||
},
|
||||
|
||||
nav: [
|
||||
{
|
||||
text: "Guide",
|
||||
link: "/guide/quick-start",
|
||||
activeMatch: "/guide/",
|
||||
},
|
||||
{
|
||||
text: "References",
|
||||
items: [
|
||||
{
|
||||
text: "Gjs Guide",
|
||||
link: "https://gjs.guide/",
|
||||
},
|
||||
{
|
||||
text: "Gjs References",
|
||||
link: "https://gjs-docs.gnome.org/",
|
||||
},
|
||||
{
|
||||
text: "Astal",
|
||||
link: "https://aylur.github.io/astal/",
|
||||
},
|
||||
{
|
||||
text: "Gnim",
|
||||
link: "https://aylur.github.io/gnim/",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
sidebar: [
|
||||
{ text: "Installation", link: "/guide/install" },
|
||||
{ text: "Quick Start", link: "/guide/quick-start" },
|
||||
{ text: "First Widgets", link: "/guide/first-widgets" },
|
||||
{ text: "Theming", link: "/guide/theming" },
|
||||
{ text: "App and CLI", link: "/guide/app-cli" },
|
||||
{ text: "Utilities", link: "/guide/utilities" },
|
||||
{ text: "Resources", link: "/guide/resources" },
|
||||
{ text: "Intrinsics", link: "/guide/intrinsics" },
|
||||
{ text: "FAQ", link: "/guide/faq" },
|
||||
{ text: "Examples", link: "/guide/examples" },
|
||||
{ text: "Nix", link: "/guide/nix" },
|
||||
{ text: "Migration Guide", link: "/guide/migration-guide" },
|
||||
],
|
||||
|
||||
socialLinks: [
|
||||
{ icon: "github", link: "https://github.com/aylur/ags" },
|
||||
{ icon: "discord", link: "https://discord.gg/CXQpHwDuhY" },
|
||||
{
|
||||
link: "https://ko-fi.com/aylur",
|
||||
icon: {
|
||||
svg: `<?xml version="1.0" encoding="utf-8"?><svg fill="#000000" width="800px" height="800px" viewBox="0 0 24 24" role="img" xmlns="http://www.w3.org/2000/svg"><path d="M23.881 8.948c-.773-4.085-4.859-4.593-4.859-4.593H.723c-.604 0-.679.798-.679.798s-.082 7.324-.022 11.822c.164 2.424 2.586 2.672 2.586 2.672s8.267-.023 11.966-.049c2.438-.426 2.683-2.566 2.658-3.734 4.352.24 7.422-2.831 6.649-6.916zm-11.062 3.511c-1.246 1.453-4.011 3.976-4.011 3.976s-.121.119-.31.023c-.076-.057-.108-.09-.108-.09-.443-.441-3.368-3.049-4.034-3.954-.709-.965-1.041-2.7-.091-3.71.951-1.01 3.005-1.086 4.363.407 0 0 1.565-1.782 3.468-.963 1.904.82 1.832 3.011.723 4.311zm6.173.478c-.928.116-1.682.028-1.682.028V7.284h1.77s1.971.551 1.971 2.638c0 1.913-.985 2.667-2.059 3.015z"/></svg>`,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
editLink: {
|
||||
pattern: "https://github.com/aylur/ags/edit/main/docs/:path",
|
||||
text: "Edit this page on GitHub",
|
||||
},
|
||||
|
||||
lastUpdated: {
|
||||
text: "Last updated",
|
||||
},
|
||||
|
||||
search: {
|
||||
provider: "local",
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,443 @@
|
||||
@media (min-width: 960px) {
|
||||
.feature {
|
||||
margin-top: 24px;
|
||||
border-radius: 12px;
|
||||
background-color: var(--vp-c-bg-soft);
|
||||
|
||||
display: grid;
|
||||
|
||||
&.feature-2-3 {
|
||||
grid-template-columns: 2fr 3fr;
|
||||
}
|
||||
|
||||
&.feature-3-2 {
|
||||
grid-template-columns: 3fr 2fr;
|
||||
}
|
||||
|
||||
div.feature-text {
|
||||
padding: 24px;
|
||||
margin: auto 0;
|
||||
|
||||
h3 {
|
||||
border: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
margin-bottom: 12px;
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
|
||||
span {
|
||||
i {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.feature-code div {
|
||||
margin: 1px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.feature-row-1 {
|
||||
grid-row: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.feature-gtk-css {
|
||||
display: flex;
|
||||
margin-top: 24px;
|
||||
|
||||
a {
|
||||
margin: 0 auto;
|
||||
padding: 8px 18px;
|
||||
border-radius: 20px;
|
||||
text-decoration: none !important;
|
||||
animation: wiggle 2s linear infinite;
|
||||
|
||||
border-color: var(--vp-button-brand-border);
|
||||
color: var(--vp-button-brand-text);
|
||||
background-color: var(--vp-button-brand-bg);
|
||||
|
||||
&:hover {
|
||||
border-color: var(--vp-button-brand-hover-border);
|
||||
color: var(--vp-button-brand-hover-text);
|
||||
background-color: var(--vp-button-brand-hover-bg);
|
||||
}
|
||||
|
||||
&:active {
|
||||
border-color: var(--vp-button-brand-active-border);
|
||||
color: var(--vp-button-brand-active-text);
|
||||
background-color: var(--vp-button-brand-active-bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes wiggle {
|
||||
0%,
|
||||
7% {
|
||||
transform: rotateZ(0);
|
||||
}
|
||||
15% {
|
||||
transform: rotateZ(-8deg);
|
||||
}
|
||||
20% {
|
||||
transform: rotateZ(5deg);
|
||||
}
|
||||
25% {
|
||||
transform: rotateZ(-8deg);
|
||||
}
|
||||
30% {
|
||||
transform: rotateZ(3deg);
|
||||
}
|
||||
35% {
|
||||
transform: rotateZ(-2deg);
|
||||
}
|
||||
40%,
|
||||
100% {
|
||||
transform: rotateZ(0);
|
||||
}
|
||||
}
|
||||
|
||||
.showcase {
|
||||
margin-bottom: 2rem;
|
||||
padding: 4px;
|
||||
border-radius: 12px;
|
||||
background-color: var(--vp-c-bg-soft);
|
||||
box-shadow: 1px 2px 5px 0 rgba(0, 0, 0, 0.3);
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.showcase-title {
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
img {
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--vp-c-bg);
|
||||
}
|
||||
}
|
||||
|
||||
:root {
|
||||
--vp-home-hero-name-color: transparent;
|
||||
--vp-home-hero-name-background: -webkit-linear-gradient(
|
||||
120deg,
|
||||
var(--vp-c-purple-3),
|
||||
var(--vp-c-brand-3)
|
||||
);
|
||||
|
||||
--vp-home-hero-image-background-image: linear-gradient(
|
||||
-45deg,
|
||||
var(--vp-c-purple-3),
|
||||
var(--vp-c-brand-3)
|
||||
);
|
||||
--vp-home-hero-image-filter: blur(44px);
|
||||
}
|
||||
|
||||
:root {
|
||||
--overlay-gradient: color-mix(in srgb, var(--vp-c-brand-1), transparent 55%);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--overlay-gradient: color-mix(in srgb, var(--vp-c-brand-1), transparent 85%);
|
||||
}
|
||||
|
||||
.home-page {
|
||||
background:
|
||||
linear-gradient(215deg, var(--overlay-gradient), transparent 40%),
|
||||
radial-gradient(var(--overlay-gradient), transparent 40%)
|
||||
no-repeat -60vw -40vh / 105vw 200vh,
|
||||
radial-gradient(var(--overlay-gradient), transparent 65%) no-repeat 50%
|
||||
calc(100% + 20rem) / 60rem 30rem;
|
||||
|
||||
.VPFeature code {
|
||||
background-color: var(--vp-code-line-highlight-color);
|
||||
color: var(--vp-code-color);
|
||||
padding: 2px;
|
||||
border-radius: 4px;
|
||||
padding: 3px 6px;
|
||||
}
|
||||
|
||||
.VPFooter {
|
||||
background-color: transparent !important;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.VPNavBar:not(.top) {
|
||||
background-color: transparent !important;
|
||||
-webkit-backdrop-filter: blur(16px);
|
||||
backdrop-filter: blur(16px);
|
||||
|
||||
div.divider {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
:root {
|
||||
--vp-home-hero-image-filter: blur(56px);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 960px) {
|
||||
:root {
|
||||
--vp-home-hero-image-filter: blur(68px);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
|
||||
*/
|
||||
|
||||
.VPNavBar .VPNavBarTitle span {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
background: linear-gradient(120deg, var(--vp-c-brand-3), var(--vp-c-brand-1));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
:root {
|
||||
--vp-c-gray-1: #dddde3;
|
||||
--vp-c-gray-2: #e4e4e9;
|
||||
--vp-c-gray-3: #ebebef;
|
||||
--vp-c-gray-soft: rgba(142, 150, 170, 0.14);
|
||||
|
||||
--vp-c-indigo-1: #3451b2;
|
||||
--vp-c-indigo-2: #3a5ccc;
|
||||
--vp-c-indigo-3: #5672cd;
|
||||
--vp-c-indigo-soft: rgba(100, 108, 255, 0.14);
|
||||
|
||||
--vp-c-purple-1: #6f42c1;
|
||||
--vp-c-purple-2: #7e4cc9;
|
||||
--vp-c-purple-3: #8e5cd9;
|
||||
--vp-c-purple-soft: rgba(159, 122, 234, 0.14);
|
||||
|
||||
--vp-c-green-1: #18794e;
|
||||
--vp-c-green-2: #299764;
|
||||
--vp-c-green-3: #30a46c;
|
||||
--vp-c-green-soft: rgba(16, 185, 129, 0.14);
|
||||
|
||||
--vp-c-yellow-1: #915930;
|
||||
--vp-c-yellow-2: #946300;
|
||||
--vp-c-yellow-3: #9f6a00;
|
||||
--vp-c-yellow-soft: rgba(234, 179, 8, 0.14);
|
||||
|
||||
--vp-c-red-1: #b8272c;
|
||||
--vp-c-red-2: #d5393e;
|
||||
--vp-c-red-3: #e0575b;
|
||||
--vp-c-red-soft: rgba(244, 63, 94, 0.14);
|
||||
|
||||
--vp-c-sponsor: #db2777;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-gray-1: #515151;
|
||||
--vp-c-gray-2: #464646;
|
||||
--vp-c-gray-3: #323232;
|
||||
--vp-c-gray-soft: hsla(0, 0%, 36%, 0.16);
|
||||
|
||||
--vp-c-indigo-1: hsl(207, 76%, 61%);
|
||||
--vp-c-indigo-2: hsl(207, 86%, 51%);
|
||||
--vp-c-indigo-3: hsl(207, 96%, 41%);
|
||||
--vp-c-indigo-soft: hsla(207, 76%, 61%, 0.18);
|
||||
|
||||
--vp-c-purple-1: #c8abfa;
|
||||
--vp-c-purple-2: #a879e6;
|
||||
--vp-c-purple-3: #8e5cd9;
|
||||
--vp-c-purple-soft: rgba(159, 122, 234, 0.16);
|
||||
|
||||
--vp-c-green-1: hsl(158, 100%, 42%);
|
||||
--vp-c-green-2: hsl(158, 95%, 37%);
|
||||
--vp-c-green-3: hsl(158, 90%, 35%);
|
||||
--vp-c-green-soft: hsla(158, 100%, 42%, 0.16);
|
||||
|
||||
--vp-c-yellow-1: #f9b44e;
|
||||
--vp-c-yellow-2: #da8b17;
|
||||
--vp-c-yellow-3: #a46a0a;
|
||||
--vp-c-yellow-soft: rgba(234, 179, 8, 0.16);
|
||||
|
||||
--vp-c-red-1: #f66f81;
|
||||
--vp-c-red-2: #f14158;
|
||||
--vp-c-red-3: #b62a3c;
|
||||
--vp-c-red-soft: rgba(244, 63, 94, 0.16);
|
||||
}
|
||||
|
||||
/* ---------- *
|
||||
* Background *
|
||||
* ---------- */
|
||||
|
||||
:root {
|
||||
--vp-c-bg: #ffffff;
|
||||
--vp-c-bg-alt: #f6f6f7;
|
||||
--vp-c-bg-elv: #ffffff;
|
||||
--vp-c-bg-soft: #f6f6f7;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-bg: #111111;
|
||||
--vp-c-bg-alt: #181818;
|
||||
--vp-c-bg-elv: #202122;
|
||||
--vp-c-bg-soft: #202122;
|
||||
}
|
||||
|
||||
/** Borders */
|
||||
:root {
|
||||
--vp-c-border: #c2c2c4;
|
||||
--vp-c-divider: #e2e2e3;
|
||||
--vp-c-gutter: #e2e2e3;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-border: #3c3d3e;
|
||||
--vp-c-divider: #2e2e2e;
|
||||
--vp-c-gutter: #000000;
|
||||
}
|
||||
|
||||
/* ---- *
|
||||
* Text *
|
||||
* ---- */
|
||||
|
||||
:root {
|
||||
--vp-c-text-1: rgba(60, 60, 67);
|
||||
--vp-c-text-2: rgba(60, 60, 67, 0.78);
|
||||
--vp-c-text-3: rgba(60, 60, 67, 0.56);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-text-1: rgba(255, 255, 245, 0.86);
|
||||
--vp-c-text-2: rgba(235, 235, 245, 0.6);
|
||||
--vp-c-text-3: rgba(235, 235, 245, 0.38);
|
||||
}
|
||||
/**
|
||||
* https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css
|
||||
*/
|
||||
|
||||
.VPNavBar .VPNavBarTitle span {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
background: linear-gradient(120deg, var(--vp-c-brand-3), var(--vp-c-brand-1));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
:root {
|
||||
--vp-c-gray-1: #dddde3;
|
||||
--vp-c-gray-2: #e4e4e9;
|
||||
--vp-c-gray-3: #ebebef;
|
||||
--vp-c-gray-soft: rgba(142, 150, 170, 0.14);
|
||||
|
||||
--vp-c-indigo-1: #3451b2;
|
||||
--vp-c-indigo-2: #3a5ccc;
|
||||
--vp-c-indigo-3: #5672cd;
|
||||
--vp-c-indigo-soft: rgba(100, 108, 255, 0.14);
|
||||
|
||||
--vp-c-purple-1: #6f42c1;
|
||||
--vp-c-purple-2: #7e4cc9;
|
||||
--vp-c-purple-3: #8e5cd9;
|
||||
--vp-c-purple-soft: rgba(159, 122, 234, 0.14);
|
||||
|
||||
--vp-c-green-1: #18794e;
|
||||
--vp-c-green-2: #299764;
|
||||
--vp-c-green-3: #30a46c;
|
||||
--vp-c-green-soft: rgba(16, 185, 129, 0.14);
|
||||
|
||||
--vp-c-yellow-1: #915930;
|
||||
--vp-c-yellow-2: #946300;
|
||||
--vp-c-yellow-3: #9f6a00;
|
||||
--vp-c-yellow-soft: rgba(234, 179, 8, 0.14);
|
||||
|
||||
--vp-c-red-1: #b8272c;
|
||||
--vp-c-red-2: #d5393e;
|
||||
--vp-c-red-3: #e0575b;
|
||||
--vp-c-red-soft: rgba(244, 63, 94, 0.14);
|
||||
|
||||
--vp-c-sponsor: #db2777;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-gray-1: #515151;
|
||||
--vp-c-gray-2: #464646;
|
||||
--vp-c-gray-3: #323232;
|
||||
--vp-c-gray-soft: hsla(0, 0%, 36%, 0.16);
|
||||
|
||||
--vp-c-indigo-1: hsl(207, 76%, 61%);
|
||||
--vp-c-indigo-2: hsl(207, 86%, 51%);
|
||||
--vp-c-indigo-3: hsl(207, 96%, 41%);
|
||||
--vp-c-indigo-soft: hsla(207, 76%, 61%, 0.18);
|
||||
|
||||
--vp-c-purple-1: #c8abfa;
|
||||
--vp-c-purple-2: #a879e6;
|
||||
--vp-c-purple-3: #8e5cd9;
|
||||
--vp-c-purple-soft: rgba(159, 122, 234, 0.16);
|
||||
|
||||
--vp-c-green-1: hsl(158, 100%, 42%);
|
||||
--vp-c-green-2: hsl(158, 95%, 37%);
|
||||
--vp-c-green-3: hsl(158, 90%, 35%);
|
||||
--vp-c-green-soft: hsla(158, 100%, 42%, 0.16);
|
||||
|
||||
--vp-c-yellow-1: #f9b44e;
|
||||
--vp-c-yellow-2: #da8b17;
|
||||
--vp-c-yellow-3: #a46a0a;
|
||||
--vp-c-yellow-soft: rgba(234, 179, 8, 0.16);
|
||||
|
||||
--vp-c-red-1: #f66f81;
|
||||
--vp-c-red-2: #f14158;
|
||||
--vp-c-red-3: #b62a3c;
|
||||
--vp-c-red-soft: rgba(244, 63, 94, 0.16);
|
||||
}
|
||||
|
||||
/* ---------- *
|
||||
* Background *
|
||||
* ---------- */
|
||||
|
||||
:root {
|
||||
--vp-c-bg: #ffffff;
|
||||
--vp-c-bg-alt: #f6f6f7;
|
||||
--vp-c-bg-elv: #ffffff;
|
||||
--vp-c-bg-soft: #f6f6f7;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-bg: #111111;
|
||||
--vp-c-bg-alt: #181818;
|
||||
--vp-c-bg-elv: #202122;
|
||||
--vp-c-bg-soft: #202122;
|
||||
}
|
||||
|
||||
/** Borders */
|
||||
:root {
|
||||
--vp-c-border: #c2c2c4;
|
||||
--vp-c-divider: #e2e2e3;
|
||||
--vp-c-gutter: #e2e2e3;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-border: #3c3d3e;
|
||||
--vp-c-divider: #2e2e2e;
|
||||
--vp-c-gutter: #000000;
|
||||
}
|
||||
|
||||
/* ---- *
|
||||
* Text *
|
||||
* ---- */
|
||||
|
||||
:root {
|
||||
--vp-c-text-1: rgba(60, 60, 67);
|
||||
--vp-c-text-2: rgba(60, 60, 67, 0.78);
|
||||
--vp-c-text-3: rgba(60, 60, 67, 0.56);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--vp-c-text-1: rgba(255, 255, 245, 0.86);
|
||||
--vp-c-text-2: rgba(235, 235, 245, 0.6);
|
||||
--vp-c-text-3: rgba(235, 235, 245, 0.38);
|
||||
}
|
||||
Reference in new issue
Block a user