@gtkx/native 0.20.0 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,106 +1,173 @@
1
1
  <p align="center">
2
- <img src="https://raw.githubusercontent.com/eugeniodepalo/gtkx/main/logo.svg" alt="GTKX" width="60" height="60">
2
+ <img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/logo.svg" alt="GTKX" width="100" />
3
3
  </p>
4
4
 
5
5
  <h1 align="center">GTKX</h1>
6
6
 
7
7
  <p align="center">
8
- <strong>Build native GTK4 desktop applications with React and TypeScript.</strong>
8
+ The React framework for Linux.<br />
9
+ Build GTK4 and Adwaita apps in TypeScript, with React components and hooks driving GNOME's own widgets. What you ship is a GNOME app.
9
10
  </p>
10
11
 
11
12
  <p align="center">
12
- <a href="https://www.npmjs.com/package/@gtkx/react"><img src="https://img.shields.io/npm/v/@gtkx/react.svg" alt="npm version"></a>
13
- <a href="https://github.com/gtkx-org/gtkx/actions"><img src="https://img.shields.io/github/actions/workflow/status/eugeniodepalo/gtkx/ci.yml" alt="CI"></a>
14
- <a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License"></a>
15
- <a href="https://github.com/gtkx-org/gtkx/discussions"><img src="https://img.shields.io/badge/discussions-GitHub-blue" alt="GitHub Discussions"></a>
13
+ <a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
14
+ <a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
15
+ <img src="https://img.shields.io/badge/node-%E2%89%A524-339933?logo=node.js&logoColor=white" alt="Node >= 24" />
16
+ <a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
17
+ <a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
18
+ <img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
19
+ </p>
20
+
21
+ <p align="center">
22
+ <a href="https://gtkx.dev">Homepage</a> &middot;
23
+ <a href="https://gtkx.dev/guide/why-gtkx">Documentation</a> &middot;
24
+ <a href="https://github.com/gtkx-org/gtkx/tree/main/examples">Examples</a> &middot;
25
+ <a href="https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md">Contributing</a>
16
26
  </p>
17
27
 
18
28
  ---
19
29
 
20
- GTKX lets you write Linux desktop applications using React. Your components render as native GTK4 widgets through a Rust FFI bridge—no webviews, no Electron, just native performance with the developer experience you already know.
30
+ GTKX generates fully typed bindings for the entire GTK4 and Adwaita surface directly from GObject-Introspection. On top of those bindings you get the React programming model: components and hooks driving GObject instances, with Fast Refresh while you develop.
21
31
 
22
- ## Quick Start
32
+ <p align="center">
33
+ <img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/examples/tutorial/assets/screenshot.png" alt="The Tasks app: an Adwaita window with a sidebar of smart views and colored lists on the left, and a boxed task list on the right." />
34
+ </p>
23
35
 
24
- ```bash
25
- npx @gtkx/cli create my-app
26
- cd my-app
27
- npm run dev
28
- ```
36
+ <p align="center">
37
+ <em>The Tasks app you build in the <a href="https://gtkx.dev/tutorial/">tutorial</a>.</em>
38
+ </p>
39
+
40
+ ## Demo
29
41
 
30
- ## Example
42
+ The intrinsic elements in this snippet render GTK4 widgets, and ordinary React hooks and events drive them:
31
43
 
