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

Comparing rxvt-unicode/src/perl/urxvt-popup (file contents):
Revision 1.9 by root, Sun Jan 8 00:41:20 2006 UTC vs.
Revision 1.17 by sf-exg, Mon Jun 11 05:03:46 2012 UTC

1#! perl 1#! perl
2 2
3# this extension implements popup-menu functionality for urxvt. it works 3# this extension implements popup-menu functionality for urxvt. it works
4# together with the urxvt::popup class. 4# together with the urxvt::popup class - "no user serviceable parts inside".
5 5
6sub refresh { 6sub refresh {
7 my ($self) = @_; 7 my ($self) = @_;
8 8
9 my $cmd = "\x1b[H"; 9 my $cmd = "\x1b[H";
10 10
11 my $row = 1; 11 my $row = 1;
12 for my $item (@{ $self->{data}{item} }) { 12 for my $item (@{ $self->{data}{item} }) {
13 my $rend = "\x1b[30;47m"; 13 my $rend = "normal";
14 14
15 if ($row == $self->{hover}) { 15 if ($row == $self->{hover}) {
16 $rend = $self->{press} ? "\x1b[m" : "\x1b[30;46m"; 16 $rend = $self->{press} ? "active" : "hover";
17 } 17 }
18 18
19 $cmd .= "$rend\x1b[K"; 19 $cmd .= "$item->{rend}{$rend}\x1b[K";
20 $cmd .= $self->locale_encode ($item->{render}->($item)); 20 $cmd .= $self->locale_encode ($item->{render}->($item));
21 $cmd .= "\015\012"; 21 $cmd .= "\015\012";
22 22
23 $row++; 23 $row++;
24 } 24 }
51} 51}
52 52
53sub on_button_release { 53sub on_button_release {
54 my ($self, $event) = @_; 54 my ($self, $event) = @_;
55 55
56 if ($event->{button} == $self->{data}{event}{button}) {
57 $self->ungrab;
58 $self->destroy;
59 }
60
61 $self->{press}[$event->{button}] = 0; 56 $self->{press}[$event->{button}] = 0;
62 57
63 my ($row, $col) = ($event->{row}, $event->{col}); 58 my ($row, $col) = ($event->{row}, $event->{col});
64 if ($col >= 0 && $col < $self->ncol 59 if ($col >= 0 && $col < $self->ncol
65 && $row >= 0 && $row < @{ $self->{data}{item} }) { 60 && $row >= 0 && $row < @{ $self->{data}{item} }) {
66 $self->{data}{item}[$row]{activate}->($event); 61 my $item = $self->{data}{item}[$row];
62 $item->{activate}->($event, $item);
67 } 63 }
68 64
69 $self->refresh; 65 $self->refresh;
66
67 if ($event->{button} == $self->{data}{event}{button}) {
68 $self->ungrab;
69 $self->destroy;
70 }
70 71
71 1 72 1
72} 73}
73 74
74sub on_focus_out { 75sub on_focus_out {
86 my $data = $self->{data} = $urxvt::popup::self; 87 my $data = $self->{data} = $urxvt::popup::self;
87 88
88 $_->{width} = $self->strwidth ($_->{text}) 89 $_->{width} = $self->strwidth ($_->{text})
89 for @{ $data->{item} }; 90 for @{ $data->{item} };
90 91
92 $self->resource (title => "URxvt Popup Menu");
93 $self->resource (name => "URxvt.popup");
94
91 $self->resource ($_ => $data->{term}->resource ($_)) 95 $self->resource ($_ => $data->{term}->resource ($_))
92 for qw(font boldFont italicFont boldItalicFont color+0 color+1); 96 for qw(font boldFont italicFont boldItalicFont color+0 color+1);
93 97
94 my $width = List::Util::max map $_->{width}, @{ $data->{item} }; 98 my $width = List::Util::max map $_->{width}, @{ $data->{item} };
95 my $height = @{ $data->{item} }; 99 my $height = @{ $data->{item} };
97 my $pos = ""; 101 my $pos = "";
98 102
99 if ($data->{event}) { 103 if ($data->{event}) {
100 my $x = int List::Util::max 0, $data->{event}{x_root} - $width * $data->{term}->fwidth * 0.5; 104 my $x = int List::Util::max 0, $data->{event}{x_root} - $width * $data->{term}->fwidth * 0.5;
101 my $y = int List::Util::max 0, $data->{event}{y_root} - $data->{term}->fheight * 0.5; 105 my $y = int List::Util::max 0, $data->{event}{y_root} - $data->{term}->fheight * 0.5;
102
103 $pos = "+$x+$y"; 106 $pos = "+$x+$y";
104 } 107 }
105 108
106 $self->resource (geometry => "${width}x${height}$pos"); 109 $self->resource (geometry => "${width}x${height}$pos");
110
111 $self->{term}{urxvt_popup_init_done} = 1;
107 112
108 () 113 ()
109} 114}
110 115
111sub on_start { 116sub on_start {
112 my ($self) = @_; 117 my ($self) = @_;
113 118
119 $self->cmd_parse ("\x1b[?25l\x1b[?7l");
120 $self->refresh;
121
114 # might fail, but try anyways 122 # might fail, but try anyways
115 $self->grab ($self->{data}{event}{time}, 1) 123 $self->grab ($self->{data}{event}{time}, 1)
116 and $self->allow_events_async; 124 and $self->allow_events_async;
117 125
118 on_button_press $self, $self->{data}{event} if $self->{data}{event}{button}; 126 on_button_press $self, $self->{data}{event} if $self->{data}{event}{button};
119
120 $self->cmd_parse ("\x1b[?25l\x1b[?7l");
121 refresh $self;
122 127
123 () 128 ()
124} 129}
125 130
126sub on_map_notify { 131sub on_map_notify {
130 $self->grab ($self->{data}{event}{time}, 1) 135 $self->grab ($self->{data}{event}{time}, 1)
131 and $self->allow_events_async; 136 and $self->allow_events_async;
132} 137}
133 138
134 139
135
136
137
138

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines