diff options
author | Ulrich Sibiller <uli42@gmx.de> | 2020-09-22 23:12:25 +0200 |
---|---|---|
committer | Ulrich Sibiller <uli42@gmx.de> | 2021-06-20 20:12:50 +0200 |
commit | e8b00edb59400d63d3c849dee6a2705228815e97 (patch) | |
tree | 67cbf758019df64a6e0135d941b0d34df8835403 | |
parent | 0ad6b8bd6013bb3040343188e0258488b6434710 (diff) | |
download | nx-libs-e8b00edb59400d63d3c849dee6a2705228815e97.tar.gz nx-libs-e8b00edb59400d63d3c849dee6a2705228815e97.tar.bz2 nx-libs-e8b00edb59400d63d3c849dee6a2705228815e97.zip |
Clipboard.c: simplify nxagentHandleSelectionRequestFromXServer
- remove redundant calls to nxagentFindLastSelectionOwnerIndex which reduce
indentation level
- scope improvements
-rw-r--r-- | nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 227 |
1 files changed, 107 insertions, 120 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 01cdcad21..5a85b0f87 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -837,17 +837,15 @@ void nxagentHandleSelectionRequestFromXServer(XEvent *X) } /* the selection in this request is none we own. */ + int index = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); + if (index == nxagentMaxSelections) { - int index = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); - if (index == nxagentMaxSelections) - { - #ifdef DEBUG - fprintf(stderr, "%s: not owning selection [%ld] - denying request.\n", __func__, X->xselectionrequest.selection); - #endif + #ifdef DEBUG + fprintf(stderr, "%s: not owning selection [%ld] - denying request.\n", __func__, X->xselectionrequest.selection); + #endif - replyRequestSelectionToXServer(X, False); - return; - } + replyRequestSelectionToXServer(X, False); + return; } /* this is a special request like TARGETS or TIMESTAMP */ @@ -874,16 +872,14 @@ void nxagentHandleSelectionRequestFromXServer(XEvent *X) int numTargets = sizeof(targets) / sizeof(targets[0]); #ifdef DEBUG + fprintf(stderr, "%s: Sending %d available targets:\n", __func__, numTargets); + for (int i = 0; i < numTargets; i++) { - fprintf(stderr, "%s: Sending %d available targets:\n", __func__, numTargets); - for (int i = 0; i < numTargets; i++) - { - char *s = XGetAtomName(nxagentDisplay, targets[i]); - fprintf(stderr, "%s: %ld %s\n", __func__, targets[i], s); - SAFE_XFree(s); - } - fprintf(stderr, "\n"); + char *s = XGetAtomName(nxagentDisplay, targets[i]); + fprintf(stderr, "%s: %ld %s\n", __func__, targets[i], s); + SAFE_XFree(s); } + fprintf(stderr, "\n"); #endif /* @@ -918,19 +914,15 @@ void nxagentHandleSelectionRequestFromXServer(XEvent *X) * FIXME: selection has already been checked above, so we do not need to check again here */ - int index = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); - if (index < nxagentMaxSelections) - { - XChangeProperty(nxagentDisplay, - X->xselectionrequest.requestor, - X->xselectionrequest.property, - XA_INTEGER, - 32, - PropModeReplace, - (unsigned char *) &lastSelectionOwner[index].lastTimeChanged, - 1); - replyRequestSelectionToXServer(X, True); - } + XChangeProperty(nxagentDisplay, + X->xselectionrequest.requestor, + X->xselectionrequest.property, + XA_INTEGER, + 32, + PropModeReplace, + (unsigned char *) &lastSelectionOwner[index].lastTimeChanged, + 1); + replyRequestSelectionToXServer(X, True); } else { @@ -956,107 +948,102 @@ void nxagentHandleSelectionRequestFromXServer(XEvent *X) */ serverLastRequestedSelection = X->xselectionrequest.selection; - /* find the index of the requested selection */ - int index = nxagentFindLastSelectionOwnerIndex(X->xselectionrequest.selection); - if (index < nxagentMaxSelections) - { #if 0 - if (lastClients[index].windowPtr != NULL && IS_INTERNAL_OWNER(index)) - { - /* - * Request the real X server to transfer the selection content - * to the NX_CUT_BUFFER_SERVER property of the serverWindow. - * We reach here as follows: - * - mark someting in the nx session - * -> nxagent claims ownership of PRIMARY on real X server - * - at the same time paste _clipboard_ to the client (now) owning primary - * ->vcxsrv will ask for primary contents to store them to Windows clipboard - * - vcxsrv request is for _primary_ and takes this path as the _clipboard_ transfer - * has set lastClients[index].windowPtr - */ - XConvertSelection(nxagentDisplay, CurrentSelections[index].selection, - X->xselectionrequest.target, serverTransToAgentProperty, - serverWindow, lastClients[index].time); - - #ifdef DEBUG - char *strTarget = XGetAtomName(nxagentDisplay, X->xselectionrequest.target); - char *strSelection = XGetAtomName(nxagentDisplay, CurrentSelections[index].selection); - char *strProperty = XGetAtomName(nxagentDisplay, serverTransToAgentProperty); - fprintf(stderr, "%s: Sent XConvertSelection: selection [%d][%s] target [%ld][%s] property [%ld][%s] window [0x%x] time [%u] .\n", __func__, - CurrentSelections[index].selection, strSelection, - X->xselectionrequest.target, strTarget, - serverTransToAgentProperty, strProperty, + if (lastClients[index].windowPtr != NULL && IS_INTERNAL_OWNER(index)) + { + /* + * Request the real X server to transfer the selection content + * to the NX_CUT_BUFFER_SERVER property of the serverWindow. + * We reach here as follows: + * - mark someting in the nx session + * -> nxagent claims ownership of PRIMARY on real X server + * - at the same time paste _clipboard_ to the client (now) owning primary + * ->vcxsrv will ask for primary contents to store them to Windows clipboard + * - vcxsrv request is for _primary_ and takes this path as the _clipboard_ transfer + * has set lastClients[index].windowPtr + */ + XConvertSelection(nxagentDisplay, CurrentSelections[index].selection, + X->xselectionrequest.target, serverTransToAgentProperty, serverWindow, lastClients[index].time); - #endif - SAFE_XFree(strTarget); - SAFE_XFree(strSelection); - SAFE_XFree(strProperty); - } - else + + #ifdef DEBUG + char *strTarget = XGetAtomName(nxagentDisplay, X->xselectionrequest.target); + char *strSelection = XGetAtomName(nxagentDisplay, CurrentSelections[index].selection); + char *strProperty = XGetAtomName(nxagentDisplay, serverTransToAgentProperty); + fprintf(stderr, "%s: Sent XConvertSelection: selection [%d][%s] target [%ld][%s] property [%ld][%s] window [0x%x] time [%u] .\n", __func__, + CurrentSelections[index].selection, strSelection, + X->xselectionrequest.target, strTarget, + serverTransToAgentProperty, strProperty, + serverWindow, lastClients[index].time); + SAFE_XFree(strTarget); + SAFE_XFree(strSelection); + SAFE_XFree(strProperty); + #endif + } + else #endif + { + /* + * if one of our clients owns the selection we ask it to copy + * the selection to the clientCutProperty on nxagent's root + * window in the first step. We then later push that property's + * content to the real X server. + */ + if (IS_INTERNAL_OWNER(index) && + (nxagentOption(Clipboard) == ClipboardServer || + nxagentOption(Clipboard) == ClipboardBoth)) { /* - * if one of our clients owns the selection we ask it to copy - * the selection to the clientCutProperty on nxagent's root - * window in the first step. We then later push that property's - * content to the real X server. + * store who on the real X server requested the data and how + * and where it wants to have it */ - if (IS_INTERNAL_OWNER(index) && - (nxagentOption(Clipboard) == ClipboardServer || - nxagentOption(Clipboard) == ClipboardBoth)) - { - /* - * store who on the real X server requested the data and how - * and where it wants to have it - */ - lastServerProperty = X->xselectionrequest.property; - lastServerRequestor = X->xselectionrequest.requestor; - lastServerTarget = X->xselectionrequest.target; - lastServerTime = X->xselectionrequest.time; - - /* by dimbor */ - if (lastServerTarget != XA_STRING) - lastServerTarget = serverUTF8_STRING; - - /* prepare the request (like XConvertSelection, but internally) */ - xEvent x = {0}; - x.u.u.type = SelectionRequest; - x.u.selectionRequest.time = GetTimeInMillis(); - x.u.selectionRequest.owner = lastSelectionOwner[index].window; - x.u.selectionRequest.selection = CurrentSelections[index].selection; - x.u.selectionRequest.property = clientCutProperty; - x.u.selectionRequest.requestor = screenInfo.screens[0]->root->drawable.id; /* Fictitious window.*/ + lastServerProperty = X->xselectionrequest.property; + lastServerRequestor = X->xselectionrequest.requestor; + lastServerTarget = X->xselectionrequest.target; + lastServerTime = X->xselectionrequest.time; - /* - * Don't send the same window, some programs are clever and - * verify cut and paste operations inside the same window and - * don't Notify at all. - * - * x.u.selectionRequest.requestor = lastSelectionOwnerWindow; - */ + /* by dimbor */ + if (lastServerTarget != XA_STRING) + lastServerTarget = serverUTF8_STRING; - /* by dimbor (idea from zahvatov) */ - if (X->xselectionrequest.target != XA_STRING) - x.u.selectionRequest.target = clientUTF8_STRING; - else - x.u.selectionRequest.target = XA_STRING; + /* prepare the request (like XConvertSelection, but internally) */ + xEvent x = {0}; + x.u.u.type = SelectionRequest; + x.u.selectionRequest.time = GetTimeInMillis(); + x.u.selectionRequest.owner = lastSelectionOwner[index].window; + x.u.selectionRequest.selection = CurrentSelections[index].selection; + x.u.selectionRequest.property = clientCutProperty; + x.u.selectionRequest.requestor = screenInfo.screens[0]->root->drawable.id; /* Fictitious window.*/ - sendEventToClient(lastSelectionOwner[index].client, &x); + /* + * Don't send the same window, some programs are clever and + * verify cut and paste operations inside the same window and + * don't Notify at all. + * + * x.u.selectionRequest.requestor = lastSelectionOwner[index].window; + */ - #ifdef DEBUG - fprintf(stderr, "%s: sent SelectionRequest event to client %s property [%d][%s]" \ - "target [%d][%s] requestor [0x%x].\n", __func__, - nxagentClientInfoString(lastSelectionOwner[index].client), - x.u.selectionRequest.property, NameForAtom(x.u.selectionRequest.property), - x.u.selectionRequest.target, NameForAtom(x.u.selectionRequest.target), - x.u.selectionRequest.requestor); - #endif - } + /* by dimbor (idea from zahvatov) */ + if (X->xselectionrequest.target != XA_STRING) + x.u.selectionRequest.target = clientUTF8_STRING; else - { - /* deny the request */ - replyRequestSelectionToXServer(X, False); - } + x.u.selectionRequest.target = XA_STRING; + + sendEventToClient(lastSelectionOwner[index].client, &x); + + #ifdef DEBUG + fprintf(stderr, "%s: sent SelectionRequest event to client %s property [%d][%s]" \ + "target [%d][%s] requestor [0x%x].\n", __func__, + nxagentClientInfoString(lastSelectionOwner[index].client), + x.u.selectionRequest.property, NameForAtom(x.u.selectionRequest.property), + x.u.selectionRequest.target, NameForAtom(x.u.selectionRequest.target), + x.u.selectionRequest.requestor); + #endif + } + else + { + /* deny the request */ + replyRequestSelectionToXServer(X, False); } } } |