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.4 by sf-exg, Sun Nov 20 11:09:22 2011 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.
28 27
29# URxvt.perl-ext-common: macosx-clipboard 28# URxvt.perl-ext-common: macosx-clipboard
30# URxvt.keysym.M-c: perl:macosx-clipboard:copy 29# URxvt.keysym.M-c: perl:macosx-clipboard:copy
31# URxvt.keysym.M-v: perl:macosx-clipboard:paste 30# URxvt.keysym.M-v: perl:macosx-clipboard:paste
32 31
33use Fcntl (); 32use Mac::Pasteboard;
34use Foundation;
35use locale;
36use utf8;
37 33
38our($appkit, $pasteboard); 34my $pasteboard = new Mac::Pasteboard;
39
40$appkit = NSBundle->alloc->init->initWithPath_('/System/Library/Frameworks/AppKit.framework');
41$appkit->load if $appkit;
42
43if ($appkit->isLoaded) {
44 no strict 'refs';
45 for my $class (qw(NSPasteboard)) {
46 @{$class . '::ISA'} = 'PerlObjCBridge';
47 }
48} else {
49 undef $appkit;
50}
51
52$pasteboard = NSPasteboard->generalPasteboard;
53 35
54sub copy { 36sub copy {
55 my ($self) = @_; 37 my ($self) = @_;
56 38
57 $pasteboard->declareTypes_owner_(NSArray->arrayWithObject_('NSStringPboardType'), undef); 39 $pasteboard->clear;
58 $pasteboard->setString_forType_($self->selection, 'NSStringPboardType'); 40 $pasteboard->copy ($self->selection);
41
59 () 42 ()
60} 43}
61 44
62sub paste { 45sub paste {
63 my ($self) = @_; 46 my ($self) = @_;
64 my ($type, $str);
65 47
66 $type = $pasteboard->availableTypeFromArray_(NSArray->arrayWithObject_('NSStringPboardType'));
67 if ($type->isEqual_('NSStringPboardType')){
68 $str = $pasteboard->stringForType_($type)->UTF8String; 48 # $str = $pasteboard->stringForType_($type)->UTF8String;
69 $str =~ tr/\n/\r/; 49 my $str = $pasteboard->paste;
70 utf8::decode($str); 50 utf8::decode $str;
71 $self->tt_write($self->locale_encode($str)); 51 $self->tt_write ($self->locale_encode ($str));
72 } 52
73 () 53 ()
74} 54}
75 55
76sub on_user_command { 56sub on_user_command {
77 my ($self, $cmd) = @_; 57 my ($self, $cmd) = @_;
81 } 61 }
82 62
83 if ($cmd eq "macosx-clipboard:paste") { 63 if ($cmd eq "macosx-clipboard:paste") {
84 $self->paste; 64 $self->paste;
85 } 65 }
66
86 () 67 ()
87} 68}
88 69

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines