-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: rxvt-unicode-sixel
action: commit
revision:
path_from:
revision_from: b2845c03603cc014887170150ffc03b31f88fb12:
path_to:
revision_to:

git.thebackupbox.net

rxvt-unicode-sixel

git://git.thebackupbox.net/rxvt-unicode-sixel

commit b2845c03603cc014887170150ffc03b31f88fb12
Author: Marc Lehmann <schmorp@schmorp.de>
Date:   Wed Jan 25 15:02:47 2006 +0000

    *** empty log message ***

diff --git a/src/perl/remote-selection b/src/perl/remote-selection
new file mode 100644
index 0000000000000000000000000000000000000000..39684a1970d99dc5883633ae9b94075de2f2e388
--- /dev/null
+++ b/src/perl/remote-selection
@@ -0,0 +1,112 @@
+#! perl
+
+use Fcntl ();
+
+sub msg {
+   my ($self, $msg) = @_;
+
+   my $ov = $self->overlay (-1, 0, $self->strwidth ($msg), 1, urxvt::OVERLAY_RSTYLE, 0);
+   $ov->set (0, 0, $msg);
+
+   $self->{msg} =
+      urxvt::timer
+              ->new
+              ->after (5)
+              ->cb (sub { delete $self->{msg}; undef $ov; });
+}
+
+sub wait_pipe {
+   my ($self, $fh, $pid, $msg) = @_;
+
+   $self->msg ("waiting for process to finish...");
+
+   my $wait_pipe; $wait_pipe = urxvt::pw->new->start ($pid)->cb (sub {
+      my ($undef, $status) = @_;
+      undef $wait_pipe;
+      close $fh;
+      $status >>= 8;
+      $self->msg ("$msg (status $status)");
+   });
+}
+
+sub store {
+   my ($self) = @_;
+
+   my $txt = $self->selection;
+
+   local %ENV = %{ $self->env };
+   if (my $pid = open my $fh, "|-:utf8", $self->{store_cmd}) {
+      fcntl $fh, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK;
+      $self->{iow} = urxvt::iow
+                     ->new
+                     ->fd (fileno $fh)
+                     ->events (urxvt::EVENT_WRITE)
+                     ->start
+                     ->cb (sub {
+         if (my $len = syswrite $fh, $txt) {
+            substr $txt, 0, $len, "";
+            $self->msg ((length $txt) . " chars to go...");
+         } else {
+            delete $self->{iow};
+            $self->wait_pipe ($fh, $pid, "selection stored");
+         }
+      });
+   }
+}
+
+sub fetch {
+   my ($self) = @_;
+
+   my $txt;
+
+   local %ENV = %{ $self->env };
+   if (my $pid = open my $fh, "-|:utf8", $self->{fetch_cmd}) {
+      fcntl $fh, &Fcntl::F_SETFL, &Fcntl::O_NONBLOCK;
+      $self->{iow} = urxvt::iow
+                     ->new
+                     ->fd (fileno $fh)
+                     ->events (urxvt::EVENT_READ)
+                     ->start
+                     ->cb (sub {
+         if (my $len = sysread $fh, $txt, 8192, length $txt) {
+            $self->msg ((length $txt) . " chars read...");
+         } else {
+            delete $self->{iow};
+            $self->selection_clear;
+            $self->selection ($txt);
+            $self->selection_make (urxvt::CurrentTime);
+            $self->wait_pipe ($fh, $pid, "selection fetched");
+         }
+      });
+   }
+}
+
+sub on_start {
+   my ($self) = @_;
+
+   $self->{store_cmd} = $self->x_resource ("remote-selection.store")
+                        || "rsh ruth 'cat >/tmp/distributed-selection'";
+
+   $self->{fetch_cmd} = $self->x_resource ("remote-selection.fetch")
+                        || "rsh ruth 'cat /tmp/distributed-selection'";
+
+   push @{ $self->{term}{selection_popup_hook} }, sub {
+      ("selection => remote" => sub { $self->store })
+   };
+   push @{ $self->{term}{selection_popup_hook} }, sub {
+      ("remote => selection" => sub { $self->fetch })
+   };
+
+   ()
+}
+
+sub on_keyboard_command {
+   my ($self, $cmd) = @_;
+
+   if ($cmd eq "selection-pastebin:remote-pastebin") {
+      $self->upload_paste;
+   }
+
+   ()
+}
+
diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs

index 918946dab4f2fb311f4492ba882ebac894ee0f63..

index ..af43e2d3721a39cfd4d2834c8ae9ec410cf8c8b9 100644

--- a/src/rxvtperl.xs
+++ b/src/rxvtperl.xs
@@ -246,15 +246,17 @@ struct pw : perl_watcher, child_watcher

 #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")

-struct overlay {
-  HV *self;
-  bool visible;
+class overlay {
   rxvt_term *THIS;
+  AV *overlay_av;
   int x, y, w, h;
   int border;
   text_t **text;
   rend_t **rend;

+public:
+  HV *self;
+
   overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
   ~overlay ();

@@ -267,7 +269,7 @@ struct overlay {
 };

 overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
-: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false)
+: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0)
 {
   if (border == 2)
     {
@@ -316,7 +318,6 @@ overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle
     }

   show ();
-  THIS->want_refresh = 1;
 }

 overlay::~overlay ()
@@ -331,45 +332,46 @@ overlay::~overlay ()

   delete [] text;
   delete [] rend;
-
-  THIS->want_refresh = 1;
 }

 void
 overlay::show ()
 {
-  if (visible)
+  if (overlay_av)
     return;

-  visible = true;
+  overlay_av = (AV *)SvREFCNT_inc (SvRV (
+        *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
+     ));
+  av_push (overlay_av, newSViv ((long)this));

-  AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
-  av_push (av, newSViv ((long)this));
+  THIS->want_refresh = 1;
 }

 void
 overlay::hide ()
 {
-  if (!visible)
+  if (!overlay_av)
     return;

-  visible = false;
-
-  AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
-
   int i;

-  for (i = AvFILL (av); i >= 0; i--)
-    if (SvIV (*av_fetch (av, i, 1)) == (long)this)
+  for (i = AvFILL (overlay_av); i >= 0; i--)
+    if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
       {
-        av_delete (av, i, G_DISCARD);
+        av_delete (overlay_av, i, G_DISCARD);
         break;
       }

-  for (; i < AvFILL (av); i++)
-    av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
+  for (; i < AvFILL (overlay_av); i++)
+    av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
+
+  av_pop (overlay_av);

-  av_pop (av);
+  SvREFCNT_dec (overlay_av);
+  overlay_av = 0;
+
+  THIS->want_refresh = 1;
 }

 void overlay::swap ()
@@ -1611,8 +1613,8 @@ rxvt_term::cur_charset ()
 	OUTPUT:
         RETVAL

-#void
-#rxvt_term::selection_clear ()
+void
+rxvt_term::selection_clear ()

 void
 rxvt_term::selection_make (Time eventtime, bool rect = false)

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

-- Response ended

-- Page fetched on Sun Jun 2 13:04:53 2024