int main(int argc, char *argv[]) { struct display *display; char buf[256], *p; int ret, fd; display = malloc(sizeof *display); assert(display); display->display = wl_display_connect(NULL); assert(display->display); display->registry = wl_display_get_registry(display->display); wl_registry_add_listener(display->registry, ®istry_listener, display); wl_display_dispatch(display->display); wl_display_dispatch(display->display); fd = 0; p = getenv("TEST_SOCKET"); if (p) fd = strtol(p, NULL, 0); while (1) { ret = read(fd, buf, sizeof buf); if (ret == -1) { fprintf(stderr, "test-client: read error: fd %d, %m\n", fd); return -1; } fprintf(stderr, "test-client: got %.*s\n", ret - 1, buf); if (strncmp(buf, "bye\n", ret) == 0) { return 0; } else if (strncmp(buf, "create-surface\n", ret) == 0) { create_surface(fd, display); } else if (strncmp(buf, "send-state\n", ret) == 0) { send_state(fd, display); } else if (strncmp(buf, "send-button-state\n", ret) == 0) { send_button_state(fd, display); } else if (strncmp(buf, "send-keyboard-state\n", ret) == 0) { send_keyboard_state(fd, display); } else { fprintf(stderr, "test-client: unknown command %.*s\n", ret, buf); return -1; } } assert(0); }
int main(int argc, char **argv) { display = wl_display_connect(NULL); if (display == NULL) { fprintf(stderr, "Can't connect to display\n"); exit(1); } printf("connected to display\n"); wl_display_disconnect(display); printf("disconnected from display\n"); exit(0); }
int main(int argc, char **argv) { struct sigaction sigint; struct display display = { 0 }; struct window window = { 0 }; window.display = &display; window.geometry.width = 250; window.geometry.height = 250; display.display = wl_display_connect(NULL); assert(display.display); wl_display_add_global_listener(display.display, display_handle_global, &display); wl_display_get_fd(display.display, event_mask_update, &display); wl_display_iterate(display.display, WL_DISPLAY_READABLE); init_egl(&display); create_surface(&window); init_gl(&window); sigint.sa_handler = signal_int; sigemptyset(&sigint.sa_mask); sigint.sa_flags = SA_RESETHAND; sigaction(SIGINT, &sigint, NULL); redraw(&window, NULL, 0); while (running) wl_display_iterate(display.display, display.mask); fprintf(stderr, "simple-egl exiting\n"); destroy_surface(&window); fini_egl(&display); if (display.shell) wl_shell_destroy(display.shell); if (display.compositor) wl_compositor_destroy(display.compositor); wl_display_flush(display.display); wl_display_disconnect(display.display); return 0; }
void QWaylandEventThread::waylandDisplayConnect() { m_display = wl_display_connect(NULL); if (m_display == NULL) { qErrnoWarning(errno, "Failed to create display"); ::exit(1); } m_displayLock->unlock(); m_fileDescriptor = wl_display_get_fd(m_display); m_readNotifier = new QSocketNotifier(m_fileDescriptor, QSocketNotifier::Read, this); connect(m_readNotifier, SIGNAL(activated(int)), this, SLOT(readWaylandEvents())); }
static gpointer is_wayland_session (gpointer user_data) { #if HAVE_WAYLAND struct wl_display *display; display = wl_display_connect (NULL); if (!display) return GUINT_TO_POINTER(FALSE); wl_display_disconnect (display); return GUINT_TO_POINTER(TRUE); #else return GUINT_TO_POINTER(FALSE); #endif }
void hello_setup_wayland(void) { struct wl_registry *registry; display = wl_display_connect(NULL); if (display == NULL) { perror("Error opening display"); exit(EXIT_FAILURE); } registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener, &compositor); wl_display_roundtrip(display); wl_registry_destroy(registry); }
GstWlDisplay * gst_wl_display_new (const gchar * name, GError ** error) { struct wl_display *display; display = wl_display_connect (name); if (!display) { *error = g_error_new (g_quark_from_static_string ("GstWlDisplay"), 0, "Failed to connect to the wayland display '%s'", name ? name : "(default)"); return NULL; } else { return gst_wl_display_new_existing (display, TRUE, error); } }
static struct touch * touch_create(int width, int height) { struct touch *touch; touch = malloc(sizeof *touch); if (touch == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } touch->display = wl_display_connect(NULL); assert(touch->display); touch->has_argb = 0; touch->registry = wl_display_get_registry(touch->display); wl_registry_add_listener(touch->registry, ®istry_listener, touch); wl_display_dispatch(touch->display); wl_display_roundtrip(touch->display); if (!touch->has_argb) { fprintf(stderr, "WL_SHM_FORMAT_ARGB32 not available\n"); exit(1); } touch->width = width; touch->height = height; touch->surface = wl_compositor_create_surface(touch->compositor); touch->shell_surface = wl_shell_get_shell_surface(touch->shell, touch->surface); create_shm_buffer(touch); if (touch->shell_surface) { wl_shell_surface_add_listener(touch->shell_surface, &shell_surface_listener, touch); wl_shell_surface_set_toplevel(touch->shell_surface); } wl_surface_set_user_data(touch->surface, touch); wl_shell_surface_set_title(touch->shell_surface, "simple-touch"); memset(touch->data, 64, width * height * 4); wl_surface_attach(touch->surface, touch->buffer, 0, 0); wl_surface_damage(touch->surface, 0, 0, width, height); wl_surface_commit(touch->surface); return touch; }
WaylandCore::WaylandCore( int width, int height, const char* title ) : mDisplay(NULL),mRegistry(NULL),mCompositor(NULL),mShm(NULL), mSeat(NULL),mPointer(NULL), mEglDisplay(EGL_NO_DISPLAY), mEglContext(EGL_NO_CONTEXT),mEglWindow(0),mShellSurface(NULL), mShouldClose(false),mWidth(0),mHeight(0) { mDisplay = wl_display_connect(NULL); setup_registry_handlers(); if( mDisplay ) { mRegistry = wl_display_get_registry( mDisplay ); } initEGL(); createWindow( width, height, title ); }
bool WLContext::InitWLContext(const struct wl_pointer_listener* wlPointerListener, const struct wl_keyboard_listener* wlKeyboardListener, const struct wl_touch_listener* wlTouchListener) { m_wlPointerListener = const_cast<wl_pointer_listener*>(wlPointerListener); m_wlKeyboardListener = const_cast<wl_keyboard_listener*>(wlKeyboardListener); m_wlTouchListener = const_cast<wl_touch_listener*>(wlTouchListener); m_wlDisplay = wl_display_connect(NULL); m_wlRegistry = wl_display_get_registry(m_wlDisplay); wl_registry_add_listener(m_wlRegistry, ®istryListener, this); wl_display_dispatch(m_wlDisplay); wl_display_roundtrip(m_wlDisplay); return true; }
GdkDisplay * _gdk_wayland_display_open (const gchar *display_name) { struct wl_display *wl_display; GdkDisplay *display; GdkWaylandDisplay *display_wayland; /* If this variable is unset then wayland initialisation will surely * fail, logging a fatal error in the process. Save ourselves from * that. */ if (g_getenv ("XDG_RUNTIME_DIR") == NULL) return NULL; wl_log_set_handler_client(log_handler); wl_display = wl_display_connect(display_name); if (!wl_display) return NULL; display = g_object_new (GDK_TYPE_WAYLAND_DISPLAY, NULL); display->device_manager = _gdk_wayland_device_manager_new (display); display_wayland = GDK_WAYLAND_DISPLAY (display); display_wayland->wl_display = wl_display; display_wayland->screen = _gdk_wayland_screen_new (display); display_wayland->event_source = _gdk_wayland_display_event_source_new (display); _gdk_wayland_display_init_cursors (display_wayland); display_wayland->wl_registry = wl_display_get_registry(display_wayland->wl_display); wl_registry_add_listener(display_wayland->wl_registry, ®istry_listener, display_wayland); /* Wait until the dust has settled during init... */ wl_display_roundtrip (display_wayland->wl_display); gdk_input_init (display); display_wayland->selection = gdk_wayland_selection_new (); g_signal_emit_by_name (display, "opened"); return display; }
int p_init(int *argc, char*** argv) { P_UNUSED(argc); P_UNUSED(argv); if (!(g_wl_display = wl_display_connect(NULL))) { p_log("Failed to connect to a Wayland compositor.\n"); return (-1); } if (get_registry_objects() < 0) { p_log("The compositor does not provide the required Wayland " "interface objects.\n"); return (-1); } return 0; /* No error. */ }
int main(int argc, char *argv[]) { struct simple_im simple_im; int ret = 0; memset(&simple_im, 0, sizeof(simple_im)); simple_im.display = wl_display_connect(NULL); if (simple_im.display == NULL) { fprintf(stderr, "failed to connect to server: %m\n"); return -1; } simple_im.registry = wl_display_get_registry(simple_im.display); wl_registry_add_listener(simple_im.registry, ®istry_listener, &simple_im); wl_display_roundtrip(simple_im.display); if (simple_im.input_method == NULL) { fprintf(stderr, "No input_method global\n"); exit(1); } simple_im.xkb_context = xkb_context_new(0); if (simple_im.xkb_context == NULL) { fprintf(stderr, "Failed to create XKB context\n"); return -1; } simple_im.context = NULL; simple_im.key_handler = simple_im_key_handler; while (ret != -1) ret = wl_display_dispatch(simple_im.display); if (ret == -1) { fprintf(stderr, "Dispatch error: %m\n"); exit(1); } return 0; }
GdkDisplay * _gdk_wayland_display_open (const gchar *display_name) { struct wl_display *wl_display; GdkDisplay *display; GdkWaylandDisplay *display_wayland; wl_log_set_handler_client(log_handler); wl_display = wl_display_connect(display_name); if (!wl_display) return NULL; display = g_object_new (GDK_TYPE_WAYLAND_DISPLAY, NULL); display_wayland = GDK_WAYLAND_DISPLAY (display); display_wayland->wl_display = wl_display; display_wayland->screen = _gdk_wayland_screen_new (display); display->device_manager = _gdk_wayland_device_manager_new (display); /* Set up listener so we'll catch all events. */ display_wayland->wl_registry = wl_display_get_registry(display_wayland->wl_display); wl_registry_add_listener(display_wayland->wl_registry, ®istry_listener, display_wayland); /* We use init_ref_count to track whether some part of our * initialization still needs a roundtrip to complete. */ wait_for_roundtrip(display_wayland); while (display_wayland->init_ref_count > 0) wl_display_roundtrip(display_wayland->wl_display); display_wayland->event_source = _gdk_wayland_display_event_source_new (display); gdk_input_init (display); g_signal_emit_by_name (display, "opened"); return display; }
/* Test that destroying a proxy object doesn't result in any more * callback being invoked, even though were many queued. */ static int client_test_proxy_destroy(void) { struct wl_display *display; struct wl_registry *registry; int counter = 0; display = wl_display_connect(SOCKET_NAME); client_assert(display); registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener, &counter); wl_display_roundtrip(display); client_assert(counter == 1); wl_display_disconnect(display); return 0; }
Display::Display() : wl_display_(wl_display_connect(0)) , wl_registry_(NULL) , globals_() , xkbContext_(NULL) { ASSERT(wl_display_ != NULL); wl_registry_ = wl_display_get_registry(*this); ASSERT(wl_registry_ != NULL); wl_display_set_user_data(*this, this); wl_registry_set_user_data(*this, this); static const struct wl_registry_listener listener = {global}; wl_registry_add_listener(wl_registry_, &listener, this); dispatch(); }
struct registry *registry_poll(void) { struct registry *registry = malloc(sizeof(struct registry)); memset(registry, 0, sizeof(struct registry)); registry->outputs = create_list(); registry->input = calloc(sizeof(struct input), 1); registry->input->xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); registry->display = wl_display_connect(NULL); if (!registry->display) { sway_log(L_ERROR, "Error opening display"); registry_teardown(registry); return NULL; } struct wl_registry *reg = wl_display_get_registry(registry->display); wl_registry_add_listener(reg, ®istry_listener, registry); wl_display_dispatch(registry->display); wl_display_roundtrip(registry->display); wl_registry_destroy(reg); return registry; }
int main () { display = wl_display_connect (NULL); struct wl_registry *registry = wl_display_get_registry (display); wl_registry_add_listener (registry, ®istry_listener, NULL); wl_display_roundtrip (display); egl_display = eglGetDisplay (display); eglInitialize (egl_display, NULL, NULL); struct window window; create_window (&window, WIDTH, HEIGHT); while (running) { wl_display_dispatch_pending (display); draw_window (&window); } delete_window (&window); eglTerminate (egl_display); wl_display_disconnect (display); return 0; }
static struct native_display * native_create_display(void *dpy, boolean use_sw) { struct wayland_display *display = NULL; boolean own_dpy = FALSE; use_sw = use_sw || debug_get_bool_option("EGL_SOFTWARE", FALSE); if (dpy == NULL) { dpy = wl_display_connect(NULL); if (dpy == NULL) return NULL; own_dpy = TRUE; } if (use_sw) { _eglLog(_EGL_INFO, "use software fallback"); display = wayland_create_shm_display((struct wl_display *) dpy, wayland_event_handler); } else { display = wayland_create_drm_display((struct wl_display *) dpy, wayland_event_handler); } if (!display) return NULL; display->base.get_param = wayland_display_get_param; display->base.get_configs = wayland_display_get_configs; display->base.get_pixmap_format = wayland_display_get_pixmap_format; display->base.copy_to_pixmap = native_display_copy_to_pixmap; display->base.create_window_surface = wayland_create_window_surface; display->base.create_pixmap_surface = wayland_create_pixmap_surface; display->own_dpy = own_dpy; return &display->base; }
bool WL_init() { _WL_display.running = true; // Initialize wayland _WL_display.display = wl_display_connect(NULL); if (!_WL_display.display) { Nerror("Can't connect to display (WL)"); return false; } // Initialize events NWMan_events_init(); // Initialize registry _WL_display.registry = wl_display_get_registry(_WL_display.display); wl_registry_add_listener(_WL_display.registry, &_WL_registry_listener, NULL); // Sync wl_display_dispatch(_WL_display.display); return true; }
struct wit_client * wit_client_populate(int sock) { struct wit_client *c = calloc(1, sizeof *c); assert(c && "Out of memory"); c->sock = sock; c->display = wl_display_connect(NULL); assertf(c->display, "Couldn't connect to display"); c->registry.proxy = (struct wl_proxy *) wl_display_get_registry(c->display); assertf(c->registry.proxy, "Couldn't get registry"); wit_client_add_listener(c, "wl_registry", ®istry_default_listener); wl_display_dispatch(c->display); assertf(wl_display_get_error(c->display) == 0, "An error in display occured"); return c; }
static gboolean gst_gl_window_wayland_egl_open (GstGLWindow * window, GError ** error) { GstGLWindowWaylandEGL *window_egl = GST_GL_WINDOW_WAYLAND_EGL (window); window_egl->display.display = wl_display_connect (NULL); if (!window_egl->display.display) { g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "Failed to connect to Wayland display server"); goto error; } window_egl->display.registry = wl_display_get_registry (window_egl->display.display); wl_registry_add_listener (window_egl->display.registry, ®istry_listener, window_egl); wl_display_dispatch (window_egl->display.display); create_surface (window_egl); window_egl->display.cursor_surface = wl_compositor_create_surface (window_egl->display.compositor); window_egl->wl_source = wayland_event_source_new (window_egl->display.display); window_egl->main_context = g_main_context_new (); window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE); g_source_attach (window_egl->wl_source, window_egl->main_context); return TRUE; error: return FALSE; }
QWaylandDisplay::QWaylandDisplay(void) : argb_visual(0), premultiplied_argb_visual(0), rgb_visual(0) { display = this; qRegisterMetaType<uint32_t>("uint32_t"); mDisplay = wl_display_connect(NULL); if (mDisplay == NULL) { qErrnoWarning(errno, "Failed to create display"); qFatal("No wayland connection available."); } wl_display_add_global_listener(mDisplay, QWaylandDisplay::displayHandleGlobal, this); #ifdef QT_WAYLAND_GL_SUPPORT mEglIntegration = QWaylandGLIntegration::createGLIntegration(this); #endif #ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT mWindowManagerIntegration = QWaylandWindowManagerIntegration::createIntegration(this); #endif blockingReadEvents(); #ifdef QT_WAYLAND_GL_SUPPORT mEglIntegration->initialize(); #endif connect(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), this, SLOT(flushRequests())); mFd = wl_display_get_fd(mDisplay, sourceUpdate, this); mReadNotifier = new QSocketNotifier(mFd, QSocketNotifier::Read, this); connect(mReadNotifier, SIGNAL(activated(int)), this, SLOT(readEvents())); waitForScreens(); }
/* Test that when receiving the first of two synchronization * callback events, destroying the second one doesn't cause any * errors even if the delete_id event is handled out of order. */ static int client_test_multiple_queues(void) { struct wl_event_queue *queue; struct wl_callback *callback1; struct multiple_queues_state state; int ret = 0; state.display = wl_display_connect(SOCKET_NAME); client_assert(state.display); /* Make the current thread the display thread. This is because * wl_display_dispatch_queue() will only read the display fd if * the main display thread has been set. */ wl_display_dispatch_pending(state.display); queue = wl_display_create_queue(state.display); client_assert(queue); state.done = false; callback1 = wl_display_sync(state.display); wl_callback_add_listener(callback1, &sync_listener, &state); wl_proxy_set_queue((struct wl_proxy *) callback1, queue); state.callback2 = wl_display_sync(state.display); wl_callback_add_listener(state.callback2, &sync_listener, NULL); wl_proxy_set_queue((struct wl_proxy *) state.callback2, queue); wl_display_flush(state.display); while (!state.done && !ret) ret = wl_display_dispatch_queue(state.display, queue); wl_display_disconnect(state.display); return ret == -1 ? -1 : 0; }
/** * * @brief init a wayland_client, it does all the dirty jobs you don't want to touch */ struct registry * client_init(const char *display_name, void (*registre)(struct wl_registry *, uint32_t, const char *, uint32_t), void (*deregistre)(struct wl_registry *, uint32_t)) { struct registry *reg = (struct registry *)malloc(sizeof(*reg)); reg->display = wl_display_connect(display_name); if (!reg->display) goto error; struct wl_registry *wayland_registry = wl_display_get_registry(reg->display); reg->registre = registre; reg->deregstre = deregistre; wl_registry_add_listener(wayland_registry, ®istry_listener, reg); wl_display_dispatch(reg->display); wl_display_roundtrip(reg->display); return reg; error: free(reg); return NULL; }
static struct display * create_display(void) { struct display *display; display = malloc(sizeof *display); display->display = wl_display_connect(NULL); assert(display->display); display->formats = 0; wl_display_add_global_listener(display->display, display_handle_global, display); wl_display_iterate(display->display, WL_DISPLAY_READABLE); wl_display_roundtrip(display->display); if (!(display->formats & (1 << WL_SHM_FORMAT_XRGB8888))) { fprintf(stderr, "WL_SHM_FORMAT_XRGB32 not available\n"); exit(1); } wl_display_get_fd(display->display, event_mask_update, display); return display; }
GdkDisplay * _gdk_wayland_display_open (const gchar *display_name) { struct wl_display *wl_display; GdkDisplay *display; GdkDisplayWayland *display_wayland; wl_display = wl_display_connect(display_name); if (!wl_display) return NULL; display = g_object_new (GDK_TYPE_DISPLAY_WAYLAND, NULL); display_wayland = GDK_DISPLAY_WAYLAND (display); display_wayland->wl_display = wl_display; display_wayland->screen = _gdk_wayland_screen_new (display); display->device_manager = _gdk_wayland_device_manager_new (display); /* Set up listener so we'll catch all events. */ wl_display_add_global_listener(display_wayland->wl_display, gdk_display_handle_global, display_wayland); gdk_display_init_egl(display); display_wayland->event_source = _gdk_wayland_display_event_source_new (display); gdk_input_init (display); g_signal_emit_by_name (display, "opened"); g_signal_emit_by_name (gdk_display_manager_get(), "display_opened", display); return display; }
static void get_server_references(void) { display = wl_display_connect(NULL); if (display == NULL) { fprintf(stderr, "Can't connect to display\n"); exit(1); } printf("connected to display\n"); struct wl_registry *registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener, NULL); wl_display_dispatch(display); wl_display_roundtrip(display); if (compositor == NULL || shell == NULL) { fprintf(stderr, "Can't find compositor or shell\n"); exit(1); } else { fprintf(stderr, "Found compositor and shell\n"); } }
struct display * display_create(int *argc, char **argv[], const GOptionEntry *option_entries) { struct display *d; GOptionContext *context; GOptionGroup *xkb_option_group; GError *error; g_type_init(); context = g_option_context_new(NULL); if (option_entries) g_option_context_add_main_entries(context, option_entries, "Wayland View"); xkb_option_group = g_option_group_new("xkb", "Keyboard options", "Show all XKB options", NULL, NULL); g_option_group_add_entries(xkb_option_group, xkb_option_entries); g_option_context_add_group (context, xkb_option_group); if (!g_option_context_parse(context, argc, argv, &error)) { fprintf(stderr, "option parsing failed: %s\n", error->message); exit(EXIT_FAILURE); } d = malloc(sizeof *d); if (d == NULL) return NULL; d->display = wl_display_connect(NULL); if (d->display == NULL) { fprintf(stderr, "failed to create display: %m\n"); return NULL; } wl_list_init(&d->input_list); /* Set up listener so we'll catch all events. */ wl_display_add_global_listener(d->display, display_handle_global, d); /* Process connection events. */ wl_display_iterate(d->display, WL_DISPLAY_READABLE); if (d->device_name && init_drm(d) < 0) return NULL; create_pointer_surfaces(d); display_render_frame(d); d->loop = g_main_loop_new(NULL, FALSE); d->source = wl_glib_source_new(d->display); g_source_attach(d->source, NULL); wl_list_init(&d->window_list); init_xkb(d); return d; }
static CoglBool _cogl_winsys_renderer_connect (CoglRenderer *renderer, CoglError **error) { CoglRendererEGL *egl_renderer; CoglRendererWayland *wayland_renderer; renderer->winsys = g_slice_new0 (CoglRendererEGL); egl_renderer = renderer->winsys; wayland_renderer = g_slice_new0 (CoglRendererWayland); egl_renderer->platform = wayland_renderer; egl_renderer->platform_vtable = &_cogl_winsys_egl_vtable; if (renderer->foreign_wayland_display) { wayland_renderer->wayland_display = renderer->foreign_wayland_display; } else { wayland_renderer->wayland_display = wl_display_connect (NULL); if (!wayland_renderer->wayland_display) { _cogl_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_INIT, "Failed to connect wayland display"); goto error; } } wayland_renderer->wayland_registry = wl_display_get_registry (wayland_renderer->wayland_display); wl_registry_add_listener (wayland_renderer->wayland_registry, ®istry_listener, egl_renderer); /* * Ensure that that we've received the messages setting up the * compostor and shell object. */ wl_display_roundtrip (wayland_renderer->wayland_display); if (!wayland_renderer->wayland_compositor || !wayland_renderer->wayland_shell) { _cogl_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_INIT, "Unable to find wl_compositor or wl_shell"); goto error; } egl_renderer->edpy = eglGetDisplay ((EGLNativeDisplayType) wayland_renderer->wayland_display); if (!_cogl_winsys_egl_renderer_connect_common (renderer, error)) goto error; wayland_renderer->fd = wl_display_get_fd (wayland_renderer->wayland_display); if (renderer->wayland_enable_event_dispatch) _cogl_poll_renderer_add_fd (renderer, wayland_renderer->fd, COGL_POLL_FD_EVENT_IN, prepare_wayland_display_events, dispatch_wayland_display_events, renderer); return TRUE; error: _cogl_winsys_renderer_disconnect (renderer); return FALSE; }