From 53d42aa351c72b184fcb1971fc48edaeea3af595 Mon Sep 17 00:00:00 2001
From: Werner Almesberger <werner@almesberger.net>
Date: Tue, 10 Jan 2017 07:40:59 -0300
Subject: [PATCH] experimental support for showing text window on alternate X
 display

Example:

DISPLAY_TEXTWND=:0.1 solvespace

Known issue: text window may close immediately after appearing.
In the test setup, toggling its visibility (with Tab) a number of
times would eventually make it stay.
---
 src/platform/gtkmain.cpp | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/platform/gtkmain.cpp b/src/platform/gtkmain.cpp
index 4337ce7..d906736 100644
--- a/src/platform/gtkmain.cpp
+++ b/src/platform/gtkmain.cpp
@@ -1207,7 +1207,7 @@ public:
         Glib::RefPtr<Gdk::Window> gdkwin = get_window();
         if(gdkwin) { // returns NULL if not realized
             Gdk::CursorType type = is_hand ? Gdk::HAND1 : Gdk::ARROW;
-            gdkwin->set_cursor(Gdk::Cursor::create(type));
+	    gdkwin->set_cursor(Gdk::Cursor::create(get_display(), type));
         }
     }
 
@@ -1251,8 +1251,31 @@ private:
 
 class TextWindowGtk : public Gtk::Window {
 public:
+    Glib::RefPtr<Gdk::Display> alt_display;
+
     TextWindowGtk() : _scrollbar(), _widget(_scrollbar.get_adjustment()),
                       _overlay(_widget), _box() {
+	const char *display_textwnd = getenv("DISPLAY_TEXTWND");
+
+	/*
+	 * If DISPLAY_TEXTWND is set, we interpret it as an X11 DISPLAY
+	 * variable to use for the text window. If opening that display fails,
+	 * we just proceed using the same display for TW and GW.
+	 *
+	 * Known issue: in the multi-display setup where this was tested, the
+	 * text window would only appear for an instant, then vanish.
+	 * Repeatedly toggling it with Tab would eventually make it stay, after
+	 * which it continued to function normally.
+	 */
+	if (display_textwnd) {
+		alt_display = Gdk::Display::open(display_textwnd);
+
+		if (alt_display)
+			set_screen(alt_display->get_default_screen());
+		else
+			fprintf(stderr, "cannot open %s\n", display_textwnd);
+	}
+
         set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
         set_skip_taskbar_hint(true);
         set_skip_pager_hint(true);
@@ -1498,7 +1521,8 @@ int main(int argc, char** argv) {
     GW.reset(new GraphicsWindowGtk);
     InitMainMenu(&GW->get_menubar());
     GW->get_menubar().accelerate(*TW);
-    TW->set_transient_for(*GW);
+    if (!TW->alt_display)
+	TW->set_transient_for(*GW);
     GW->set_icon(icon_gdk);
     TW->set_icon(icon_gdk);
 
-- 
2.9.3

