aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2020-01-07 20:52:37 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2020-05-07 12:55:03 +0200
commit8a5c1d3d89e14959ad9aa74d24e3544b50ef37e5 (patch)
tree42fd02e1dc8a45d15a6653b287c2c1169abd6b43 /nx-X11/programs
parent2594ca998798ac867b903083eb697c59f37e693c (diff)
downloadnx-libs-8a5c1d3d89e14959ad9aa74d24e3544b50ef37e5.tar.gz
nx-libs-8a5c1d3d89e14959ad9aa74d24e3544b50ef37e5.tar.bz2
nx-libs-8a5c1d3d89e14959ad9aa74d24e3544b50ef37e5.zip
Atoms.c: some code cleanup
add else clauses, improve debugging, add comments
Diffstat (limited to 'nx-X11/programs')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Atoms.c126
1 files changed, 71 insertions, 55 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
index c7b3882fc..b2d7cdc6f 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Atoms.c
@@ -610,17 +610,14 @@ static AtomMap* nxagentFindAtomByName(char *string, unsigned int length)
* really asking to X-server and caching them.
* FIXME: I don't really know if is better to allocate
* an automatic variable like ret_value and write it, instead of make all
- * these return!, perhaps this way the code is a little bit easyer to read.
+ * these return!, perhaps this way the code is a little bit easier to read.
* I think this and the 2 .*Find.* are the only functions to look for performances.
*/
XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
{
- AtomMap *current;
-
/*
- * Surely MakeAtom is faster than
- * our nxagentFindAtomByName.
+ * Surely MakeAtom is faster than our nxagentFindAtomByName.
*/
Atom local = MakeAtom(string, length, Makeit);
@@ -635,6 +632,8 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return local;
}
+ AtomMap *current;
+
if ((current = nxagentFindAtomByLocalValue(local)))
{
/*
@@ -643,8 +642,7 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return current->remote;
}
-
- if ((current = nxagentFindAtomByName(string, length)))
+ else if ((current = nxagentFindAtomByName(string, length)))
{
/*
* Found cached by name.
@@ -656,26 +654,29 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
return current->remote;
}
-
- /*
- * We really have to ask the Xserver for it.
- */
-
+ else
{
+ /*
+ * We really have to ask the Xserver for it.
+ */
+
+ /* FIXME: why is Makeit inverted here? */
XlibAtom remote = XInternAtom(nxagentDisplay, string, !Makeit);
if (remote == None)
{
#ifdef WARNING
- fprintf(stderr, "nxagentMakeAtom: WARNING XInternAtom failed.\n");
+ fprintf(stderr, "nxagentMakeAtom: WARNING XInternAtom(.., %s, ..) failed.\n", string);
#endif
return None;
}
+ else
+ {
+ nxagentWriteAtom(local, remote, string, True);
- nxagentWriteAtom(local, remote, string, True);
-
- return remote;
+ return remote;
+ }
}
}
@@ -693,6 +694,7 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
return None;
}
+ /* no mapping required for built-in atoms */
if (local <= XA_LAST_PREDEFINED)
{
#ifdef DEBUG
@@ -705,32 +707,39 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
if (current)
{
- #ifdef TEST
- fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote);
+ #ifdef DEBUG
+ if (current->string)
+ fprintf(stderr, "%s: local [%d] -> remote [%d (%s)]\n", __func__, local, current->remote, current->string);
+ else
+ fprintf(stderr, "%s: local [%d] -> remote [%d]\n", __func__, local, current->remote);
#endif
+
return current->remote;
}
+ else
+ {
+ const char *string = NameForAtom(local);
- const char *string = NameForAtom(local);
-
- XlibAtom remote = XInternAtom(nxagentDisplay, string, False);
+ /* FIXME: why False? */
+ XlibAtom remote = XInternAtom(nxagentDisplay, string, False);
- if (remote == None)
- {
- #ifdef WARNING
- fprintf(stderr, "nxagentLocalToRemoteAtom: WARNING XInternAtom failed.\n");
- #endif
+ if (remote == None)
+ {
+ #ifdef WARNING
+ fprintf(stderr, "nxagentLocalToRemoteAtom: WARNING XInternAtom failed.\n");
+ #endif
- return None;
- }
+ return None;
+ }
- nxagentWriteAtom(local, remote, string, True);
+ nxagentWriteAtom(local, remote, string, True);
- #ifdef TEST
- fprintf(stderr, "%s: local [%d] -> remote [%d (%s)]\n", __func__, local, remote, string);
- #endif
+ #ifdef TEST
+ fprintf(stderr, "%s: local [%d (%s)] -> remote [%d]\n", __func__, local, string, remote);
+ #endif
- return remote;
+ return remote;
+ }
}
Atom nxagentRemoteToLocalAtom(XlibAtom remote)
@@ -743,6 +752,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
return None;
}
+ /* no mapping required for built-in atoms */
if (remote <= XA_LAST_PREDEFINED)
{
#ifdef DEBUG
@@ -774,41 +784,47 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
}
#ifdef DEBUG
- fprintf(stderr, "%s: remote [%d] -> local [%d]\n", __func__, remote, current->local);
+ if (current->string)
+ fprintf(stderr, "%s: remote [%d] -> local [%d (%s)]\n", __func__, remote, current->local, current->string);
+ else
+ fprintf(stderr, "%s: remote [%d] -> local [%d]\n", __func__, remote, current->local);
#endif
+
return current->local;
}
-
- char *string = XGetAtomName(nxagentDisplay, remote);
-
- if (string)
+ else
{
- Atom local = MakeAtom(string, strlen(string), True);
+ char *string = XGetAtomName(nxagentDisplay, remote);
- if (!ValidAtom(local))
+ if (string)
{
- #ifdef WARNING
- fprintf(stderr, "%s: WARNING MakeAtom failed.\n", __func__);
+ Atom local = MakeAtom(string, strlen(string), True);
+
+ if (!ValidAtom(local))
+ {
+ #ifdef WARNING
+ fprintf(stderr, "%s: WARNING MakeAtom failed.\n", __func__);
+ #endif
+
+ local = None;
+ }
+
+ nxagentWriteAtom(local, remote, string, True);
+
+ #ifdef TEST
+ fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local);
#endif
+ SAFE_XFree(string);
- local = None;
+ return local;
}
- nxagentWriteAtom(local, remote, string, True);
-
- #ifdef TEST
- fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local);
+ #ifdef WARNING
+ fprintf(stderr, "%s: WARNING failed to get name from remote atom.\n", __func__);
#endif
- SAFE_XFree(string);
- return local;
+ return None;
}
-
- #ifdef WARNING
- fprintf(stderr, "%s: WARNING failed to get name from remote atom.\n", __func__);
- #endif
-
- return None;
}
#ifdef DEBUG