aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2020-09-22 22:00:20 +0200
committerUlrich Sibiller <uli42@gmx.de>2021-06-20 20:12:50 +0200
commitedfea3cd18853ff82d866168186dd5687dba56f9 (patch)
tree2632fa5bc75c92a9a0f4fb37ea1dc8df6e189991
parent550742511cc6d546b3618c0944396767e53d3829 (diff)
downloadnx-libs-edfea3cd18853ff82d866168186dd5687dba56f9.tar.gz
nx-libs-edfea3cd18853ff82d866168186dd5687dba56f9.tar.bz2
nx-libs-edfea3cd18853ff82d866168186dd5687dba56f9.zip
Clipboard.c: introduce translateLocalToRemote* helpers
This also unifies target handling to never use TEXT or COMPOUND_TEXT (despite announcing it)
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Clipboard.c198
1 files changed, 90 insertions, 108 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
index f35ab583a..a07e5a5e8 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
@@ -262,6 +262,9 @@ static void replyRequestSelectionToXServer(XEvent *X, Bool success);
void nxagentPrintClipboardStat(char *);
+XlibAtom translateLocalToRemoteSelection(Atom local);
+XlibAtom translateLocalToRemoteTarget(Atom local);
+
#ifdef NXAGENT_TIMESTAMP
extern unsigned long startTime;
#endif
@@ -2079,64 +2082,24 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
if ((GetTimeInMillis() - lastClients[index].reqTime) >= CONVERSION_TIMEOUT)
lastClients[index].reqTime = GetTimeInMillis();
- XlibAtom remSelection = 0;
-
- /* FIXME: we should use/have a function for stuff like that */
- if (selection == XA_PRIMARY)
- {
- remSelection = XA_PRIMARY;
- }
- else if (selection == clientCLIPBOARD)
- {
- remSelection = lastSelectionOwner[nxagentClipboardSelection].remSelection;
- }
- else
- {
- remSelection = nxagentLocalToRemoteAtom(selection);
- }
-
- /*
- * we only convert to either UTF8 or XA_STRING, despite accepting
- * TEXT and COMPOUND_TEXT.
- */
+ XlibAtom remSelection = translateLocalToRemoteSelection(selection);
+ XlibAtom remTarget = translateLocalToRemoteTarget(target);
XlibAtom remProperty = serverTransToAgentProperty;
- XlibAtom remTarget;
- #ifdef DEBUG
- char * pstr = "NX_CUT_BUFFER_SERVER";
- const char * tstr;
- #endif
- if (target == clientUTF8_STRING)
- {
- remTarget = serverUTF8_STRING;
- #ifdef DEBUG
- tstr = szAgentUTF8_STRING;
- #endif
- }
- else
- {
- remTarget = XA_STRING;
- #ifdef DEBUG
- tstr = validateString(NameForAtom(XA_STRING));
- #endif
- }
#ifdef DEBUG
- /* FIXME: check Atoms.c for alternative to XGetAtomName */
- fprintf(stderr, "%s: mapping local to remote Atom: [%d][%s] -> [%ld][%s]\n",
- __func__, selection, NameForAtom(selection), remSelection,
- XGetAtomName(nxagentDisplay, remSelection));
- fprintf(stderr, "%s: mapping local to remote Atom: [%d][%s] -> [%ld][%s]\n",
- __func__, target, NameForAtom(target), remTarget, tstr);
- fprintf(stderr, "%s: mapping local to remote Atom: [%d][%s] -> [%ld][%s]\n",
- __func__, property, NameForAtom(property), remProperty, pstr);
+ fprintf(stderr, "%s: replacing local by remote property: [%d][%s] -> [%ld][%s]\n",
+ __func__, property, NameForAtom(property),
+ remProperty, "NX_CUT_BUFFER_SERVER");
#endif
/* FIXME: check why using CurrentTime will not replace the value
* by a real time. The reply also contains time "0" which is
* unexpected (for me) */
#ifdef DEBUG
- fprintf(stderr, "%s: Sending XConvertSelection to real X server: requestor [0x%x] target [%ld][%s] property [%ld][%s] selection [%ld] time [0][CurrentTime]\n", __func__,
- serverWindow, remTarget, tstr, remProperty, pstr, remSelection);
+ fprintf(stderr, "%s: Sending XConvertSelection to real X server: requestor [0x%x] target [%ld][%s] property [%ld][%s] selection [%ld][%s] time [0][CurrentTime]\n", __func__,
+ serverWindow, remTarget, XGetAtomName(nxagentDisplay, remTarget),
+ remProperty, XGetAtomName(nxagentDisplay, remProperty),
+ remSelection, XGetAtomName(nxagentDisplay, remSelection));
#endif
XConvertSelection(nxagentDisplay, remSelection, remTarget, remProperty, serverWindow, CurrentTime);
@@ -2144,7 +2107,7 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
/* XConvertSelection will always return (check the source!), so no need to check */
#ifdef DEBUG
- fprintf(stderr, "%s: Sent XConvertSelection with target [%s], property [%s]\n", __func__, tstr, pstr);
+ fprintf(stderr, "%s: Sent XConvertSelection\n", __func__);
#endif
return 1;
@@ -2164,6 +2127,81 @@ int nxagentConvertSelection(ClientPtr client, WindowPtr pWin, Atom selection,
return 0;
}
+XlibAtom translateLocalToRemoteSelection(Atom local)
+{
+ /*
+ * On the real server, the right CLIPBOARD atom is
+ * XInternAtom(nxagentDisplay, "CLIPBOARD", 1), which is stored in
+ * lastSelectionOwner[nxagentClipboardSelection].remSelection. For
+ * PRIMARY there's nothing to map because that is identical on all
+ * X servers (defined in Xatom.h).
+ */
+
+ XlibAtom remote;
+
+ if (local == XA_PRIMARY)
+ {
+ remote = XA_PRIMARY;
+ }
+ else if (local == clientCLIPBOARD)
+ {
+ remote = lastSelectionOwner[nxagentClipboardSelection].remSelection;
+ }
+ else
+ {
+ remote = nxagentLocalToRemoteAtom(local);
+ }
+
+ #ifdef DEBUG
+ fprintf(stderr, "%s: mapping local to remote selection: [%d][%s] -> [%ld] [%s]\n", __func__,
+ local, NameForAtom(local), remote, XGetAtomName(nxagentDisplay, remote));
+ #endif
+
+ return remote;
+}
+
+XlibAtom translateLocalToRemoteTarget(Atom local)
+{
+ /*
+ * .target must be translated, too, as a client on the real
+ * server is requested to fill our property and it needs to know
+ * the format.
+ */
+
+ XlibAtom remote;
+
+ /*
+ * we only convert to either UTF8 or XA_STRING, despite accepting
+ * TEXT and COMPOUND_TEXT.
+ */
+
+ if (local == clientUTF8_STRING)
+ {
+ remote = serverUTF8_STRING;
+ }
+#if 0
+ else if (local == clientTEXT)
+ {
+ remote = serverTEXT;
+ }
+ else if (local == clientCOMPOUND_TEXT)
+ {
+ remote = serverCOMPOUND_TEXT;
+ }
+#endif
+ else
+ {
+ remote = XA_STRING;
+ }
+
+ #ifdef DEBUG
+ fprintf(stderr, "%s: mapping local to remote target: [%d][%s] -> [%ld] [%s]\n", __func__,
+ local, NameForAtom(local), remote, XGetAtomName(nxagentDisplay, remote));
+ #endif
+
+ return remote;
+}
+
/*
* This is _only_ called from ProcSendEvent in NXevents.c. It is used
* to send a SelectionNotify event to our server window which will
@@ -2235,68 +2273,12 @@ int nxagentSendNotify(xEvent *event)
XSelectionEvent eventSelection = {
.requestor = serverWindow,
- .selection = event->u.selectionNotify.selection,
- .target = event->u.selectionNotify.target,
+ .selection = translateLocalToRemoteSelection(event->u.selectionNotify.selection),
+ .target = translateLocalToRemoteTarget(event->u.selectionNotify.target),
.property = serverTransFromAgentProperty,
.time = CurrentTime,
};
- /*
- * On the real server, the right CLIPBOARD atom is
- * XInternAtom(nxagentDisplay, "CLIPBOARD", 1), which is stored in
- * lastSelectionOwner[nxagentClipboardSelection].selection. For
- * PRIMARY there's nothing to map because that is identical on all
- * X servers (defined in Xatom.h).
- */
-
- if (event->u.selectionNotify.selection == XA_PRIMARY)
- {
- eventSelection.selection = XA_PRIMARY;
- }
- else if (event->u.selectionNotify.selection == clientCLIPBOARD)
- {
- eventSelection.selection = lastSelectionOwner[nxagentClipboardSelection].remSelection;
- }
- else
- {
- eventSelection.selection = nxagentLocalToRemoteAtom(event->u.selectionNotify.selection);
- }
-
- /*
- * .target must be translated, too, as a client on the real
- * server is requested to fill our property and it needs to know
- * the format.
- */
-
- if (event->u.selectionNotify.target == clientUTF8_STRING)
- {
- eventSelection.target = serverUTF8_STRING;
- }
- else if (event->u.selectionNotify.target == clientTEXT)
- {
- eventSelection.target = serverTEXT;
- }
- else if (event->u.selectionNotify.target == clientCOMPOUND_TEXT)
- {
- eventSelection.target = serverCOMPOUND_TEXT;
- }
- else
- {
- eventSelection.target = XA_STRING;
- }
-
- #ifdef DEBUG
- fprintf(stderr, "%s: mapping local to remote Atom: [%d] -> [%ld] [%s]\n", __func__,
- event->u.selectionNotify.selection, eventSelection.selection,
- NameForAtom(event->u.selectionNotify.selection));
- fprintf(stderr, "%s: mapping local to remote Atom: [%d] -> [%ld] [%s]\n", __func__,
- event->u.selectionNotify.target, eventSelection.target,
- NameForAtom(event->u.selectionNotify.target));
- fprintf(stderr, "%s: mapping local to remote Atom: [%d] -> [%ld] [%s]\n", __func__,
- event->u.selectionNotify.property, eventSelection.property,
- NameForAtom(event->u.selectionNotify.property));
- #endif
-
sendSelectionNotifyEventToXServer(&eventSelection);
return 1;