コード例 #1
0
WaylandDisplay::WaylandDisplay()
{
    m_display = wl_display_connect(nullptr);
    m_registry = wl_display_get_registry(m_display);

    wl_registry_add_listener(m_registry, &g_registryListener, &m_interfaces);
    wl_display_roundtrip(m_display);

    m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource));
    auto* source = reinterpret_cast<EventSource*>(m_eventSource);
    source->display = m_display;

    source->pfd.fd = wl_display_get_fd(m_display);
    source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
    source->pfd.revents = 0;
    g_source_add_poll(m_eventSource, &source->pfd);

    g_source_set_name(m_eventSource, "[WPE] WaylandDisplay");
    g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30);
    g_source_set_can_recurse(m_eventSource, TRUE);
    g_source_attach(m_eventSource, g_main_context_get_thread_default());

    if (m_interfaces.xdg) {
        xdg_shell_add_listener(m_interfaces.xdg, &g_xdgShellListener, nullptr);
        xdg_shell_use_unstable_version(m_interfaces.xdg, 5);
    }
}
コード例 #2
0
TestBase::TestBase()
: wlDisplay(NULL)
, wlRegistry(NULL)
{
    wlDisplay = wl_display_connect(NULL);
    if (!wlDisplay)
    {
        throw std::runtime_error("could not connect to wayland display");
    }
    wlRegistry = wl_display_get_registry(wlDisplay);

    static const struct wl_registry_listener registry_listener = {
        registry_listener_callback,
        NULL
    };

    wl_registry_add_listener(wlRegistry, &registry_listener, &wlCompositor);

    if (wl_display_roundtrip(wlDisplay) == -1 || wl_display_roundtrip(wlDisplay) == -1)
    {
        throw std::runtime_error("wl_display error");
    }

    wlSurfaces.reserve(10);
    for (int i = 0; i < wlSurfaces.capacity(); ++i)
    {
        wlSurfaces.push_back(wl_compositor_create_surface(wlCompositor));
    }
}
コード例 #3
0
ファイル: Wayland_Util.cpp プロジェクト: Chiri23/dolphin
bool cWaylandInterface::Initialize(void *config)
{
	if (!GLWin.wl_display) {
		printf("Error: couldn't open wayland display\n");
		return false;
	}

	GLWin.pointer.wl_pointer = nullptr;
	GLWin.keyboard.wl_keyboard = nullptr;

	GLWin.keyboard.xkb.context = xkb_context_new((xkb_context_flags) 0);
	if (GLWin.keyboard.xkb.context == nullptr) {
		fprintf(stderr, "Failed to create XKB context\n");
		return nullptr;
	}

	GLWin.wl_registry = wl_display_get_registry(GLWin.wl_display);
	wl_registry_add_listener(GLWin.wl_registry,
				 &registry_listener, nullptr);

	while (!GLWin.wl_compositor)
		wl_display_dispatch(GLWin.wl_display);

	GLWin.wl_cursor_surface =
		wl_compositor_create_surface(GLWin.wl_compositor);

	return true;
}
コード例 #4
0
ファイル: simple-dmabuf.c プロジェクト: kwm81/weston
static struct display *
create_display(void)
{
	struct display *display;

	display = malloc(sizeof *display);
	if (display == NULL) {
		fprintf(stderr, "out of memory\n");
		exit(1);
	}
	display->display = wl_display_connect(NULL);
	assert(display->display);

	/* XXX: fake, because the compositor does not yet advertise anything */
	display->xrgb8888_format_found = 1;

	display->registry = wl_display_get_registry(display->display);
	wl_registry_add_listener(display->registry,
				 &registry_listener, display);
	wl_display_roundtrip(display->display);
	if (display->dmabuf == NULL) {
		fprintf(stderr, "No zwp_linux_dmabuf global\n");
		exit(1);
	}

	wl_display_roundtrip(display->display);

	if (!display->xrgb8888_format_found) {
		fprintf(stderr, "DRM_FORMAT_XRGB8888 not available\n");
		exit(1);
	}

	return display;
}
コード例 #5
0
	xdl_int initWayland() {

		//
		// Connect to the Wayland server.
		//
		display = wl_display_connect(nullptr);
		if(display == nullptr) {
			std::cerr << "## XdevLWindowWayland::wl_display_connect failed" << std::endl;
			return xdl::ERR_ERROR;
		}

		// We get the registry for the window which holds extension
		// of the wayland server.
		m_registry = wl_display_get_registry(display);
		if(m_registry == nullptr) {
			std::cerr << "## XdevLWindowWayland::wl_display_get_registry failed" << std::endl;
			return ERR_ERROR;
		}

		// Now we tell the registry that we want to listen to events.
		wl_registry_add_listener(m_registry, &registry_listener, nullptr);
		wl_display_dispatch(display);

		return ERR_OK;
	}
