summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-12-19 15:48:26 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-12-19 15:48:26 +0100
commit96bacd3f9dff5b428a7826bbd507b1c02b2bcbba (patch)
tree5674931747b9a1db95466b6cdd8ce95b5079b890
parent1e6ac9c9bb11d126e5046fd71b9e569e5adb593b (diff)
Procedure to instruct FLTK to use given X11 connexion (#149)
-rw-r--r--FL/x11.H6
-rw-r--r--documentation/src/osissues.dox4
-rw-r--r--src/Fl_x.cxx7
-rw-r--r--src/drivers/X11/Fl_X11_Screen_Driver.cxx3
4 files changed, 17 insertions, 3 deletions
diff --git a/FL/x11.H b/FL/x11.H
index 73af4e7fc..2c98bc39f 100644
--- a/FL/x11.H
+++ b/FL/x11.H
@@ -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;
diff --git a/documentation/src/osissues.dox b/documentation/src/osissues.dox
index fa17aec7e..1c8718c62 100644
--- a/documentation/src/osissues.dox
+++ b/documentation/src/osissues.dox
@@ -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
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index 79d0a8fea..07f80cde7 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -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();
}
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
index 9e3465f13..7fc7e2b01 100644
--- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
@@ -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) {