]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - weechat/perl/buffers.pl
Update the stuff
[rbdr/dotfiles] / weechat / perl / buffers.pl
... / ...
CommitLineData
1#
2# Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org>
3# Copyright (C) 2011-2012 Nils G <weechatter@arcor.de>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17#
18#
19# Display sidebar with list of buffers.
20#
21# History:
22#
23# 2012-06-02, nils_2 <weechatter@arcor.de>:
24# v3.5: add values "server|channel|private|all|keepserver|none" to option "hide_merged_buffers" (suggested by dominikh).
25# 2012-05-25, nils_2 <weechatter@arcor.de>:
26# v3.4: add new option "show_lag".
27# 2012-04-07, Sebastien Helleu <flashcode@flashtux.org>:
28# v3.3: fix truncation of wide chars in buffer name (option name_size_max) (bug #36034)
29# 2012-03-15, nils_2 <weechatter@arcor.de>:
30# v3.2: add new option "detach"(weechat >= 0.3.8)
31# add new option "immune_detach_buffers" (requested by Mkaysi)
32# add new function buffers_whitelist add|del|reset (suggested by FiXato)
33# add new function buffers_detach add|del|reset
34# 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
35# v3.1: fix reload of config file
36# 2012-01-29, nils_2 <weechatter@arcor.de>:
37# v3.0: fix: buffers did not update directly during window_switch (reported by FiXato)
38# 2012-01-29, nils_2 <weechatter@arcor.de>:
39# v2.9: add options "name_size_max" and "name_crop_suffix"
40# 2012-01-08, nils_2 <weechatter@arcor.de>:
41# v2.8: fix indenting for option "show_number off"
42# fix unset of buffer activity in hotlist when buffer was moved with mouse
43# add buffer with free content and core buffer sorted first (suggested by nyuszika7h)
44# add options queries_default_fg/bg and queries_message_fg/bg (suggested by FiXato)
45# add clicking with left button on current buffer will do a jump_previously_visited_buffer (suggested by FiXato)
46# add clicking with right button on current buffer will do a jump_next_visited_buffer
47# add additional informations in help texts
48# add default_fg and default_bg for whitelist channels
49# internal changes (script is now 3Kb smaller)
50# 2012-01-04, Sebastien Helleu <flashcode@flashtux.org>:
51# v2.7: fix regex lookup in whitelist buffers list
52# 2011-12-04, nils_2 <weechatter@arcor.de>:
53# v2.6: add own config file (buffers.conf)
54# add new behavior for indenting (under_name)
55# add new option to set different color for server buffers and buffers with free content
56# 2011-10-30, nils_2 <weechatter@arcor.de>:
57# v2.5: add new options "show_number_char" and "color_number_char",
58# add help-description for options
59# 2011-08-24, Sebastien Helleu <flashcode@flashtux.org>:
60# v2.4: add mouse support
61# 2011-06-06, nils_2 <weechatter@arcor.de>:
62# v2.3: added: missed option "color_whitelist_default"
63# 2011-03-23, Sebastien Helleu <flashcode@flashtux.org>:
64# v2.2: fix color of nick prefix with WeeChat >= 0.3.5
65# 2011-02-13, nils_2 <weechatter@arcor.de>:
66# v2.1: add options "color_whitelist_*"
67# 2010-10-05, Sebastien Helleu <flashcode@flashtux.org>:
68# v2.0: add options "sort" and "show_number"
69# 2010-04-12, Sebastien Helleu <flashcode@flashtux.org>:
70# v1.9: replace call to log() by length() to align buffer numbers
71# 2010-04-02, Sebastien Helleu <flashcode@flashtux.org>:
72# v1.8: fix bug with background color and option indenting_number
73# 2010-04-02, Helios <helios@efemes.de>:
74# v1.7: add indenting_number option
75# 2010-02-25, m4v <lambdae2@gmail.com>:
76# v1.6: add option to hide empty prefixes
77# 2010-02-12, Sebastien Helleu <flashcode@flashtux.org>:
78# v1.5: add optional nick prefix for buffers like IRC channels
79# 2009-09-30, Sebastien Helleu <flashcode@flashtux.org>:
80# v1.4: remove spaces for indenting when bar position is top/bottom
81# 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
82# v1.3: add option "hide_merged_buffers"
83# 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
84# v1.2: improve display with merged buffers
85# 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
86# v1.1: sync with last API changes
87# 2009-02-21, Sebastien Helleu <flashcode@flashtux.org>:
88# v1.0: remove timer used to update bar item first time (not needed any more)
89# 2009-02-17, Sebastien Helleu <flashcode@flashtux.org>:
90# v0.9: fix bug with indenting of private buffers
91# 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
92# v0.8: update syntax for command /set (comments)
93# 2008-10-20, Jiri Golembiovsky <golemj@gmail.com>:
94# v0.7: add indenting option
95# 2008-10-01, Sebastien Helleu <flashcode@flashtux.org>:
96# v0.6: add default color for buffers, and color for current active buffer
97# 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
98# v0.5: fix color for "low" level entry in hotlist
99# 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
100# v0.4: rename option "show_category" to "short_names",
101# remove option "color_slash"
102# 2008-09-15, Sebastien Helleu <flashcode@flashtux.org>:
103# v0.3: fix bug with priority in hotlist (var not defined)
104# 2008-09-02, Sebastien Helleu <flashcode@flashtux.org>:
105# v0.2: add color for buffers with activity and config options for
106# colors, add config option to display/hide categories
107# 2008-03-15, Sebastien Helleu <flashcode@flashtux.org>:
108# v0.1: script creation
109#
110# Help about settings:
111# display all settings for script (or use iset.pl script to change settings):
112# /set buffers*
113# show help text for option buffers.look.whitelist_buffers:
114# /help buffers.look.whitelist_buffers
115#
116# Mouse-support (standard key bindings):
117# left mouse-button:
118# - click on a buffer to switch to selected buffer
119# - click on current buffer will do action jump_previously_visited_buffer
120# - drag a buffer and drop it on another position will move the buffer to position
121# right mouse-button:
122# - click on current buffer will do action jump_next_visited_buffer
123# - moving buffer to the left/right will close buffer.
124#
125
126use strict;
127use Encode qw( decode encode );
128# -------------------------------[ internal ]-------------------------------------
129my $version = "3.5";
130
131my $BUFFERS_CONFIG_FILE_NAME = "buffers";
132my $buffers_config_file;
133my $cmd_buffers_whitelist= "buffers_whitelist";
134my $cmd_buffers_detach = "buffers_detach";
135
136my %mouse_keys = ("\@item(buffers):button1*" => "hsignal:buffers_mouse", # catch all left mouse button gestures
137 "\@item(buffers):button2" => "hsignal:buffers_mouse"); # catch right mouse button
138my %options;
139my %hotlist_level = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
140my @whitelist_buffers = ();
141my @immune_detach_buffers= ();
142my @buffers_focus = ();
143my %buffers_timer = ();
144my %Hooks = ();
145
146# --------------------------------[ init ]--------------------------------------
147weechat::register("buffers", "Sebastien Helleu <flashcode\@flashtux.org>", $version,
148 "GPL3", "Sidebar with list of buffers", "", "");
149my $weechat_version = weechat::info_get("version_number", "") || 0;
150
151buffers_config_init();
152buffers_config_read();
153
154weechat::bar_item_new("buffers", "build_buffers", "");
155weechat::bar_new("buffers", "0", "0", "root", "", "left", "horizontal",
156 "vertical", "0", "0", "default", "default", "default", "1",
157 "buffers");
158weechat::hook_signal("buffer_*", "buffers_signal_buffer", "");
159weechat::hook_signal("window_switch", "buffers_signal_buffer", "");
160weechat::hook_signal("hotlist_*", "buffers_signal_hotlist", "");
161weechat::bar_item_update("buffers");
162if ($weechat_version >= 0x00030600)
163{
164 weechat::hook_focus("buffers", "buffers_focus_buffers", "");
165 weechat::hook_hsignal("buffers_mouse", "buffers_hsignal_mouse", "");
166 weechat::key_bind("mouse", \%mouse_keys);
167}
168
169weechat::hook_command( $cmd_buffers_whitelist,
170 "add/del current buffer to/from buffers whitelist",
171 "[add] || [del] || [reset]",
172
173 " add: add current buffer in configuration file\n".
174 " del: delete current buffer from configuration file\n".
175 "reset: reset all buffers from configuration file (no confirmation!)\n\n".
176 "Examples:\n".
177 "/$cmd_buffers_whitelist add\n",
178 "add %-||".
179 "del %-||".
180 "reset %-",
181 "buffers_cmd_whitelist", "");
182
183weechat::hook_command( $cmd_buffers_detach,
184 "add/del current buffer to/from buffers detach",
185 "[add] || [del] || [reset]",
186
187 " add: add current buffer in configuration file\n".
188 " del: delete current buffer from configuration file\n".
189 "reset: reset all buffers from configuration file (no confirmation!)\n\n".
190 "Examples:\n".
191 "/$cmd_buffers_detach add\n",
192 "add %-||".
193 "del %-||".
194 "reset %-",
195 "buffers_cmd_detach", "");
196
197if ($weechat_version >= 0x00030800)
198{
199 weechat::hook_config("buffers.look.detach", "hook_timer_detach", "");
200}
201
202 weechat::hook_config("buffers.look.show_lag", "hook_timer_lag", "");
203
204# -------------------------------- [ command ] --------------------------------
205sub buffers_cmd_whitelist
206{
207my ( $data, $buffer, $args ) = @_;
208 $args = lc($args);
209 my $buffers_whitelist = weechat::config_string( weechat::config_get("buffers.look.whitelist_buffers") );
210 return weechat::WEECHAT_RC_OK if ( $buffers_whitelist eq "" and $args eq "del" or $buffers_whitelist eq "" and $args eq "reset" );
211 my @buffers_list = split( /,/, $buffers_whitelist );
212 # get buffers name
213 my $infolist = weechat::infolist_get("buffer", weechat::current_buffer(), "");
214 weechat::infolist_next($infolist);
215 my $buffers_name = weechat::infolist_string($infolist, "name");
216 weechat::infolist_free($infolist);
217 return weechat::WEECHAT_RC_OK if ( $buffers_name eq "" ); # should never happen
218
219 if ( $args eq "add" )
220 {
221 return weechat::WEECHAT_RC_OK if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
222 push @buffers_list,( $buffers_name );
223 my $buffers_list = &create_whitelist(\@buffers_list);
224 weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), $buffers_list,1 );
225 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" added to buffers whitelist");
226 }
227 elsif ( $args eq "del" )
228 {
229 return weechat::WEECHAT_RC_OK unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
230 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
231 my $buffers_list = &create_whitelist(\@buffers_list);
232 weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), $buffers_list,1 );
233 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" deleted from buffers whitelist");
234 }
235 elsif ( $args eq "reset" )
236 {
237 return weechat::WEECHAT_RC_OK if ( $buffers_whitelist eq "" );
238 weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), "",1 );
239 weechat::print(weechat::current_buffer(), "buffers whitelist is empty, now...");
240 }
241 return weechat::WEECHAT_RC_OK;
242}
243sub buffers_cmd_detach
244{
245my ( $data, $buffer, $args ) = @_;
246 $args = lc($args);
247 my $immune_detach_buffers = weechat::config_string( weechat::config_get("buffers.look.immune_detach_buffers") );
248 return weechat::WEECHAT_RC_OK if ( $immune_detach_buffers eq "" and $args eq "del" or $immune_detach_buffers eq "" and $args eq "reset" );
249 my @buffers_list = split( /,/, $immune_detach_buffers );
250 # get buffers name
251 my $infolist = weechat::infolist_get("buffer", weechat::current_buffer(), "");
252 weechat::infolist_next($infolist);
253 my $buffers_name = weechat::infolist_string($infolist, "name");
254 weechat::infolist_free($infolist);
255 return weechat::WEECHAT_RC_OK if ( $buffers_name eq "" ); # should never happen
256
257 if ( $args eq "add" )
258 {
259 return weechat::WEECHAT_RC_OK if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
260 push @buffers_list,( $buffers_name );
261 my $buffers_list = &create_whitelist(\@buffers_list);
262 weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), $buffers_list,1 );
263 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" added to immune detach buffers");
264 }
265 elsif ( $args eq "del" )
266 {
267 return weechat::WEECHAT_RC_OK unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
268 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
269 my $buffers_list = &create_whitelist(\@buffers_list);
270 weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), $buffers_list,1 );
271 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" deleted from immune detach buffers");
272 }
273 elsif ( $args eq "reset" )
274 {
275 return weechat::WEECHAT_RC_OK if ( $immune_detach_buffers eq "" );
276 weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), "",1 );
277 weechat::print(weechat::current_buffer(), "immune detach buffers is empty, now...");
278 }
279 return weechat::WEECHAT_RC_OK;
280}
281sub create_whitelist
282{
283 my @buffers_list = @{$_[0]};
284 my $buffers_list = "";
285 foreach (@buffers_list)
286 {
287 $buffers_list .= $_ .",";
288 }
289 chop $buffers_list; # remove last ","
290 return $buffers_list;
291}
292
293# -------------------------------- [ config ] --------------------------------
294sub hook_timer_detach
295{
296 my $detach = $_[2];
297 if ( $detach eq 0 )
298 {
299 weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
300 $Hooks{timer_detach} = "";
301 }
302 else
303 {
304 weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
305 $Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer( $options{"detach"}) * 1000, 60, 0, "buffers_signal_buffer", "");
306 }
307 weechat::bar_item_update("buffers");
308 return weechat::WEECHAT_RC_OK;
309}
310
311sub hook_timer_lag
312{
313 my $lag = $_[2];
314 if ( $lag eq 0 )
315 {
316 weechat::unhook($Hooks{timer_lag}) if $Hooks{timer_lag};
317 $Hooks{timer_lag} = "";
318 }
319 else
320 {
321 weechat::unhook($Hooks{timer_lag}) if $Hooks{timer_lag};
322 $Hooks{timer_lag} = weechat::hook_timer( weechat::config_integer(weechat::config_get("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
323 }
324 weechat::bar_item_update("buffers");
325 return weechat::WEECHAT_RC_OK;
326}
327
328sub buffers_config_read
329{
330 return weechat::config_read($buffers_config_file) if ($buffers_config_file ne "");
331}
332sub buffers_config_write
333{
334 return weechat::config_write($buffers_config_file) if ($buffers_config_file ne "");
335}
336sub buffers_config_reload_cb
337{
338 my ($data,$config_file) = ($_[0], $_[1]);
339 return weechat::config_reload($config_file)
340}
341sub buffers_config_init
342{
343 $buffers_config_file = weechat::config_new($BUFFERS_CONFIG_FILE_NAME,"buffers_config_reload_cb","");
344 return if ($buffers_config_file eq "");
345
346my %default_options_color =
347("color_current_fg" => ["current_fg", "color", "foreground color for current buffer", "", 0, 0,"lightcyan", "lightcyan", 0, "", "","buffers_signal_config", "", "", ""],
348 "color_current_bg" => ["current_bg", "color", "background color for current buffer", "", 0, 0,"red", "red", 0, "", "","buffers_signal_config", "", "", ""],
349 "color_default_fg" => ["default_fg", "color", "default foreground color for buffer name", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
350 "color_default_bg" => ["default_bg", "color", "default background color for buffer name", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
351 "color_hotlist_highlight_fg" => ["hotlist_highlight_fg", "color", "change foreground color of buffer name if a highlight messaged received","", 0, 0,"magenta", "magenta", 0, "", "","buffers_signal_config", "", "", ""],
352 "color_hotlist_highlight_bg" => ["hotlist_highlight_bg", "color", "change background color of buffer name if a highlight messaged received", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
353 "color_hotlist_low_fg" => ["hotlist_low_fg", "color", "change foreground color of buffer name if a low message received", "", 0, 0,"white", "white", 0, "", "","buffers_signal_config", "", "", ""],
354 "color_hotlist_low_bg" => ["hotlist_low_bg", "color", "change background color of buffer name if a low message received", "", 0, 0,
355 "default", "default", 0, "", "","buffers_signal_config", "", "", ""],
356 "color_hotlist_message_fg" => ["hotlist_message_fg", "color", "change foreground color of buffer name if a normal message received", "", 0, 0,"yellow", "yellow", 0, "", "","buffers_signal_config", "", "", ""],
357 "color_hotlist_message_bg" => ["hotlist_message_bg", "color", "change background color of buffer name if a normal message received", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
358 "color_hotlist_private_fg" => ["hotlist_private_fg", "color", "change foreground color of buffer name if a private message received", "", 0, 0,"lightgreen", "lightgreen", 0, "", "","buffers_signal_config", "", "", ""],
359 "color_hotlist_private_bg" => ["hotlist_private_bg", "color", "change background color of buffer name if a private message received", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
360 "color_number" => ["number", "color", "color for buffer number", "", 0, 0,"lightgreen", "lightgreen", 0, "", "","buffers_signal_config", "", "", ""],
361 "color_number_char" => ["number_char", "color", "color for buffer number char", "", 0, 0,"lightgreen", "lightgreen", 0, "", "","buffers_signal_config", "", "", ""],
362 "color_whitelist_default_fg" => ["whitelist_default_fg", "color", "default foreground color for whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
363 "color_whitelist_default_bg" => ["whitelist_default_bg", "color", "default background color for whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
364 "color_whitelist_low_fg" => ["whitelist_low_fg", "color", "low color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
365 "color_whitelist_low_bg" => ["whitelist_low_bg", "color", "low color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
366 "color_whitelist_message_fg" => ["whitelist_message_fg", "color", "message color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
367 "color_whitelist_message_bg" => ["whitelist_message_bg", "color", "message color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
368 "color_whitelist_private_fg" => ["whitelist_private_fg", "color", "private color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
369 "color_whitelist_private_bg" => ["whitelist_private_bg", "color", "private color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
370 "color_whitelist_highlight_fg" => ["whitelist_highlight_fg", "color", "highlight color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
371 "color_whitelist_highlight_bg" => ["whitelist_highlight_bg", "color", "highlight color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
372 "color_none_channel_fg" => ["none_channel_fg", "color", "foreground color for none channel buffer (e.g.: core/server/plugin buffer)", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
373 "color_none_channel_bg" => ["none_channel_bg", "color", "background color for none channel buffer (e.g.: core/server/plugin buffer)", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
374 "queries_default_fg" => ["queries_default_fg", "color", "foreground color for query buffer without message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
375 "queries_default_bg" => ["queries_default_bg", "color", "background color for query buffer without message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
376 "queries_message_fg" => ["queries_message_fg", "color", "foreground color for query buffer with unread message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
377 "queries_message_bg" => ["queries_message_bg", "color", "background color for query buffer with unread message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
378 "queries_highlight_fg" => ["queries_highlight_fg", "color", "foreground color for query buffer with unread highlight", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
379 "queries_highlight_bg" => ["queries_highlight_bg", "color", "background color for query buffer with unread highlight", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
380);
381
382my %default_options_look =
383(
384 "show_lag" => ["show_lag","boolean","show lag behind servername. This option is using \"irc.color.item_lag_finished\", \"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"","",0,0,"off","off",0,"","","buffers_signal_config","","",""],
385 "look_whitelist_buffers" => ["whitelist_buffers", "string", "comma separated list of buffers for using a differnt color scheme (for example: freenode.#weechat,freenode.#weechat-fr)", "", 0, 0,"", "", 0, "", "", "buffers_signal_config_whitelist", "", "", ""],
386 "hide_merged_buffers" => ["hide_merged_buffers", "integer", "hide merged buffers. The value determines which merged buffers should be hidden, keepserver meaning 'all except server buffers'. Other values correspondent to the buffer type.", "server|channel|private|keepserver|all|none", 0, 0,"none", "none", 0, "", "", "buffers_signal_config", "", "", ""],
387 "indenting" => ["indenting", "integer", "use indenting for channel and query buffers. This option only takes effect if bar is left/right positioned", "off|on|under_name", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
388 "indenting_number" => ["indenting_number", "boolean", "use indenting for numbers. This option only takes effect if bar is left/right positioned", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
389 "short_names" => ["short_names", "boolean", "display short names (remove text before first \".\" in buffer name)", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
390 "show_number" => ["show_number", "boolean", "display channel number in front of buffername", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
391 "show_number_char" => ["number_char", "string", "display a char after channel number", "", 0, 0,".", ".", 0, "", "", "buffers_signal_config", "", "", ""],
392 "show_prefix" => ["prefix", "boolean", "show your prefix for channel", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
393 "show_prefix_empty" => ["prefix_empty", "boolean", "use a placeholder for channels without prefix", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
394 "sort" => ["sort", "integer", "sort buffer-list by \"number\" or \"name\"", "number|name", 0, 0,"number", "number", 0, "", "", "buffers_signal_config", "", "", ""],
395 "core_to_front" => ["core_to_front", "boolean", "core buffer and buffers with free content will be listed first. Take only effect if buffer sort is by name", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
396 "jump_prev_next_visited_buffer" => ["jump_prev_next_visited_buffer", "boolean", "jump to previously or next visited buffer if you click with left/right mouse button on currently visiting buffer", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
397 "name_size_max" => ["name_size_max","integer","maximum size of buffer name. 0 means no limitation","",0,256,0,0,0, "", "", "buffers_signal_config", "", "", ""],
398 "name_crop_suffix" => ["name_crop_suffix","string","contains an optional char(s) that is appended when buffer name is shortened","",0,0,"+","+",0,"","","buffers_signal_config", "", "", ""],
399 "detach" => ["detach", "integer","detach channel from buffers list after a specific period of time (in seconds) without action (weechat ≥ 0.3.8 required)", "", 0, 31536000,0, "number", 0, "", "", "buffers_signal_config", "", "", ""],
400 "immune_detach_buffers" => ["immune_detach_buffers", "string", "comma separated list of buffers which will not get detached automatically. Good with e.g. BitlBee", "", 0, 0,"", "", 0, "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""],
401);
402 # section "color"
403 my $section_color = weechat::config_new_section($buffers_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
404 if ($section_color eq "")
405 {
406 weechat::config_free($buffers_config_file);
407 return;
408 }
409 foreach my $option (keys %default_options_color)
410 {
411 $options{$option} = weechat::config_new_option($buffers_config_file, $section_color,
412 $default_options_color{$option}[0],$default_options_color{$option}[1],$default_options_color{$option}[2],
413 $default_options_color{$option}[3],$default_options_color{$option}[4],$default_options_color{$option}[5],
414 $default_options_color{$option}[6],$default_options_color{$option}[7],$default_options_color{$option}[8],
415 $default_options_color{$option}[9],$default_options_color{$option}[10],$default_options_color{$option}[11],
416 $default_options_color{$option}[12],$default_options_color{$option}[13],$default_options_color{$option}[14]);
417 }
418
419 # section "look"
420 my $section_look = weechat::config_new_section($buffers_config_file,"look", 0, 0, "", "", "", "", "", "", "", "", "", "");
421 if ($section_look eq "")
422 {
423 weechat::config_free($buffers_config_file);
424 return;
425 }
426 foreach my $option (keys %default_options_look)
427 {
428 $options{$option} = weechat::config_new_option($buffers_config_file, $section_look,
429 $default_options_look{$option}[0],$default_options_look{$option}[1],$default_options_look{$option}[2],
430 $default_options_look{$option}[3],$default_options_look{$option}[4],$default_options_look{$option}[5],
431 $default_options_look{$option}[6],$default_options_look{$option}[7],$default_options_look{$option}[8],
432 $default_options_look{$option}[9],$default_options_look{$option}[10],$default_options_look{$option}[11],
433 $default_options_look{$option}[12],$default_options_look{$option}[13],$default_options_look{$option}[14]);
434 }
435}
436
437sub build_buffers
438{
439 my $str = "";
440
441 # get bar position (left/right/top/bottom)
442 my $position = "left";
443 my $option_position = weechat::config_get("weechat.bar.buffers.position");
444 if ($option_position ne "")
445 {
446 $position = weechat::config_string($option_position);
447 }
448
449 # read hotlist
450 my %hotlist;
451 my $infolist = weechat::infolist_get("hotlist", "", "");
452 while (weechat::infolist_next($infolist))
453 {
454 $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")} =
455 weechat::infolist_integer($infolist, "priority");
456 }
457 weechat::infolist_free($infolist);
458
459 # read buffers list
460 @buffers_focus = ();
461 my @buffers;
462 my @current1 = ();
463 my @current2 = ();
464 my $old_number = -1;
465 my $max_number = 0;
466 my $max_number_digits = 0;
467 my $active_seen = 0;
468 $infolist = weechat::infolist_get("buffer", "", "");
469 while (weechat::infolist_next($infolist))
470 {
471 my $buffer;
472 my $number = weechat::infolist_integer($infolist, "number");
473 if ($number ne $old_number)
474 {
475 @buffers = (@buffers, @current2, @current1);
476 @current1 = ();
477 @current2 = ();
478 $active_seen = 0;
479 }
480 if ($number > $max_number)
481 {
482 $max_number = $number;
483 }
484 $old_number = $number;
485 my $active = weechat::infolist_integer($infolist, "active");
486 if ($active)
487 {
488 $active_seen = 1;
489 }
490 $buffer->{"pointer"} = weechat::infolist_pointer($infolist, "pointer");
491 $buffer->{"number"} = $number;
492 $buffer->{"active"} = $active;
493 $buffer->{"current_buffer"} = weechat::infolist_integer($infolist, "current_buffer");
494 $buffer->{"plugin_name"} = weechat::infolist_string($infolist, "plugin_name");
495 $buffer->{"name"} = weechat::infolist_string($infolist, "name");
496 $buffer->{"short_name"} = weechat::infolist_string($infolist, "short_name");
497 $buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
498 $buffer->{"type"} = weechat::buffer_get_string($buffer->{"pointer"},"localvar_type");
499# weechat::print("",$buffer->{"type"});
500
501 unless( grep {$_ eq $buffer->{"name"}} @immune_detach_buffers )
502 {
503 my $detach_time = weechat::config_integer( $options{"detach"});
504 my $current_time = time();
505 # set timer for buffers with no hotlist action
506 $buffers_timer{$buffer->{"pointer"}} = $current_time
507 if ( not exists $hotlist{$buffer->{"pointer"}}
508 and $buffer->{"type"} eq "channel"
509 and not exists $buffers_timer{$buffer->{"pointer"}}
510 and $detach_time > 0);
511
512 # check for detach
513 unless ( $buffer->{"current_buffer"} eq 0
514 and not exists $hotlist{$buffer->{"pointer"}}
515 and $buffer->{"type"} eq "channel"
516 and exists $buffers_timer{$buffer->{"pointer"}}
517 and $detach_time > 0
518 and $weechat_version >= 0x00030800
519 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time )
520 {
521 if ($active_seen)
522 {
523 push(@current2, $buffer);
524 }
525 else
526 {
527 push(@current1, $buffer);
528 }
529 }
530 }
531 else
532 {
533 if ($active_seen)
534 {
535 push(@current2, $buffer);
536 }
537 else
538 {
539 push(@current1, $buffer);
540 }
541 }
542
543 } # while end
544
545
546 if ($max_number >= 1)
547 {
548 $max_number_digits = length(int($max_number));
549 }
550 @buffers = (@buffers, @current2, @current1);
551 weechat::infolist_free($infolist);
552
553 # sort buffers by number, name or shortname
554 my %sorted_buffers;
555 if (1)
556 {
557 my $number = 0;
558 for my $buffer (@buffers)
559 {
560 my $key;
561 if (weechat::config_integer( $options{"sort"} ) eq 1) # number = 0; name = 1
562 {
563 my $name = $buffer->{"name"};
564 $name = $buffer->{"short_name"} if (weechat::config_boolean( $options{"short_names"} ) eq 1);
565 if (weechat::config_integer($options{"name_size_max"}) >= 1){
566 $name = encode("UTF-8", substr(decode("UTF-8", $name), 0, weechat::config_integer($options{"name_size_max"})));
567 }
568 if ( weechat::config_boolean($options{"core_to_front"}) eq 1)
569 {
570 if ( (weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private") )
571 {
572 my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
573 if ( $type eq "" and $name ne "weechat")
574 {
575 $name = " " . $name
576 }else
577 {
578 $name = " " . $name;
579 }
580 }
581 }
582 $key = sprintf("%s%08d", lc($name), $buffer->{"number"});
583 }
584 else
585 {
586 $key = sprintf("%08d", $number);
587 }
588 $sorted_buffers{$key} = $buffer;
589 $number++;
590 }
591 }
592
593 # build string with buffers
594 $old_number = -1;
595 foreach my $key (sort keys %sorted_buffers)
596 {
597 my $buffer = $sorted_buffers{$key};
598
599 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "server" )
600 {
601 # buffer type "server" or merged with core?
602 if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
603 {
604 next;
605 }
606 }
607 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "channel" )
608 {
609 # buffer type "channel" or merged with core?
610 if ( ($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
611 {
612 next;
613 }
614 }
615 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "private" )
616 {
617 # buffer type "private" or merged with core?
618 if ( ($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
619 {
620 next;
621 }
622 }
623 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "keepserver" )
624 {
625 if ( ($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
626 {
627 next;
628 }
629 }
630 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "all" )
631 {
632 if ( ! $buffer->{"active"} )
633 {
634 next;
635 }
636 }
637
638 push(@buffers_focus, $buffer); # buffer > buffers_focus, for mouse support
639 my $color = "";
640 my $bg = "";
641
642 $color = weechat::config_color( $options{"color_default_fg"} );
643 $bg = weechat::config_color( $options{"color_default_bg"} );
644
645 if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
646 {
647 if ( (weechat::config_color($options{"queries_default_bg"})) ne "default" || (weechat::config_color($options{"queries_default_fg"})) ne "default" )
648 {
649 $bg = weechat::config_color( $options{"queries_default_bg"} );
650 $color = weechat::config_color( $options{"queries_default_fg"} );
651 }
652 }
653 # check for core and buffer with free content
654 if ( (weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private") )
655 {
656 $color = weechat::config_color( $options{"color_none_channel_fg"} );
657 $bg = weechat::config_color( $options{"color_none_channel_bg"} );
658 }
659 # default whitelist buffer?
660 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
661 {
662 $color = weechat::config_color( $options{"color_whitelist_default_fg"} );
663 $bg = weechat::config_color( $options{"color_whitelist_default_bg"} );
664 }
665
666 $color = "default" if ($color eq "");
667
668 # color for channel and query buffer
669 if (exists $hotlist{$buffer->{"pointer"}})
670 {
671 delete $buffers_timer{$buffer->{"pointer"}};
672 # check if buffer is in whitelist buffer
673 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
674 {
675 $bg = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
676 $color = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
677 }
678 elsif ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
679 {
680 # queries_default_fg/bg and buffers.color.queries_message_fg/bg
681 if ( (weechat::config_color($options{"queries_highlight_fg"})) ne "default" ||
682 (weechat::config_color($options{"queries_highlight_bg"})) ne "default" ||
683 (weechat::config_color($options{"queries_message_fg"})) ne "default" ||
684 (weechat::config_color($options{"queries_message_bg"})) ne "default" )
685 {
686 if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
687 {
688 $bg = weechat::config_color( $options{"queries_message_bg"} );
689 $color = weechat::config_color( $options{"queries_message_fg"} );
690 }
691
692 elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
693 {
694 $bg = weechat::config_color( $options{"queries_highlight_bg"} );
695 $color = weechat::config_color( $options{"queries_highlight_fg"} );
696 }
697 }else
698 {
699 $bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
700 $color = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
701 }
702 }else
703 {
704 $bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
705 $color = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
706 }
707 }
708
709 if ($buffer->{"current_buffer"})
710 {
711 $color = weechat::config_color( $options{"color_current_fg"} );
712 $bg = weechat::config_color( $options{"color_current_bg"} );
713 }
714 my $color_bg = "";
715 $color_bg = weechat::color(",".$bg) if ($bg ne "");
716
717 # create channel number for output
718 if ( weechat::config_boolean( $options{"show_number"} ) eq 1 ) # on
719 {
720 if (( weechat::config_boolean( $options{"indenting_number"} ) eq 1)
721 && (($position eq "left") || ($position eq "right")))
722 {
723 $str .= weechat::color("default").$color_bg
724 .(" " x ($max_number_digits - length(int($buffer->{"number"}))));
725 }
726 if ($old_number ne $buffer->{"number"})
727 {
728 $str .= weechat::color( weechat::config_color( $options{"color_number"} ) )
729 .$color_bg
730 .$buffer->{"number"}
731 .weechat::color("default")
732 .$color_bg
733 .weechat::color( weechat::config_color( $options{"color_number_char"} ) )
734 .weechat::config_string( $options{"show_number_char"} )
735 .$color_bg;
736 }
737 else
738 {
739 my $indent = "";
740 $indent = ((" " x length($buffer->{"number"}))." ") if (($position eq "left") || ($position eq "right"));
741 $str .= weechat::color("default")
742 .$color_bg
743 .$indent;
744 }
745 }
746
747 if (( weechat::config_integer( $options{"indenting"} ) ne 0 ) # indenting NOT off
748 && (($position eq "left") || ($position eq "right")))
749 {
750 my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
751 if (($type eq "channel") || ($type eq "private"))
752 {
753 if ( weechat::config_integer( $options{"indenting"} ) eq 1 )
754 {
755 $str .= " ";
756 }
757 elsif ( (weechat::config_integer($options{"indenting"}) eq 2) and (weechat::config_integer($options{"indenting_number"}) eq 0) ) #under_name
758 {
759 if ( weechat::config_boolean( $options{"show_number"} ) eq 0 )
760 {
761 $str .= " ";
762 }else
763 {
764 $str .= ( (" " x ( $max_number_digits - length($buffer->{"number"}) ))." " );
765 }
766 }
767 }
768 }
769 if (weechat::config_boolean( $options{"show_prefix"} ) eq 1)
770 {
771 my $nickname = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_nick");
772 if ($nickname ne "")
773 {
774 # with version >= 0.3.2, this infolist will return only nick
775 # with older versions, whole nicklist is returned for buffer, and this can be very slow
776 my $infolist_nick = weechat::infolist_get("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
777 if ($infolist_nick ne "")
778 {
779 my $version = weechat::info_get("version_number", "");
780 $version = 0 if ($version eq "");
781 while (weechat::infolist_next($infolist_nick))
782 {
783 if ((weechat::infolist_string($infolist_nick, "type") eq "nick")
784 && (weechat::infolist_string($infolist_nick, "name") eq $nickname))
785 {
786 my $prefix = weechat::infolist_string($infolist_nick, "prefix");
787 if (($prefix ne " ") or (weechat::config_boolean( $options{"show_prefix_empty"} ) eq 1))
788 {
789 # with version >= 0.3.5, it is now a color name (for older versions: option name with color)
790 if (int($version) >= 0x00030500)
791 {
792 $str .= weechat::color(weechat::infolist_string($infolist_nick, "prefix_color"));
793 }
794 else
795 {
796 $str .= weechat::color(weechat::config_color(
797 weechat::config_get(
798 weechat::infolist_string($infolist_nick, "prefix_color"))));
799 }
800 $str .= $prefix;
801 }
802 last;
803 }
804 }
805 weechat::infolist_free($infolist_nick);
806 }
807 }
808 }
809 $str .= weechat::color($color) . weechat::color(",".$bg);
810
811 if (weechat::config_boolean( $options{"short_names"} ) eq 1)
812 {
813 if (weechat::config_integer($options{"name_size_max"}) >= 1) # check max_size of buffer name
814 {
815 $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"short_name"}), 0, weechat::config_integer($options{"name_size_max"})));
816 $str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"short_name"}) > weechat::config_integer($options{"name_size_max"}));
817 }
818 else
819 {
820 $str .= $buffer->{"short_name"};
821 }
822 }
823 else
824 {
825 if (weechat::config_integer($options{"name_size_max"}) >= 1) # check max_size of buffer name
826 {
827 $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"name"},), 0, weechat::config_integer($options{"name_size_max"})));
828 $str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"name"}) > weechat::config_integer($options{"name_size_max"}));
829 }
830 else
831 {
832 $str .= $buffer->{"name"};
833 }
834 }
835 if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "server" and weechat::config_boolean($options{"show_lag"}) eq 1)
836 {
837 my $color_lag = weechat::config_color(weechat::config_get("irc.color.item_lag_finished"));
838 my $min_lag = weechat::config_integer(weechat::config_get("irc.network.lag_min_show"));
839 my $infolist_server = weechat::infolist_get("irc_server","",$buffer->{"short_name"});
840 weechat::infolist_next($infolist_server);
841 my $lag = (weechat::infolist_integer($infolist_server, "lag"));
842 weechat::infolist_free($infolist_server);
843 if ( int($lag) > int($min_lag) )
844 {
845 $lag = $lag / 1000;
846 $str .= weechat::color("default") . " (" . weechat::color($color_lag) . $lag . weechat::color("default") . ")";
847 }
848 }
849 $str .= "\n";
850 $old_number = $buffer->{"number"};
851 }
852
853 return $str;
854}
855
856sub buffers_signal_buffer
857{
858my ($data, $signal, $signal_data) = @_;
859 # check for buffer_switch and set the detach time or remove detach time
860 if ($weechat_version >= 0x00030800)
861 {
862 if ($signal eq "buffer_switch")
863 {
864 my $pointer = weechat::hdata_get_list (weechat::hdata_get("buffer"), "gui_buffer_last_displayed"); # get switched buffer
865 my $current_time = time();
866 if ( weechat::buffer_get_string($pointer, "localvar_type") eq "channel")
867 {
868 $buffers_timer{$pointer} = $current_time;
869 }
870 else
871 {
872 delete $buffers_timer{$pointer};
873 }
874 }
875 if ($signal eq "buffer_opened")
876 {
877 my $current_time = time();
878 $buffers_timer{$signal_data} = $current_time;
879 }
880 if ($signal eq "buffer_closing")
881 {
882 delete $buffers_timer{$signal_data};
883 }
884 }
885
886 weechat::bar_item_update("buffers");
887 return weechat::WEECHAT_RC_OK;
888}
889
890sub buffers_signal_hotlist
891{
892 weechat::bar_item_update("buffers");
893 return weechat::WEECHAT_RC_OK;
894}
895
896
897sub buffers_signal_config_whitelist
898{
899 @whitelist_buffers = ();
900 @whitelist_buffers = split( /,/, weechat::config_string( $options{"look_whitelist_buffers"} ) );
901 weechat::bar_item_update("buffers");
902 return weechat::WEECHAT_RC_OK;
903}
904sub buffers_signal_config_immune_detach_buffers
905{
906 @immune_detach_buffers = ();
907 @immune_detach_buffers = split( /,/, weechat::config_string( $options{"immune_detach_buffers"} ) );
908 weechat::bar_item_update("buffers");
909 return weechat::WEECHAT_RC_OK;
910}
911
912sub buffers_signal_config
913{
914 weechat::bar_item_update("buffers");
915 return weechat::WEECHAT_RC_OK;
916}
917
918# called when mouse click occured in buffers item: this callback returns buffer
919# hash according to line of item where click occured
920sub buffers_focus_buffers
921{
922 my %info = %{$_[1]};
923 my $item_line = int($info{"_bar_item_line"});
924 undef my $hash;
925 if (($info{"_bar_item_name"} eq "buffers") && ($item_line >= 0) && ($item_line <= $#buffers_focus))
926 {
927 $hash = $buffers_focus[$item_line];
928 }
929 else
930 {
931 $hash = {};
932 my $hash_focus = $buffers_focus[0];
933 foreach my $key (keys %$hash_focus)
934 {
935 $hash->{$key} = "?";
936 }
937 }
938 return $hash;
939}
940
941# called when a mouse action is done on buffers item, to execute action
942# possible actions: jump to a buffer or move buffer in list (drag & drop of buffer)
943sub buffers_hsignal_mouse
944{
945 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
946 my $current_buffer = weechat::buffer_get_integer(weechat::current_buffer(), "number"); # get current buffer number
947
948 if ( $hash{"_key"} eq "button1" ) # left mouse button
949 {
950 if ($hash{"number"} eq $hash{"number2"})
951 {
952 if ( weechat::config_integer($options{"jump_prev_next_visited_buffer"}) eq 1 )
953 {
954 if ( $current_buffer eq $hash{"number"} )
955 {
956 weechat::command("","/input jump_previously_visited_buffer");
957 }
958 else
959 {
960 weechat::command("", "/buffer ".$hash{"full_name"});
961 }
962 }
963 else
964 {
965 weechat::command("", "/buffer ".$hash{"full_name"});
966 }
967 }
968 else
969 {
970 move_buffer(%hash);
971 }
972 }
973 elsif ( ($hash{"_key"} eq "button2") && (weechat::config_integer($options{"jump_prev_next_visited_buffer"}) eq 1) )# right mouse button
974 {
975 if ( $current_buffer eq $hash{"number2"} )
976 {
977 weechat::command("","/input jump_next_visited_buffer");
978 }
979 }
980 else
981 {
982 move_buffer(%hash);
983 }
984}
985sub move_buffer
986{
987 my %hash = @_;
988 my $number2 = $hash{"number2"};
989 if ($number2 eq "?")
990 {
991 # if number 2 is not known (end of gesture outside buffers list), then set it
992 # according to mouse gesture
993 $number2 = "999999";
994 $number2 = "1" if (($hash{"_key"} =~ /gesture-left/) || ($hash{"_key"} =~ /gesture-up/));
995 }
996 my $ptrbuf = weechat::current_buffer();
997 weechat::command($hash{"pointer"}, "/buffer move ".$number2);
998}