XOpenDisplay(3)

okay so bestie, we're in the XLIB FUNCTIONS manual and this page is all about XOpenDisplay(3) β€” the one that opens your connection to the X server β€” plus its ride-or-die XCloseDisplay. let's get into it 🫢

✨ NAME ✨

XOpenDisplay, XCloseDisplay β€” connect or disconnect to X server

πŸ’… SYNTAX πŸ’…

Display *XOpenDisplay(_Xconst char *display_name);

int XCloseDisplay(Display *display);

πŸŽ€ ARGUMENTS πŸŽ€

  • display β€” this specifies the connection to the X server. that's the whole vibe of this argument, bestie.
  • display_name β€” the hardware display name, which determines the display and communications domain to be used. on a POSIX-conformant system, if display_name is NULL, it defaults to the value of the DISPLAY environment variable. periodt πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so XOpenDisplay returns a Display structure that serves as the connection to the X server and that contains all the information about that X server. it connects your application to the X server through TCP or DECnet communications protocols, or through some local inter-process communication protocol. iconic behavior honestly 🌈

here's the transport tea, because the punctuation is doing a lot of work:

  • if the hostname is a host machine name and a single colon (:) separates the hostname and display number, XOpenDisplay connects using TCP streams.
  • if the hostname is not specified, Xlib uses whatever it believes is the fastest transport.
  • if the hostname is a host machine name and a double colon (::) separates the hostname and display number, XOpenDisplay connects using DECnet.
  • a single X server can support any or all of these transport mechanisms simultaneously. and a particular Xlib implementation can support many more of these transport mechanisms. no cap πŸ”₯

if successful, XOpenDisplay returns a pointer to a Display structure, which is defined in X11/Xlib.h. if XOpenDisplay does not succeed, it returns NULL. after a successful call to XOpenDisplay, all of the screens in the display can be used by the client. the screen number specified in the display_name argument is returned by the DefaultScreen macro (or the XDefaultScreen function). you can access elements of the Display and Screen structures only by using the information macros or functions. for information about using macros and functions to obtain information from the Display structure, see section 2.2.1. iykyk πŸ“š

now for XCloseDisplay: it closes the connection to the X server for the display specified in the Display structure and destroys all windows, resource IDs (Window, Font, Pixmap, Colormap, Cursor, and GContext), or other resources that the client has created on this display, unless the close-down mode of the resource has been changed (see XSetCloseDownMode). therefore, these windows, resource IDs, and other resources should never be referenced again or an error will be generated. like, ever. do not come back for them, bestie 😭

before exiting, you should call XCloseDisplay explicitly so that any pending errors are reported as XCloseDisplay performs a final XSync operation. and heads up: XCloseDisplay can generate a BadGC error. πŸ’€

πŸ’– SEE ALSO πŸ’–


that's the whole page, bestie β€” from X Version 11, libX11 1.8.14. mwah! πŸ’‹πŸ‘‘

πŸ“¦ where this page comes from