Skip to content
h4rldevPublic

Latest commit

 

History

51 Commits

Folders and files

Repository files navigation

bread

A platform/windowing layer in C, with backends for Wayland and X11 (XCB).

Status

Usable for windowed 2D apps, still under development. X11 and Wayland both work; the API may change.

Backends

Chosen by which library is built (BREAD_WAYLAND / BREAD_X11):

  • Wayland (via xdg-shell), with xdg-decoration support
  • X11 (XCB)

bread_get_backend_type() reports the active backend.

Features

  • Windows: create and tear down a window (bread_window_init / bread_window_destroy), set a title and minimum size (bread_window_set_title, bread_window_set_min_size), and hand the native surface to a renderer (bread_window_get_surface).
  • Event loop: bread_window_poll (non-blocking) or bread_window_wait_events (blocks up to a timeout) plus bread_window_should_close drive the loop; a callback (bread_window_set_event_callback) receives bread_event_t close, resize, key, mouse and scroll events. Prefer bread_window_wait_events over a consumer-side sleep to avoid busy-waiting.
  • Input: key events to unicode/string (bread_event_key_to_unicode, bread_event_key_to_cstr), and the current keyboard/mouse state (bread_window_get_input).
  • Clipboard: read and write the selection as text (bread_clipboard_get, bread_clipboard_set), native to each backend.
  • Cursors: a set of standard cursors (bread_cursor_type_t, bread_set_cursor) loaded from the user's cursor theme, set up and torn down with the window.
  • Backend abstraction: a bread_backend_vtable_t so both platforms share one window/event/input API.

Building

bread builds with conjure:

conjure build -p wayland-release          # libbread-wayland.so
conjure build -p wayland-release-static   # libbread-wayland.a
conjure build -p wayland-debug            # libbread-wayland-debug.a
# ...and the x11-* equivalents

Profiles are <wayland|x11>-<debug|release|release-static>. Debug builds are static archives; release builds are shared unless built with the -static profile.

The Wayland build generates its xdg-shell and xdg-decoration protocol sources with wayland-scanner before compiling.

A Nix flake provides the six library packages plus a dev shell:

nix build .#bread-wayland-release
nix develop

Tests

src/test holds a small windowed example (main) and an interactive clipboard test (clipboard). Build them with conjure test -p wayland-debug (or x11-debug).

License

This project is licensed under the BSD 3-Clause License - See the LICENSE file for details.

Releases

Packages

Contributors

Languages