[X2Go-Commits] [nx-libs] 341/429: Atoms.c: add helper to easily print Atom names in debugging

git-admin at x2go.org git-admin at x2go.org
Mon Oct 18 09:37:02 CEST 2021


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch 3.6.x
in repository nx-libs.

commit 27ecb8959669207aaab2c8d5fae12e51b4708f57
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Tue Oct 13 00:22:22 2020 +0200

    Atoms.c: add helper to easily print Atom names in debugging
---
 nx-X11/programs/Xserver/hw/nxagent/Atoms.c | 48 ++++++++++++++++++++++++++++++
 nx-X11/programs/Xserver/hw/nxagent/Atoms.h | 16 ++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
index 2ddf87e55..d9ee678fa 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
@@ -750,6 +750,54 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
   }
 }
 
+/*
+ * This is mainly used to simplify debug prints. It returns
+ * the string for a remote atom or NULL if atom is unknown/invalid
+ *
+ * The string must NOT be freed by the caller.
+ */
+const char *nxagentRemoteAtomToString(XlibAtom remote)
+{
+  if (remote == None || remote == BAD_RESOURCE)
+  {
+    #ifdef DEBUG
+    fprintf(stderr, "%s: remote [%d] is None or BAD_RESOURCE\n", __func__, remote);
+    #endif
+    return NULL;
+  }
+
+  /* no mapping required for built-in atoms */
+  if (remote <= XA_LAST_PREDEFINED)
+  {
+    #ifdef DEBUG
+    fprintf(stderr, "%s: remote [%d] is <= XA_LAST_PREDEFINED [%d]\n", __func__, remote, XA_LAST_PREDEFINED);
+    #endif
+
+    /* simply use the builtin string that is the same on every X server */
+    return NameForAtom(remote);
+  }
+
+  AtomMap *current = nxagentFindAtomByRemoteValue(remote);
+  if (current)
+  {
+    return current->string;
+  }
+  else
+  {
+    /* fill up the cache */
+    Atom local = nxagentRemoteToLocalAtom(remote);
+    if (local != None)
+    {
+      current = nxagentFindAtomByRemoteValue(remote);
+      if (current)
+      {
+        return current->string;
+      }
+    }
+  }
+  return NULL;
+}
+
 Atom nxagentRemoteToLocalAtom(XlibAtom remote)
 {
   if (remote == None || remote == BAD_RESOURCE)
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Atoms.h b/nx-X11/programs/Xserver/hw/nxagent/Atoms.h
index 9006b2253..8fe79883c 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Atoms.h
+++ b/nx-X11/programs/Xserver/hw/nxagent/Atoms.h
@@ -71,12 +71,24 @@ void nxagentWMDetect(void);
 XlibAtom nxagentMakeAtom(char *, unsigned, Bool);
 
 /*
- * Converts local atoms in remote atoms and viceversa.
+ * Converts local atoms to remote atoms and viceversa.
  */
 
 Atom nxagentRemoteToLocalAtom(XlibAtom);
 XlibAtom nxagentLocalToRemoteAtom(Atom);
 
-#endif
+/*
+ * return the string belonging to an atom. String MUST NOT
+ * be freed by the caller!
+ */
+const char *nxagentRemoteAtomToString(XlibAtom remote);
+
+/*
+ * As nxagentRemoteAtomToString() is similar to NameForAtom() we
+ * supply a macro for calling it.
+ */
+#define NameForRemAtom(arg) nxagentRemoteAtomToString(arg)
+
+#endif /* XlibAtom */
 
 #endif /* __Atoms_H__ */

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list