int main(int argc, char *argv[]) { struct editor editor; editor.display = display_create(argc, argv); if (editor.display == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } wl_display_add_global_listener(display_get_display(editor.display), global_handler, &editor); editor.window = window_create(editor.display); editor.widget = frame_create(editor.window, &editor); editor.entry = text_entry_create(&editor, "Entry"); editor.editor = text_entry_create(&editor, "Editor"); window_set_title(editor.window, "Text Editor"); widget_set_redraw_handler(editor.widget, redraw_handler); widget_set_resize_handler(editor.widget, resize_handler); widget_set_button_handler(editor.widget, button_handler); window_schedule_resize(editor.window, 500, 400); display_run(editor.display); text_entry_destroy(editor.entry); text_entry_destroy(editor.editor); return 0; }
QWaylandWindowManagerIntegration::QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay) : mWaylandDisplay(waylandDisplay) , mWaylandWindowManager(0) { wl_display_add_global_listener(mWaylandDisplay->wl_display(), QWaylandWindowManagerIntegration::wlHandleListenerGlobal, this); }
QWaylandXCompositeGLXIntegration::QWaylandXCompositeGLXIntegration(QWaylandDisplay * waylandDispaly) : QWaylandGLIntegration() , mWaylandDisplay(waylandDispaly) { qDebug() << "Using XComposite-GLX"; wl_display_add_global_listener(waylandDispaly->wl_display(), QWaylandXCompositeGLXIntegration::wlDisplayHandleGlobal, this); }
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; }
int main(int argc, char *argv[]) { struct display *d; struct wscreensaver screensaver = { 0 }; init_frand(); argc = parse_options(wscreensaver_options, ARRAY_LENGTH(wscreensaver_options), argc, argv); d = display_create(argc, argv); if (d == NULL) { fprintf(stderr, "failed to create display: %m\n"); return EXIT_FAILURE; } if (!demo_mode) { /* iterates already known globals immediately */ wl_display_add_global_listener(display_get_display(d), global_handler, &screensaver); if (!screensaver.interface) { fprintf(stderr, "Server did not offer screensaver interface," " exiting.\n"); return EXIT_FAILURE; } } if (init_wscreensaver(&screensaver, d) < 0) { fprintf(stderr, "wscreensaver init failed.\n"); return EXIT_FAILURE; } display_run(d); free((void *)progname); return EXIT_SUCCESS; }
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(); }
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 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; }
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 gboolean _cogl_winsys_renderer_connect (CoglRenderer *renderer, GError **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; /* The EGL API doesn't provide for a way to explicitly select a * platform when the driver can support multiple. Mesa allows * selection using an environment variable though so that's what * we're doing here... */ g_setenv ("EGL_PLATFORM", "wayland", 1); if (renderer->foreign_wayland_display) { wayland_renderer->wayland_display = renderer->foreign_wayland_display; /* XXX: For now we have to assume that if a foreign display is * given then a foreign compositor and shell must also have been * given because wayland doesn't provide a way to * retrospectively be notified of the these objects. */ g_assert (renderer->foreign_wayland_compositor); g_assert (renderer->foreign_wayland_shell); wayland_renderer->wayland_compositor = renderer->foreign_wayland_compositor; wayland_renderer->wayland_shell = renderer->foreign_wayland_shell; } else { wayland_renderer->wayland_display = wl_display_connect (NULL); if (!wayland_renderer->wayland_display) { g_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_INIT, "Failed to connect wayland display"); goto error; } wl_display_add_global_listener (wayland_renderer->wayland_display, display_handle_global_cb, egl_renderer); } /* * Ensure that that we've received the messages setting up the * compostor and shell object. This is better than just * wl_display_iterate since it will always ensure that something * is available to be read */ while (!(wayland_renderer->wayland_compositor && wayland_renderer->wayland_shell)) wl_display_roundtrip (wayland_renderer->wayland_display); egl_renderer->edpy = eglGetDisplay ((EGLNativeDisplayType) wayland_renderer->wayland_display); if (!_cogl_winsys_egl_renderer_connect_common (renderer, error)) goto error; return TRUE; error: _cogl_winsys_renderer_disconnect (renderer); return FALSE; }
struct wl_global_listener * _wl_display_add_global_listener(struct wl_display *display, void *data) { return wl_display_add_global_listener(display, (wl_display_global_func_t)_go_global_handler, data); }
static gboolean clutter_backend_wayland_post_parse (ClutterBackend *backend, GError **error) { ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend); EGLBoolean status; g_atexit (clutter_backend_at_exit); /* TODO: expose environment variable/commandline option for this... */ backend_wayland->wayland_display = wl_display_connect (NULL); if (!backend_wayland->wayland_display) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Failed to open Wayland display socket"); return FALSE; } backend_wayland->wayland_source = _clutter_event_source_wayland_new (backend_wayland->wayland_display); g_source_attach (backend_wayland->wayland_source, NULL); /* Set up listener so we'll catch all events. */ wl_display_add_global_listener (backend_wayland->wayland_display, display_handle_global, backend_wayland); /* Process connection events. */ wl_display_iterate (backend_wayland->wayland_display, WL_DISPLAY_READABLE); if (!try_get_display(backend_wayland, error)) return FALSE; status = eglInitialize (backend_wayland->edpy, &backend_wayland->egl_version_major, &backend_wayland->egl_version_minor); if (status != EGL_TRUE) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Unable to Initialize EGL"); return FALSE; } CLUTTER_NOTE (BACKEND, "EGL Reports version %i.%i", backend_wayland->egl_version_major, backend_wayland->egl_version_minor); backend_wayland->drm_enabled = try_enable_drm(backend_wayland, error); if (!backend_wayland->drm_enabled) { if (backend_wayland->wayland_shm == NULL) return FALSE; g_debug("Could not enable DRM buffers, falling back to SHM buffers"); g_clear_error(error); } return TRUE; }