--- rxvt-unicode/src/perl/macosx-clipboard 2007/11/12 14:41:42 1.2 +++ rxvt-unicode/src/perl/macosx-clipboard 2009/05/30 08:47:07 1.3 @@ -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,46 +29,27 @@ # URxvt.keysym.M-c: perl:macosx-clipboard:copy # URxvt.keysym.M-v: perl:macosx-clipboard:paste -use Fcntl (); -use Foundation; -use locale; -use utf8; - -our($appkit, $pasteboard); - -$appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); -$appkit->load if $appkit; - -if ($appkit->isLoaded) { - no strict 'refs'; - for my $class (qw(NSPasteboard)) { - @{$class . '::ISA'} = 'PerlObjCBridge'; - } -} else { - undef $appkit; -} +use Mac::Pasteboard; -$pasteboard = NSPasteboard->generalPasteboard; +my $pasteboard = new Mac::Pasteboard; sub copy { my ($self) = @_; - $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); - $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); + $pasteboard->clear; + $pasteboard->copy ($self->selection); + () } sub paste { my ($self) = @_; - my ($type, $str); - $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)); - } + # $str = $pasteboard->stringForType_($type)->UTF8String; + my $str = $pasteboard->paste; + utf8::decode $str; + $self->tt_write ($self->locale_encode ($str)); + () } @@ -83,6 +63,7 @@ if ($cmd eq "macosx-clipboard:paste") { $self->paste; } + () }