ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/macosx-clipboard
Revision: 1.1
Committed: Thu Dec 7 20:59:59 2006 UTC (17 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-8_1, rel-8_4, rel-8_2, rel-8_3
Log Message:
*** empty log message ***

File Contents

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