1 |
root |
1.1 |
#! perl -w |
2 |
|
|
|
3 |
root |
1.4 |
=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 |
21 |
|
|
|
22 |
root |
1.1 |
# ---------------------------------------------------------------------- |
23 |
|
|
# File: macosx-clipboard-native |
24 |
|
|
# ---------------------------------------------------------------------- |
25 |
sf-exg |
1.2 |
# |
26 |
root |
1.1 |
# All portions of code are copyright by their respective author/s. |
27 |
|
|
# Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net> |
28 |
|
|
# |
29 |
|
|
# This program is free software; you can redistribute it and/or modify |
30 |
|
|
# it under the terms of the GNU General Public License as published by |
31 |
|
|
# the Free Software Foundation; either version 2 of the License, or |
32 |
|
|
# (at your option) any later version. |
33 |
|
|
# |
34 |
|
|
# This program is distributed in the hope that it will be useful, |
35 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
36 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
37 |
|
|
# GNU General Public License for more details. |
38 |
|
|
# |
39 |
|
|
# You should have received a copy of the GNU General Public License |
40 |
|
|
# along with this program; if not, write to the Free Software |
41 |
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
42 |
|
|
# ---------------------------------------------------------------------- |
43 |
|
|
|
44 |
|
|
# Usage: |
45 |
|
|
|
46 |
|
|
# URxvt.perl-ext-common: macosx-clipboard |
47 |
|
|
# URxvt.keysym.M-c: perl:macosx-clipboard:copy |
48 |
|
|
# URxvt.keysym.M-v: perl:macosx-clipboard:paste |
49 |
|
|
|
50 |
|
|
use Foundation; |
51 |
|
|
|
52 |
sf-exg |
1.3 |
my $appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); |
53 |
root |
1.1 |
$appkit->load if $appkit; |
54 |
|
|
|
55 |
|
|
if ($appkit->isLoaded) { |
56 |
|
|
no strict 'refs'; |
57 |
|
|
for my $class (qw(NSPasteboard)) { |
58 |
|
|
@{$class . '::ISA'} = 'PerlObjCBridge'; |
59 |
|
|
} |
60 |
|
|
} else { |
61 |
|
|
undef $appkit; |
62 |
|
|
} |
63 |
|
|
|
64 |
sf-exg |
1.3 |
my $pasteboard = NSPasteboard->generalPasteboard; |
65 |
root |
1.1 |
|
66 |
|
|
sub copy { |
67 |
|
|
my ($self) = @_; |
68 |
|
|
|
69 |
|
|
$pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); |
70 |
|
|
$pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); |
71 |
|
|
|
72 |
|
|
() |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
sub paste { |
76 |
|
|
my ($self) = @_; |
77 |
|
|
|
78 |
sf-exg |
1.3 |
my $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); |
79 |
|
|
if ($type->isEqual_('NSStringPboardType')) { |
80 |
|
|
my $str = $pasteboard->stringForType_($type)->UTF8String; |
81 |
root |
1.1 |
$str =~ tr/\n/\r/; |
82 |
|
|
utf8::decode($str); |
83 |
|
|
$self->tt_write($self->locale_encode($str)); |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
() |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
sub on_user_command { |
90 |
|
|
my ($self, $cmd) = @_; |
91 |
|
|
|
92 |
|
|
if ($cmd eq "macosx-clipboard:copy") { |
93 |
|
|
$self->copy; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
if ($cmd eq "macosx-clipboard:paste") { |
97 |
|
|
$self->paste; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
() |
101 |
|
|
} |
102 |
|
|
|