Replacing gdk_display_open(char*)



gdk_display_open() is really only even meaningful on libX11 - it's
basically a paper-thin wrapper around XOpenDisplay(). The idea of a
display name string doesn't seem to have much meaning on other
platforms*: neither the win32 or quartz backends have any use for a
'char *display_name' parameter, and just require it to be NULL; even
the stub xcb backend branch just has a comment that it has no idea
what to do with it, either.

Since even if the other platforms had a use for it, the format of a
"display name" string would be platform-specific, gdk_display_open()
seems like a bad abstraction - the only cross-platform way to use it
is to just pass NULL. I'd propose that for GTK3, it be removed and
replaced by either calls to gdk_display_get_default(), or, if an app
does need to open a specific display, calls to new backend-specific
function like these:

gdk_x11_display_open (Display *xdisplay);
gdk_xcb_display_open (xcb_connection_t *xconn);

There's no apparent need for or even an obvious way to do
platform-specific variants for other backends yet: The current win32
and quartz implementations both just initialize a singleton global
GdkDisplay that's declared in gdkglobals-win32.c and
gdkglobals-quartz.c, respectively, with a bunch of esoteric init()
calls, and then reuse that on subsequent calls.

Any usage of gdk_display_open(NULL) can probably be replaced with
gdk_display_get_default() (assuming the gdk_init(), etc functions
already set the default)**. An app that calls gdk_display_open() with
an actual string is already going to fail on anything but libX11, so
there's no loss in cross-platform-ness in changing an app to include
the X11 headers and call XOpenDisplay() itself first.

There aren't many uses of gdk_display_open() in the tree - the first
two, at least, are pretty much X11-specific already:
demos/gtk-demo/changedisplay.c
tests/testmultidisplay.c
tests/testerrors.c (just calls it with NULL)
tests/testgtk.c (should #ifdef X server display-name stuff out)
gdk/gdk.c

I don't know how many or which apps depend on this function right now,
though - thoughts?


* BTW, are there any plans to add multihead on other platforms? The
docs haven't changed since 2002.
<http://git.gnome.org/browse/gtk+/tree/docs/reference/gdk/multihead.sgml>

** At first, gdk_display_open_default_libgtk_only() looked like a good
replacement, but it's blatantly marked as "don't let applications use
this", so I'm assuming it's a bad idea for some reason. Will it still
be exported in GTK3?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]