1 | #! perl -w |
1 | #! perl -w |
2 | |
2 | |
3 | # http://triplefusion.net/system/macosx-clipboard |
3 | =head1 NAME |
|
|
4 | |
|
|
5 | macosx-clipboard-native - apple is evil |
|
|
6 | |
|
|
7 | =head1 SYNOPSIS |
|
|
8 | |
|
|
9 | urxvt -pe macosx-clipboard-native |
|
|
10 | |
|
|
11 | =head1 DESCRIPTION |
|
|
12 | |
|
|
13 | This extension does something with the clipboard on some Apple OS X |
|
|
14 | systems. Apple is a vile company that actively fights free software, |
|
|
15 | do not support them by using it! This extension is only included in |
|
|
16 | rxvt-unicode because the maintainer was too weak! Do not give in to |
|
|
17 | similar feelings! It hasn't even been changed to automatically load when |
|
|
18 | resources are used! Plus, it's totally undocumented! |
|
|
19 | |
|
|
20 | =cut |
4 | |
21 | |
5 | # ---------------------------------------------------------------------- |
22 | # ---------------------------------------------------------------------- |
6 | # File: macosx-clipboard-native |
23 | # File: macosx-clipboard-native |
7 | # ---------------------------------------------------------------------- |
24 | # ---------------------------------------------------------------------- |
8 | # |
25 | # |
9 | # All portions of code are copyright by their respective author/s. |
26 | # All portions of code are copyright by their respective author/s. |
10 | # Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net> |
27 | # Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net> |
11 | # |
28 | # |
12 | # This program is free software; you can redistribute it and/or modify |
29 | # This program is free software; you can redistribute it and/or modify |
13 | # it under the terms of the GNU General Public License as published by |
30 | # it under the terms of the GNU General Public License as published by |
… | |
… | |
28 | |
45 | |
29 | # URxvt.perl-ext-common: macosx-clipboard |
46 | # URxvt.perl-ext-common: macosx-clipboard |
30 | # URxvt.keysym.M-c: perl:macosx-clipboard:copy |
47 | # URxvt.keysym.M-c: perl:macosx-clipboard:copy |
31 | # URxvt.keysym.M-v: perl:macosx-clipboard:paste |
48 | # URxvt.keysym.M-v: perl:macosx-clipboard:paste |
32 | |
49 | |
33 | use Fcntl (); |
|
|
34 | use Foundation; |
50 | use Foundation; |
35 | |
51 | |
36 | our $appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); |
52 | my $appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); |
37 | $appkit->load if $appkit; |
53 | $appkit->load if $appkit; |
38 | |
54 | |
39 | if ($appkit->isLoaded) { |
55 | if ($appkit->isLoaded) { |
40 | no strict 'refs'; |
56 | no strict 'refs'; |
41 | for my $class (qw(NSPasteboard)) { |
57 | for my $class (qw(NSPasteboard)) { |
… | |
… | |
43 | } |
59 | } |
44 | } else { |
60 | } else { |
45 | undef $appkit; |
61 | undef $appkit; |
46 | } |
62 | } |
47 | |
63 | |
48 | our $pasteboard = NSPasteboard->generalPasteboard; |
64 | my $pasteboard = NSPasteboard->generalPasteboard; |
49 | |
65 | |
50 | sub copy { |
66 | sub copy { |
51 | my ($self) = @_; |
67 | my ($self) = @_; |
52 | |
68 | |
53 | $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); |
69 | $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); |
… | |
… | |
56 | () |
72 | () |
57 | } |
73 | } |
58 | |
74 | |
59 | sub paste { |
75 | sub paste { |
60 | my ($self) = @_; |
76 | my ($self) = @_; |
61 | my ($type, $str); |
|
|
62 | |
77 | |
63 | $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); |
78 | my $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); |
64 | if ($type->isEqual_('NSStringPboardType')){ |
79 | if ($type->isEqual_('NSStringPboardType')) { |
65 | $str = $pasteboard->stringForType_($type)->UTF8String; |
80 | my $str = $pasteboard->stringForType_($type)->UTF8String; |
66 | $str =~ tr/\n/\r/; |
81 | $str =~ tr/\n/\r/; |
67 | utf8::decode($str); |
82 | utf8::decode($str); |
68 | $self->tt_write($self->locale_encode($str)); |
83 | $self->tt_write($self->locale_encode($str)); |
69 | } |
84 | } |
70 | |
85 | |