Procedure to instruct FLTK to use given X11 connexion (#149)

This commit is contained in:
ManoloFLTK 2023-12-19 15:48:26 +01:00
parent 1e6ac9c9bb
commit 96bacd3f9d
4 changed files with 17 additions and 3 deletions

View File

@ -26,6 +26,11 @@
/** Returns the X11 Display in use */
extern Display *fl_x11_display();
/** Have FLTK use a pre-established X11 connexion.
This function should be called before FLTK attempts to open its own X11 connexion.
\param d the X11 Display* value representing a valid, pre-established X11 connexion
*/
extern void fl_x11_use_display(Display *d);
/** Returns the Window reference for the given Fl_Window, or zero if not \c shown(). */
extern Window fl_x11_xid(const Fl_Window *win);
/** Returns the Fl_Window corresponding to the given Window reference. */
@ -58,6 +63,7 @@ extern GLXContext fl_x11_glcontext(GLContext rc);
// constant info about the X server connection:
extern FL_EXPORT Display *fl_display;
extern FL_EXPORT Display *fl_x11_display();
extern FL_EXPORT void fl_x11_use_display(Display *);
extern FL_EXPORT Window fl_x11_xid(const Fl_Window *win);
extern FL_EXPORT Fl_Window *fl_x11_find(Window);
extern FL_EXPORT int fl_screen;

View File

@ -268,6 +268,10 @@ code will be called before the first \c show() of a window.
\par
This may call Fl::abort() if there is an error opening the display.
void fl_x11_use_display(Display *d)
\par
Directs FLTK to use a pre-established X11 connexion.
void fl_close_display()
\par

View File

@ -531,7 +531,8 @@ void Fl_X11_Screen_Driver::disable_im() {
}
void Fl_X11_Screen_Driver::open_display_platform() {
if (fl_display) return;
static GC gc = NULL;
if (gc) return;
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
@ -539,7 +540,7 @@ void Fl_X11_Screen_Driver::open_display_platform() {
XSetIOErrorHandler(io_error_handler);
XSetErrorHandler(xerror_handler);
Display *d = XOpenDisplay(0);
Display *d = (fl_display ? fl_display : XOpenDisplay(0));
if (!d) {
Fl::fatal("Can't open display: %s", XDisplayName(0)); // does not return
return; // silence static code analyzer
@ -547,7 +548,7 @@ void Fl_X11_Screen_Driver::open_display_platform() {
open_display_i(d);
// the unique GC used by all X windows
GC gc = XCreateGC(fl_display, RootWindow(fl_display, fl_screen), 0, 0);
gc = XCreateGC(fl_display, RootWindow(fl_display, fl_screen), 0, 0);
Fl_Graphics_Driver::default_driver().gc(gc);
fl_create_print_window();
}

View File

@ -80,6 +80,9 @@ void Fl_X11_Screen_Driver::display(const char *d)
if (d) setenv("DISPLAY", d, 1);
}
void fl_x11_use_display(Display *d) {
fl_display = d;
}
int Fl_X11_Screen_Driver::XParseGeometry(const char* string, int* x, int* y,
unsigned int* width, unsigned int* height) {