### Desktop Capture Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Example demonstrating how to create a desktop capture instance, subscribe to output changes, and get desktop dimensions. ```c #include "desktop.h" #include "observer.h" void on_output_added(struct observer* obs, void* arg) { struct desktop* desktop = (struct desktop*)arg; printf("New output added to desktop\n"); } // Create desktop capture struct desktop* desktop = desktop_new(&wayland->outputs); if (!desktop) { fprintf(stderr, "Failed to create desktop\n"); return; } // Subscribe to output changes struct observer obs; observer_init(&obs, &desktop->observable.output_added_observer, on_output_added); // Get desktop dimensions int width, height; image_source_get_logical_size(&desktop->image_source, &width, &height); printf("Desktop size: %dx%d\n", width, height); // Cleanup observer_deinit(&obs); desktop_destroy(desktop); ``` -------------------------------- ### Example Usage Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-screencopy.md A comprehensive example demonstrating the setup, configuration, and execution of screen capturing using the screencopy API. ```c #include "screencopy-interface.h" void on_frame_ready(enum screencopy_result result, struct wv_buffer* buffer, struct image_source* source, void* userdata) { if (result != SCREENCOPY_DONE) { fprintf(stderr, "Capture failed\n"); return; } printf("Captured %dx%d frame\n", buffer->width, buffer->height); printf("Format: 0x%08x, Stride: %d\n", buffer->format, buffer->stride); // Process pixel data // buffer->pixels points to raw frame data } // Setup struct image_source* source = get_output_or_desktop(); struct screencopy* sc = screencopy_create(source, true); // With cursor if (!sc) { fprintf(stderr, "Failed to create screencopy\n"); return; } // Configure sc->on_done = on_frame_ready; sc->userdata = my_context; sc->rate_limit = 60.0; // 60 FPS // Start capturing if (screencopy_start(sc, false) < 0) { fprintf(stderr, "Failed to start capture\n"); screencopy_destroy(sc); return; } // ... run event loop ... // Stop and cleanup screencopy_stop(sc); screencopy_destroy(sc); ``` -------------------------------- ### Keysym Examples Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-input.md Examples of common XKB keysyms. ```text - XK_a = 'a' key - XK_Return = Enter key - XK_shift_L = Left shift - XK_ctrl_L = Left control ``` -------------------------------- ### Build Workflow Example Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Example of a GitHub Actions workflow for building and testing on Ubuntu. ```yaml name: Build and Test on: push: branches: [ main ] pull_request: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Python 3.10 uses: actions/setup-python@v3 with: python-version: "3.10" - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | pytest ``` -------------------------------- ### Command-Line Usage Examples Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-client.md Examples of common commands executed via the wayvncctl command-line tool. ```bash # List outputs wayvncctl output-list # Attach to specific output wayvncctl attach HDMI-1 # Cycle to next output wayvncctl output-cycle --direction forward # Get JSON output wayvncctl --json output-list # Wait for socket if not running wayvncctl --wait attach eDP-1 # Listen for events wayvncctl event-receive ``` -------------------------------- ### Toplevel Capture Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Example demonstrating how to find a specific toplevel by its application ID, set a close callback, and get its dimensions. ```c #include "toplevel.h" void on_window_closed(struct toplevel* toplevel) { printf("Window closed: %s\n", toplevel->title); } // Find specific window struct toplevel* target = NULL; struct toplevel* toplevel; wl_list_for_each(toplevel, &wayland->toplevels, link) { if (strcmp(toplevel->app_id, "org.gnome.TextEditor") == 0) { target = toplevel; break; } } if (!target) { fprintf(stderr, "Window not found\n"); return; } // Setup capture target->on_closed = on_window_closed; target->userdata = my_context; // Get window dimensions int width, height; image_source_get_logical_size(&target->image_source, &width, &height); printf("Capturing: %s (%dx%d)\n", target->title, width, height); ``` -------------------------------- ### Example: Checking for DMABUF Availability Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-buffer.md An example demonstrating how to check if DMABUF is available. ```c enum wv_buffer_type available = wv_buffer_get_available_types(); if (available & WV_BUFFER_DMABUF) { // DMABUF available, can use GPU acceleration } ``` -------------------------------- ### Pointer Usage Examples Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Examples demonstrating pointer declaration and array-like access using pointers. ```c char* some_text = "some text"; char* just_text = text + 5; char t = *just_text; char e = just_text[1]; ``` -------------------------------- ### Implementation Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-server.md A complete example demonstrating how to set up and use the Wayvnc control server, including defining actions and handling client connections. ```c #include "ctl-server.h" struct my_app_context { // Application state }; struct cmd_response* handle_attach(struct ctl* ctl, const char* display, enum image_source_type type, const char* name) { struct my_app_context* ctx = ctl_server_userdata(ctl); // Validate and perform attach if (!validate_output(name)) { return cmd_failed("Output not found: %s", name); } if (do_attach(ctx, name, type) < 0) { return cmd_failed("Failed to attach"); } // Emit event ctl_server_event_capture_changed(ctl, name); return cmd_ok(); } // Setup struct ctl_server_actions actions = { .userdata = my_context, .on_attach = handle_attach, .on_detach = handle_detach, .on_output_cycle = handle_cycle, .on_output_switch = handle_switch, .on_disconnect_client = handle_disconnect, .on_set_desktop_name = handle_set_name, .on_wayvnc_exit = handle_exit, .client_next = get_next_client, .client_info = get_client_info, .get_output_list = get_outputs, }; struct ctl* ctl = ctl_server_new("/tmp/wayvncctl-1000", &actions); if (!ctl) { fprintf(stderr, "Failed to create control server\n"); return -1; } // Server is now listening for connections... // Cleanup ctl_server_destroy(ctl); ``` -------------------------------- ### Example Usage: Cycle Outputs Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Example of cycling through outputs. ```c struct output* next = output_cycle(outputs, current, OUTPUT_CYCLE_FORWARD); ``` -------------------------------- ### Usage Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Example of subscribing to observable events, specifically power changes. ```c struct observer power_observer; void on_power_change(struct observer* obs, void* arg) { struct image_source* source = (struct image_source*)arg; enum image_source_power_state power = image_source_get_power(source); printf("Power changed to: %s\n", image_source_power_state_name(power)); } // Subscribe observer_init(&power_observer, &source->observable.power_change, on_power_change); // Unsubscribe observer_deinit(&power_observer); ``` -------------------------------- ### Option Parser Integration Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-client.md Example demonstrating how to initialize and use the option_parser with control client options. ```c #include "option-parser.h" struct wv_option options[] = { { .short_opt = 'h', .long_opt = "help", .help = "Show help message", }, { .long_opt = "json", .help = "Output as JSON", }, { .long_opt = "wait", .help = "Wait for socket to become available", }, { 0 } }; struct option_parser parser; option_parser_init(&parser, options); if (option_parser_parse(&parser, argc, argv) < 0) { option_parser_print_usage(&parser, stderr); return 1; } ``` -------------------------------- ### Keyboard and Pointer Integration Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-input.md This example demonstrates how to initialize keyboard and pointer devices, send input events, and clean up resources using the provided C API. ```c #include "keyboard.h" #include "pointer.h" #include "seat.h" // Setup struct xkb_rule_names rules = { .rules = "evdev", .model = "pc104", .layout = "us", .variant = NULL, .options = NULL, }; struct keyboard kbd; keyboard_init(&kbd, &rules); struct pointer ptr; pointer_init(&ptr); // Send keyboard input keyboard_feed(&kbd, XK_a, true); // 'a' down keyboard_feed(&kbd, XK_a, false); // 'a' up // Send pointer input pointer_set(&ptr, 500, 400, NVNC_BUTTON_LEFT); // Left click at 500,400 pointer_set(&ptr, 500, 400, 0); // Release // Cleanup keyboard_destroy(&kbd); pointer_destroy(&ptr); ``` -------------------------------- ### Install vncdotool Source: https://github.com/any1/wayvnc/blob/master/test/integration/README.md Installs the vncdotool Python package using pip. ```bash pip install vncdotool ``` -------------------------------- ### Example of observer_init() usage Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-utilities.md Demonstrates how to initialize an observer and register a callback function. ```c void on_output_changed(struct observer* obs, void* arg) { struct output* output = (struct output*)arg; printf("Output changed: %s\n", output_get_name(output)); } struct observer my_observer; observer_init(&my_observer, &output->observable.power_change, on_output_changed); ``` -------------------------------- ### Function Declaration Example Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Example of a static function declaration following the project's style guide. ```c static int do_something(int number, const char* text) { body of function } ``` -------------------------------- ### Example Usage: Connecting and Enumerating Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-wayland.md A comprehensive example demonstrating how to connect to Wayland with specific flags, wait for initialization, enumerate outputs, find a keyboard seat, subscribe to changes, and clean up. ```c #include "wayland.h" #include "output.h" #include "seat.h" // Connect with full features struct wayland* wl = wayland_connect(NULL, WAYLAND_FLAG_ENABLE_INPUT | WAYLAND_FLAG_ENABLE_TOPLEVEL_CAPTURE); if (!wl) { fprintf(stderr, "Failed to connect to Wayland\n"); return -1; } // Wait for initialization in event loop... // (aml integration handles this) // Enumerate outputs struct output* output; wl_list_for_each(output, &wl->outputs, link) { int w, h; output_get_logical_size(output, &w, &h); printf("Display: %s (%dx%d)\n", output_get_name(output), w, h); } // Find keyboard seat struct seat* seat = seat_find_by_name(&wl->seats, "seat0"); if (seat && (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) { printf("Can use keyboard on seat0\n"); } // Subscribe to changes struct observer obs; observer_init(&obs, &wl->observable.output_added, (observer_notify_fn)on_new_output); // Cleanup observer_deinit(&obs); wayland_destroy(wl); ``` -------------------------------- ### Power Management Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Example showing how to use power management functions to keep the display on during capture and allow it to sleep afterward. ```c // Request display to stay on during capture image_source_acquire_power_on(&source->image_source); // Allow display to sleep when done image_source_release_power_on(&source->image_source); ``` -------------------------------- ### Programmatic Usage Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-client.md Example of how to use the control client API programmatically in C. ```c #include "ctl-client.h" #include "option-parser.h" // Create client struct ctl_client* client = ctl_client_new("/tmp/wayvncctl-1000", NULL); if (!client) { fprintf(stderr, "Failed to create control client\n"); return -1; } // Setup command options struct wv_option options[] = { { .positional = "command", .help = "Command to execute" }, { 0 } }; struct option_parser parser; option_parser_init(&parser, options); // Parse and execute if (option_parser_parse(&parser, argc, argv) >= 0) { int result = ctl_client_run_command(client, &parser, CTL_CLIENT_PRINT_JSON | CTL_CLIENT_SOCKET_WAIT); if (result < 0) { fprintf(stderr, "Command failed\n"); } } // Cleanup ctl_client_destroy(client); ``` -------------------------------- ### Pixel Format Utilities Examples Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-buffer.md Examples of using utility functions for pixel format conversions and calculations. ```c // Convert DRM fourcc to Wayland SHM format enum wl_shm_format wl_fmt = fourcc_to_wl_shm(DRM_FORMAT_ARGB8888); // Convert Wayland SHM format to DRM fourcc uint32_t fourcc = fourcc_from_wl_shm(WL_SHM_FORMAT_ARGB8888); // Get pixel size for format int pixel_bytes = pixel_size_from_fourcc(DRM_FORMAT_ARGB8888); // Returns 4 // Calculate damage region area uint32_t area = calculate_region_area(&buf->frame_damage); ``` -------------------------------- ### Client Connection Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-server.md Example of how a client can connect to the control server using socat and the control-IPC protocol. ```bash socat - UNIX-CONNECT:$XDG_RUNTIME_DIR/wayvncctl ``` -------------------------------- ### cmd_failed Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-server.md Example of creating an error response using the cmd_failed function. ```c return cmd_failed("Output %s not found", output_name); ``` -------------------------------- ### Example Usage: Enumerate Outputs Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Example function to iterate through all outputs and print their names and logical sizes. ```c void enumerate_outputs(struct wl_list* outputs) { struct output* output; wl_list_for_each(output, outputs, link) { int w, h; output_get_logical_size(output, &w, &h); printf("%s: %dx%d\n", output_get_name(output), w, h); } } ``` -------------------------------- ### Example Usage: Output Added Callback Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Example of a callback function that is triggered when an output is added. ```c #include "output.h" #include "observer.h" void on_output_added(struct observer* obs, void* arg) { struct output* output = (struct output*)arg; printf("Output connected: %s\n", output_get_name(output)); } ``` -------------------------------- ### Authentication and Security Settings Source: https://github.com/any1/wayvnc/blob/master/_autodocs/configuration.md Examples of security-related configuration options and their implications. ```text enable_auth=false address=0.0.0.0 ``` ```text allow_broken_crypto=true ``` -------------------------------- ### Switch Statement Example Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Example of a switch statement, including case, default, and fallthrough comments. ```c switch (value) { case 3: printf("three!\n"); break; case 5: printf("five!\n"); break; case 42: printf("the answer to life, the universe and everything: "); // fallthrough default: printf("%d\n", value); break; } ``` -------------------------------- ### Subscribing to Events Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-wayland.md Example code demonstrating how to subscribe to the `output_added` observable event. ```c #include "observer.h" void on_output_added(struct observer* obs, void* arg) { struct output* output = (struct output*)arg; printf("Output connected: %s\n", output_get_name(output)); } struct observer obs; observer_init(&obs, &wayland->observable.output_added, on_output_added); // Later: observer_deinit(&obs); ``` -------------------------------- ### Arithmetic Operation Example Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Example of a simple arithmetic operation. ```c int a = b * c + 5; ``` -------------------------------- ### Ubuntu Build Dependencies Source: https://github.com/any1/wayvnc/blob/master/README.md Package installation command for Ubuntu. ```bash apt install meson libdrm-dev libxkbcommon-dev libwlroots-dev libjansson-dev libpam0g-dev libgnutls28-dev libavfilter-dev libavcodec-dev libavutil-dev libturbojpeg0-dev scdoc ``` -------------------------------- ### Example Usage: Creating and Using a Buffer Pool Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-buffer.md Demonstrates the creation, acquisition, modification, and release of buffers using a buffer pool. ```c #include "buffer.h" // Create pool for 1920x1080 ARGB8888 frames struct wv_buffer_config config = { .type = WV_BUFFER_SHM, .width = 1920, .height = 1080, .stride = 1920 * 4, .format = DRM_FORMAT_ARGB8888, }; struct wv_buffer_pool* pool = wv_buffer_pool_create(&config); if (!pool) { fprintf(stderr, "Failed to create buffer pool\n"); return; } // Acquire buffer for frame struct wv_buffer* buf = wv_buffer_pool_acquire(pool); if (!buf) { fprintf(stderr, "No buffers available\n"); return; } // Mark modified region wv_buffer_damage_rect(buf, 100, 100, 200, 200); // Process pixel data // buf->pixels contains frame data // buf->stride gives bytes per row // Return buffer to pool wv_buffer_release(buf); // Cleanup wv_buffer_pool_destroy(pool); ``` -------------------------------- ### on_done Callback Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-screencopy.md An example implementation of the `on_done` callback function, demonstrating how to process a captured frame or handle errors. ```c void frame_ready(enum screencopy_result result, struct wv_buffer* buffer, struct image_source* source, void* userdata) { if (result == SCREENCOPY_DONE) { int width = buffer->width; int height = buffer->height; void* pixels = buffer->pixels; // Process frame } else { // Retry or handle error } } sc->on_done = frame_ready; sc->userdata = my_context; ``` -------------------------------- ### Basic Configuration (No Authentication) Source: https://github.com/any1/wayvnc/blob/master/_autodocs/configuration.md A basic configuration example with no authentication enabled, listening on all interfaces and port 5900, with US keyboard layout. ```ini address=0.0.0.0 port=5900 xkb_layout=us ``` -------------------------------- ### Output List Response Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON response for the 'output-list' command, showing available outputs. ```json { "result": { "outputs": [ { "name": "HDMI-1", "description": "HDMI-1 (1920x1080)", "width": 1920, "height": 1080, "captured": true, "power": "on" } ] } } ``` -------------------------------- ### pointer_set() Example Usage Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-input.md Demonstrates how to use pointer_set() for button presses and scrolling. ```c // Left button down pointer_set(ptr, 100, 200, NVNC_BUTTON_LEFT); // Left button up pointer_set(ptr, 100, 200, 0); // Scroll wheel pointer_set(ptr, 100, 200, NVNC_SCROLL_UP); ``` -------------------------------- ### If Statement Examples Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Examples of various if statement structures, including single and multiple statements, with and without else. ```c // Single statement if (condition) do_this(); // Multiple statements if (condition) { do_this(2, "41"); do_that(); } // Single statement if/else if (condition) do_this(); else do_that(); // Multi-statement if/else if (condition) { do_this(); do_that(); } else { otherwise(); } ``` -------------------------------- ### Client List Response Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON response for the 'client-list' command, showing connected clients. ```json { "result": { "clients": [ { "id": "127.0.0.1:12345", "username": "user", "seat": "seat0" } ] } } ``` -------------------------------- ### Example Commit Message Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md An example of a well-formatted commit message following the 8 rules, including a prefix for the component. ```git ctl-client: Print trailing newline for events If someone wants to parse this instead of using jq, a trailing newline delimits the end of the event. ``` -------------------------------- ### Configuration File Format Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Example of the configuration file format used by Wayvnc, including key-value pairs and comments. ```ini key=value # comments are ignored use_relative_paths=true address=0.0.0.0 port=5900 enable_auth=true username=user password=secret xkb_layout=us private_key_file=tls_key.pem certificate_file=tls_cert.pem ``` -------------------------------- ### Setup XDG Output Managers Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Sets up XDG output managers for all outputs, enabling logical size and layout queries. Should be called after all outputs are added. ```c void output_setup_xdg_output_managers(struct wayland* wayland, struct wl_list* list); ``` -------------------------------- ### desktop_from_image_source() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Gets the desktop structure from an image source. ```c struct desktop* desktop_from_image_source(const struct image_source* source); ``` -------------------------------- ### screencopy_start() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-screencopy.md Starts capturing frames. The 'immediate' parameter determines if capture is immediate or waits for damage. ```c int screencopy_start(struct screencopy* self, bool immediate); ``` -------------------------------- ### Fedora 37 Build Dependencies Source: https://github.com/any1/wayvnc/blob/master/README.md Package installation command for Fedora 37. ```bash dnf install -y meson gcc ninja-build pkg-config egl-wayland egl-wayland-devel mesa-libEGL-devel mesa-libEGL libwayland-egl libglvnd-devel libglvnd-core-devel libglvnd mesa-libGLES-devel mesa-libGLES libxkbcommon-devel libxkbcommon libwayland-client pam-devel pixman-devel libgbm-devel libdrm-devel scdoc libavcodec-free-devel libavfilter-free-devel libavutil-free-devel turbojpeg-devel wayland-devel gnutls-devel jansson-devel ``` -------------------------------- ### client_next Handler Usage Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-server.md Example of iterating over connected VNC clients using the client_next handler. ```c struct ctl_server_client* client = NULL; while ((client = action->client_next(ctl, client))) { // Process client } ``` -------------------------------- ### Debian (unstable / testing) Build Dependencies Source: https://github.com/any1/wayvnc/blob/master/README.md Build dependency installation command for Debian. ```bash apt build-dep wayvnc ``` -------------------------------- ### Cursor Callbacks Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-screencopy.md Provides examples of setting up callback functions for cursor events such as entering, leaving, or changing hotspot. ```c // Called when cursor enters the capture area sc->cursor_enter = (void(*)(void*))my_cursor_enter_handler; // Called when cursor leaves the capture area sc->cursor_leave = (void(*)(void*))my_cursor_leave_handler; // Called when cursor hotspot changes sc->cursor_hotspot = (void(*)(int,int,void*))my_cursor_hotspot_handler; ``` -------------------------------- ### Frame Capture - Creation and Start Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Details the process of creating a screencopy object and initiating frame capture, including the callback mechanism. ```c screencopy_create() → Image source → With/without cursor → Returns struct screencopy screencopy_start() → Initiates capture (immediate or damage-based) → Calls on_done callback when frame ready → Returns struct wv_buffer ``` -------------------------------- ### Arch Linux Build Dependencies Source: https://github.com/any1/wayvnc/blob/master/README.md Package installation command for Arch Linux. ```bash pacman -S base-devel libglvnd libxkbcommon pixman gnutls jansson ``` -------------------------------- ### ctl_server_new() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-server.md Creates and starts the control server on a Unix domain socket. ```c struct ctl* ctl_server_new(const char* socket_path, const struct ctl_server_actions* actions); ``` -------------------------------- ### toplevel_from_image_source() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Function signature for getting a toplevel from an image source. ```c struct toplevel* toplevel_from_image_source(const struct image_source* source); ``` -------------------------------- ### Pixel Format Conversion Example Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-screencopy.md Demonstrates how to convert FourCC pixel format codes to Wayland SHM formats and determine pixel size. ```c enum wl_shm_format wl_fmt = fourcc_to_wl_shm(format); int pixel_size = pixel_size_from_fourcc(format); ``` -------------------------------- ### Wayvnc Configuration for RSA-AES Authentication Source: https://github.com/any1/wayvnc/blob/master/README.md Example configuration file content for RSA-AES authentication. ```ini use_relative_paths=true address=0.0.0.0 enable_auth=true username=luser password=p455w0rd rsa_private_key_file=rsa_key.pem ``` -------------------------------- ### Wayvnc Configuration for VeNCrypt Source: https://github.com/any1/wayvnc/blob/master/README.md Example configuration file content for VeNCrypt (TLS) authentication. ```ini use_relative_paths=true address=0.0.0.0 enable_auth=true username=luser password=p455w0rd private_key_file=tls_key.pem certificate_file=tls_cert.pem ``` -------------------------------- ### Output List Command Request Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON request to list available outputs. ```json { "method": "output-list" } ``` -------------------------------- ### Example of checking for cursor capture capability Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-screencopy.md Demonstrates how to check if the screencopy implementation supports cursor capture using the SCREENCOPY_CAP_CURSOR flag. ```c enum screencopy_capabilitites caps = screencopy_get_capabilities(sc); if (caps & SCREENCOPY_CAP_CURSOR) { // Cursor capture is available } ``` -------------------------------- ### image_source_describe() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get human-readable description of the image source. ```c const char* image_source_describe(const struct image_source* self, char* description, size_t maxlen); ``` -------------------------------- ### Client List Command Request Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON request to list connected VNC clients. ```json { "method": "client-list" } ``` -------------------------------- ### Connecting to a running Wayland session via SSH Source: https://github.com/any1/wayvnc/blob/master/FAQ.md This example demonstrates how to connect to a running Wayland session on a remote host using SSH tunneling and wayvnc. ```bash ssh -L 5900:localhost:5900 $user@$host WAYLAND_DISPLAY=wayland-1 wayvnc localhost ``` ```bash vncviewer localhost:5900 ``` -------------------------------- ### Output Set Command Request Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON request to switch to a specific output. ```json { "method": "output-set", "params": { "output": "HDMI-1" } } ``` -------------------------------- ### Output Cycle Command Request Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON request to cycle through outputs. ```json { "method": "output-cycle", "params": { "direction": "forward" } } ``` -------------------------------- ### Get Output Description Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Retrieves a human-readable description of an output, like "HDMI-1 (1920x1080)". ```c const char* output_get_description(const struct output* self); ``` -------------------------------- ### Get Buffer Size Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Gets the native or buffer dimensions of an output in pixels. ```c void output_get_buffer_size(const struct output* self, int* width, int* height); ``` -------------------------------- ### keyboard_init() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-input.md Initializes the keyboard with specified XKB configuration rules. ```c int keyboard_init(struct keyboard* self, const struct xkb_rule_names* rule_names); ``` -------------------------------- ### Get Logical Size Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Gets the logical (scaled) dimensions of an output in pixels. ```c void output_get_logical_size(const struct output* self, int* width, int* height); ``` -------------------------------- ### desktop_new() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Creates a desktop capture source covering all outputs. ```c struct desktop* desktop_new(struct wl_list* output_list); ``` -------------------------------- ### cfg_load() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/configuration.md Loads configuration from the specified file path, or from the default location if path is NULL. ```c int cfg_load(struct cfg* self, const char* path); ``` -------------------------------- ### toplevel_new() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Creates a toplevel (window) capture source. ```c struct toplevel* toplevel_new(struct ext_foreign_toplevel_handle_v1* handle); ``` -------------------------------- ### Get Output Position Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Gets the output's position within the global coordinate space. (0,0) is typically the top-left of the primary monitor. ```c void output_get_pos(const struct output* self, int* x, int* y); ``` -------------------------------- ### pointer_init() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-input.md Initializes the pointer device. ```c int pointer_init(struct pointer* self); ``` -------------------------------- ### image_source_get_transform() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get rotation/transform of the display. ```c enum wl_output_transform image_source_get_transform( const struct image_source* self); ``` -------------------------------- ### image_source_get_power() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get power state of the display. ```c enum image_source_power_state image_source_get_power( const struct image_source* self); ``` -------------------------------- ### wayvncctl Command-Line Tool Usage Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-client.md Synopsis and options for the wayvncctl command-line tool. ```bash wayvncctl [OPTIONS] COMMAND [ARGS] Options: --json Output as JSON --wait Wait for socket --help Show help --version Show version Commands: attach [OUTPUT|--desktop|--toplevel ID] detach output-cycle [--direction FORWARD|REVERSE] output-set OUTPUT output-list client-list client-disconnect ID set-desktop-name NAME exit event-receive ``` -------------------------------- ### image_source_power_state_name() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get string name of power state. ```c const char* image_source_power_state_name(enum image_source_power_state state); ``` -------------------------------- ### observable_init() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-utilities.md Initializes an observable. ```c static inline void observable_init(struct observable* self) ``` -------------------------------- ### image_source_get_min_scale() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get minimum supported scaling factor. ```c double image_source_get_min_scale(const struct image_source* self); ``` -------------------------------- ### data_control_init() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-utilities.md Initialize data control (clipboard) for a seat. ```c void data_control_init(struct data_control* self, struct nvnc* server, struct wl_seat* seat); ``` -------------------------------- ### image_source_get_scale() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get horizontal and vertical scaling factors. ```c bool image_source_get_scale(const struct image_source* self, double* h_scale, double* v_scale); ``` -------------------------------- ### image_source_init() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Initialize an image source with a virtual implementation. ```c void image_source_init(struct image_source* self, struct image_source_impl* impl); ``` -------------------------------- ### image_source_get_buffer_size() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get native/buffer dimensions of the image source. ```c bool image_source_get_buffer_size(const struct image_source* self, int* width, int* height); ``` -------------------------------- ### Acquire Power On Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Requests an output to turn on if it is powered off. This is reference counted and should be paired with a release call. ```c int output_acquire_power_on(struct output* output); ``` -------------------------------- ### image_source_get_logical_size() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Get logical (scaled) dimensions of the image source. ```c bool image_source_get_logical_size(const struct image_source* self, int* width, int* height); ``` -------------------------------- ### Run Unit Tests Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Command to run unit tests locally using meson. ```bash meson test -C build ``` -------------------------------- ### Configure and Build Wayvnc Source: https://github.com/any1/wayvnc/blob/master/README.md Commands to configure and build the project using Meson and Ninja. ```bash meson build ninja -C build ``` -------------------------------- ### Get Output Name Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Retrieves the name of an output, such as "HDMI-1". ```c const char* output_get_name(const struct output* self); ``` -------------------------------- ### Sourcehut Build Configuration (FreeBSD) Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Configuration file for building on FreeBSD using Sourcehut. ```yaml image: freebsd:latest packages: - python3 - py39-pip - py39-pytest - py39-flake8 update_script: - pip-3.9 install --upgrade pip test_script: - pip-3.9 install -r requirements.txt - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - pytest ``` -------------------------------- ### on_set_desktop_name handler signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-server.md Callback function signature for handling setting the desktop name. ```c struct cmd_response* (*on_set_desktop_name)(struct ctl* ctl, const char* desktop_name); ``` -------------------------------- ### Attach Command Request Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON request to attach to a specific output. ```json { "method": "attach", "params": { "output": "HDMI-1" } } ``` -------------------------------- ### image_source_acquire_power_on() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-image-source.md Request display to turn on if powered off. ```c int image_source_acquire_power_on(struct image_source* self); ``` -------------------------------- ### Run Unit Tests Source: https://github.com/any1/wayvnc/blob/master/README.md Command to run unit tests. ```bash meson test -C build ``` -------------------------------- ### ctl_client_print_command_list() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-client.md Prints a list of available commands and their descriptions to a specified stream. ```c void ctl_client_print_command_list(FILE* stream); ``` -------------------------------- ### Detach Command Request Source: https://github.com/any1/wayvnc/blob/master/_autodocs/control-ipc.md Example JSON request to detach from the current capture source. ```json { "method": "detach" } ``` -------------------------------- ### Wayland Connection Initialization Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Steps involved in establishing a connection to the Wayland compositor and discovering devices. ```c wayland_connect() → Registry enumeration → Protocol binding → Output/seat discovery → Async initialization ``` -------------------------------- ### observer_init() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-utilities.md Registers an observer to be notified of observable events. ```c static inline void observer_init( struct observer* self, struct observable* subject, observer_notify_fn notify ) ``` -------------------------------- ### PAM Authentication Configuration Source: https://github.com/any1/wayvnc/blob/master/_autodocs/configuration.md Configuration using PAM for authentication, with a German keyboard layout specified. ```ini address=0.0.0.0 enable_pam=true xkb_layout=de ``` -------------------------------- ### pam_auth() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-utilities.md Authenticate user via PAM (Pluggable Authentication Modules). ```c bool pam_auth(const char* username, const char* password); ``` -------------------------------- ### Run Wayvnc from Build Directory Source: https://github.com/any1/wayvnc/blob/master/README.md Command to run the wayvnc server from the build directory. ```bash ./build/wayvnc ``` -------------------------------- ### Run Integration Tests Source: https://github.com/any1/wayvnc/blob/master/README.md Command to run integration tests. ```bash ./test/integration/integration.sh ``` -------------------------------- ### Sway configuration for passthrough mode Source: https://github.com/any1/wayvnc/blob/master/FAQ.md This snippet shows how to create a passthrough mode in Sway to pass mod-keys to a remote desktop session. It includes an example of disabling floating modifiers. ```bash mode passthrough { bindsym $mod+Pause mode default } bindsym $mod+Pause mode passthrough ``` ```bash mode passthrough { bindsym $mod+Pause mode default; floating_modifier $mod normal } bindsym $mod+Pause mode passthrough; floating_modifier none ``` -------------------------------- ### Input Handling - Keyboard Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Details the components and functionality of the virtual keyboard input handler. ```c struct keyboard ├── XKB context (libxkbcommon) ├── Keymap & state ├── Keysym↔keycode translation └── Virtual keyboard protocol ``` -------------------------------- ### Configuration Structure Source: https://github.com/any1/wayvnc/blob/master/_autodocs/types.md The `cfg` struct holds all configuration settings for the wayvnc server. ```c struct cfg { char* directory; bool enable_auth; bool relax_encryption; bool allow_broken_crypto; char* private_key_file; char* certificate_file; char* rsa_private_key_file; char* username; char* password; char* address; uint32_t port; bool enable_pam; char* xkb_rules; char* xkb_model; char* xkb_layout; char* xkb_variant; char* xkb_options; bool use_relative_paths; }; ``` -------------------------------- ### Desktop Output Structure Definition Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Defines the structure for a desktop output, including associated output, parent desktop, observers for power and geometry changes, and screencopy pointers. ```c struct desktop_output { LIST_ENTRY(desktop_output) link; struct output* output; // Associated output struct desktop* desktop; // Parent desktop struct observer power_change_observer; // Power state changes struct observer geometry_change_observer; // Size/position changes struct screencopy* sc; // Frame screencopy struct screencopy* cursor_sc; // Cursor screencopy }; ``` -------------------------------- ### data_control_to_clipboard() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-utilities.md Copy text from VNC client to system clipboard. ```c void data_control_to_clipboard(struct data_control* self, const char* text, size_t len); ``` -------------------------------- ### desktop_destroy() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Destroys desktop capture and frees resources. ```c void desktop_destroy(struct desktop* self); ``` -------------------------------- ### Run Wayvnc Accepting Connections from Any Interface Source: https://github.com/any1/wayvnc/blob/master/README.md Command to run wayvnc and accept connections from any network interface. ```bash ./build/wayvnc 0.0.0.0 ``` -------------------------------- ### TLS/VeNCrypt Configuration Source: https://github.com/any1/wayvnc/blob/master/_autodocs/configuration.md Configuration for TLS/VeNCrypt encryption, enabling authentication, and specifying certificate and key files. Relative paths are enabled. ```ini use_relative_paths=true address=0.0.0.0 enable_auth=true username=user password=secret private_key_file=tls_key.pem certificate_file=tls_cert.pem ``` -------------------------------- ### Run Integration Tests Source: https://github.com/any1/wayvnc/blob/master/CONTRIBUTING.md Command to run integration tests locally. ```bash ./test/integration/integration.sh ``` -------------------------------- ### jprintf() Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-utilities.md Create JSON object using printf-style format. ```c json_t* jprintf(const char* fmt, ...); ``` -------------------------------- ### Desktop Structure Definition Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-desktop-toplevel.md Defines the structure for desktop capture, including image source interface, output lists, observers, and capture pointers. ```c struct desktop { struct image_source image_source; // Image source interface struct desktop_output_list outputs; // List of outputs struct observer output_added_observer; // Observer for new outputs struct observer output_removed_observer; // Observer for removed outputs struct desktop_capture* capture; // Main frame capture struct desktop_capture* cursor_capture; // Cursor capture }; ``` -------------------------------- ### output_first() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-output.md Retrieves the first output object from a given list. ```c struct output* output_first(struct wl_list* list); ``` -------------------------------- ### Input Handling - Pointer Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Describes the virtual pointer input handler, including its position, state, and protocol. ```c struct pointer ├── Position (x, y) ├── Button state └── Virtual pointer protocol ``` -------------------------------- ### Check Compositor Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Command to check the Wayland compositor. ```bash wayland-info ``` -------------------------------- ### RSA-AES Configuration Source: https://github.com/any1/wayvnc/blob/master/_autodocs/configuration.md Configuration for RSA-AES security type, enabling authentication, and specifying the RSA private key file. Relative paths are enabled. ```ini use_relative_paths=true address=0.0.0.0 enable_auth=true username=user password=secret rsa_private_key_file=rsa_key.pem ``` -------------------------------- ### ctl_client_print_event_list() function signature Source: https://github.com/any1/wayvnc/blob/master/_autodocs/api-reference-control-client.md Prints a list of available events and their descriptions to a specified stream. ```c void ctl_client_print_event_list(FILE* stream); ``` -------------------------------- ### Cloning and Linking Subprojects Source: https://github.com/any1/wayvnc/blob/master/README.md Steps to clone and link neatvnc and aml subprojects for building. ```bash git clone https://github.com/any1/wayvnc.git git clone https://github.com/any1/neatvnc.git git clone https://github.com/any1/aml.git mkdir wayvnc/subprojects cd wayvnc/subprojects ln -s ../../neatvnc . ln -s ../../aml . cd - mkdir neatvnc/subprojects cd neatvnc/subprojects ln -s ../../aml . cd - ``` -------------------------------- ### Main Program Flow Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md C code snippet illustrating the main program flow orchestrated by main.c, including initialization and cleanup steps. ```c main() │ ├─ parse_arguments() ├─ cfg_load() // Load configuration │ ├─ aml_new() // Event loop │ ├─ wayland_connect() // Connect to Wayland │ └─ Async init in event loop │ ├─ desktop_new() // Create desktop capture │ └─ Observer for output changes │ ├─ keyboard_init() // Initialize virtual keyboard ├─ pointer_init() // Initialize virtual pointer │ ├─ nvnc_new() // Create VNC server │ └─ Listen on TCP port (default 5900) │ ├─ ctl_server_new() // Create control socket │ └─ Listen on Unix domain socket │ ├─ screencopy_start() // Start frame capture │ ├─ aml_run() // Event loop │ ├─ Handle Wayland events │ ├─ Handle VNC connections │ ├─ Handle frame ready callbacks │ ├─ Handle control socket commands │ └─ Handle signals (SIGTERM, etc.) │ └─ cleanup() ├─ screencopy_stop() ├─ wayland_destroy() ├─ ctl_server_destroy() ├─ nvnc_destroy() └─ aml_unref() ``` -------------------------------- ### Check DMABUF Support Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Command to check for DMABUF support in Wayland. ```bash wayland-info | grep dmabuf ``` -------------------------------- ### Check Protocol Support Source: https://github.com/any1/wayvnc/blob/master/_autodocs/architecture.md Command to check supported Wayland protocols. ```bash wayland-info | grep protocol ```