1 | #! perl -w |
1 | #! perl -w |
2 | |
|
|
3 | # http://triplefusion.net/system/macosx-clipboard |
|
|
4 | |
2 | |
5 | # ---------------------------------------------------------------------- |
3 | # ---------------------------------------------------------------------- |
6 | # File: macosx-clipboard-native |
4 | # File: macosx-clipboard-native |
7 | # ---------------------------------------------------------------------- |
5 | # ---------------------------------------------------------------------- |
8 | # |
6 | # |
… | |
… | |
28 | |
26 | |
29 | # URxvt.perl-ext-common: macosx-clipboard |
27 | # URxvt.perl-ext-common: macosx-clipboard |
30 | # URxvt.keysym.M-c: perl:macosx-clipboard:copy |
28 | # URxvt.keysym.M-c: perl:macosx-clipboard:copy |
31 | # URxvt.keysym.M-v: perl:macosx-clipboard:paste |
29 | # URxvt.keysym.M-v: perl:macosx-clipboard:paste |
32 | |
30 | |
33 | use Fcntl (); |
|
|
34 | use Foundation; |
31 | use Foundation; |
35 | |
32 | |
36 | our $appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); |
33 | my $appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); |
37 | $appkit->load if $appkit; |
34 | $appkit->load if $appkit; |
38 | |
35 | |
39 | if ($appkit->isLoaded) { |
36 | if ($appkit->isLoaded) { |
40 | no strict 'refs'; |
37 | no strict 'refs'; |
41 | for my $class (qw(NSPasteboard)) { |
38 | for my $class (qw(NSPasteboard)) { |
… | |
… | |
43 | } |
40 | } |
44 | } else { |
41 | } else { |
45 | undef $appkit; |
42 | undef $appkit; |
46 | } |
43 | } |
47 | |
44 | |
48 | our $pasteboard = NSPasteboard->generalPasteboard; |
45 | my $pasteboard = NSPasteboard->generalPasteboard; |
49 | |
46 | |
50 | sub copy { |
47 | sub copy { |
51 | my ($self) = @_; |
48 | my ($self) = @_; |
52 | |
49 | |
53 | $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); |
50 | $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); |
… | |
… | |
56 | () |
53 | () |
57 | } |
54 | } |
58 | |
55 | |
59 | sub paste { |
56 | sub paste { |
60 | my ($self) = @_; |
57 | my ($self) = @_; |
61 | my ($type, $str); |
|
|
62 | |
58 | |
63 | $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); |
59 | my $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); |
64 | if ($type->isEqual_('NSStringPboardType')){ |
60 | if ($type->isEqual_('NSStringPboardType')) { |
65 | $str = $pasteboard->stringForType_($type)->UTF8String; |
61 | my $str = $pasteboard->stringForType_($type)->UTF8String; |
66 | $str =~ tr/\n/\r/; |
62 | $str =~ tr/\n/\r/; |
67 | utf8::decode($str); |
63 | utf8::decode($str); |
68 | $self->tt_write($self->locale_encode($str)); |
64 | $self->tt_write($self->locale_encode($str)); |
69 | } |
65 | } |
70 | |
66 | |