--- rxvt-unicode/src/perl/macosx-clipboard 2006/12/07 20:59:59 1.1 +++ rxvt-unicode/src/perl/macosx-clipboard 2012/09/23 08:03:44 1.9 @@ -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 @@ -24,57 +23,45 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ---------------------------------------------------------------------- -# Usage: +=head1 NAME -# URxvt.perl-ext-common: macosx-clipboard -# URxvt.keysym.M-c: perl:macosx-clipboard:copy -# URxvt.keysym.M-v: perl:macosx-clipboard:paste - -use Fcntl (); -use Foundation; -use locale; -use utf8; +macosx-clipboard - Mac OS X clipboard support -our($appkit, $pasteboard); +=head1 SYNOPSIS -sub copy { - my ($self) = @_; + urxvt -pe macosx-clipboard - $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); - $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); - () -} +=head1 DESCRIPTION -sub paste { +This extension implements commands to interact with the Mac OS X +clipboard and requires the C module. It is used like +this: + + URxvt.keysym.M-c: perl:macosx-clipboard:copy + URxvt.keysym.M-v: perl:macosx-clipboard:paste + +=cut + +use Mac::Pasteboard; + +my $pasteboard = new Mac::Pasteboard; + +sub copy { 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)); - } + $pasteboard->clear; + $pasteboard->copy ($self->selection); + () } -sub on_start { +sub paste { my ($self) = @_; - $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; - } + my $str = $pasteboard->paste; + utf8::decode $str; + $self->tt_write ($self->locale_encode ($str)); - $pasteboard = NSPasteboard->generalPasteboard; () } @@ -88,6 +75,7 @@ if ($cmd eq "macosx-clipboard:paste") { $self->paste; } + () }