[X2Go-Commits] [nx-libs] 331/429: Clipboard.c: remove superflous index determination

git-admin at x2go.org git-admin at x2go.org
Mon Oct 18 09:36:58 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 a3adf6641e9d93fdeb7d345b28f59f6415bb9aa6
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Wed Sep 23 23:21:37 2020 +0200

    Clipboard.c: remove superflous index determination
    
    we already have it at that stage
---
 nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 172 ++++++++++++-------------
 1 file changed, 84 insertions(+), 88 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
index 40a812b9b..da07cad40 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c
@@ -1554,32 +1554,46 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X)
   }
   else
   {
-    int index = nxagentFindLastSelectionOwnerIndex(X->xselection.selection);
-    if (index < nxagentMaxSelections)
+    /* if the last owner was an internal one, read the
+     * clientCutProperty and push the contents to the
+     * lastServers[index].requestor on the real X server.
+     */
+    if (IS_INTERNAL_OWNER(index) &&
+           lastSelectionOwner[index].windowPtr != NULL &&
+               X->xselection.property == serverTransFromAgentProperty)
     {
-      /* if the last owner was an internal one, read the
-       * clientCutProperty and push the contents to the
-       * lastServers[index].requestor on the real X server.
-       */
-      if (IS_INTERNAL_OWNER(index) &&
-             lastSelectionOwner[index].windowPtr != NULL &&
-                 X->xselection.property == serverTransFromAgentProperty)
-      {
-        Atom            atomReturnType;
-        int             resultFormat;
-        unsigned long   ulReturnItems;
-        unsigned long   ulReturnBytesLeft;
-        unsigned char   *pszReturnData = NULL;
+      Atom            atomReturnType;
+      int             resultFormat;
+      unsigned long   ulReturnItems;
+      unsigned long   ulReturnBytesLeft;
+      unsigned char   *pszReturnData = NULL;
 
-        /* first get size values ... */
-        int result = GetWindowProperty(lastSelectionOwner[index].windowPtr, clientCutProperty, 0, 0, False,
-                                           AnyPropertyType, &atomReturnType, &resultFormat,
-                                               &ulReturnItems, &ulReturnBytesLeft, &pszReturnData);
+      /* first get size values ... */
+      int result = GetWindowProperty(lastSelectionOwner[index].windowPtr, clientCutProperty, 0, 0, False,
+                                         AnyPropertyType, &atomReturnType, &resultFormat,
+                                             &ulReturnItems, &ulReturnBytesLeft, &pszReturnData);
 
+      #ifdef DEBUG
+      fprintf(stderr, "%s: GetWindowProperty() window [0x%x] property [%d] returned [%s]\n", __func__,
+                  lastSelectionOwner[index].window, clientCutProperty, getXErrorString(result));
+      #endif
+      if (result == BadAlloc || result == BadAtom ||
+              result == BadWindow || result == BadValue)
+      {
+        lastServers[index].property = None;
+      }
+      else
+      {
+        /* ... then use the size values for the actual request */
+        result = GetWindowProperty(lastSelectionOwner[index].windowPtr, clientCutProperty, 0,
+                                       ulReturnBytesLeft, False, AnyPropertyType, &atomReturnType,
+                                           &resultFormat, &ulReturnItems, &ulReturnBytesLeft,
+                                               &pszReturnData);
         #ifdef DEBUG
         fprintf(stderr, "%s: GetWindowProperty() window [0x%x] property [%d] returned [%s]\n", __func__,
                     lastSelectionOwner[index].window, clientCutProperty, getXErrorString(result));
         #endif
+
         if (result == BadAlloc || result == BadAtom ||
                 result == BadWindow || result == BadValue)
         {
@@ -1587,84 +1601,66 @@ void nxagentHandleSelectionNotifyFromXServer(XEvent *X)
         }
         else
         {
-          /* ... then use the size values for the actual request */
-          result = GetWindowProperty(lastSelectionOwner[index].windowPtr, clientCutProperty, 0,
-                                         ulReturnBytesLeft, False, AnyPropertyType, &atomReturnType,
-                                             &resultFormat, &ulReturnItems, &ulReturnBytesLeft,
-                                                 &pszReturnData);
-          #ifdef DEBUG
-          fprintf(stderr, "%s: GetWindowProperty() window [0x%x] property [%d] returned [%s]\n", __func__,
-                      lastSelectionOwner[index].window, clientCutProperty, getXErrorString(result));
-          #endif
+          /* Fill the property on the initial requestor with the requested data */
+          /* The XChangeProperty source code reveals it will always
+             return 1, no matter what, so no need to check the result */
+          /* FIXME: better use the format returned by above request */
+          XChangeProperty(nxagentDisplay,
+                          lastServers[index].requestor,
+                          lastServers[index].property,
+                          lastServers[index].target,
+                          8,
+                          PropModeReplace,
+                          pszReturnData,
+                          ulReturnItems);
 
-          if (result == BadAlloc || result == BadAtom ||
-                  result == BadWindow || result == BadValue)
-          {
-            lastServers[index].property = None;
-          }
-          else
+          #ifdef DEBUG
           {
-            /* Fill the property on the initial requestor with the requested data */
-            /* The XChangeProperty source code reveals it will always
-               return 1, no matter what, so no need to check the result */
-            /* FIXME: better use the format returned by above request */
-            XChangeProperty(nxagentDisplay,
-                            lastServers[index].requestor,
-                            lastServers[index].property,
-                            lastServers[index].target,
-                            8,
-                            PropModeReplace,
-                            pszReturnData,
-                            ulReturnItems);
-
-            #ifdef DEBUG
-            {
-              char *s = XGetAtomName(nxagentDisplay, lastServers[index].property);
-              fprintf(stderr, "%s: XChangeProperty sent to window [0x%x] for property [%ld][%s] value [\"%*.*s\"...]\n",
-                      __func__,
-                      lastServers[index].requestor,
-                      lastServers[index].property,
-                      s,
-                      (int)(min(20, ulReturnItems * 8 / 8)),
-                      (int)(min(20, ulReturnItems * 8 / 8)),
-                      pszReturnData);
-              SAFE_XFree(s);
-            }
-            #endif
+            char *s = XGetAtomName(nxagentDisplay, lastServers[index].property);
+            fprintf(stderr, "%s: XChangeProperty sent to window [0x%x] for property [%ld][%s] value [\"%*.*s\"...]\n",
+                    __func__,
+                    lastServers[index].requestor,
+                    lastServers[index].property,
+                    s,
+                    (int)(min(20, ulReturnItems * 8 / 8)),
+                    (int)(min(20, ulReturnItems * 8 / 8)),
+                    pszReturnData);
+            SAFE_XFree(s);
           }
-
-          /* FIXME: free it or not? */
-          /*
-           * SAFE_XFree(pszReturnData);
-           */
+          #endif
         }
 
+        /* FIXME: free it or not? */
         /*
-         * inform the initial requestor that the requested data has
-         * arrived in the desired property. If we have been unable to
-         * get the data from the owner XChangeProperty will not have
-         * been called and lastServers[index].property will be None which
-         * effectively will send a "Request denied" to the initial
-         * requestor.
+         * SAFE_XFree(pszReturnData);
          */
-        XSelectionEvent eventSelection = {
-          .requestor = lastServers[index].requestor,
-          .selection = X->xselection.selection,
-          /* .target = X->xselection.target, */
-          .target    = lastServers[index].target,
-          .property  = lastServers[index].property,
-          .time      = lastServers[index].time,
-          /* .time   = CurrentTime */
-        };
-        #ifdef DEBUG
-        fprintf(stderr, "%s: Sending SelectionNotify event to requestor [%p].\n", __func__,
-                (void *)eventSelection.requestor);
-        #endif
+      }
 
-        sendSelectionNotifyEventToXServer(&eventSelection);
+      /*
+       * inform the initial requestor that the requested data has
+       * arrived in the desired property. If we have been unable to
+       * get the data from the owner XChangeProperty will not have
+       * been called and lastServers[index].property will be None which
+       * effectively will send a "Request denied" to the initial
+       * requestor.
+       */
+      XSelectionEvent eventSelection = {
+        .requestor = lastServers[index].requestor,
+        .selection = X->xselection.selection,
+        /* .target = X->xselection.target, */
+        .target    = lastServers[index].target,
+        .property  = lastServers[index].property,
+        .time      = lastServers[index].time,
+        /* .time   = CurrentTime */
+      };
+      #ifdef DEBUG
+      fprintf(stderr, "%s: Sending SelectionNotify event to requestor [%p].\n", __func__,
+              (void *)eventSelection.requestor);
+      #endif
 
-        lastServers[index].requestor = None; /* allow further request */
-      }
+      sendSelectionNotifyEventToXServer(&eventSelection);
+
+      lastServers[index].requestor = None; /* allow further request */
     }
   }
 }

--
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