---
name: "wl_display_connect"
section: "3"
platform: "linux"
package: "libwayland-doc"
version: "1.18.0-2~exp1.1"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/wl_display_connect"
---

# wl\_display\_connect(3)

Connect to a Wayland socket

## NAME

wl\_display\_connect, wl\_display\_connect\_to\_fd - Connect to a Wayland socket

## SYNOPSIS

```
#include <wayland-client.h>
```

**struct wl\_display \*wl\_display\_connect(const char \****name***);**

**struct wl\_display \*wl\_display\_connect\_to\_fd(int** *fd***);**

## DESCRIPTION

**wl\_display\_connect** connects to a Wayland socket that was previously opened by a Wayland server. The server socket must be placed in **XDG\_RUNTIME\_DIR** when **WAYLAND\_DISPLAY** (or *name*, see below) is a simple name, for this function to find it. The server socket is also allowed to exist at an arbitrary path; usage details follow. See below for compatibility issue details.

The *name* argument specifies the name of the socket or **NULL** to use the default (which is **"wayland-0"**). The environment variable **WAYLAND\_DISPLAY** replaces the default value. If *name* is an absolute path, then that path is used as the Wayland socket to which the connection is attempted. Note that in combination with the default-value behavior described above, this implies that setting **WAYLAND\_DISPLAY** to an absolute path will implicitly cause *name* to take on that absolute path if *name* is **NULL**. If **WAYLAND\_SOCKET** is set, this function behaves like **wl\_display\_connect\_to\_fd** with the file-descriptor number taken from the environment variable.

Support for interpreting **WAYLAND\_DISPLAY** as an absolute path is a change in behavior compared to **wl\_display\_connect**'s behavior in versions 1.14 and older of Wayland. It is no longer guaranteed in versions 1.15 and higher that the Wayland socket chosen is equivalent to manually constructing a socket pathname by concatenating **XDG\_RUNTIME\_DIR** and **WAYLAND\_DISPLAY**. Manual construction of the socket path must account for the possibility that **WAYLAND\_DISPLAY** contains an absolute path.

**wl\_display\_connect\_to\_fd** connects to a Wayland socket with an explicit file-descriptor. The file-descriptor is passed as argument *fd*.

## RETURN VALUE

**wl\_display\_connect** and **wl\_display\_connect\_to\_fd** return a new display context object or NULL on failure. *errno* is set correspondingly.

## SEE ALSO

**wayland-client**(7), **wl\_display\_disconnect**(3), **wl\_display\_iterate**(3)