32
44
  ```tsx
33
- import {
34
- GtkApplicationWindow,
35
- GtkBox,
36
- GtkButton,
37
- GtkLabel,
38
- quit,
39
- render,
40
- } from "@gtkx/react";
41
- import * as Gtk from "@gtkx/ffi/gtk";
45
+ import * as Gtk from "@gtkx/gi/gtk";
46
+ import { GtkApplication, GtkApplicationWindow, GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
47
+ import { createRoot, quit } from "@gtkx/react";
42
48
  import { useState } from "react";
43
49
 
44
- const App = () => {
50
+ const Counter = () => {
45
51
  const [count, setCount] = useState(0);
46
52
 
47
53
  return (
48
54
  <GtkApplicationWindow
49
- title="Counter"
50
- defaultWidth={300}
51
- defaultHeight={200}
52
- onClose={quit}
55
+ title="Hello GTKX"
56
+ defaultWidth={400}
57
+ defaultHeight={300}
58
+ onCloseRequest={quit}
53
59
  >
54
60
  <GtkBox
55
61
  orientation={Gtk.Orientation.VERTICAL}
56
62
  spacing={20}
63
+ marginTop={40}
64
+ marginBottom={40}
65
+ marginStart={40}
66
+ marginEnd={40}
57
67
  valign={Gtk.Align.CENTER}
68
+ halign={Gtk.Align.CENTER}
58
69
  >
59
- <GtkLabel label={`Count: ${count}`} cssClasses={["title-1"]} />
60
- <GtkButton label="Increment" onClicked={() => setCount((c) => c + 1)} />
70
+ <GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
71
+ <GtkLabel cssClasses={["title-2"]}>{`Count: ${count}`}</GtkLabel>
72
+ <GtkButton
73
+ label="Increment"
74
+ onClicked={() => setCount((c) => c + 1)}
75
+ cssClasses={["suggested-action", "pill"]}
76
+ />
61
77
  </GtkBox>
62
78
  </GtkApplicationWindow>
63
79
  );
64
80
  };
65
81
 
66
- render(<App />, "com.example.counter");
82
+ const App = () => (
83
+ <GtkApplication>
84
+ <Counter />
85
+ </GtkApplication>
86
+ );
87
+
88
+ createRoot().render(<App />);
67
89
  ```
68
90
 
69
- ## Features
91
+ This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world) example, with `app.tsx` and `index.tsx` combined into a single snippet. `@gtkx/gi` and `@gtkx/jsx` are per-project bindings generated by the CLI, not packages you install from npm.
70
92
 
71
- - **React 19** — Hooks, concurrent features, and the component model you know
72
- - **Native GTK4 widgets** — Real native controls, not web components in a webview
73
- - **Adwaita support** — Modern GNOME styling with Libadwaita components
74
- - **Declarative animations** — Framer Motion-like API using native Adwaita animations
75
- - **Hot Module Replacement** — Fast refresh during development
76
- - **TypeScript first** — Full type safety with auto-generated bindings
77
- - **CSS-in-JS styling** — Familiar styling patterns adapted for GTK
78
- - **Testing utilities** — Component testing similar to Testing Library
93
+ ## Why GTKX
79
94
 
