repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: bf23538a3c56394049c50fea844893c503306a6c:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit bf23538a3c56394049c50fea844893c503306a6c
Author: Emanuele Giaquinta 
Date:   Fri Jul 1 19:07:08 2011 +0000

    Maintain an AV per terminal of the associated rxvt_selection objects
    and delete all the requests on terminal destruction.

diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs
index f450350517fdf810f2e814b995a13e109d4ff4c8..
index ..0e3e7ccabe9e1ad5d6e5e0d727de0255eaaf4ad0 100644
--- a/src/rxvtperl.xs
+++ b/src/rxvtperl.xs
@@ -369,6 +369,7 @@ rxvt_perl_interp::init (rxvt_term *term)
       // runs outside of perls ENV
       term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
       hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
+      hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0);
     }
 }

@@ -399,6 +400,16 @@ rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
       for (int i = 0; i <= AvFILL (av); i++)
         ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
     }
+  else if (htype == HOOK_DESTROY)
+    {
+      AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
+
+      for (int i = AvFILL (av); i >= 0; i--)
+        {
+          rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0));
+          delete req;
+        }
+    }

   bool event_consumed;

@@ -878,6 +889,8 @@ _new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom p
 	CODE:
         rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term);
         req->cb_sv = newSVsv (cb);
+        AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
+        av_push (av, newSViv ((IV)req));
         RETVAL = (IV)req;
 	OUTPUT:
         RETVAL
@@ -886,6 +899,18 @@ void
 _delete_selection_request (IV req_)
 	CODE:
         rxvt_selection *req = (rxvt_selection *)req_;
+        AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0));
+        int i;
+
+        for (i = AvFILL (av); i >= 0; i--)
+          if (SvIV (*av_fetch (av, i, 1)) == req_)
+            break;
+
+        for (; i < AvFILL (av); i++)
+          av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
+
+        av_pop (av);
+
         delete req;

 MODULE = urxvt             PACKAGE = urxvt::term

-----END OF PAGE-----