GdkDisplay * _gdk_wayland_display_open (const gchar *display_name) { struct wl_display *wl_display; GdkDisplay *display; GdkWaylandDisplay *display_wayland; GDK_NOTE (MISC, g_message ("opening display %s", display_name ? display_name : "")); /* 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); display_wayland->known_globals = g_hash_table_new_full (NULL, NULL, NULL, g_free); _gdk_wayland_display_init_cursors (display_wayland); _gdk_wayland_display_prepare_cursor_themes (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); _gdk_wayland_display_async_roundtrip (display_wayland); /* Wait for initializing to complete. This means waiting for all * asynchrounous roundtrips that were triggered during initial roundtrip. */ while (g_list_length (display_wayland->async_roundtrips) > 0) { if (wl_display_dispatch (display_wayland->wl_display) < 0) { g_object_unref (display); return NULL; } } gdk_input_init (display); display_wayland->selection = gdk_wayland_selection_new (); g_signal_emit_by_name (display, "opened"); return display; }
struct client * client_create(int x, int y, int width, int height) { struct client *client; struct surface *surface; wl_log_set_handler_client(log_handler); /* connect to display */ client = xzalloc(sizeof *client); client->wl_display = wl_display_connect(NULL); assert(client->wl_display); wl_list_init(&client->global_list); /* setup registry so we can bind to interfaces */ client->wl_registry = wl_display_get_registry(client->wl_display); wl_registry_add_listener(client->wl_registry, ®istry_listener, client); /* trigger global listener */ wl_display_dispatch(client->wl_display); wl_display_roundtrip(client->wl_display); /* must have WL_SHM_FORMAT_ARGB32 */ assert(client->has_argb); /* must have wl_test interface */ assert(client->test); /* must have an output */ assert(client->output); /* initialize the client surface */ surface = xzalloc(sizeof *surface); surface->wl_surface = wl_compositor_create_surface(client->wl_compositor); assert(surface->wl_surface); wl_surface_add_listener(surface->wl_surface, &surface_listener, surface); client->surface = surface; wl_surface_set_user_data(surface->wl_surface, surface); surface->width = width; surface->height = height; surface->wl_buffer = create_shm_buffer(client, width, height, &surface->data); memset(surface->data, 64, width * height * 4); move_client(client, x, y); return client; }
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; }
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; }