From c88e87bc8c6d4ee414533c28b600dff70f5ad62a Mon Sep 17 00:00:00 2001
From: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Date: Tue, 30 May 2017 21:33:33 +0200
Subject: hw/nxagnet/Atoms.c: In DEBUG mode, we need validateString() which is
 not statically defined in Utils.h. Thus including it for DEBUG builds.

---
 nx-X11/programs/Xserver/hw/nxagent/Atoms.c | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'nx-X11/programs/Xserver/hw')

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
index 0784d6c2c..9bcdee628 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
@@ -53,6 +53,11 @@
 #undef  TEST
 #undef  DEBUG
 
+#ifdef DEBUG
+/* for validateString() */
+#include "Utils.h"
+#endif
+
 /*
  * These values should be moved in
  * the option repository.
-- 
cgit v1.2.3


From 588be6386adf9dd25bb942af9456d6c07eda4676 Mon Sep 17 00:00:00 2001
From: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Date: Tue, 30 May 2017 21:28:03 +0200
Subject: hw/nxagent/Window.c: Introduce NX_REAL_WINDOW window property.

 In nxagent sessions, all X11 clients have a representation of their NX
 session-side window object on the real X-Server side.

 The window object gets stored in the new NX_REAL_WINDOW window property
 immediately after window creation. This mapping is created in
 nxagentCreateWindow().

 On session resumption, the client side window IDs normally change. Thus,
 during session resumption, all NX_REAL_WINDOW properties require being
 updated. This happens in nxagentReconnectWindow().

 While a session is suspended, the NX_REAL_WINDOW property does not
 exist. It gets removed during nxagentDisconnectWindow().
---
 nx-X11/programs/Xserver/hw/nxagent/Args.c        |  6 ++++
 nx-X11/programs/Xserver/hw/nxagent/Args.h        |  1 +
 nx-X11/programs/Xserver/hw/nxagent/Window.c      | 36 ++++++++++++++++++++++++
 nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 |  2 ++
 4 files changed, 45 insertions(+)

(limited to 'nx-X11/programs/Xserver/hw')

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c
index 5db7e0110..5d74f212c 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Args.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c
@@ -128,6 +128,7 @@ extern const char *__progname;
 
 char nxagentDisplayName[1024];
 Bool nxagentSynchronize = False;
+Bool nxagentRealWindowProp = False;
 
 char nxagentShadowDisplayName[1024] = {0};
 
@@ -404,6 +405,11 @@ int ddxProcessArgument(int argc, char *argv[], int i)
     return 1;
   }
 
+  if (!strcmp(argv[i], "-nxrealwindowprop")) {
+    nxagentRealWindowProp = True;
+    return 1;
+  }
+
   if (!strcmp(argv[i], "-full")) {
     nxagentFullGeneration = True;
     return 1;
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.h b/nx-X11/programs/Xserver/hw/nxagent/Args.h
index 5192783e5..09d045514 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Args.h
+++ b/nx-X11/programs/Xserver/hw/nxagent/Args.h
@@ -59,6 +59,7 @@ extern char nxagentWindowName[];
 extern char nxagentDialogName[];
 
 extern Bool nxagentSynchronize;
+extern Bool nxagentRealWindowProp;
 extern Bool nxagentFullGeneration;
 extern int nxagentDefaultClass;
 extern Bool nxagentUserDefaultClass;
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c
index 23e1d5452..8d2123095 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Window.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c
@@ -466,6 +466,18 @@ FIXME: Do all the windows for which nxagentWindowTopLevel(pWin)
     nxagentRedirectWindow(pWin);
   }
 
+  if ((nxagentRealWindowProp) && (!nxagentWindowTopLevel(pWin)))
+  {
+    Atom prop = MakeAtom("NX_REAL_WINDOW", strlen("NX_REAL_WINDOW"), True);
+
+    if (ChangeWindowProperty(pWin, prop, XA_WINDOW, 32, PropModeReplace, 1, nxagentWindowPriv(pWin), 1) != Success)
+        fprintf(stderr, "nxagentCreateWindow: Adding NX_REAL_WINDOW failed.\n");
+#ifdef DEBUG
+    else
+        fprintf(stderr, "nxagentCreateWindow: Added NX_REAL_WINDOW for Window ID [%x].\n", nxagentWindowPriv(pWin)->window);
+#endif
+  }
+
   nxagentWindowPriv(pWin)->x = pWin->origin.x - wBorderWidth(pWin);
   nxagentWindowPriv(pWin)->y = pWin->origin.y - wBorderWidth(pWin);
   nxagentWindowPriv(pWin)->width = pWin->drawable.width;
@@ -2674,6 +2686,18 @@ void nxagentDisconnectWindow(void * p0, XID x1, void * p2)
   }
   #endif
 
+  if ((nxagentRealWindowProp) && (!nxagentWindowTopLevel(pWin)))
+  {
+    Atom prop = MakeAtom("NX_REAL_WINDOW", strlen("NX_REAL_WINDOW"), True);
+
+    if (DeleteProperty(pWin, prop) != Success)
+        fprintf(stderr, "nxagentDisconnectWindow: Deleting NX_REAL_WINDOW failed.\n");
+#ifdef DEBUG
+    else
+        fprintf(stderr, "nxagentDisconnectWindow: Deleting NX_REAL_WINDOW from Window ID [%x].\n", nxagentWindowPriv(pWin)->window);
+#endif
+  }
+
   nxagentWindow(pWin) = None;
 
   if (nxagentDrawableStatus((DrawablePtr) pWin) == NotSynchronized)
@@ -3111,6 +3135,18 @@ FIXME: Do we need to set save unders attribute here?
     }
   }
 
+  if ((nxagentRealWindowProp) && (!nxagentWindowTopLevel(pWin)))
+  {
+    Atom prop = MakeAtom("NX_REAL_WINDOW", strlen("NX_REAL_WINDOW"), True);
+
+    if (ChangeWindowProperty(pWin, prop, XA_WINDOW, 32, PropModeReplace, 1, nxagentWindowPriv(pWin), 1) != Success)
+        fprintf(stderr, "nxagentReconnectWindow: Updating NX_REAL_WINDOW failed.\n");
+#ifdef DEBUG
+    else
+        fprintf(stderr, "nxagentReconnectWindow: Updated NX_REAL_WINDOW for Window ID [%x].\n", nxagentWindowPriv(pWin)->window);
+#endif
+  }
+
   if (nxagentDrawableStatus((DrawablePtr) pWin) == NotSynchronized)
   {
     nxagentAllocateCorruptedResource((DrawablePtr) pWin, RT_NX_CORR_WINDOW);
diff --git a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
index 1abec5753..89985a2f7 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
+++ b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1
@@ -368,6 +368,8 @@ The nx-X11 system adds the following command line arguments:
 .TP 8
 .B \-forcenx
 force use of NX protocol messages assuming communication through nxproxy
+.B \-nxrealwindowprop
+set property NX_REAL_WINDOW for each X11 client inside NX Agent, providing the window XID of the corresponding window object on the X server that NX Agent runs on
 .TP 8
 .B \-timeout \fIint\fP
 auto-disconnect timeout in seconds (minimum allowed: 60)
-- 
cgit v1.2.3