コード例 #6
0
ファイル: fg_init_wl.c プロジェクト: Enseed/FreeGLUT
void fgPlatformInitialize( const char* displayName )
{
    fgDisplay.pDisplay.display = wl_display_connect( NULL );

    if( fgDisplay.pDisplay.display == NULL )
        fgError( "failed to connect to a Wayland compositor" );

    fgDisplay.pDisplay.registry = wl_display_get_registry(
                                    fgDisplay.pDisplay.display );
    wl_registry_add_listener( fgDisplay.pDisplay.registry,
                              &fghRegistryListener,
                              &fgDisplay.pDisplay );
    wl_display_roundtrip( fgDisplay.pDisplay.display );

    if( fgDisplay.pDisplay.compositor == NULL ||
        fgDisplay.pDisplay.shell == NULL ||
        fgDisplay.pDisplay.seat == NULL ||
        fgDisplay.pDisplay.shm == NULL )
          fgError( "failed to discover all needed compositor interfaces" );

    fghInitialiseCursorTheme();

    fghPlatformInitializeEGL();

    /* Get start time */
    fgState.Time = fgSystemTime();

    fgState.Initialised = GL_TRUE;

    atexit(fgDeinitialize);

    /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */
    fgPlatformInitialiseInputDevices();
}
コード例 #7
0
ファイル: WaylandQueue.cpp プロジェクト: kwtskran/XCSoar
WaylandEventQueue::WaylandEventQueue(IOLoop &_io_loop, EventQueue &_queue)
  :io_loop(_io_loop), queue(_queue),
   display(wl_display_connect(nullptr))
{
  if (display == nullptr) {
    fprintf(stderr, "wl_display_connect() failed\n");
    exit(EXIT_FAILURE);
  }

  auto registry = wl_display_get_registry(display);
  wl_registry_add_listener(registry, &registry_listener, this);

  wl_display_dispatch(display);
  wl_display_roundtrip(display);

  if (compositor == nullptr) {
    fprintf(stderr, "No Wayland compositor found\n");
    exit(EXIT_FAILURE);
  }

  if (seat == nullptr) {
    fprintf(stderr, "No Wayland seat found\n");
    exit(EXIT_FAILURE);
  }

  if (shell == nullptr) {
    fprintf(stderr, "No Wayland shell found\n");
    exit(EXIT_FAILURE);
  }

  io_loop.Add(FileDescriptor(wl_display_get_fd(display)), io_loop.READ, *this);
}
コード例 #8
0
ファイル: wlfreerdp.c プロジェクト: hyacinthes/FreeRDP
BOOL wl_pre_connect(freerdp* instance)
{
	struct display* display;
	struct wl_context* context;

	freerdp_channels_pre_connect(instance->context->channels, instance);

	display = malloc(sizeof(*display));
	display->display = wl_display_connect(NULL);

	if (!display->display)
	{
		fprintf(stderr, "wl_pre_connect: failed to connect to Wayland compositor\n");
		fprintf(stderr, "Please check that the XDG_RUNTIME_DIR environment variable is properly set.\n");
		free(display);
		return FALSE;
	}

	display->registry = wl_display_get_registry(display->display);
	wl_registry_add_listener(display->registry, &wl_registry_listener, display);
	wl_display_roundtrip(display->display);

	if (!display->compositor || !display->shell || !display->shm)
	{
		fprintf(stderr, "wl_pre_connect: failed to find needed compositor interfaces\n");
		free(display);
		return FALSE;
	}

	 /* put Wayland data in the context here */
	context = (struct wl_context*) instance->context;
	context->display = display;

	return TRUE;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: kendling/orbital
int main(int argc, char **argv)
{
    Helper helper;

    helper.display = wl_display_connect(nullptr);

    helper.registry = wl_display_get_registry(helper.display);
    static const wl_registry_listener registryListener = {
        wrapInterface(&Helper::global),
        wrapInterface(&Helper::globalRemove)
    };
    wl_registry_add_listener(helper.registry, &registryListener, &helper);

    wl_display_roundtrip(helper.display);
    if (!helper.helper) {
        qWarning("No orbital_authorizer_helper interface.");
        exit(1);
    }

    int ret = 0;
    while (ret != -1)
        ret = wl_display_dispatch(helper.display);

    return 0;
}
コード例 #10
0
WaylandDisplay::WaylandDisplay()
{
    m_display = wl_display_connect(nullptr);
    m_registry = wl_display_get_registry(m_display);

    wl_registry_add_listener(m_registry, &g_registryListener, &m_interfaces);
    wl_display_roundtrip(m_display);

    m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource));
    auto* source = reinterpret_cast<EventSource*>(m_eventSource);
    source->display = m_display;

    source->pfd.fd = wl_display_get_fd(m_display);
    source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
    source->pfd.revents = 0;
    g_source_add_poll(m_eventSource, &source->pfd);

    g_source_set_name(m_eventSource, "[WPE] WaylandDisplay");
    g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30);
    g_source_set_can_recurse(m_eventSource, TRUE);
    g_source_attach(m_eventSource, g_main_context_get_thread_default());

    if (m_interfaces.xdg) {
        xdg_shell_add_listener(m_interfaces.xdg, &g_xdgShellListener, nullptr);
        xdg_shell_use_unstable_version(m_interfaces.xdg, 5);
    }

    wl_seat_add_listener(m_interfaces.seat, &g_seatListener, &m_seatData);

    m_seatData.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
    m_seatData.xkb.composeTable = xkb_compose_table_new_from_locale(m_seatData.xkb.context, setlocale(LC_CTYPE, nullptr), XKB_COMPOSE_COMPILE_NO_FLAGS);
    if (m_seatData.xkb.composeTable)
        m_seatData.xkb.composeState = xkb_compose_state_new(m_seatData.xkb.composeTable, XKB_COMPOSE_STATE_NO_FLAGS);
}
コード例 #11
0
ファイル: chromakey.c プロジェクト: Airtau/genivi
static int createWLContext()
{
    t_ilm_bool result = ILM_TRUE;

    g_wlContextStruct.wlDisplay = wl_display_connect(NULL);
    if (NULL == g_wlContextStruct.wlDisplay)
    {
        printf("Error: wl_display_connect() failed.\n");
    }

    g_wlContextStruct.wlRegistry = wl_display_get_registry(g_wlContextStruct.wlDisplay);
    wl_registry_add_listener(g_wlContextStruct.wlRegistry, &registry_listener, &g_wlContextStruct);
    wl_display_dispatch(g_wlContextStruct.wlDisplay);
    wl_display_roundtrip(g_wlContextStruct.wlDisplay);

    g_wlContextStruct.wlSurface = wl_compositor_create_surface(g_wlContextStruct.wlCompositor);
    if (NULL == g_wlContextStruct.wlSurface)
    {
        printf("Error: wl_compositor_create_surface failed.\n");
        destroyWLContext();
    }

    createShmBuffer();

    return result;
}
コード例 #12
0
void DrmEglServerBufferIntegration::initialize(QWaylandDisplay *display)
{
    m_egl_display = eglGetDisplay((EGLNativeDisplayType) display->wl_display());
    if (EGL_NO_DISPLAY) {
        qWarning("Failed to initialize drm egl server buffer integration. Could not get egl display from wl_display.");
        return;
    }

    const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS);
    if (!extensionString || !strstr(extensionString, "EGL_KHR_image")) {
        qWarning("Failed to initialize drm egl server buffer integration. There is no EGL_KHR_image extension.\n");
        return;
    }
    m_egl_create_image = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
    m_egl_destroy_image = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
    if (!m_egl_create_image || !m_egl_destroy_image) {
        qWarning("Failed to initialize drm egl server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR");
        return;
    }

    m_gl_egl_image_target_texture = reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(eglGetProcAddress("glEGLImageTargetTexture2DOES"));
    if (!m_gl_egl_image_target_texture) {
        qWarning("Failed to initialize drm egl server buffer integration. Could not resolve glEGLImageTargetTexture2DOES");
        return;
    }

    QtWayland::wl_registry::init(wl_display_get_registry(display->wl_display()));
}
コード例 #13
0
ファイル: client.cpp プロジェクト: 01org/wayland-fits
Client::Client(wl_display* dpy)
	: wfits_input_(NULL)
	, wfits_query_(NULL)
	, wfits_manip_(NULL)
	, yieldFactor_(1.f)
{
	ASSERT(NULL != dpy);

	wl_registry *reg = wl_display_get_registry(dpy);

	static const struct wl_registry_listener listener = {bind_wfits};

	wl_registry_add_listener(reg, &listener, this);

	wl_display_roundtrip(dpy);

	ASSERT(NULL != wfits_input_);
	ASSERT(NULL != wfits_query_);
	ASSERT(NULL != wfits_manip_);

	const char* emu(getenv("WFITS_YIELD_FACTOR"));
	if (emu != NULL)
	{
		yieldFactor_ = boost::lexical_cast<float>(emu);
	}
}
コード例 #14
0
ファイル: wayland_window.cpp プロジェクト: kgunn/libhybris
WaylandNativeWindow::WaylandNativeWindow(struct wl_egl_window *window, struct wl_display *display, const gralloc_module_t* gralloc, alloc_device_t* alloc_device)
{
	int i;

	this->m_window = window;
	this->m_display = display;
	this->m_width = window->width;
	this->m_height = window->height;
	this->m_defaultWidth = window->width;
	this->m_defaultHeight = window->height;
	this->m_format = 1;
        this->wl_queue = wl_display_create_queue(display);
	this->frame_callback = NULL;
	this->registry = wl_display_get_registry(display);
   	wl_proxy_set_queue((struct wl_proxy *) this->registry,
                      this->wl_queue);
        wl_registry_add_listener(this->registry, &registry_listener, this);

	assert(wayland_roundtrip(this) >= 0);
        assert(this->m_android_wlegl != NULL);
        
        this->m_gralloc = gralloc;
        this->m_alloc = alloc_device;
        
	m_usage=GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
	pthread_mutex_init(&mutex, NULL);

        TRACE("WaylandNativeWindow created in %p", pthread_self());
}
コード例 #15
0
PlatformDisplayWayland::PlatformDisplayWayland(struct wl_display* wlDisplay)
    : m_display(wlDisplay)
    , m_registry(wl_display_get_registry(m_display))
    , m_eglConfigChosen(false)
{
    wl_registry_add_listener(m_registry, &m_registryListener, this);
    wl_display_roundtrip(m_display);

    static const EGLint configAttributes[] = {
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_RED_SIZE, 1,
        EGL_GREEN_SIZE, 1,
        EGL_BLUE_SIZE, 1,
        EGL_ALPHA_SIZE, 1,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
        EGL_NONE
    };

    m_eglDisplay = eglGetDisplay(m_display);
    PlatformDisplay::initializeEGLDisplay();
    if (m_eglDisplay == EGL_NO_DISPLAY)
        return;

    EGLint numberOfConfigs;
    if (!eglChooseConfig(m_eglDisplay, configAttributes, &m_eglConfig, 1, &numberOfConfigs) || numberOfConfigs != 1) {
        g_warning("PlatformDisplayWayland initialization: failed to find the desired EGL configuration.");
        return;
    }

    m_eglConfigChosen = true;
}
コード例 #16
0
ファイル: wlf_display.c プロジェクト: BUGgs/FreeRDP
wlfDisplay* wlf_CreateDisplay(void)
{
	wlfDisplay* display;

	display = (wlfDisplay*) calloc(1, sizeof(wlfDisplay));

	if (display)
	{
		display->display = wl_display_connect(NULL);

		if (!display->display)
		{
			WLog_ERR(TAG, "wl_pre_connect: failed to connect to Wayland compositor");
			WLog_ERR(TAG, "Please check that the XDG_RUNTIME_DIR environment variable is properly set.");
			free(display);
			return NULL;
		}

		display->registry = wl_display_get_registry(display->display);
		wl_registry_add_listener(display->registry, &wl_registry_listener, display);
		wl_display_roundtrip(display->display);

		if (!display->compositor || !display->shell || !display->shm)
		{
			WLog_ERR(TAG, "wl_pre_connect: failed to find needed compositor interfaces");
			free(display);
			return NULL;
		}
	}

	return display;
}
コード例 #17
0
static struct cursor_viewer *
cursor_viewer_create(void)
{
    struct cursor_viewer *viewer = calloc(1, sizeof (struct cursor_viewer));
    if (!viewer)
        die("Cannot allocate memory for cursor_viewer\n");

    viewer->display = wl_display_connect(NULL);
    if (!viewer->display) {
        cursor_viewer_destroy(viewer);
        die("Cannot connect to Wayland display\n");
    }

    viewer->registry = wl_display_get_registry(viewer->display);
    if (!viewer->registry) {
        cursor_viewer_destroy(viewer);
        die("Cannot get registry from Wayland display\n");
    }
    wl_registry_add_listener(viewer->registry, &registry_listener, viewer);

    wl_display_roundtrip(viewer->display);
    wl_display_roundtrip(viewer->display);

    return viewer;
}
コード例 #18
0
ファイル: simple-damage.c プロジェクト: ChristophHaag/weston
static struct display *
create_display(int version)
{
	struct display *display;

	display = malloc(sizeof *display);
	if (display == NULL) {
		fprintf(stderr, "out of memory\n");
		exit(1);
	}
	display->display = wl_display_connect(NULL);
	assert(display->display);

	display->compositor_version = version;
	display->formats = 0;
	display->registry = wl_display_get_registry(display->display);
	wl_registry_add_listener(display->registry,
				 &registry_listener, display);
	wl_display_roundtrip(display->display);
	if (display->shm == NULL) {
		fprintf(stderr, "No wl_shm global\n");
		exit(1);
	}

	wl_display_roundtrip(display->display);

	if (!(display->formats & (1 << WL_SHM_FORMAT_XRGB8888))) {
		fprintf(stderr, "WL_SHM_FORMAT_XRGB32 not available\n");
		exit(1);
	}

	return display;
}
コード例 #19
0
static struct display *
create_display (void)
{
  struct display *display;

  display = malloc (sizeof *display);
  display->display = wl_display_connect (NULL);

  if (display->display == NULL) {
    free (display);
    return NULL;
  }

  display->registry = wl_display_get_registry (display->display);
  wl_registry_add_listener (display->registry, &registry_listener, display);

  wl_display_roundtrip (display->display);
  if (display->shm == NULL) {
    GST_ERROR ("No wl_shm global..");
    return NULL;
  }

  wl_display_roundtrip (display->display);

  if (!(display->formats & (1 << WL_SHM_FORMAT_XRGB8888))) {
    GST_ERROR ("WL_SHM_FORMAT_XRGB32 not available");
    return NULL;
  }

  wl_display_get_fd (display->display);

  return display;
}
コード例 #20
0
WaylandNativeWindow::WaylandNativeWindow(struct wl_egl_window *window, struct wl_display *display, const gralloc_module_t* gralloc, alloc_device_t* alloc_device)
{
    int wayland_ok;

    HYBRIS_TRACE_BEGIN("wayland-platform", "create_window", "");
    this->m_window = window;
    this->m_window->nativewindow = (void *) this;
    this->m_display = display;
    this->m_width = window->width;
    this->m_height = window->height;
    this->m_defaultWidth = window->width;
    this->m_defaultHeight = window->height;
    this->m_window->resize_callback = resize_callback;
    this->m_format = 1;
    this->wl_queue = wl_display_create_queue(display);
    this->frame_callback = NULL;
    this->registry = wl_display_get_registry(display);
    wl_proxy_set_queue((struct wl_proxy *) this->registry,
            this->wl_queue);
    wl_registry_add_listener(this->registry, &registry_listener, this);

    wayland_ok = wayland_roundtrip(this);
    assert(wayland_ok >= 0);
    assert(this->m_android_wlegl != NULL);

    this->m_gralloc = gralloc;
    this->m_alloc = alloc_device;

    m_usage=GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
    pthread_mutex_init(&mutex, NULL);
    pthread_cond_init(&cond, NULL);
    m_freeBufs = 0;
    setBufferCount(3);
    HYBRIS_TRACE_END("wayland-platform", "create_window", "");
}
コード例 #21
0
bool WaylandEGLContext::attach (GtkWidget *widget)
{
    GdkWindow *window = gtk_widget_get_window (widget);

    if (!GDK_IS_WAYLAND_WINDOW (window))
        return false;

    gdk_window = window;
    gdk_window_get_geometry (gdk_window, &x, &y, &width, &height);

    display  = gdk_wayland_display_get_wl_display (gdk_window_get_display (gdk_window));
    parent   = gdk_wayland_window_get_wl_surface (gdk_window);
    registry = wl_display_get_registry (display);

    wl_registry_add_listener (registry, &wl_registry_listener, this);
    wl_display_roundtrip (display);

    if (!compositor || !subcompositor)
        return false;

    child = wl_compositor_create_surface (compositor);
    region = wl_compositor_create_region (compositor);
    subsurface = wl_subcompositor_get_subsurface (subcompositor, child, parent);

    wl_surface_set_input_region (child, region);
    wl_subsurface_set_desync (subsurface);
    wl_subsurface_set_position (subsurface, x, y);

    return true;
}
コード例 #22
0
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, &registry_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;
}
コード例 #23
0
ファイル: wl_init.c プロジェクト: Piotrek1910/Painter
int _glfwPlatformInit(void)
{
    _glfw.wl.display = wl_display_connect(NULL);
    if (!_glfw.wl.display)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Failed to connect to display");
        return GLFW_FALSE;
    }

    _glfw.wl.registry = wl_display_get_registry(_glfw.wl.display);
    wl_registry_add_listener(_glfw.wl.registry, &registryListener, NULL);

    _glfw.wl.monitors = calloc(4, sizeof(_GLFWmonitor*));
    _glfw.wl.monitorsSize = 4;

    _glfw.wl.xkb.context = xkb_context_new(0);
    if (!_glfw.wl.xkb.context)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Failed to initialize xkb context");
        return GLFW_FALSE;
    }

    // Sync so we got all registry objects
    wl_display_roundtrip(_glfw.wl.display);

    // Sync so we got all initial output events
    wl_display_roundtrip(_glfw.wl.display);

    if (!_glfwInitContextAPI())
        return GLFW_FALSE;

    _glfwInitTimer();
    _glfwInitJoysticks();

    if (_glfw.wl.pointer && _glfw.wl.shm)
    {
        _glfw.wl.cursorTheme = wl_cursor_theme_load(NULL, 32, _glfw.wl.shm);
        if (!_glfw.wl.cursorTheme)
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "Wayland: Unable to load default cursor theme\n");
            return GLFW_FALSE;
        }
        _glfw.wl.defaultCursor =
            wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, "left_ptr");
        if (!_glfw.wl.defaultCursor)
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "Wayland: Unable to load default left pointer\n");
            return GLFW_FALSE;
        }
        _glfw.wl.cursorSurface =
            wl_compositor_create_surface(_glfw.wl.compositor);
    }

    return GLFW_TRUE;
}
コード例 #24
0
ファイル: wldisplay.c プロジェクト: Lachann/gst-plugins-bad
GstWlDisplay *
gst_wl_display_new_existing (struct wl_display * display,
    gboolean take_ownership, GError ** error)
{
  GstWlDisplay *self;
  GError *err = NULL;
  gint i;

  g_return_val_if_fail (display != NULL, NULL);

  self = g_object_new (GST_TYPE_WL_DISPLAY, NULL);
  self->display = display;
  self->own_display = take_ownership;

  self->queue = wl_display_create_queue (self->display);
  self->registry = wl_display_get_registry (self->display);
  wl_proxy_set_queue ((struct wl_proxy *) self->registry, self->queue);
  wl_registry_add_listener (self->registry, &registry_listener, self);

  /* we need exactly 2 roundtrips to discover global objects and their state */
  for (i = 0; i < 2; i++) {
    if (gst_wl_display_roundtrip (self) < 0) {
      *error = g_error_new (g_quark_from_static_string ("GstWlDisplay"), 0,
          "Error communicating with the wayland display");
      g_object_unref (self);
      return NULL;
    }
  }

  /* verify we got all the required interfaces */
#define VERIFY_INTERFACE_EXISTS(var, interface) \
  if (!self->var) { \
    g_set_error (error, g_quark_from_static_string ("GstWlDisplay"), 0, \
        "Could not bind to " interface ". Either it is not implemented in " \
        "the compositor, or the implemented version doesn't match"); \
    g_object_unref (self); \
    return NULL; \
  }

  VERIFY_INTERFACE_EXISTS (compositor, "wl_compositor");
  VERIFY_INTERFACE_EXISTS (subcompositor, "wl_subcompositor");
  VERIFY_INTERFACE_EXISTS (shell, "wl_shell");
  VERIFY_INTERFACE_EXISTS (shm, "wl_shm");
  VERIFY_INTERFACE_EXISTS (scaler, "wl_scaler");

#undef VERIFY_INTERFACE_EXISTS

  self->thread = g_thread_try_new ("GstWlDisplay", gst_wl_display_thread_run,
      self, &err);
  if (err) {
    g_propagate_prefixed_error (error, err,
        "Failed to start thread for the display's events");
    g_object_unref (self);
    return NULL;
  }

  return self;
}
コード例 #25
0
bool
va_wayland_drm_create(VADisplayContextP pDisplayContext)
{
    VADriverContextP const ctx = pDisplayContext->pDriverContext;
    struct va_wayland_drm_context *wl_drm_ctx;
    struct drm_state *drm_state;

    wl_drm_ctx = malloc(sizeof(*wl_drm_ctx));
    if (!wl_drm_ctx)
        return false;
    wl_drm_ctx->base.destroy            = va_wayland_drm_destroy;
    wl_drm_ctx->handle                  = NULL;
    wl_drm_ctx->drm                     = NULL;
    wl_drm_ctx->drm_interface           = NULL;
    wl_drm_ctx->is_authenticated        = 0;
    pDisplayContext->opaque             = wl_drm_ctx;
    pDisplayContext->vaGetDriverName    = va_DisplayContextGetDriverName;

    drm_state = calloc(1, sizeof(struct drm_state));
    if (!drm_state)
        return false;
    drm_state->fd        = -1;
    drm_state->auth_type = 0;
    ctx->drm_state       = drm_state;

    wl_drm_ctx->handle = dlopen(LIBWAYLAND_DRM_NAME, RTLD_LAZY|RTLD_LOCAL);
    if (!wl_drm_ctx->handle)
        return false;

    wl_drm_ctx->drm_interface =
        dlsym(wl_drm_ctx->handle, "wl_drm_interface");
    if (!wl_drm_ctx->drm_interface)
        return false;

    wl_drm_ctx->registry = wl_display_get_registry(ctx->native_dpy);
    wl_registry_add_listener(wl_drm_ctx->registry, &registry_listener, wl_drm_ctx);
    wl_display_roundtrip(ctx->native_dpy);

    /* registry_handle_global should have been called by the
     * wl_display_roundtrip above
     */

    if (!wl_drm_ctx->drm)
        return false;

    wl_drm_add_listener(wl_drm_ctx->drm, &drm_listener, pDisplayContext);
    wl_display_roundtrip(ctx->native_dpy);
    if (drm_state->fd < 0)
        return false;

    wl_display_roundtrip(ctx->native_dpy);
    if (!wl_drm_ctx->is_authenticated)
        return false;
    return true;
}
コード例 #26
0
ファイル: test1.cpp プロジェクト: darkenk/wayland-test
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");

    struct wl_registry *registry = wl_display_get_registry(display);
    wl_registry_add_listener(registry, &registry_listener, NULL);

    wl_display_dispatch(display);
    wl_display_roundtrip(display);

    if (compositor == NULL) {
        fprintf(stderr, "Can't find compositor\n");
        exit(1);
    } else {
        fprintf(stderr, "Found compositor\n");
    }

    surface = wl_compositor_create_surface(compositor);
    if (surface == NULL) {
        fprintf(stderr, "Can't create surface\n");
        exit(1);
    } else {
        fprintf(stderr, "Created surface\n");
    }

    shell_surface = wl_shell_get_shell_surface(shell, surface);
    if (shell_surface == NULL) {
        fprintf(stderr, "Can't create shell surface\n");
        exit(1);
    } else {
        fprintf(stderr, "Created shell surface\n");
    }
    wl_shell_surface_set_toplevel(shell_surface);

    wl_shell_surface_add_listener(shell_surface,
                                  &shell_surface_listener, NULL);


    create_window();
    paint_pixels();

    while (wl_display_dispatch(display) != -1) {
        ;
    }

    wl_display_disconnect(display);
    printf("disconnected from display\n");

    exit(0);
}
コード例 #27
0
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, &registry_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;
}
コード例 #28
0
static gboolean
clutter_backend_wayland_post_parse (ClutterBackend  *backend,
                                    GError         **error)
{
  ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend);

  /* 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_registry =
    wl_display_get_registry (backend_wayland->wayland_display);

  backend_wayland->wayland_source =
    _clutter_event_source_wayland_new (backend_wayland->wayland_display);
  g_source_attach (backend_wayland->wayland_source, NULL);

  g_object_set (clutter_settings_get_default (), "font-dpi", 96 * 1024, NULL);

  /* XXX: We require the device manager to exist as soon as we connect to the
   * compositor and setup an event handler because we will immediately be
   * notified of the available input devices which need to be associated with
   * the device-manager.
   *
   * FIXME: At some point we could perhaps just collapse the
   * _clutter_backend_post_parse(), and _clutter_backend_init_events()
   * functions into one called something like _clutter_backend_init() which
   * would allow the real backend to manage the precise order of
   * initialization.
   */
  backend_wayland->device_manager =
    _clutter_device_manager_wayland_new (backend);

  /* Set up listener so we'll catch all events. */
  wl_registry_add_listener (backend_wayland->wayland_registry,
                            &wayland_registry_listener,
                            backend_wayland);

  /* Wait until we have been notified about the compositor and shell objects */
  while (!(backend_wayland->wayland_compositor &&
           backend_wayland->wayland_shell))
    wl_display_roundtrip (backend_wayland->wayland_display);

  /* We need the shm object before we can create the cursor */
  clutter_backend_wayland_load_cursor (backend_wayland);

  return TRUE;
}
コード例 #29
0
ファイル: imwaylandgtk.c プロジェクト: endlessm/gtk
static void
gtk_im_context_wayland_global_init (GdkDisplay *display)
{
  g_return_if_fail (global == NULL);

  global = g_new0 (GtkIMContextWaylandGlobal, 1);
  global->display = gdk_wayland_display_get_wl_display (display);
  global->registry = wl_display_get_registry (global->display);

  wl_registry_add_listener (global->registry, &registry_listener, global);
}
コード例 #30
0
ファイル: maynard.c プロジェクト: Artox/maynard
int
main (int argc,
    char *argv[])
{
  struct desktop *desktop;

  gdk_set_allowed_backends ("wayland");

  gtk_init (&argc, &argv);

  g_resources_register (maynard_get_resource ());

  desktop = malloc (sizeof *desktop);
  desktop->output = NULL;
  desktop->shell = NULL;
  desktop->helper = NULL;

  desktop->gdk_display = gdk_display_get_default ();
  desktop->display =
    gdk_wayland_display_get_wl_display (desktop->gdk_display);
  if (desktop->display == NULL)
    {
      fprintf (stderr, "failed to get display: %m\n");
      return -1;
    }

  desktop->registry = wl_display_get_registry (desktop->display);
  wl_registry_add_listener (desktop->registry,
      &registry_listener, desktop);

  /* Wait until we have been notified about the compositor,
   * shell, and shell helper objects */
  while (!desktop->output || !desktop->shell || !desktop->helper)
    wl_display_roundtrip (desktop->display);

  desktop->grid_visible = FALSE;
  desktop->system_visible = FALSE;
  desktop->volume_visible = FALSE;

  css_setup (desktop);
  background_create (desktop);

  /* panel needs to be first so the clock and launcher grid can
   * be added to its layer */
  panel_create (desktop);
  clock_create (desktop);
  launcher_grid_create (desktop);

  gtk_main ();

  /* TODO cleanup */
  return EXIT_SUCCESS;
}