1 |
#! perl |
2 |
|
3 |
=head1 NAME |
4 |
|
5 |
xim-onthespot - implement XIM "on-the-spot" behaviour |
6 |
|
7 |
=head1 DESCRIPTION |
8 |
|
9 |
This perl extension implements OnTheSpot editing. It does not work |
10 |
perfectly, and some input methods don't seem to work well with OnTheSpot |
11 |
editing in general, but it seems to work at least for SCIM and kinput2. |
12 |
|
13 |
You enable it by specifying this extension and a preedit style of |
14 |
C<OnTheSpot>, i.e.: |
15 |
|
16 |
urxvt -pt OnTheSpot -pe xim-onthespot |
17 |
|
18 |
=cut |
19 |
|
20 |
# |
21 |
# problems with this implementation include |
22 |
# |
23 |
# - primary, secondary, tertiary are NO different to other highlighting styles |
24 |
# - if rend values are missing, they are not being interpolated |
25 |
# |
26 |
|
27 |
my $SIZEOF_LONG = length pack "l!", 0; |
28 |
|
29 |
sub refresh { |
30 |
my ($self) = @_; |
31 |
|
32 |
delete $self->{overlay}; |
33 |
|
34 |
my $text = $self->{text}; |
35 |
|
36 |
return unless length $text; |
37 |
|
38 |
my ($row, $col) = $self->screen_cur; |
39 |
|
40 |
my $idx = 0; |
41 |
|
42 |
my @rend = map { |
43 |
my $rstyle = $self->{caret} == $idx ? urxvt::OVERLAY_RSTYLE : $self->rstyle; |
44 |
|
45 |
$rstyle |= urxvt::RS_Uline if $_ & (urxvt::XIMUnderline | urxvt::XIMPrimary); |
46 |
$rstyle |= urxvt::RS_RVid if $_ & (urxvt::XIMReverse | urxvt::XIMSecondary); |
47 |
$rstyle |= urxvt::RS_Italic if $_ & (urxvt::XIMHighlight | urxvt::XIMTertiary); |
48 |
|
49 |
($rstyle) x ($self->strwidth (substr $text, $idx++, 1)) |
50 |
} unpack "l!*", $self->{rend}; |
51 |
|
52 |
if ($self->{caret} >= length $text) { |
53 |
$text .= " "; |
54 |
push @rend, urxvt::OVERLAY_RSTYLE; |
55 |
} |
56 |
|
57 |
$self->{overlay} = $self->overlay ($col, $row, $self->strwidth ($text), 1, $self->rstyle, 0); |
58 |
$self->{overlay}->set (0, 0, $self->special_encode ($text), \@rend); |
59 |
} |
60 |
|
61 |
sub on_xim_preedit_start { |
62 |
my ($self) = @_; |
63 |
|
64 |
() |
65 |
} |
66 |
|
67 |
sub on_xim_preedit_done { |
68 |
my ($self) = @_; |
69 |
|
70 |
delete $self->{overlay}; |
71 |
delete $self->{text}; |
72 |
delete $self->{rend}; |
73 |
|
74 |
() |
75 |
} |
76 |
|
77 |
sub on_xim_preedit_draw { |
78 |
my ($self, $caret, $pos, $len, $feedback, $chars) = @_; |
79 |
|
80 |
$self->{caret} = $caret; |
81 |
|
82 |
substr $self->{rend}, $pos * $SIZEOF_LONG, $len * $SIZEOF_LONG, $feedback; |
83 |
substr $self->{text}, $pos , $len , $chars if defined $feedback || !defined $chars; |
84 |
|
85 |
$self->refresh; |
86 |
|
87 |
() |
88 |
} |
89 |
|
90 |
|