Skip to content

Latest commit

 

History

History

rust

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

nativeapi for Rust

Rust bindings for nativeapi — unified access to native system APIs: windows, tray icons, menus, displays, keyboard, dialogs, storage and more.

Linux macOS Windows
✅ ✅ ✅

🚧 Work in Progress: this crate is under active development.

Installation

cargo add nativeapi

Building requires CMake and a C++17 compiler (the core library is compiled by build.rs). On Linux, also install:

sudo apt install libgtk-3-dev libx11-dev libxi-dev

The crate is split into nativeapi (safe API) and cnativeapi (raw FFI).

Quick Start

use nativeapi::DisplayManager;

fn main() {
    for display in DisplayManager::get_all() {
        let size = display.size();
        println!("{}: {}x{}", display.name().unwrap_or_default(), size.width, size.height);
    }
}

Examples

The examples are the rust_* directories in the repository's examples/, members of the cargo workspace at the repository root. Each is a crate covering one module:

cargo run -p display_example
cargo run -p window_example
cargo run -p tray_icon_example

shortcut_example and keyboard_example need accessibility permission on macOS — run accessibility_example first.

GPUI

nativeapi_gpui integrates nativeapi with GPUI: the nativeapi Window behind a GPUI window, event delivery to GPUI entities, geometry and color conversions, and DragToMoveArea / DragToResizeArea elements. The gpui_* directories in examples/ are built on it; each is its own cargo workspace (cd examples/gpui_window_example && cargo run).

Native Shell

The NSH examples combine Native Shell 0.4.0 Rust components with nativeapi tray icons, global shortcuts and message dialogs on macOS and Windows. They share a separate Cargo workspace; start with cargo run --manifest-path examples/nsh_tray_icon_example/Cargo.toml from the repository root. The shared host dispatches native UI calls to the platform thread and delivers callbacks to the NSH engine through channels.

Contributing

Development happens in nativeapi, which holds every binding and the code generator and checks out the core library as a submodule:

git clone --recursive https://github.com/libnativeapi/nativeapi.git

Files marked AUTO-GENERATED. DO NOT EDIT. are generated from the C++ headers in nativeapi. To change the API, send a pull request there; maintainers regenerate the bindings.

License

MIT