5 use Glib
qw(TRUE FALSE);
9 my $widget = Glib
::Object
->new_from_pointer( get_info
( "win_ptr" ), 0 );
12 my @containers = ($widget);
14 while( @containers ) {
15 my $container = shift @containers;
17 for my $child ( $container->get_children ) {
18 if( $child->get( "name" ) eq 'xchat-inputbox' ) {
21 } elsif( $child->isa( "Gtk2::Container" ) ) {
22 push @containers, $child;
33 while( $widget->parent ) {
34 if( $widget->parent->isa( "Gtk2::HBox" ) ) {
35 return $widget->parent;
37 $widget = $widget->parent;
42 my $input_box = get_inputbox
();
45 my $hbox = get_hbox
( $input_box );
47 my $label = Gtk2
::Label
->new();
48 $label->set_alignment( 0.5, ($label->get_alignment)[1] );
49 $hbox->pack_end( $label, 0, 0, 5 );
52 my $update_label = sub {
53 my $ctx_type = context_info
->{"type"};
55 if( $ctx_type == 2 || $ctx_type == 3 ) {
56 my $count = length get_info
"inputbox";
57 $label->set_text( $count ?
$count : "" );
59 $label->set_text( "" );
66 hook_print
( "Key Press", $update_label );
67 hook_print
( "Focus Tab", $update_label );
68 hook_print
( "Focus Window", $update_label );
71 $label->set_text( "" );
77 my $buffer = $input_box->get_buffer;
78 my $handler = sub { $update_label->(); return TRUE
};
80 if( $buffer->isa( "Gtk2::TextBuffer" ) ) {
81 push @handlers, $buffer->signal_connect( "changed", $handler );
82 } elsif( $buffer->isa( "Gtk2::EntryBuffer" ) ) {
84 $buffer->signal_connect( "deleted-text", $handler );
85 $buffer->signal_connect( "inserted-text", $handler );
88 register
( "Character Counter", "1.0.0",
89 "Display the number of characters in the inputbox",
91 $hbox->remove( $label );
92 $buffer->signal_handler_disconnect( $_ ) for @handlers;
96 prnt
"Counldn't find hbox";
100 prnt
"Couldn't fint input box";