--- rxvt-unicode/src/perl/macosx-clipboard 2006/12/07 20:59:59 1.1 +++ rxvt-unicode/src/perl/macosx-clipboard 2011/11/22 17:04:28 1.5 @@ -1,13 +1,12 @@ #! perl -w -# http://triplefusion.net/system/macosx-clipboard - # ---------------------------------------------------------------------- # File: macosx-clipboard # ---------------------------------------------------------------------- -# +# # All portions of code are copyright by their respective author/s. # Copyright (c) 2006 Samuel Ljungkvist +# 2009 Reza Jelveh # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,51 +29,26 @@ # URxvt.keysym.M-c: perl:macosx-clipboard:copy # URxvt.keysym.M-v: perl:macosx-clipboard:paste -use Fcntl (); -use Foundation; -use locale; -use utf8; +use Mac::Pasteboard; -our($appkit, $pasteboard); +my $pasteboard = new Mac::Pasteboard; sub copy { my ($self) = @_; - $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); - $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); - () -} - -sub paste { - my ($self) = @_; - my ($type, $str); + $pasteboard->clear; + $pasteboard->copy ($self->selection); - $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); - if ($type->isEqual_('NSStringPboardType')){ - $str = $pasteboard->stringForType_($type)->UTF8String; - $str =~ tr/\n/\r/; - utf8::decode($str); - $self->tt_write($self->locale_encode($str)); - } () } -sub on_start { +sub paste { my ($self) = @_; - $appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); - $appkit->load if $appkit; + my $str = $pasteboard->paste; + utf8::decode $str; + $self->tt_write ($self->locale_encode ($str)); - if ($appkit->isLoaded) { - no strict 'refs'; - for my $class (qw(NSPasteboard)) { - @{$class . '::ISA'} = 'PerlObjCBridge'; - } - } else { - undef $appkit; - } - - $pasteboard = NSPasteboard->generalPasteboard; () } @@ -88,6 +62,7 @@ if ($cmd eq "macosx-clipboard:paste") { $self->paste; } + () }