Oops, no, that's wrong. When we lose the selection, we must stop
[sgt/utils] / xcopy / xcopy.c
index 2ee43c6..bb72814 100644 (file)
@@ -519,6 +519,16 @@ Atom convert_sel_inner(Window requestor, Atom target, Atom property) {
 }
 
 Atom convert_sel_outer(Window requestor, Atom target, Atom property) {
+    /*
+     * ICCCM 2.2 says that obsolete clients requesting the selection
+     * request may not specify a property name under which they want
+     * the data written to their window; selection owners are
+     * encouraged to support such clients by reusing the selection
+     * target name as the property.
+     */
+    if (property == None)
+        property = target;
+
     if (target == multiple_atom) {
        /*
         * Support for the MULTIPLE selection type, since it's
@@ -600,22 +610,27 @@ void run_X(void) {
                 return;
             }
         } else {
+            int have_ownership = True;
+
             switch (ev.type) {
               case SelectionClear:
                 /* Selection has been cleared by another app. */
-                return;
+                have_ownership = False;
+                break;
               case SelectionRequest:
-                e2.xselection.type = SelectionNotify;
-                e2.xselection.requestor = ev.xselectionrequest.requestor;
-                e2.xselection.selection = ev.xselectionrequest.selection;
-                e2.xselection.target = ev.xselectionrequest.target;
-                e2.xselection.time = ev.xselectionrequest.time;
-                e2.xselection.property =
-                   convert_sel_outer(ev.xselectionrequest.requestor,
-                                     ev.xselectionrequest.target,
-                                     ev.xselectionrequest.property);
-                XSendEvent (disp, ev.xselectionrequest.requestor,
-                           False, 0, &e2);
+                if (have_ownership) {
+                    e2.xselection.type = SelectionNotify;
+                    e2.xselection.requestor = ev.xselectionrequest.requestor;
+                    e2.xselection.selection = ev.xselectionrequest.selection;
+                    e2.xselection.target = ev.xselectionrequest.target;
+                    e2.xselection.time = ev.xselectionrequest.time;
+                    e2.xselection.property =
+                        convert_sel_outer(ev.xselectionrequest.requestor,
+                                          ev.xselectionrequest.target,
+                                          ev.xselectionrequest.property);
+                    XSendEvent (disp, ev.xselectionrequest.requestor,
+                                False, 0, &e2);
+                }
                 break;
               case PropertyNotify:
                 for (i = j = 0; i < nincrs; i++) {
@@ -654,6 +669,8 @@ void run_X(void) {
                 nincrs = j;
                 break;
             }
+            if (nincrs == 0 && !have_ownership)
+                return;
         }
     }
 }