80
- ## Examples
95
+ ### A declarative layer for the GNOME stack
96
+
97
+ GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing re-renders that interface when your application state changes, and nothing hot-reloads it as you work. GTKX adds that missing layer, and the tooling around it, on top of the stack you already know:
98
+
99
+ - a React reconciler that exposes every GObject as a JSX element,
100
+ - a CLI for scaffolding, development, and production builds,
101
+ - a dev server with Fast Refresh that patches your running UI in place,
102
+ - CSS-in-JS styling and high-level list, grid, and dialog components,
103
+ - a Testing Library-style API for querying and driving your widgets in tests,
104
+ - and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
105
+
106
+ ### The full GNOME API surface
107
+
108
+ React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX exposes it: GTK4, Adwaita, and any other GObject-Introspection library on your system. Linux-only by design.
109
+
110
+ ### Why Node.js, and why generated bindings
111
+
112
+ GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [why-gtkx guide](https://gtkx.dev/guide/why-gtkx) covers the comparison in full.
113
+
114
+ GTKX generates the TypeScript types and the native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. Codegen covers the whole GTK4 and Adwaita surface.
115
+
116
+ At runtime, the native Rust core calls straight into the system GTK4, Adwaita, and GLib libraries through libffi, without loading libgirepository at all.
81
117
 
82
- Explore complete applications in the [`examples/`](./examples) directory:
118
+ ## Quick start
83
119
 
84
- - **[gtk-demo](./examples/gtk-demo)** Full replica of the official GTK demo app
85
- - **[hello-world](./examples/hello-world)** — Minimal application showing a counter
86
- - **[todo](./examples/todo)** Full-featured todo application with Adwaita styling and testing
87
- - **[x-showcase](./examples/x-showcase)** — Showcase of all x.\* virtual components
88
- - **[browser](./examples/browser)** — Simple browser using WebKitWebView
89
- - **[deploying](./examples/deploying)** — Example of packaging and distributing a GTKX app
120
+ GTKX is Linux-only and needs Node.js 24 or later. See [Requirements](#requirements).
121
+
122
+ Scaffold a new app with the `create-gtkx` initializer:
123
+
124
+ ```sh
125
+ npm create gtkx@rc
126
+ ```
127
+
128
+ The same command works with other package managers: `pnpm create gtkx@rc` or `yarn create gtkx@rc`.
129
+
130
+ Then run your new app:
131
+
132
+ ```sh
133
+ cd my-app
134
+ npm run dev
135
+ ```
136
+
137
+ To go further, follow the [tutorial](https://gtkx.dev/tutorial/).
90
138
 
91
139
  ## Documentation
92
140
 
93
- Visit [https://gtkx.dev](https://gtkx.dev) for the full documentation.
141
+ The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tutorial that builds a complete GNOME app, from scaffolding to packaging and shipping, plus guides and a full API reference.
94
142
 
95
- ## Contributing
143
+ **[Read the docs &rarr;](https://gtkx.dev/guide/why-gtkx)**
96
144
 
97
- Contributions are welcome! Please see the [contributing guidelines](./CONTRIBUTING.md) and check out the [good first issues](https://github.com/gtkx-org/gtkx/labels/good%20first%20issue).
145
+ ## Requirements
98
146
 
99
- ## Community
147
+ GTKX is Linux-only. You need:
148
+
149
+ - Linux with the GTK4 (4.20 or later), Adwaita (1.8 or later), and GLib development libraries
150
+ - Node.js 24 or later
151
+
152
+ The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
153
+
154
+ ## Examples
155
+
156
+ Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
157
+
158
+ - [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the counter above.
159
+ - [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): a React port of the official GTK4 widget showcase, covering lists, dialogs, gestures, CSS, and OpenGL.
160
+ - [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): a WebKitWebView-based web browser.
161
+ - [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
162
+
163
+ ## Status
164
+
165
+ GTKX 1.0 is at the release candidate stage.
166
+
167
+ ## Contributing
100
168
 
101
- - [GitHub Discussions](https://github.com/gtkx-org/gtkx/discussions) Questions, ideas, and general discussion
102
- - [Issue Tracker](https://github.com/gtkx-org/gtkx/issues) — Bug reports and feature requests
169
+ Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 24 or later, pnpm, and a Rust toolchain.
103
170
 
104
171
  ## License
105
172
 
106
- [MPL-2.0](./LICENSE)
173
+ GTKX is licensed under [MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
package/index.d.ts ADDED
@@ -0,0 +1,170 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ export declare class ExternalObject<T> {
5
+ readonly '': {
6
+ readonly '': unique symbol
7
+ [K: symbol]: T
8
+ }
9
+ }
10
+ /**
11
+ * Allocates a zero-filled native memory block of `size` bytes and returns an opaque handle to it.
12
+ * The optional `typeName` tags the boxed allocation with a GType name.
13
+ */
14
+ export declare function alloc(size: number, typeName?: string | undefined | null): ExternalObject<Handle>
15
+
16
+ /**
17
+ * Container layout used to marshal an array: a plain C `array`, a `glist`, `gslist`, `gptrarray`,
18
+ * `garray`, `gbytearray`, a `sized` buffer, or a `fixed`-length buffer.
19
+ */
20
+ export type ArrayKind = 'array'|
21
+ 'glist'|
22
+ 'gslist'|
23
+ 'gptrarray'|
24
+ 'garray'|
25
+ 'gbytearray'|
26
+ 'sized'|
27
+ 'fixed';
28
+
29
+ /**
30
+ * Resolves `symbolName` in `sharedLibrary` and precompiles its argument and return marshalling
31
+ * into a reusable call descriptor that `call` can invoke.
32
+ */
33
+ export declare function bind(sharedLibrary: string, symbolName: string, argDescriptors: Array<Descriptor>, returnDescriptor: Descriptor): ExternalObject<CallDescriptor>
34
+
35
+ /**
36
+ * Invokes a previously bound native function, encoding `values` and decoding the return value
37
+ * according to the call descriptor. Out and inout ('ref') arguments are written back in place.
38
+ */
39
+ export declare function call(descriptor: ExternalObject<CallDescriptor>, values: unknown[]): unknown
40
+
41
+ /**
42
+ * Lifetime of a marshalled callback closure: `call` lasts only for the duration of the call,
43
+ * `notified` is freed by a destroy notify, `async` spans a single async use, `forever` is never freed.
44
+ */
45
+ export type CallbackScope = 'call'|
46
+ 'notified'|
47
+ 'async'|
48
+ 'forever';
49
+
50
+ /** Copies `size` bytes from the `src` handle's memory into the `dest` handle's memory. */
51
+ export declare function copy(dest: ExternalObject<Handle>, src: ExternalObject<Handle>, size: number): unknown
52
+
53
+ /**
54
+ * Describes how a single native value (a function argument, a return value, or a struct field)
55
+ * is marshalled between JavaScript and C. The `kind` field selects the variant.
56
+ */
57
+ export type Descriptor =
58
+ | { kind: 'int8' }
59
+ | { kind: 'uint8' }
60
+ | { kind: 'int16' }
61
+ | { kind: 'uint16' }
62
+ | { kind: 'int32' }
63
+ | { kind: 'uint32' }
64
+ | { kind: 'int64' }
65
+ | { kind: 'uint64' }
66
+ | { kind: 'bigint64' }
67
+ | { kind: 'biguint64' }
68
+ | { kind: 'float32' }
69
+ | { kind: 'float64' }
70
+ | { kind: 'enum', sharedLibrary: string, getTypeFnName: string, signed: boolean }
71
+ | { kind: 'flags', sharedLibrary: string, getTypeFnName: string, signed: boolean }
72
+ | { kind: 'boolean' }
73
+ | { kind: 'string', ownership: Ownership, length?: number }
74
+ | { kind: 'object', ownership: Ownership }
75
+ | { kind: 'unichar' }
76
+ | { kind: 'void' }
77
+ | { kind: 'buffer' }
78
+ | { kind: 'boxed', ownership: Ownership, typeName: string, sharedLibrary?: string, getTypeFnName?: string, freeFnName?: string, callerAllocated?: boolean, size?: number }
79
+ | { kind: 'struct', ownership: Ownership, size?: number, callerAllocated?: boolean }
80
+ | { kind: 'fundamental', ownership: Ownership, sharedLibrary: string, refFnName: string, unrefFnName: string, typeName?: string }
81
+ | { kind: 'array', itemDescriptor: Descriptor, arrayKind: ArrayKind, ownership: Ownership, sizeParamIndex?: number, fixedSize?: number, elementSize?: number }
82
+ | { kind: 'hashtable', keyDescriptor: Descriptor, valueDescriptor: Descriptor, ownership: Ownership }
83
+ | { kind: 'callback', argDescriptors: Array<Descriptor>, returnDescriptor: Descriptor, hasDestroy?: boolean, userDataIndex?: number, scope?: CallbackScope }
84
+ | { kind: 'ref', innerDescriptor: Descriptor, inout?: boolean }
85
+
86
+ /** Returns the GType of the GObject referenced by `handle`, or 0 when the pointer is null. */
87
+ export declare function getType(handle: ExternalObject<Handle>): bigint
88
+
89
+ /**
90
+ * Returns the JavaScript wrapper object previously attached to the handle's GObject,
91
+ * or null when no wrapper is set.
92
+ */
93
+ export declare function getWrapper(handle: ExternalObject<Handle>): object | null
94
+
95
+ /**
96
+ * Installs the Node environment bridge and the GLib main loop integration into the current thread.
97
+ * Call once before any other native function.
98
+ */
99
+ export declare function init(): void
100
+
101
+ /** Enables or disables keeping the Node event loop alive while the GLib run loop is otherwise idle. */
102
+ export declare function keepAlive(enable: boolean): void
103
+
104
+ /**
105
+ * Ownership transfer mode for a marshalled value: `borrowed` leaves the native side owning it,
106
+ * `full` transfers ownership (and the responsibility to free it) across the FFI boundary.
107
+ */
108
+ export type Ownership = 'borrowed'|
109
+ 'full';
110
+
111
+ /** Tears down the GLib main loop integration installed by `init`. */
112
+ export declare function quit(): void
113
+
114
+ /**
115
+ * Reads and decodes a value at `offset` bytes into the handle's memory, using `fieldDescriptor`
116
+ * to interpret the raw bytes.
117
+ */
118
+ export declare function read(handle: ExternalObject<Handle>, fieldDescriptor: Descriptor, offset: number): unknown
119
+
120
+ /**
121
+ * Registers a new GObject subtype named `name` deriving from `parentType`, wiring up any vfunc
122
+ * overrides and implemented interfaces, and returns the new GType.
123
+ */
124
+ export declare function registerClass(name: string, parentType: bigint, options?: RegisterClassOptions | undefined | null): bigint
125
+
126
+ /** An interface a registered class implements, together with the interface vfuncs it provides. */
127
+ export interface RegisterClassInterface {
128
+ /** GType of the interface to implement. */
129
+ type: bigint
130
+ /** Interface vfunc implementations to install. */
131
+ vfuncs: Array<RegisterClassVfunc>
132
+ }
133
+
134
+ /** Optional configuration for `registerClass`: vfunc overrides and implemented interfaces. */
135
+ export interface RegisterClassOptions {
136
+ /** Virtual function overrides for the class itself. */
137
+ vfuncs?: Array<RegisterClassVfunc>
138
+ /** Interfaces the class implements, each with its own vfuncs. */
139
+ interfaces?: Array<RegisterClassInterface>
140
+ }
141
+
142
+ /**
143
+ * A single virtual function override for a registered class: which slot to patch and how its
144
+ * arguments and return value are marshalled to and from the JavaScript implementation.
145
+ */
146
+ export interface RegisterClassVfunc {
147
+ /** Byte offset of the vfunc slot within the class (or interface) struct. */
148
+ byteOffset: number
149
+ /** Descriptor for each argument passed to the JavaScript implementation. */
150
+ argDescriptors: Array<Descriptor>
151
+ /** Descriptor for the value the JavaScript implementation returns. */
152
+ returnDescriptor: Descriptor
153
+ /** The JavaScript function that implements the vfunc. */
154
+ fn: (...args: never[]) => unknown
155
+ }
156
+
157
+ /**
158
+ * Calls the `getTypeFnName` registration function in `sharedLibrary` and returns the resulting
159
+ * GType, or 0 when the symbol is absent.
160
+ */
161
+ export declare function resolveType(sharedLibrary: string, getTypeFnName: string): bigint
162
+
163
+ /**
164
+ * Attaches the JavaScript `wrapper` object to the handle's GObject and registers a finalizer
165
+ * that releases it when the wrapper is garbage collected.
166
+ */
167
+ export declare function setWrapper(handle: ExternalObject<Handle>, wrapper: object): void
168
+
169
+ /** Encodes `value` with `fieldDescriptor` and writes it into the handle's memory at `offset` bytes. */
170
+ export declare function write(handle: ExternalObject<Handle>, fieldDescriptor: Descriptor, offset: number, value: unknown): unknown