# scrollbar.pl by ArZa : A scrollbar # This program is free software: you can modify/redistribute it under the terms of # GNU General Public License by Free Software Foundation, either version 3 or later # which you can get from . # This program is distributed in the hope that it will be useful, but without any warranty. weechat::register("scrollbar", "ArZa ", "0.1", "GPL3", "A scrollbar", "", ""); weechat::bar_item_new("scrollbar", "sbf", "") unless weechat::bar_item_search("scrollbar"); weechat::bar_new("scrollbar", "off", 0, "window", "", "right", "horizontal", "vertical", 1, 1, "default", "default", "default", "off", "scrollbar"); weechat::hook_command("sbscroll", "", "", "", "", "sbscroll", ""); weechat::hook_signal("window_scrolled", "scroll", ""); weechat::hook_print("", "", "", 0, "print", ""); my %keys=('@item(scrollbar):button1-gesture-*' => '/sbscroll ${_y2}-${_y}'); weechat::key_bind('mouse', \%keys); weechat::bar_item_update("scrollbar"); sub sbf { my ($item, $window) = ($_[1], $_[2]); my $buffer=weechat::window_get_pointer($window, "buffer"); my $infolist=weechat::infolist_get("buffer_lines", $buffer, ""); my $full=1; $full++ while weechat::infolist_next $infolist; weechat::infolist_free($infolist); #$infolist=weechat::infolist_get("bar_window", "", ""); #while(weechat::infolist_next($infolist)){ # weechat::print("", weechat::infolist_integer($infolist, "height"));# if weechat::infolist_string($infolist, "") eq "scrollbar"; #} #weechat::infolist_free($infolist); my $screen=weechat::window_get_integer($window, "win_height")-3; my $after=weechat::window_get_integer($window, "lines_after"); my $before=$full-$after-$screen; $before=0 if $before<0 or weechat::window_get_integer($window, "first_line_displayed"); my $p1=int($before/$full*$screen); my $p2=int($screen/$full*$screen+1); my $p3=$screen-$p1-$p2; $p2=$screen if $screen>$full; my $str=""; for my $i (1..$p1){ $str.=weechat::color(",234")." \n"; } for my $i (1..$p2){ $str.=weechat::color("88,52")."│\n"; } for my $i (1..$p3){ $str.=weechat::color(",234")." \n"; } return $str; } sub scroll { weechat::bar_item_update("scrollbar"); } sub sbscroll { my $buffer=weechat::current_buffer(); my $window=weechat::current_window(); my $screen=weechat::window_get_integer($window, "win_height")-3; my $infolist=weechat::infolist_get("buffer_lines", $buffer, ""); my $full=0; $full++ while weechat::infolist_next $infolist; weechat::infolist_free($infolist); my $scroll=int(eval($_[2])*($full/$screen)); $scroll="+".$scroll if $scroll>0; weechat::command($_[1], "/window scroll $scroll"); } sub print { weechat::bar_item_update("scrollbar") if $_[1] eq weechat::current_buffer(); }