ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/macosx-clipboard
(Generate patch)

Comparing rxvt-unicode/src/perl/macosx-clipboard (file contents):
Revision 1.2 by ayin, Mon Nov 12 14:41:42 2007 UTC vs.
Revision 1.9 by sf-exg, Sun Sep 23 08:03:44 2012 UTC

1#! perl -w 1#! perl -w
2
3# http://triplefusion.net/system/macosx-clipboard
4 2
5# ---------------------------------------------------------------------- 3# ----------------------------------------------------------------------
6# File: macosx-clipboard 4# File: macosx-clipboard
7# ---------------------------------------------------------------------- 5# ----------------------------------------------------------------------
8# 6#
9# All portions of code are copyright by their respective author/s. 7# All portions of code are copyright by their respective author/s.
10# Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net> 8# Copyright (c) 2006 Samuel Ljungkvist <salj@triplefusion.net>
9# 2009 Reza Jelveh <reza.jelveh@gmail.com>
11# 10#
12# This program is free software; you can redistribute it and/or modify 11# 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 12# 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 13# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version. 14# (at your option) any later version.
22# You should have received a copy of the GNU General Public License 21# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software 22# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25# ---------------------------------------------------------------------- 24# ----------------------------------------------------------------------
26 25
27# Usage: 26=head1 NAME
28 27
29# URxvt.perl-ext-common: macosx-clipboard 28macosx-clipboard - Mac OS X clipboard support
30# URxvt.keysym.M-c: perl:macosx-clipboard:copy
31# URxvt.keysym.M-v: perl:macosx-clipboard:paste
32 29
33use Fcntl (); 30=head1 SYNOPSIS
34use Foundation;
35use locale;
36use utf8;
37 31
38our($appkit, $pasteboard); 32 urxvt -pe macosx-clipboard
39 33
40$appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework'); 34=head1 DESCRIPTION
41$appkit->load if $appkit;
42 35
43if ($appkit->isLoaded) { 36This extension implements commands to interact with the Mac OS X
44 no strict 'refs'; 37clipboard and requires the C<Mac::Pasteboard> module. It is used like
45 for my $class (qw(NSPasteboard)) { 38this:
46 @{$class . '::ISA'} = 'PerlObjCBridge';
47 }
48} else {
49 undef $appkit;
50}
51 39
52$pasteboard = NSPasteboard->generalPasteboard; 40 URxvt.keysym.M-c: perl:macosx-clipboard:copy
41 URxvt.keysym.M-v: perl:macosx-clipboard:paste
42
43=cut
44
45use Mac::Pasteboard;
46
47my $pasteboard = new Mac::Pasteboard;
53 48
54sub copy { 49sub copy {
55 my ($self) = @_; 50 my ($self) = @_;
56 51
57 $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); 52 $pasteboard->clear;
58 $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); 53 $pasteboard->copy ($self->selection);
54
59 () 55 ()
60} 56}
61 57
62sub paste { 58sub paste {
63 my ($self) = @_; 59 my ($self) = @_;
64 my ($type, $str);
65 60
66 $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType')); 61 my $str = $pasteboard->paste;
67 if ($type->isEqual_('NSStringPboardType')){
68 $str = $pasteboard->stringForType_($type)->UTF8String;
69 $str =~ tr/\n/\r/;
70 utf8::decode($str); 62 utf8::decode $str;
71 $self->tt_write($self->locale_encode($str)); 63 $self->tt_write ($self->locale_encode ($str));
72 } 64
73 () 65 ()
74} 66}
75 67
76sub on_user_command { 68sub on_user_command {
77 my ($self, $cmd) = @_; 69 my ($self, $cmd) = @_;
81 } 73 }
82 74
83 if ($cmd eq "macosx-clipboard:paste") { 75 if ($cmd eq "macosx-clipboard:paste") {
84 $self->paste; 76 $self->paste;
85 } 77 }
78
86 () 79 ()
87} 80}
88 81

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines