[Xcb] xcb_setup_roots_iterator

Alan Coopersmith alan.coopersmith at oracle.com
Sat Jul 18 08:42:48 PDT 2015

On 07/17/15 05:45 PM, Ben Hildred wrote:
> So I wanted to really understand how the xcb layer works, so I thought I would
> port a couple c language XCB examples to perl. I assure you this is a great way
> to learn especially as X11::XCB is a work in progress. Anyway I hit a line that
> I really don't understand, that I was hoping that someone could explain to me,
> or point me to the relevant doc.
> xcb_connection_t    *c;
> xcb_screen_t        *screen;
> c = xcb_connect (NULL, NULL);
> screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
> so we declare some variables, and connect. ok all good so far, and screen is a
> pointer to a useful struct that contains a lot of useful information, that I'm
> learning to use, but why are we doing a double function call? this does seem to
> be a common idiom as I have seen it from at least three different programmers.
> What are these two functions documented and why does noone keep the results from
> xcb_get_setup around so that you don't have to keep calling it especially when
> calling xcb_setup_toots_iterator which always seems to also call xcb_get_setup?
> At the moment this is not a critical problem as I am writing code that works, I
> just don't understand what is going on with that line.

xcb_get_setup() is just an accessor function that returns a pointer to data
stored in the opaque xcb_connection_t - you don't need to save the pointer
since the data is already saved and it's cheap to get the pointer again from
the xcb_connection_t - if you look at the function, it's literally just a
check for whether the connection is real or a fake error-handling placeholder,
and then returning a pointer from a member of the opaque struct.

xcb_setup_roots_iterator just sets up a small structure with pointers to the
list of roots in the xcb_setup_t and the mechanism to walk it without exposing
the structure details to callers.

	-Alan Coopersmith-              alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc

More information about the Xcb mailing list