Give an example of a simple program that uses the wayland interface
- User
Give an example of a simple program that uses the wayland interface
Assistant
Here is a simple Wayland program that opens a window and draws a rectangle:
#include <wayland-client.h> #include <cairo/cairo.h> #include <stdlib.h> int main() { struct wl_display *display = wl_display_connect(NULL); struct wl_surface *surface = wl_compositor_create_surface(wl_compositor_create(display)); struct wl_shell_surface *shell_surface = wl_shell_get_shell_surface(wl_shell_create(display), surface); wl_shell_surface_set_toplevel(shell_surface); cairo_surface_t *cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 400, 400); cairo_t *cr = cairo_create(cairo_surface); cairo_rectangle(cr, 0, 0, 300, 300); cairo_set_source_rgb(cr, 1, 0, 0); cairo_fill(cr); wl_surface_attach(surface, wl_shm_create_buffer(wl_shm_create(display), 400, 400, 400 * 4, WL_SHM_FORMAT_ARGB8888), 0, 0); wl_surface_damage(surface, 0, 0, 400, 400); wl_surface_commit(surface); wl_display_roundtrip(display); cairo_destroy(cr); cairo_surface_destroy(cairo_surface); wl_shell_surface_destroy(shell_surface); wl_surface_destroy(surface); wl_compositor_destroy(wl_compositor_create(display)); wl_display_disconnect(display); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.