Neat VNC

repository·master·Indexed 41 days ago

https://github.com/any1/neatvnc

A fast, lightweight VNC server library designed for speed and interoperability with the Freedesktop.org ecosystem. It provides structures like `nvnc` for server implementation and `nvnc_client` for session management, supporting various authentication states via `nvnc_client_state` and damage region management using `nvnc__damage_region`.

Tokens
1.3K
Snippets
5
Records
7
Agent score
50%

What's inside Neat VNC

  1. Build Neat VNC from source

    master

    To build Neat VNC, you must have the build dependencies installed. The build process uses the meson build system and ninja build tool.

    Build Dependencies

    • libdrm
    • meson
    • pkg-config

    Runtime Dependencies

    • aml
    • pixman
    • zlib
    • Optional: ffmpeg, gbm, gnutls, libdrm, libturbojpeg, nettle, hogweed, gmp
    meson build
    ninja -C build
  2. Manage server damage regions with `nvnc__damage_region`

    master

    When the underlying framebuffer changes, you must notify the Neat VNC server so it can update the connected clients. Use nvnc__damage_region to specify the area of the screen that has changed using a pixman_region16 object. This triggers the necessary encoding and transmission processes to the clients.

    void nvnc__damage_region(struct nvnc* self, const struct pixman_region16* damage);
  3. Implement a VNC server using the `nvnc` struct

    master

    To implement a VNC server, you interact with the nvnc structure. This structure acts as the central controller for the server instance, managing sockets, connected clients, displays, and user-provided callback functions for handling input and clipboard operations.

    Key responsibilities managed via the nvnc struct include:

    • Input Handling: Providing callbacks for keys (key_fn), key codes (key_code_fn), and pointer movements (pointer_fn, normalised_pointer_fn).
    • Clipboard: Managing cut text via cut_text_fn and handling external clipboard messages.
    • Client Management: Using new_client_fn to handle new connections.
    • Display Management: Managing multiple displays via the displays array and desktop_layout_fn.
    • Security: Configuring authentication via auth_fn and defining supported security_types.
    /* Example of the nvnc struct members used for server implementation */
    struct nvnc {
        void* userdata;
        nvnc_cleanup_fn cleanup_fn;
        // ... input callbacks
        nvnc_key_fn key_fn;
        nvnc_key_fn key_code_fn;
        nvnc_pointer_fn pointer_fn;
        nvnc_normalised_pointer_fn normalised_pointer_fn;
        // ... client and clipboard callbacks
        nvnc_client_fn new_client_fn;
        nvnc_cut_text_fn cut_text_fn;
        // ... display and security
        nvnc_desktop_layout_fn desktop_layout_fn;
        struct nvnc_display* displays[NVNC_FB_COMPOSITE_MAX];
        nvnc_auth_fn auth_fn;
        void* auth_ud;
        enum rfb_security_type security_types[MAX_SECURITY_TYPES];
    };
  4. Reset encoders with `nvnc__reset_encoders`

    master

    Use nvnc__reset_encoders to force the server to reset its encoding state. This is typically used when the underlying display properties or framebuffer format changes significantly, requiring clients to re-initialize their decoders.

    void nvnc__reset_encoders(struct nvnc* self);
  5. Manage VNC client state with nvnc_client_state

    master

    The nvnc_client_state enumeration tracks the lifecycle of a VNC client connection, from initial handshake to a ready state. This is useful for monitoring the connection progress or implementing state-dependent logic in your application.

    Available states include:

    • VNC_CLIENT_STATE_WAITING_FOR_VERSION: Initial state, waiting for the server to send its RFB version.
    • VNC_CLIENT_STATE_WAITING_FOR_SECURITY: Waiting for the server to negotiate security types.
    • VNC_CLIENT_STATE_WAITING_FOR_VENCRYPT_VERSION / SUBTYPE / PLAIN_AUTH: (If ENABLE_TLS is defined) States related to Vencrypt TLS negotiation.
    • VNC_CLIENT_STATE_WAITING_FOR_DES_AUTH_RESPONSE / APPLE_DH_RESPONSE / RSA_AES_*: (If HAVE_CRYPTO is defined) States for various cryptographic authentication handshakes.
    • VNC_CLIENT_STATE_WAITING_FOR_INIT: Waiting for the server's Init message.
    • VNC_CLIENT_STATE_WAITING_FOR_AUTH: Waiting for authentication to complete.
    • VNC_CLIENT_STATE_READY: The client is fully connected and ready for interaction.
  6. Use the nvnc_client structure

    master

    The nvnc_client struct is the primary object representing a VNC client session. It contains connection state, network stream information, pixel formats, supported encodings, and buffers for message processing.

    Note: This is an opaque-style structure intended to be managed by the library. Users typically interact with it via the public API functions (defined in neatvnc.h) rather than manipulating these fields directly.