~ubuntu-branches/ubuntu/dapper/rxvt-unicode/dapper

« back to all changes in this revision

Viewing changes to src/perl/urxvt-popup

  • Committer: Bazaar Package Importer
  • Author(s): Eduard Bloch
  • Date: 2006-01-16 16:51:28 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116165128-dmz1wi3x3e17gu43
Tags: 7.0-1
* New upstream release
  + autodetection of (incorrect) Latin1 in pure UTF-8 environment works
    again (closes: #347718)
* removed the font name preset, automatic selection works acceptably well

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! perl
 
2
 
 
3
# this extension implements popup-menu functionality for urxvt. it works
 
4
# together with the urxvt::popup class.
 
5
 
 
6
sub refresh {
 
7
   my ($self) = @_;
 
8
 
 
9
   my $cmd = "\x1b[H";
 
10
 
 
11
   my $row = 1;
 
12
   for my $item (@{ $self->{data}{item} }) {
 
13
      my $rend = "normal";
 
14
 
 
15
      if ($row == $self->{hover}) {
 
16
         $rend = $self->{press} ? "active" : "hover";
 
17
      }
 
18
 
 
19
      $cmd .= "$item->{rend}{$rend}\x1b[K";
 
20
      $cmd .= $self->locale_encode ($item->{render}->($item));
 
21
      $cmd .= "\015\012";
 
22
 
 
23
      $row++;
 
24
   }
 
25
 
 
26
   $self->cmd_parse (substr $cmd, 0, -2);
 
27
}
 
28
 
 
29
sub on_motion_notify {
 
30
   my ($self, $event) = @_;
 
31
 
 
32
   delete $self->{hover};
 
33
 
 
34
   my ($row, $col) = ($event->{row}, $event->{col});
 
35
   if ($col >= 0 && $col < $self->ncol
 
36
       && $row >= 0 && $row < @{ $self->{data}{item} }) {
 
37
      $self->{hover} = $event->{row} + 1;
 
38
   }
 
39
   $self->refresh;
 
40
 
 
41
   1
 
42
}
 
43
 
 
44
sub on_button_press {
 
45
   my ($self, $event) = @_;
 
46
 
 
47
   $self->{press}[$event->{button}] = 1;
 
48
   $self->refresh;
 
49
 
 
50
   1
 
51
}
 
52
 
 
53
sub on_button_release {
 
54
   my ($self, $event) = @_;
 
55
 
 
56
   if ($event->{button} == $self->{data}{event}{button}) {
 
57
      $self->ungrab;
 
58
      $self->destroy;
 
59
   }
 
60
 
 
61
   $self->{press}[$event->{button}] = 0;
 
62
 
 
63
   my ($row, $col) = ($event->{row}, $event->{col});
 
64
   if ($col >= 0 && $col < $self->ncol
 
65
       && $row >= 0 && $row < @{ $self->{data}{item} }) {
 
66
      my $item = $self->{data}{item}[$row];
 
67
      $item->{activate}->($event, $item);
 
68
   }
 
69
 
 
70
   $self->refresh;
 
71
 
 
72
   1
 
73
}
 
74
 
 
75
sub on_focus_out {
 
76
   my ($self) = @_;
 
77
 
 
78
   delete $self->{hover};
 
79
   $self->refresh;
 
80
 
 
81
   ()
 
82
}
 
83
 
 
84
sub on_init {
 
85
   my ($self) = @_;
 
86
 
 
87
   my $data = $self->{data} = $urxvt::popup::self;
 
88
 
 
89
   $_->{width} = $self->strwidth ($_->{text})
 
90
      for @{ $data->{item} };
 
91
 
 
92
   $self->resource ($_ => $data->{term}->resource ($_))
 
93
      for qw(font boldFont italicFont boldItalicFont color+0 color+1);
 
94
 
 
95
   my $width  = List::Util::max map $_->{width}, @{ $data->{item} };
 
96
   my $height = @{ $data->{item} };
 
97
 
 
98
   my $pos = "";
 
99
 
 
100
   if ($data->{event}) {
 
101
      my $x = int List::Util::max 0, $data->{event}{x_root} - $width * $data->{term}->fwidth  * 0.5;
 
102
      my $y = int List::Util::max 0, $data->{event}{y_root} -          $data->{term}->fheight * 0.5;
 
103
      $pos = "+$x+$y";
 
104
   }
 
105
 
 
106
   $self->resource (geometry => "${width}x${height}$pos");
 
107
 
 
108
   ()
 
109
}
 
110
 
 
111
sub on_start {
 
112
   my ($self) = @_;
 
113
 
 
114
   $self->cmd_parse ("\x1b[?25l\x1b[?7l");
 
115
   $self->refresh;
 
116
 
 
117
   # might fail, but try anyways
 
118
   $self->grab ($self->{data}{event}{time}, 1)
 
119
      and $self->allow_events_async;
 
120
 
 
121
   on_button_press $self, $self->{data}{event} if $self->{data}{event}{button};
 
122
 
 
123
   ()
 
124
}
 
125
 
 
126
sub on_map_notify {
 
127
   my ($self, $event) = @_;
 
128
 
 
129
   # should definitely not fail
 
130
   $self->grab ($self->{data}{event}{time}, 1)
 
131
      and $self->allow_events_async;
 
132
}
 
133
 
 
134