]> git.rmz.io Git - dotfiles.git/blob - weechat/perl/buffers.pl
offlineimap: sync labels and switch to daemon mode
[dotfiles.git] / weechat / perl / buffers.pl
1 #
2 # Copyright (C) 2008-2014 Sebastien Helleu <flashcode@flashtux.org>
3 # Copyright (C) 2011-2013 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 # 2014-07-19, Sebastien Helleu <flashcode@flashtux.org>:
24 # v4.8: add support of ctrl + mouse wheel to jump to previous/next buffer,
25 # new option "mouse_wheel"
26 # 2014-06-22, Sebastien Helleu <flashcode@flashtux.org>:
27 # v4.7: fix typos in options
28 # 2014-04-05, Sebastien Helleu <flashcode@flashtux.org>:
29 # v4.6: add support of hidden buffers (WeeChat >= 0.4.4)
30 # 2014-01-01, Sebastien Helleu <flashcode@flashtux.org>:
31 # v4.5: add option "mouse_move_buffer"
32 # 2013-12-11, Sebastien Helleu <flashcode@flashtux.org>:
33 # v4.4: fix buffer number on drag to the end of list when option
34 # weechat.look.buffer_auto_renumber is off
35 # 2013-12-10, nils_2@freenode.#weechat:
36 # v4.3: add options "prefix_bufname" and "suffix_bufname (idea by silverd)
37 # : fix hook_timer() for show_lag wasn't disabled
38 # : improved signal handling (less updating of buffers list)
39 # 2013-11-07, Sebastien Helleu <flashcode@flashtux.org>:
40 # v4.2: use default filling "columns_vertical" when bar position is top/bottom
41 # 2013-10-31, nils_2@freenode.#weechat:
42 # v4.1: add option "detach_buffer_immediately" (idea by farn)
43 # 2013-10-20, nils_2@freenode.#weechat:
44 # v4.0: add options "detach_displayed_buffers", "detach_display_window_number"
45 # 2013-09-27, nils_2@freenode.#weechat:
46 # v3.9: add option "toggle_bar" and option "show_prefix_query" (idea by IvarB)
47 # : fix problem with linefeed at end of list of buffers (reported by grawity)
48 # 2012-10-18, nils_2@freenode.#weechat:
49 # v3.8: add option "mark_inactive", to mark buffers you are not in (idea by xrdodrx)
50 # : add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
51 # : add new options "detach_query" and "detach_free_content" (idea by StarWeaver)
52 # 2012-10-06, Nei <anti.teamidiot.de>:
53 # v3.7: call menu on right mouse if menu script is loaded.
54 # 2012-10-06, nils_2 <weechatter@arcor.de>:
55 # v3.6: add new option "hotlist_counter" (idea by torque).
56 # 2012-06-02, nils_2 <weechatter@arcor.de>:
57 # v3.5: add values "server|channel|private|all|keepserver|none" to option "hide_merged_buffers" (suggested by dominikh).
58 # 2012-05-25, nils_2 <weechatter@arcor.de>:
59 # v3.4: add new option "show_lag".
60 # 2012-04-07, Sebastien Helleu <flashcode@flashtux.org>:
61 # v3.3: fix truncation of wide chars in buffer name (option name_size_max) (bug #36034)
62 # 2012-03-15, nils_2 <weechatter@arcor.de>:
63 # v3.2: add new option "detach"(weechat >= 0.3.8)
64 # add new option "immune_detach_buffers" (requested by Mkaysi)
65 # add new function buffers_whitelist add|del|reset (suggested by FiXato)
66 # add new function buffers_detach add|del|reset
67 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
68 # v3.1: fix reload of config file
69 # 2012-01-29, nils_2 <weechatter@arcor.de>:
70 # v3.0: fix: buffers did not update directly during window_switch (reported by FiXato)
71 # 2012-01-29, nils_2 <weechatter@arcor.de>:
72 # v2.9: add options "name_size_max" and "name_crop_suffix"
73 # 2012-01-08, nils_2 <weechatter@arcor.de>:
74 # v2.8: fix indenting for option "show_number off"
75 # fix unset of buffer activity in hotlist when buffer was moved with mouse
76 # add buffer with free content and core buffer sorted first (suggested by nyuszika7h)
77 # add options queries_default_fg/bg and queries_message_fg/bg (suggested by FiXato)
78 # add clicking with left button on current buffer will do a jump_previously_visited_buffer (suggested by FiXato)
79 # add clicking with right button on current buffer will do a jump_next_visited_buffer
80 # add additional informations in help texts
81 # add default_fg and default_bg for whitelist channels
82 # internal changes (script is now 3Kb smaller)
83 # 2012-01-04, Sebastien Helleu <flashcode@flashtux.org>:
84 # v2.7: fix regex lookup in whitelist buffers list
85 # 2011-12-04, nils_2 <weechatter@arcor.de>:
86 # v2.6: add own config file (buffers.conf)
87 # add new behavior for indenting (under_name)
88 # add new option to set different color for server buffers and buffers with free content
89 # 2011-10-30, nils_2 <weechatter@arcor.de>:
90 # v2.5: add new options "show_number_char" and "color_number_char",
91 # add help-description for options
92 # 2011-08-24, Sebastien Helleu <flashcode@flashtux.org>:
93 # v2.4: add mouse support
94 # 2011-06-06, nils_2 <weechatter@arcor.de>:
95 # v2.3: added: missed option "color_whitelist_default"
96 # 2011-03-23, Sebastien Helleu <flashcode@flashtux.org>:
97 # v2.2: fix color of nick prefix with WeeChat >= 0.3.5
98 # 2011-02-13, nils_2 <weechatter@arcor.de>:
99 # v2.1: add options "color_whitelist_*"
100 # 2010-10-05, Sebastien Helleu <flashcode@flashtux.org>:
101 # v2.0: add options "sort" and "show_number"
102 # 2010-04-12, Sebastien Helleu <flashcode@flashtux.org>:
103 # v1.9: replace call to log() by length() to align buffer numbers
104 # 2010-04-02, Sebastien Helleu <flashcode@flashtux.org>:
105 # v1.8: fix bug with background color and option indenting_number
106 # 2010-04-02, Helios <helios@efemes.de>:
107 # v1.7: add indenting_number option
108 # 2010-02-25, m4v <lambdae2@gmail.com>:
109 # v1.6: add option to hide empty prefixes
110 # 2010-02-12, Sebastien Helleu <flashcode@flashtux.org>:
111 # v1.5: add optional nick prefix for buffers like IRC channels
112 # 2009-09-30, Sebastien Helleu <flashcode@flashtux.org>:
113 # v1.4: remove spaces for indenting when bar position is top/bottom
114 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
115 # v1.3: add option "hide_merged_buffers"
116 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
117 # v1.2: improve display with merged buffers
118 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
119 # v1.1: sync with last API changes
120 # 2009-02-21, Sebastien Helleu <flashcode@flashtux.org>:
121 # v1.0: remove timer used to update bar item first time (not needed any more)
122 # 2009-02-17, Sebastien Helleu <flashcode@flashtux.org>:
123 # v0.9: fix bug with indenting of private buffers
124 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
125 # v0.8: update syntax for command /set (comments)
126 # 2008-10-20, Jiri Golembiovsky <golemj@gmail.com>:
127 # v0.7: add indenting option
128 # 2008-10-01, Sebastien Helleu <flashcode@flashtux.org>:
129 # v0.6: add default color for buffers, and color for current active buffer
130 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
131 # v0.5: fix color for "low" level entry in hotlist
132 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
133 # v0.4: rename option "show_category" to "short_names",
134 # remove option "color_slash"
135 # 2008-09-15, Sebastien Helleu <flashcode@flashtux.org>:
136 # v0.3: fix bug with priority in hotlist (var not defined)
137 # 2008-09-02, Sebastien Helleu <flashcode@flashtux.org>:
138 # v0.2: add color for buffers with activity and config options for
139 # colors, add config option to display/hide categories
140 # 2008-03-15, Sebastien Helleu <flashcode@flashtux.org>:
141 # v0.1: script creation
142 #
143 # Help about settings:
144 # display all settings for script (or use iset.pl script to change settings):
145 # /set buffers*
146 # show help text for option buffers.look.whitelist_buffers:
147 # /help buffers.look.whitelist_buffers
148 #
149 # Mouse-support (standard key bindings):
150 # left mouse-button:
151 # - click on a buffer to switch to selected buffer
152 # - click on current buffer will do action jump_previously_visited_buffer
153 # - drag a buffer and drop it on another position will move the buffer to position
154 # right mouse-button:
155 # - click on current buffer will do action jump_next_visited_buffer
156 # - moving buffer to the left/right will close buffer.
157 #
158
159 use strict;
160 use Encode qw( decode encode );
161 # -----------------------------[ internal ]-------------------------------------
162 my $SCRIPT_NAME = "buffers";
163 my $SCRIPT_VERSION = "4.8";
164
165 my $BUFFERS_CONFIG_FILE_NAME = "buffers";
166 my $buffers_config_file;
167 my $cmd_buffers_whitelist= "buffers_whitelist";
168 my $cmd_buffers_detach = "buffers_detach";
169
170 my %mouse_keys = ("\@item(buffers):button1*" => "hsignal:buffers_mouse",
171 "\@item(buffers):button2*" => "hsignal:buffers_mouse",
172 "\@bar(buffers):ctrl-wheelup" => "hsignal:buffers_mouse",
173 "\@bar(buffers):ctrl-wheeldown" => "hsignal:buffers_mouse");
174 my %options;
175 my %hotlist_level = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
176 my @whitelist_buffers = ();
177 my @immune_detach_buffers= ();
178 my @detach_buffer_immediately= ();
179 my @buffers_focus = ();
180 my %buffers_timer = ();
181 my %Hooks = ();
182
183 # --------------------------------[ init ]--------------------------------------
184 weechat::register($SCRIPT_NAME, "Sebastien Helleu <flashcode\@flashtux.org>",
185 $SCRIPT_VERSION, "GPL3",
186 "Sidebar with list of buffers", "shutdown_cb", "");
187 my $weechat_version = weechat::info_get("version_number", "") || 0;
188
189 buffers_config_init();
190 buffers_config_read();
191
192 weechat::bar_item_new($SCRIPT_NAME, "build_buffers", "");
193 weechat::bar_new($SCRIPT_NAME, "0", "0", "root", "", "left", "columns_vertical",
194 "vertical", "0", "0", "default", "default", "default", "1",
195 $SCRIPT_NAME);
196
197 if ( check_bar_item() == 0 )
198 {
199 weechat::command("", "/bar show " . $SCRIPT_NAME) if ( weechat::config_boolean($options{"toggle_bar"}) eq 1 );
200 }
201
202 weechat::hook_signal("buffer_opened", "buffers_signal_buffer", "");
203 weechat::hook_signal("buffer_closed", "buffers_signal_buffer", "");
204 weechat::hook_signal("buffer_merged", "buffers_signal_buffer", "");
205 weechat::hook_signal("buffer_unmerged", "buffers_signal_buffer", "");
206 weechat::hook_signal("buffer_moved", "buffers_signal_buffer", "");
207 weechat::hook_signal("buffer_renamed", "buffers_signal_buffer", "");
208 weechat::hook_signal("buffer_switch", "buffers_signal_buffer", "");
209 weechat::hook_signal("buffer_hidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
210 weechat::hook_signal("buffer_unhidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
211
212 weechat::hook_signal("window_switch", "buffers_signal_buffer", "");
213 weechat::hook_signal("hotlist_changed", "buffers_signal_hotlist", "");
214 #weechat::hook_command_run("/input switch_active_*", "buffers_signal_buffer", "");
215 weechat::bar_item_update($SCRIPT_NAME);
216
217
218 if ($weechat_version >= 0x00030600)
219 {
220 weechat::hook_focus($SCRIPT_NAME, "buffers_focus_buffers", "");
221 weechat::hook_hsignal("buffers_mouse", "buffers_hsignal_mouse", "");
222 weechat::key_bind("mouse", \%mouse_keys);
223 }
224
225 weechat::hook_command($cmd_buffers_whitelist,
226 "add/del current buffer to/from buffers whitelist",
227 "[add] || [del] || [reset]",
228 " add: add current buffer in configuration file\n".
229 " del: delete current buffer from configuration file\n".
230 "reset: reset all buffers from configuration file ".
231 "(no confirmation!)\n\n".
232 "Examples:\n".
233 "/$cmd_buffers_whitelist add\n",
234 "add %-||".
235 "del %-||".
236 "reset %-",
237 "buffers_cmd_whitelist", "");
238 weechat::hook_command($cmd_buffers_detach,
239 "add/del current buffer to/from buffers detach",
240 "[add] || [del] || [reset]",
241 " add: add current buffer in configuration file\n".
242 " del: delete current buffer from configuration file\n".
243 "reset: reset all buffers from configuration file ".
244 "(no confirmation!)\n\n".
245 "Examples:\n".
246 "/$cmd_buffers_detach add\n",
247 "add %-||".
248 "del %-||".
249 "reset %-",
250 "buffers_cmd_detach", "");
251
252 if ($weechat_version >= 0x00030800)
253 {
254 weechat::hook_config("buffers.look.detach", "hook_timer_detach", "");
255 if (weechat::config_integer($options{"detach"}) > 0)
256 {
257 $Hooks{timer_detach} = weechat::hook_timer(weechat::config_integer($options{"detach"}) * 1000,
258 60, 0, "buffers_signal_hotlist", "");
259 }
260 }
261
262 weechat::hook_config("buffers.look.show_lag", "hook_timer_lag", "");
263
264 if (weechat::config_boolean($options{"show_lag"}))
265 {
266 $Hooks{timer_lag} = weechat::hook_timer(
267 weechat::config_integer(weechat::config_get("irc.network.lag_refresh_interval")) * 1000,
268 0, 0, "buffers_signal_hotlist", "");
269 }
270
271 # -------------------------------- [ command ] --------------------------------
272 sub buffers_cmd_whitelist
273 {
274 my ( $data, $buffer, $args ) = @_;
275 $args = lc($args);
276 my $buffers_whitelist = weechat::config_string( weechat::config_get("buffers.look.whitelist_buffers") );
277 return weechat::WEECHAT_RC_OK if ( $buffers_whitelist eq "" and $args eq "del" or $buffers_whitelist eq "" and $args eq "reset" );
278 my @buffers_list = split( /,/, $buffers_whitelist );
279 # get buffers name
280 my $infolist = weechat::infolist_get("buffer", weechat::current_buffer(), "");
281 weechat::infolist_next($infolist);
282 my $buffers_name = weechat::infolist_string($infolist, "name");
283 weechat::infolist_free($infolist);
284 return weechat::WEECHAT_RC_OK if ( $buffers_name eq "" ); # should never happen
285
286 if ( $args eq "add" )
287 {
288 return weechat::WEECHAT_RC_OK if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
289 push @buffers_list, ( $buffers_name );
290 my $buffers_list = &create_whitelist(\@buffers_list);
291 weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), $buffers_list, 1);
292 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" added to buffers whitelist");
293 }
294 elsif ( $args eq "del" )
295 {
296 return weechat::WEECHAT_RC_OK unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
297 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
298 my $buffers_list = &create_whitelist(\@buffers_list);
299 weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), $buffers_list, 1);
300 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" deleted from buffers whitelist");
301 }
302 elsif ( $args eq "reset" )
303 {
304 return weechat::WEECHAT_RC_OK if ( $buffers_whitelist eq "" );
305 weechat::config_option_set( weechat::config_get("buffers.look.whitelist_buffers"), "", 1);
306 weechat::print(weechat::current_buffer(), "buffers whitelist is empty, now...");
307 }
308 return weechat::WEECHAT_RC_OK;
309 }
310 sub buffers_cmd_detach
311 {
312 my ( $data, $buffer, $args ) = @_;
313 $args = lc($args);
314 my $immune_detach_buffers = weechat::config_string( weechat::config_get("buffers.look.immune_detach_buffers") );
315 return weechat::WEECHAT_RC_OK if ( $immune_detach_buffers eq "" and $args eq "del" or $immune_detach_buffers eq "" and $args eq "reset" );
316
317 my @buffers_list = split( /,/, $immune_detach_buffers );
318 # get buffers name
319 my $infolist = weechat::infolist_get("buffer", weechat::current_buffer(), "");
320 weechat::infolist_next($infolist);
321 my $buffers_name = weechat::infolist_string($infolist, "name");
322 weechat::infolist_free($infolist);
323 return weechat::WEECHAT_RC_OK if ( $buffers_name eq "" ); # should never happen
324
325 if ( $args eq "add" )
326 {
327 return weechat::WEECHAT_RC_OK if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
328 push @buffers_list, ( $buffers_name );
329 my $buffers_list = &create_whitelist(\@buffers_list);
330 weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), $buffers_list, 1);
331 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" added to immune detach buffers");
332 }
333 elsif ( $args eq "del" )
334 {
335 return weechat::WEECHAT_RC_OK unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
336 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
337 my $buffers_list = &create_whitelist(\@buffers_list);
338 weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), $buffers_list, 1);
339 weechat::print(weechat::current_buffer(), "buffer \"$buffers_name\" deleted from immune detach buffers");
340 }
341 elsif ( $args eq "reset" )
342 {
343 return weechat::WEECHAT_RC_OK if ( $immune_detach_buffers eq "" );
344 weechat::config_option_set( weechat::config_get("buffers.look.immune_detach_buffers"), "", 1);
345 weechat::print(weechat::current_buffer(), "immune detach buffers is empty, now...");
346 }
347 return weechat::WEECHAT_RC_OK;
348 }
349
350 sub create_whitelist
351 {
352 my @buffers_list = @{$_[0]};
353 my $buffers_list = "";
354 foreach (@buffers_list)
355 {
356 $buffers_list .= $_ .",";
357 }
358 # remove last ","
359 chop $buffers_list;
360 return $buffers_list;
361 }
362
363 # -------------------------------- [ config ] --------------------------------
364 sub hook_timer_detach
365 {
366 my $detach = $_[2];
367 if ( $detach eq 0 )
368 {
369 weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
370 $Hooks{timer_detach} = "";
371 }
372 else
373 {
374 weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
375 $Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer( $options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "");
376 }
377 weechat::bar_item_update($SCRIPT_NAME);
378 return weechat::WEECHAT_RC_OK;
379 }
380
381 sub hook_timer_lag
382 {
383 my $lag = $_[2];
384 if ( $lag eq "off" )
385 {
386 weechat::unhook($Hooks{timer_lag}) if $Hooks{timer_lag};
387 $Hooks{timer_lag} = "";
388 }
389 else
390 {
391 weechat::unhook($Hooks{timer_lag}) if $Hooks{timer_lag};
392 $Hooks{timer_lag} = weechat::hook_timer( weechat::config_integer(weechat::config_get("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
393 }
394 weechat::bar_item_update($SCRIPT_NAME);
395 return weechat::WEECHAT_RC_OK;
396 }
397
398 sub buffers_config_read
399 {
400 return weechat::config_read($buffers_config_file) if ($buffers_config_file ne "");
401 }
402 sub buffers_config_write
403 {
404 return weechat::config_write($buffers_config_file) if ($buffers_config_file ne "");
405 }
406 sub buffers_config_reload_cb
407 {
408 my ($data, $config_file) = ($_[0], $_[1]);
409 return weechat::config_reload($config_file)
410 }
411 sub buffers_config_init
412 {
413 $buffers_config_file = weechat::config_new($BUFFERS_CONFIG_FILE_NAME,
414 "buffers_config_reload_cb", "");
415 return if ($buffers_config_file eq "");
416
417 my %default_options_color =
418 ("color_current_fg" => [
419 "current_fg", "color",
420 "foreground color for current buffer",
421 "", 0, 0, "lightcyan", "lightcyan", 0,
422 "", "", "buffers_signal_config", "", "", ""
423 ],
424 "color_current_bg" => [
425 "current_bg", "color",
426 "background color for current buffer",
427 "", 0, 0, "red", "red", 0,
428 "", "", "buffers_signal_config", "", "", ""
429 ],
430 "color_default_fg" => [
431 "default_fg", "color",
432 "default foreground color for buffer name",
433 "", 0, 0, "default", "default", 0,
434 "", "", "buffers_signal_config", "", "", ""
435 ],
436 "color_default_bg" => [
437 "default_bg", "color",
438 "default background color for buffer name",
439 "", 0, 0, "default", "default", 0,
440 "", "", "buffers_signal_config", "", "", ""
441 ],
442 "color_hotlist_highlight_fg" => [
443 "hotlist_highlight_fg", "color",
444 "change foreground color of buffer name if a highlight messaged received",
445 "", 0, 0, "magenta", "magenta", 0,
446 "", "", "buffers_signal_config", "", "", ""
447 ],
448 "color_hotlist_highlight_bg" => [
449 "hotlist_highlight_bg", "color",
450 "change background color of buffer name if a highlight messaged received",
451 "", 0, 0, "default", "default", 0,
452 "", "", "buffers_signal_config", "", "", ""
453 ],
454 "color_hotlist_low_fg" => [
455 "hotlist_low_fg", "color",
456 "change foreground color of buffer name if a low message received",
457 "", 0, 0, "white", "white", 0,
458 "", "", "buffers_signal_config", "", "", ""
459 ],
460 "color_hotlist_low_bg" => [
461 "hotlist_low_bg", "color",
462 "change background color of buffer name if a low message received",
463 "", 0, 0, "default", "default", 0,
464 "", "", "buffers_signal_config", "", "", ""
465 ],
466 "color_hotlist_message_fg" => [
467 "hotlist_message_fg", "color",
468 "change foreground color of buffer name if a normal message received",
469 "", 0, 0, "yellow", "yellow", 0,
470 "", "", "buffers_signal_config", "", "", ""
471 ],
472 "color_hotlist_message_bg" => [
473 "hotlist_message_bg", "color",
474 "change background color of buffer name if a normal message received",
475 "", 0, 0, "default", "default", 0,
476 "", "", "buffers_signal_config", "", "", ""
477 ],
478 "color_hotlist_private_fg" => [
479 "hotlist_private_fg", "color",
480 "change foreground color of buffer name if a private message received",
481 "", 0, 0, "lightgreen", "lightgreen", 0,
482 "", "", "buffers_signal_config", "", "", ""
483 ],
484 "color_hotlist_private_bg" => [
485 "hotlist_private_bg", "color",
486 "change background color of buffer name if a private message received",
487 "", 0, 0, "default", "default", 0,
488 "", "", "buffers_signal_config", "", "", ""
489 ],
490 "color_number" => [
491 "number", "color",
492 "color for buffer number",
493 "", 0, 0, "lightgreen", "lightgreen", 0,
494 "", "", "buffers_signal_config", "", "", ""
495 ],
496 "color_number_char" => [
497 "number_char", "color",
498 "color for buffer number char",
499 "", 0, 0, "lightgreen", "lightgreen", 0,
500 "", "", "buffers_signal_config", "", "", ""
501 ],
502 "color_whitelist_default_fg" => [
503 "whitelist_default_fg", "color",
504 "default foreground color for whitelist buffer name",
505 "", 0, 0, "", "", 0,
506 "", "", "buffers_signal_config", "", "", ""
507 ],
508 "color_whitelist_default_bg" => [
509 "whitelist_default_bg", "color",
510 "default background color for whitelist buffer name",
511 "", 0, 0, "", "", 0,
512 "", "", "buffers_signal_config", "", "", ""
513 ],
514 "color_whitelist_low_fg" => [
515 "whitelist_low_fg", "color",
516 "low color of whitelist buffer name",
517 "", 0, 0, "", "", 0,
518 "", "", "buffers_signal_config", "", "", ""
519 ],
520 "color_whitelist_low_bg" => [
521 "whitelist_low_bg", "color",
522 "low color of whitelist buffer name",
523 "", 0, 0, "", "", 0,
524 "", "", "buffers_signal_config", "", "", ""
525 ],
526 "color_whitelist_message_fg" => [
527 "whitelist_message_fg", "color",
528 "message color of whitelist buffer name",
529 "", 0, 0, "", "", 0,
530 "", "", "buffers_signal_config", "", "", ""
531 ],
532 "color_whitelist_message_bg" => [
533 "whitelist_message_bg", "color",
534 "message color of whitelist buffer name",
535 "", 0, 0, "", "", 0,
536 "", "", "buffers_signal_config", "", "", ""
537 ],
538 "color_whitelist_private_fg" => [
539 "whitelist_private_fg", "color",
540 "private color of whitelist buffer name",
541 "", 0, 0, "", "", 0,
542 "", "", "buffers_signal_config", "", "", ""
543 ],
544 "color_whitelist_private_bg" => [
545 "whitelist_private_bg", "color",
546 "private color of whitelist buffer name",
547 "", 0, 0, "", "", 0,
548 "", "", "buffers_signal_config", "", "", ""
549 ],
550 "color_whitelist_highlight_fg" => [
551 "whitelist_highlight_fg", "color",
552 "highlight color of whitelist buffer name",
553 "", 0, 0, "", "", 0,
554 "", "", "buffers_signal_config", "", "", ""
555 ],
556 "color_whitelist_highlight_bg" => [
557 "whitelist_highlight_bg", "color",
558 "highlight color of whitelist buffer name",
559 "", 0, 0, "", "", 0,
560 "", "", "buffers_signal_config", "", "", ""
561 ],
562 "color_none_channel_fg" => [
563 "none_channel_fg", "color",
564 "foreground color for none channel buffer (e.g.: core/server/plugin ".
565 "buffer)",
566 "", 0, 0, "default", "default", 0,
567 "", "", "buffers_signal_config", "", "", ""
568 ],
569 "color_none_channel_bg" => [
570 "none_channel_bg", "color",
571 "background color for none channel buffer (e.g.: core/server/plugin ".
572 "buffer)",
573 "", 0, 0, "default", "default", 0,
574 "", "", "buffers_signal_config", "", "", ""
575 ],
576 "queries_default_fg" => [
577 "queries_default_fg", "color",
578 "foreground color for query buffer without message",
579 "", 0, 0, "default", "default", 0,
580 "", "", "buffers_signal_config", "", "", ""
581 ],
582 "queries_default_bg" => [
583 "queries_default_bg", "color",
584 "background color for query buffer without message",
585 "", 0, 0, "default", "default", 0,
586 "", "", "buffers_signal_config", "", "", ""
587 ],
588 "queries_message_fg" => [
589 "queries_message_fg", "color",
590 "foreground color for query buffer with unread message",
591 "", 0, 0, "default", "default", 0,
592 "", "", "buffers_signal_config", "", "", ""
593 ],
594 "queries_message_bg" => [
595 "queries_message_bg", "color",
596 "background color for query buffer with unread message",
597 "", 0, 0, "default", "default", 0,
598 "", "", "buffers_signal_config", "", "", ""
599 ],
600 "queries_highlight_fg" => [
601 "queries_highlight_fg", "color",
602 "foreground color for query buffer with unread highlight",
603 "", 0, 0, "default", "default", 0,
604 "", "", "buffers_signal_config", "", "", ""
605 ],
606 "queries_highlight_bg" => [
607 "queries_highlight_bg", "color",
608 "background color for query buffer with unread highlight",
609 "", 0, 0, "default", "default", 0,
610 "", "", "buffers_signal_config", "", "", ""
611 ],
612 "color_prefix_bufname" => [
613 "prefix_bufname", "color",
614 "color for prefix of buffer name",
615 "", 0, 0, "default", "default", 0,
616 "", "", "buffers_signal_config", "", "", ""
617 ],
618 "color_suffix_bufname" => [
619 "suffix_bufname", "color",
620 "color for suffix of buffer name",
621 "", 0, 0, "default", "default", 0,
622 "", "", "buffers_signal_config", "", "", ""
623 ],
624 );
625
626 my %default_options_look =
627 (
628 "hotlist_counter" => [
629 "hotlist_counter", "boolean",
630 "show number of message for the buffer (this option needs WeeChat >= ".
631 "0.3.5). The relevant option for notification is \"weechat.look.".
632 "buffer_notify_default\"",
633 "", 0, 0, "off", "off", 0,
634 "", "", "buffers_signal_config", "", "", ""
635 ],
636 "show_lag" => [
637 "show_lag", "boolean",
638 "show lag behind server name. This option is using \"irc.color.".
639 "item_lag_finished\", ".
640 "\"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"",
641 "", 0, 0, "off", "off", 0,
642 "", "", "buffers_signal_config", "", "", ""
643 ],
644 "look_whitelist_buffers" => [
645 "whitelist_buffers", "string",
646 "comma separated list of buffers for using a different color scheme ".
647 "(for example: freenode.#weechat,freenode.#weechat-fr)",
648 "", 0, 0, "", "", 0,
649 "", "", "buffers_signal_config_whitelist", "", "", ""
650 ],
651 "hide_merged_buffers" => [
652 "hide_merged_buffers", "integer",
653 "hide merged buffers. The value determines which merged buffers should ".
654 "be hidden, keepserver meaning 'all except server buffers'. Other values ".
655 "correspondent to the buffer type.",
656 "server|channel|private|keepserver|all|none", 0, 0, "none", "none", 0,
657 "", "", "buffers_signal_config", "", "", ""
658 ],
659 "indenting" => [
660 "indenting", "integer", "use indenting for channel and query buffers. ".
661 "This option only takes effect if bar is left/right positioned",
662 "off|on|under_name", 0, 0, "off", "off", 0,
663 "", "", "buffers_signal_config", "", "", ""
664 ],
665 "indenting_number" => [
666 "indenting_number", "boolean",
667 "use indenting for numbers. This option only takes effect if bar is ".
668 "left/right positioned",
669 "", 0, 0, "on", "on", 0,
670 "", "", "buffers_signal_config", "", "", ""
671 ],
672 "short_names" => [
673 "short_names", "boolean",
674 "display short names (remove text before first \".\" in buffer name)",
675 "", 0, 0, "on", "on", 0,
676 "", "", "buffers_signal_config", "", "", ""
677 ],
678 "show_number" => [
679 "show_number", "boolean",
680 "display buffer number in front of buffer name",
681 "", 0, 0, "on", "on", 0,
682 "", "", "buffers_signal_config", "", "", ""
683 ],
684 "show_number_char" => [
685 "number_char", "string",
686 "display a char behind buffer number",
687 "", 0, 0, ".", ".", 0,
688 "", "", "buffers_signal_config", "", "", ""
689 ],
690 "show_prefix_bufname" => [
691 "prefix_bufname", "string",
692 "prefix displayed in front of buffer name",
693 "", 0, 0, "", "", 0,
694 "", "", "buffers_signal_config", "", "", ""
695 ],
696 "show_suffix_bufname" => [
697 "suffix_bufname", "string",
698 "suffix displayed at end of buffer name",
699 "", 0, 0, "", "", 0,
700 "", "", "buffers_signal_config", "", "", ""
701 ],
702 "show_prefix" => [
703 "prefix", "boolean",
704 "displays your prefix for channel in front of buffer name",
705 "", 0, 0, "off", "off", 0,
706 "", "", "buffers_signal_config", "", "", ""
707 ],
708 "show_prefix_empty" => [
709 "prefix_empty", "boolean",
710 "use a placeholder for channels without prefix",
711 "", 0, 0, "on", "on", 0,
712 "", "", "buffers_signal_config", "", "", ""
713 ],
714 "show_prefix_query" => [
715 "prefix_for_query", "string",
716 "prefix displayed in front of query buffer",
717 "", 0, 0, "", "", 0,
718 "", "", "buffers_signal_config", "", "", ""
719 ],
720 "sort" => [
721 "sort", "integer",
722 "sort buffer-list by \"number\" or \"name\"",
723 "number|name", 0, 0, "number", "number", 0,
724 "", "", "buffers_signal_config", "", "", ""
725 ],
726 "core_to_front" => [
727 "core_to_front", "boolean",
728 "core buffer and buffers with free content will be listed first. ".
729 "Take only effect if buffer sort is by name",
730 "", 0, 0, "off", "off", 0,
731 "", "", "buffers_signal_config", "", "", ""
732 ],
733 "jump_prev_next_visited_buffer" => [
734 "jump_prev_next_visited_buffer", "boolean",
735 "jump to previously or next visited buffer if you click with ".
736 "left/right mouse button on currently visiting buffer",
737 "", 0, 0, "off", "off", 0,
738 "", "", "buffers_signal_config", "", "", ""
739 ],
740 "name_size_max" => [
741 "name_size_max", "integer",
742 "maximum size of buffer name. 0 means no limitation",
743 "", 0, 256, 0, 0, 0,
744 "", "", "buffers_signal_config", "", "", ""
745 ],
746 "name_crop_suffix" => [
747 "name_crop_suffix", "string",
748 "contains an optional char(s) that is appended when buffer name is ".
749 "shortened",
750 "", 0, 0, "+", "+", 0,
751 "", "", "buffers_signal_config", "", "", ""
752 ],
753 "detach" => [
754 "detach", "integer",
755 "detach buffer from buffers list after a specific period of time ".
756 "(in seconds) without action (weechat ≥ 0.3.8 required) (0 means \"off\")",
757 "", 0, 31536000, 0, "number", 0,
758 "", "", "buffers_signal_config", "", "", ""
759 ],
760 "immune_detach_buffers" => [
761 "immune_detach_buffers", "string",
762 "comma separated list of buffers to NOT automatically detach. ".
763 "Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"",
764 "", 0, 0, "", "", 0,
765 "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""
766 ],
767 "detach_query" => [
768 "detach_query", "boolean",
769 "query buffer will be detached",
770 "", 0, 0, "off", "off", 0,
771 "", "", "buffers_signal_config", "", "", ""
772 ],
773 "detach_buffer_immediately" => [
774 "detach_buffer_immediately", "string",
775 "comma separated list of buffers to detach immediately. A query and ".
776 "highlight message will attach buffer again. Allows \"*\" wildcard. ".
777 "Ex: \"BitlBee,freenode.*\"",
778 "", 0, 0, "", "", 0,
779 "", "", "buffers_signal_config_detach_buffer_immediately", "", "", ""
780 ],
781 "detach_free_content" => [
782 "detach_free_content", "boolean",
783 "buffers with free content will be detached (Ex: iset, chanmon)",
784 "", 0, 0, "off", "off", 0,
785 "", "", "buffers_signal_config", "", "", ""
786 ],
787 "detach_displayed_buffers" => [
788 "detach_displayed_buffers", "boolean",
789 "buffers displayed in a (split) window will be detached",
790 "", 0, 0, "on", "on", 0,
791 "", "", "buffers_signal_config", "", "", ""
792 ],
793 "detach_display_window_number" => [
794 "detach_display_window_number", "boolean",
795 "window number will be add, behind buffer name (this option takes only ".
796 "effect with \"detach_displayed_buffers\" option)",
797 "", 0, 0, "off", "off", 0,
798 "", "", "buffers_signal_config", "", "", ""
799 ],
800 "mark_inactive" => [
801 "mark_inactive", "boolean",
802 "if option is \"on\", inactive buffers (those you are not in) will have ".
803 "parentheses around them. An inactive buffer will not be detached.",
804 "", 0, 0, "off", "off", 0,
805 "", "", "buffers_signal_config", "", "", ""
806 ],
807 "toggle_bar" => [
808 "toggle_bar", "boolean",
809 "if option is \"on\", buffers bar will hide/show when script is ".
810 "(un)loaded.",
811 "", 0, 0, "on", "on", 0,
812 "", "", "buffers_signal_config", "", "", ""
813 ],
814 "mouse_move_buffer" => [
815 "mouse_move_buffer", "boolean",
816 "if option is \"on\", mouse gestures (drag & drop) can move buffers in list.",
817 "", 0, 0, "on", "on", 0,
818 "", "", "buffers_signal_config", "", "", ""
819 ],
820 "mouse_wheel" => [
821 "mouse_wheel", "boolean",
822 "if option is \"on\", mouse wheel jumps to previous/next buffer in list.",
823 "", 0, 0, "on", "on", 0,
824 "", "", "buffers_signal_config", "", "", ""
825 ],
826 );
827 # section "color"
828 my $section_color = weechat::config_new_section(
829 $buffers_config_file,
830 "color", 0, 0, "", "", "", "", "", "", "", "", "", "");
831 if ($section_color eq "")
832 {
833 weechat::config_free($buffers_config_file);
834 return;
835 }
836 foreach my $option (keys %default_options_color)
837 {
838 $options{$option} = weechat::config_new_option(
839 $buffers_config_file,
840 $section_color,
841 $default_options_color{$option}[0],
842 $default_options_color{$option}[1],
843 $default_options_color{$option}[2],
844 $default_options_color{$option}[3],
845 $default_options_color{$option}[4],
846 $default_options_color{$option}[5],
847 $default_options_color{$option}[6],
848 $default_options_color{$option}[7],
849 $default_options_color{$option}[8],
850 $default_options_color{$option}[9],
851 $default_options_color{$option}[10],
852 $default_options_color{$option}[11],
853 $default_options_color{$option}[12],
854 $default_options_color{$option}[13],
855 $default_options_color{$option}[14]);
856 }
857
858 # section "look"
859 my $section_look = weechat::config_new_section(
860 $buffers_config_file,
861 "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
862 if ($section_look eq "")
863 {
864 weechat::config_free($buffers_config_file);
865 return;
866 }
867 foreach my $option (keys %default_options_look)
868 {
869 $options{$option} = weechat::config_new_option(
870 $buffers_config_file,
871 $section_look,
872 $default_options_look{$option}[0],
873 $default_options_look{$option}[1],
874 $default_options_look{$option}[2],
875 $default_options_look{$option}[3],
876 $default_options_look{$option}[4],
877 $default_options_look{$option}[5],
878 $default_options_look{$option}[6],
879 $default_options_look{$option}[7],
880 $default_options_look{$option}[8],
881 $default_options_look{$option}[9],
882 $default_options_look{$option}[10],
883 $default_options_look{$option}[11],
884 $default_options_look{$option}[12],
885 $default_options_look{$option}[13],
886 $default_options_look{$option}[14],
887 $default_options_look{$option}[15]);
888 }
889 }
890
891 sub build_buffers
892 {
893 my $str = "";
894
895 # get bar position (left/right/top/bottom)
896 my $position = "left";
897 my $option_position = weechat::config_get("weechat.bar.buffers.position");
898 if ($option_position ne "")
899 {
900 $position = weechat::config_string($option_position);
901 }
902
903 # read hotlist
904 my %hotlist;
905 my $infolist = weechat::infolist_get("hotlist", "", "");
906 while (weechat::infolist_next($infolist))
907 {
908 $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")} =
909 weechat::infolist_integer($infolist, "priority");
910 if ( weechat::config_boolean( $options{"hotlist_counter"} ) eq 1 and $weechat_version >= 0x00030500)
911 {
912 $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_00"} =
913 weechat::infolist_integer($infolist, "count_00"); # low message
914 $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_01"} =
915 weechat::infolist_integer($infolist, "count_01"); # channel message
916 $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_02"} =
917 weechat::infolist_integer($infolist, "count_02"); # private message
918 $hotlist{weechat::infolist_pointer($infolist, "buffer_pointer")."_count_03"} =
919 weechat::infolist_integer($infolist, "count_03"); # highlight message
920 }
921 }
922 weechat::infolist_free($infolist);
923
924 # read buffers list
925 @buffers_focus = ();
926 my @buffers;
927 my @current1 = ();
928 my @current2 = ();
929 my $old_number = -1;
930 my $max_number = 0;
931 my $max_number_digits = 0;
932 my $active_seen = 0;
933 $infolist = weechat::infolist_get("buffer", "", "");
934 while (weechat::infolist_next($infolist))
935 {
936 # ignore hidden buffers (WeeChat >= 0.4.4)
937 if ($weechat_version >= 0x00040400)
938 {
939 next if (weechat::infolist_integer($infolist, "hidden"));
940 }
941 my $buffer;
942 my $number = weechat::infolist_integer($infolist, "number");
943 if ($number ne $old_number)
944 {
945 @buffers = (@buffers, @current2, @current1);
946 @current1 = ();
947 @current2 = ();
948 $active_seen = 0;
949 }
950 if ($number > $max_number)
951 {
952 $max_number = $number;
953 }
954 $old_number = $number;
955 my $active = weechat::infolist_integer($infolist, "active");
956 if ($active)
957 {
958 $active_seen = 1;
959 }
960 $buffer->{"pointer"} = weechat::infolist_pointer($infolist, "pointer");
961 $buffer->{"number"} = $number;
962 $buffer->{"active"} = $active;
963 $buffer->{"current_buffer"} = weechat::infolist_integer($infolist, "current_buffer");
964 $buffer->{"num_displayed"} = weechat::infolist_integer($infolist, "num_displayed");
965 $buffer->{"plugin_name"} = weechat::infolist_string($infolist, "plugin_name");
966 $buffer->{"name"} = weechat::infolist_string($infolist, "name");
967 $buffer->{"short_name"} = weechat::infolist_string($infolist, "short_name");
968 $buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
969 $buffer->{"type"} = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
970 #weechat::print("", $buffer->{"type"});
971
972 # check if buffer is active (or maybe a /part, /kick channel)
973 if ($buffer->{"type"} eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1)
974 {
975 my $server = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_server");
976 my $channel = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_channel");
977 my $infolist_channel = weechat::infolist_get("irc_channel", "", $server.",".$channel);
978 if ($infolist_channel)
979 {
980 weechat::infolist_next($infolist_channel);
981 $buffer->{"nicks_count"} = weechat::infolist_integer($infolist_channel, "nicks_count");
982 }else
983 {
984 $buffer->{"nicks_count"} = 0;
985 }
986 weechat::infolist_free($infolist_channel);
987 }
988
989 my $result = check_immune_detached_buffers($buffer->{"name"}); # checking for wildcard
990
991 next if ( check_detach_buffer_immediately($buffer->{"name"}) eq 1
992 and $buffer->{"current_buffer"} eq 0
993 and ( not exists $hotlist{$buffer->{"pointer"}} or $hotlist{$buffer->{"pointer"}} < 2) ); # checking for buffer to immediately detach
994
995 unless ($result)
996 {
997 my $detach_time = weechat::config_integer( $options{"detach"});
998 my $current_time = time();
999 # set timer for buffers with no hotlist action
1000 $buffers_timer{$buffer->{"pointer"}} = $current_time
1001 if ( not exists $hotlist{$buffer->{"pointer"}}
1002 and $buffer->{"type"} eq "channel"
1003 and not exists $buffers_timer{$buffer->{"pointer"}}
1004 and $detach_time > 0);
1005
1006 $buffers_timer{$buffer->{"pointer"}} = $current_time
1007 if (weechat::config_boolean($options{"detach_query"}) eq 1
1008 and not exists $hotlist{$buffer->{"pointer"}}
1009 and $buffer->{"type"} eq "private"
1010 and not exists $buffers_timer{$buffer->{"pointer"}}
1011 and $detach_time > 0);
1012
1013 $detach_time = 0
1014 if (weechat::config_boolean($options{"detach_query"}) eq 0
1015 and $buffer->{"type"} eq "private");
1016
1017 # free content buffer
1018 $buffers_timer{$buffer->{"pointer"}} = $current_time
1019 if (weechat::config_boolean($options{"detach_free_content"}) eq 1
1020 and not exists $hotlist{$buffer->{"pointer"}}
1021 and $buffer->{"type"} eq ""
1022 and not exists $buffers_timer{$buffer->{"pointer"}}
1023 and $detach_time > 0);
1024 $detach_time = 0
1025 if (weechat::config_boolean($options{"detach_free_content"}) eq 0
1026 and $buffer->{"type"} eq "");
1027
1028 $detach_time = 0 if (weechat::config_boolean($options{"mark_inactive"}) eq 1 and defined $buffer->{"nicks_count"} and $buffer->{"nicks_count"} == 0);
1029
1030 # check for detach
1031 unless ( $buffer->{"current_buffer"} eq 0
1032 and not exists $hotlist{$buffer->{"pointer"}}
1033 # and $buffer->{"type"} eq "channel"
1034 and exists $buffers_timer{$buffer->{"pointer"}}
1035 and $detach_time > 0
1036 and $weechat_version >= 0x00030800
1037 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1038 {
1039 if ($active_seen)
1040 {
1041 push(@current2, $buffer);
1042 }
1043 else
1044 {
1045 push(@current1, $buffer);
1046 }
1047 }
1048 elsif ( $buffer->{"current_buffer"} eq 0
1049 and not exists $hotlist{$buffer->{"pointer"}}
1050 # and $buffer->{"type"} eq "channel"
1051 and exists $buffers_timer{$buffer->{"pointer"}}
1052 and $detach_time > 0
1053 and $weechat_version >= 0x00030800
1054 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1055 { # check for option detach_displayed_buffers and if buffer is displayed in a split window
1056 if ( $buffer->{"num_displayed"} eq 1
1057 and weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0 )
1058 {
1059 my $infolist_window = weechat::infolist_get("window", "", "");
1060 while (weechat::infolist_next($infolist_window))
1061 {
1062 my $buffer_ptr = weechat::infolist_pointer($infolist_window, "buffer");
1063 if ($buffer_ptr eq $buffer->{"pointer"})
1064 {
1065 $buffer->{"window"} = weechat::infolist_integer($infolist_window, "number");
1066 }
1067 }
1068 weechat::infolist_free($infolist_window);
1069
1070 push(@current2, $buffer);
1071 }
1072 }
1073 }
1074 else # buffer in "immune_detach_buffers"
1075 {
1076 if ($active_seen)
1077 {
1078 push(@current2, $buffer);
1079 }
1080 else
1081 {
1082 push(@current1, $buffer);
1083 }
1084 }
1085 } # while end
1086
1087
1088 if ($max_number >= 1)
1089 {
1090 $max_number_digits = length(int($max_number));
1091 }
1092 @buffers = (@buffers, @current2, @current1);
1093 weechat::infolist_free($infolist);
1094
1095 # sort buffers by number, name or shortname
1096 my %sorted_buffers;
1097 if (1)
1098 {
1099 my $number = 0;
1100 for my $buffer (@buffers)
1101 {
1102 my $key;
1103 if (weechat::config_integer( $options{"sort"} ) eq 1) # number = 0; name = 1
1104 {
1105 my $name = $buffer->{"name"};
1106 $name = $buffer->{"short_name"} if (weechat::config_boolean( $options{"short_names"} ) eq 1);
1107 if (weechat::config_integer($options{"name_size_max"}) >= 1){
1108 $name = encode("UTF-8", substr(decode("UTF-8", $name), 0, weechat::config_integer($options{"name_size_max"})));
1109 }
1110 if ( weechat::config_boolean($options{"core_to_front"}) eq 1)
1111 {
1112 if ( (weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private") )
1113 {
1114 my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
1115 if ( $type eq "" and $name ne "weechat")
1116 {
1117 $name = " " . $name
1118 }else
1119 {
1120 $name = " " . $name;
1121 }
1122 }
1123 }
1124 $key = sprintf("%s%08d", lc($name), $buffer->{"number"});
1125 }
1126 else
1127 {
1128 $key = sprintf("%08d", $number);
1129 }
1130 $sorted_buffers{$key} = $buffer;
1131 $number++;
1132 }
1133 }
1134
1135 # build string with buffers
1136 $old_number = -1;
1137 foreach my $key (sort keys %sorted_buffers)
1138 {
1139 my $buffer = $sorted_buffers{$key};
1140
1141 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "server" )
1142 {
1143 # buffer type "server" or merged with core?
1144 if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1145 {
1146 next;
1147 }
1148 }
1149 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "channel" )
1150 {
1151 # buffer type "channel" or merged with core?
1152 if ( ($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1153 {
1154 next;
1155 }
1156 }
1157 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "private" )
1158 {
1159 # buffer type "private" or merged with core?
1160 if ( ($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1161 {
1162 next;
1163 }
1164 }
1165 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "keepserver" )
1166 {
1167 if ( ($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1168 {
1169 next;
1170 }
1171 }
1172 if ( weechat::config_string($options{"hide_merged_buffers"}) eq "all" )
1173 {
1174 if ( ! $buffer->{"active"} )
1175 {
1176 next;
1177 }
1178 }
1179
1180 push(@buffers_focus, $buffer); # buffer > buffers_focus, for mouse support
1181 my $color = "";
1182 my $bg = "";
1183
1184 $color = weechat::config_color( $options{"color_default_fg"} );
1185 $bg = weechat::config_color( $options{"color_default_bg"} );
1186
1187 if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
1188 {
1189 if ( (weechat::config_color($options{"queries_default_bg"})) ne "default" || (weechat::config_color($options{"queries_default_fg"})) ne "default" )
1190 {
1191 $bg = weechat::config_color( $options{"queries_default_bg"} );
1192 $color = weechat::config_color( $options{"queries_default_fg"} );
1193 }
1194 }
1195 # check for core and buffer with free content
1196 if ( (weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") ne "private") )
1197 {
1198 $color = weechat::config_color( $options{"color_none_channel_fg"} );
1199 $bg = weechat::config_color( $options{"color_none_channel_bg"} );
1200 }
1201 # default whitelist buffer?
1202 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1203 {
1204 $color = weechat::config_color( $options{"color_whitelist_default_fg"} );
1205 $bg = weechat::config_color( $options{"color_whitelist_default_bg"} );
1206 }
1207
1208 $color = "default" if ($color eq "");
1209
1210 # color for channel and query buffer
1211 if (exists $hotlist{$buffer->{"pointer"}})
1212 {
1213 delete $buffers_timer{$buffer->{"pointer"}};
1214 # check if buffer is in whitelist buffer
1215 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1216 {
1217 $bg = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1218 $color = weechat::config_color( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1219 }
1220 elsif ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "private" )
1221 {
1222 # queries_default_fg/bg and buffers.color.queries_message_fg/bg
1223 if ( (weechat::config_color($options{"queries_highlight_fg"})) ne "default" ||
1224 (weechat::config_color($options{"queries_highlight_bg"})) ne "default" ||
1225 (weechat::config_color($options{"queries_message_fg"})) ne "default" ||
1226 (weechat::config_color($options{"queries_message_bg"})) ne "default" )
1227 {
1228 if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
1229 {
1230 $bg = weechat::config_color( $options{"queries_message_bg"} );
1231 $color = weechat::config_color( $options{"queries_message_fg"} );
1232 }
1233
1234 elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
1235 {
1236 $bg = weechat::config_color( $options{"queries_highlight_bg"} );
1237 $color = weechat::config_color( $options{"queries_highlight_fg"} );
1238 }
1239 }else
1240 {
1241 $bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1242 $color = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1243 }
1244 }else
1245 {
1246 $bg = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1247 $color = weechat::config_color( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1248 }
1249 }
1250
1251 if ($buffer->{"current_buffer"})
1252 {
1253 $color = weechat::config_color( $options{"color_current_fg"} );
1254 $bg = weechat::config_color( $options{"color_current_bg"} );
1255 }
1256 my $color_bg = "";
1257 $color_bg = weechat::color(",".$bg) if ($bg ne "");
1258
1259 # create channel number for output
1260 if ( weechat::config_string( $options{"show_prefix_bufname"} ) ne "" )
1261 {
1262 $str .= $color_bg .
1263 weechat::color( weechat::config_color( $options{"color_prefix_bufname"} ) ).
1264 weechat::config_string( $options{"show_prefix_bufname"} ).
1265 weechat::color("default");
1266 }
1267
1268 if ( weechat::config_boolean( $options{"show_number"} ) eq 1 ) # on
1269 {
1270 if (( weechat::config_boolean( $options{"indenting_number"} ) eq 1)
1271 && (($position eq "left") || ($position eq "right")))
1272 {
1273 $str .= weechat::color("default").$color_bg
1274 .(" " x ($max_number_digits - length(int($buffer->{"number"}))));
1275 }
1276 if ($old_number ne $buffer->{"number"})
1277 {
1278 $str .= weechat::color( weechat::config_color( $options{"color_number"} ) )
1279 .$color_bg
1280 .$buffer->{"number"}
1281 .weechat::color("default")
1282 .$color_bg
1283 .weechat::color( weechat::config_color( $options{"color_number_char"} ) )
1284 .weechat::config_string( $options{"show_number_char"} )
1285 .$color_bg;
1286 }
1287 else
1288 {
1289 my $indent = "";
1290 $indent = ((" " x length($buffer->{"number"}))." ") if (($position eq "left") || ($position eq "right"));
1291 $str .= weechat::color("default")
1292 .$color_bg
1293 .$indent;
1294 }
1295 }
1296
1297 if (( weechat::config_integer( $options{"indenting"} ) ne 0 ) # indenting NOT off
1298 && (($position eq "left") || ($position eq "right")))
1299 {
1300 my $type = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type");
1301 if (($type eq "channel") || ($type eq "private"))
1302 {
1303 if ( weechat::config_integer( $options{"indenting"} ) eq 1 )
1304 {
1305 $str .= " ";
1306 }
1307 elsif ( (weechat::config_integer($options{"indenting"}) eq 2) and (weechat::config_integer($options{"indenting_number"}) eq 0) ) #under_name
1308 {
1309 if ( weechat::config_boolean( $options{"show_number"} ) eq 0 )
1310 {
1311 $str .= " ";
1312 }else
1313 {
1314 $str .= ( (" " x ( $max_number_digits - length($buffer->{"number"}) ))." " );
1315 }
1316 }
1317 }
1318 }
1319
1320 $str .= weechat::config_string( $options{"show_prefix_query"}) if (weechat::config_string( $options{"show_prefix_query"} ) ne "" and $buffer->{"type"} eq "private");
1321
1322 if (weechat::config_boolean( $options{"show_prefix"} ) eq 1)
1323 {
1324 my $nickname = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_nick");
1325 if ($nickname ne "")
1326 {
1327 # with version >= 0.3.2, this infolist will return only nick
1328 # with older versions, whole nicklist is returned for buffer, and this can be very slow
1329 my $infolist_nick = weechat::infolist_get("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
1330 if ($infolist_nick ne "")
1331 {
1332 while (weechat::infolist_next($infolist_nick))
1333 {
1334 if ((weechat::infolist_string($infolist_nick, "type") eq "nick")
1335 && (weechat::infolist_string($infolist_nick, "name") eq $nickname))
1336 {
1337 my $prefix = weechat::infolist_string($infolist_nick, "prefix");
1338 if (($prefix ne " ") or (weechat::config_boolean( $options{"show_prefix_empty"} ) eq 1))
1339 {
1340 # with version >= 0.3.5, it is now a color name (for older versions: option name with color)
1341 if (int($weechat_version) >= 0x00030500)
1342 {
1343 $str .= weechat::color(weechat::infolist_string($infolist_nick, "prefix_color"));
1344 }
1345 else
1346 {
1347 $str .= weechat::color(weechat::config_color(
1348 weechat::config_get(
1349 weechat::infolist_string($infolist_nick, "prefix_color"))));
1350 }
1351 $str .= $prefix;
1352 }
1353 last;
1354 }
1355 }
1356 weechat::infolist_free($infolist_nick);
1357 }
1358 }
1359 }
1360 if ($buffer->{"type"} eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0)
1361 {
1362 $str .= "(";
1363 }
1364
1365 $str .= weechat::color($color) . weechat::color(",".$bg);
1366
1367 if (weechat::config_boolean( $options{"short_names"} ) eq 1)
1368 {
1369 if (weechat::config_integer($options{"name_size_max"}) >= 1) # check max_size of buffer name
1370 {
1371 $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"short_name"}), 0, weechat::config_integer($options{"name_size_max"})));
1372 $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"}));
1373 $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
1374 $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
1375 }
1376 else
1377 {
1378 $str .= $buffer->{"short_name"};
1379 $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
1380 $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
1381 }
1382 }
1383 else
1384 {
1385 if (weechat::config_integer($options{"name_size_max"}) >= 1) # check max_size of buffer name
1386 {
1387 $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"name"},), 0, weechat::config_integer($options{"name_size_max"})));
1388 $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"}));
1389 $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
1390 $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
1391 }
1392 else
1393 {
1394 $str .= $buffer->{"name"};
1395 $str .= add_inactive_parentless($buffer->{"type"}, $buffer->{"nicks_count"});
1396 $str .= add_hotlist_count($buffer->{"pointer"}, %hotlist);
1397 }
1398 }
1399 if ( weechat::buffer_get_string($buffer->{"pointer"}, "localvar_type") eq "server" and weechat::config_boolean($options{"show_lag"}) eq 1)
1400 {
1401 my $color_lag = weechat::config_color(weechat::config_get("irc.color.item_lag_finished"));
1402 my $min_lag = weechat::config_integer(weechat::config_get("irc.network.lag_min_show"));
1403 my $infolist_server = weechat::infolist_get("irc_server", "", $buffer->{"short_name"});
1404 weechat::infolist_next($infolist_server);
1405 my $lag = (weechat::infolist_integer($infolist_server, "lag"));
1406 weechat::infolist_free($infolist_server);
1407 if ( int($lag) > int($min_lag) )
1408 {
1409 $lag = $lag / 1000;
1410 $str .= weechat::color("default") . " (" . weechat::color($color_lag) . $lag . weechat::color("default") . ")";
1411 }
1412 }
1413 if (weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0
1414 and weechat::config_boolean($options{"detach_display_window_number"}) eq 1)
1415 {
1416 if ($buffer->{"window"})
1417 {
1418 $str .= weechat::color("default") . " (" . weechat::color(weechat::config_color( $options{"color_number"})) . $buffer->{"window"} . weechat::color("default") . ")";
1419 }
1420 }
1421 $str .= weechat::color("default");
1422
1423 if ( weechat::config_string( $options{"show_suffix_bufname"} ) ne "" )
1424 {
1425 $str .= weechat::color( weechat::config_color( $options{"color_suffix_bufname"} ) ).
1426 weechat::config_string( $options{"show_suffix_bufname"} ).
1427 weechat::color("default");
1428 }
1429
1430 $str .= "\n";
1431 $old_number = $buffer->{"number"};
1432 }
1433
1434 # remove spaces and/or linefeed at the end
1435 $str =~ s/\s+$//;
1436 chomp($str);
1437 return $str;
1438 }
1439
1440 sub add_inactive_parentless
1441 {
1442 my ($buf_type, $buf_nicks_count) = @_;
1443 my $str = "";
1444 if ($buf_type eq "channel" and weechat::config_boolean( $options{"mark_inactive"} ) eq 1 and $buf_nicks_count == 0)
1445 {
1446 $str .= weechat::color(weechat::config_color( $options{"color_number_char"}));
1447 $str .= ")";
1448 }
1449 return $str;
1450 }
1451
1452 sub add_hotlist_count
1453 {
1454 my ($bufpointer, %hotlist) = @_;
1455
1456 return "" if ( weechat::config_boolean( $options{"hotlist_counter"} ) eq 0 or ($weechat_version < 0x00030500)); # off
1457 my $col_number_char = weechat::color(weechat::config_color( $options{"color_number_char"}) );
1458 my $str = " ".$col_number_char."(";
1459
1460 # 0 = low level
1461 if (defined $hotlist{$bufpointer."_count_00"})
1462 {
1463 my $bg = weechat::config_color( $options{"color_hotlist_low_bg"} );
1464 my $color = weechat::config_color( $options{"color_hotlist_low_fg"} );
1465 $str .= weechat::color($bg).
1466 weechat::color($color).
1467 $hotlist{$bufpointer."_count_00"} if ($hotlist{$bufpointer."_count_00"} ne "0");
1468 }
1469
1470 # 1 = message
1471 if (defined $hotlist{$bufpointer."_count_01"})
1472 {
1473 my $bg = weechat::config_color( $options{"color_hotlist_message_bg"} );
1474 my $color = weechat::config_color( $options{"color_hotlist_message_fg"} );
1475 if ($str =~ /[0-9]$/)
1476 {
1477 $str .= ",".
1478 weechat::color($bg).
1479 weechat::color($color).
1480 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1481 }else
1482 {
1483 $str .= weechat::color($bg).
1484 weechat::color($color).
1485 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1486 }
1487 }
1488 # 2 = private
1489 if (defined $hotlist{$bufpointer."_count_02"})
1490 {
1491 my $bg = weechat::config_color( $options{"color_hotlist_private_bg"} );
1492 my $color = weechat::config_color( $options{"color_hotlist_private_fg"} );
1493 if ($str =~ /[0-9]$/)
1494 {
1495 $str .= ",".
1496 weechat::color($bg).
1497 weechat::color($color).
1498 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1499 }else
1500 {
1501 $str .= weechat::color($bg).
1502 weechat::color($color).
1503 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1504 }
1505 }
1506 # 3 = highlight
1507 if (defined $hotlist{$bufpointer."_count_03"})
1508 {
1509 my $bg = weechat::config_color( $options{"color_hotlist_highlight_bg"} );
1510 my $color = weechat::config_color( $options{"color_hotlist_highlight_fg"} );
1511 if ($str =~ /[0-9]$/)
1512 {
1513 $str .= ",".
1514 weechat::color($bg).
1515 weechat::color($color).
1516 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1517 }else
1518 {
1519 $str .= weechat::color($bg).
1520 weechat::color($color).
1521 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1522 }
1523 }
1524 $str .= $col_number_char. ")";
1525
1526 $str = "" if (weechat::string_remove_color($str, "") eq " ()"); # remove color and check for buffer with no messages
1527 return $str;
1528 }
1529
1530 sub buffers_signal_buffer
1531 {
1532 my ($data, $signal, $signal_data) = @_;
1533
1534 # check for buffer_switch and set or remove detach time
1535 if ($weechat_version >= 0x00030800)
1536 {
1537 if ($signal eq "buffer_switch")
1538 {
1539 my $pointer = weechat::hdata_get_list (weechat::hdata_get("buffer"), "gui_buffer_last_displayed"); # get switched buffer
1540 my $current_time = time();
1541 if ( weechat::buffer_get_string($pointer, "localvar_type") eq "channel")
1542 {
1543 $buffers_timer{$pointer} = $current_time;
1544 }
1545 else
1546 {
1547 delete $buffers_timer{$pointer};
1548 }
1549 }
1550 if ($signal eq "buffer_opened")
1551 {
1552 my $current_time = time();
1553 $buffers_timer{$signal_data} = $current_time;
1554 }
1555 if ($signal eq "buffer_closing")
1556 {
1557 delete $buffers_timer{$signal_data};
1558 }
1559 }
1560 weechat::bar_item_update($SCRIPT_NAME);
1561 return weechat::WEECHAT_RC_OK;
1562 }
1563
1564 sub buffers_signal_hotlist
1565 {
1566 weechat::bar_item_update($SCRIPT_NAME);
1567 return weechat::WEECHAT_RC_OK;
1568 }
1569
1570
1571 sub buffers_signal_config_whitelist
1572 {
1573 @whitelist_buffers = ();
1574 @whitelist_buffers = split( /,/, weechat::config_string( $options{"look_whitelist_buffers"} ) );
1575 weechat::bar_item_update($SCRIPT_NAME);
1576 return weechat::WEECHAT_RC_OK;
1577 }
1578
1579 sub buffers_signal_config_immune_detach_buffers
1580 {
1581 @immune_detach_buffers = ();
1582 @immune_detach_buffers = split( /,/, weechat::config_string( $options{"immune_detach_buffers"} ) );
1583 weechat::bar_item_update($SCRIPT_NAME);
1584 return weechat::WEECHAT_RC_OK;
1585 }
1586
1587 sub buffers_signal_config_detach_buffer_immediately
1588 {
1589 @detach_buffer_immediately = ();
1590 @detach_buffer_immediately = split( /,/, weechat::config_string( $options{"detach_buffer_immediately"} ) );
1591 weechat::bar_item_update($SCRIPT_NAME);
1592 return weechat::WEECHAT_RC_OK;
1593 }
1594
1595 sub buffers_signal_config
1596 {
1597 weechat::bar_item_update($SCRIPT_NAME);
1598 return weechat::WEECHAT_RC_OK;
1599 }
1600
1601 # called when mouse click occured in buffers item: this callback returns buffer
1602 # hash according to line of item where click occured
1603 sub buffers_focus_buffers
1604 {
1605 my %info = %{$_[1]};
1606 my $item_line = int($info{"_bar_item_line"});
1607 undef my $hash;
1608 if (($info{"_bar_item_name"} eq $SCRIPT_NAME) && ($item_line >= 0) && ($item_line <= $#buffers_focus))
1609 {
1610 $hash = $buffers_focus[$item_line];
1611 }
1612 else
1613 {
1614 $hash = {};
1615 my $hash_focus = $buffers_focus[0];
1616 foreach my $key (keys %$hash_focus)
1617 {
1618 $hash->{$key} = "?";
1619 }
1620 }
1621 return $hash;
1622 }
1623
1624 # called when a mouse action is done on buffers item, to execute action
1625 # possible actions: jump to a buffer or move buffer in list (drag & drop of buffer)
1626 sub buffers_hsignal_mouse
1627 {
1628 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
1629 my $current_buffer = weechat::buffer_get_integer(weechat::current_buffer(), "number"); # get current buffer number
1630
1631 if ( $hash{"_key"} eq "button1" )
1632 {
1633 # left mouse button
1634 if ($hash{"number"} eq $hash{"number2"})
1635 {
1636 if ( weechat::config_boolean($options{"jump_prev_next_visited_buffer"}) )
1637 {
1638 if ( $current_buffer eq $hash{"number"} )
1639 {
1640 weechat::command("", "/input jump_previously_visited_buffer");
1641 }
1642 else
1643 {
1644 weechat::command("", "/buffer ".$hash{"full_name"});
1645 }
1646 }
1647 else
1648 {
1649 weechat::command("", "/buffer ".$hash{"full_name"});
1650 }
1651 }
1652 else
1653 {
1654 move_buffer(%hash) if (weechat::config_boolean($options{"mouse_move_buffer"}));
1655 }
1656 }
1657 elsif ( ($hash{"_key"} eq "button2") && (weechat::config_boolean($options{"jump_prev_next_visited_buffer"})) )
1658 {
1659 # right mouse button
1660 if ( $current_buffer eq $hash{"number2"} )
1661 {
1662 weechat::command("", "/input jump_next_visited_buffer");
1663 }
1664 }
1665 elsif ( $hash{"_key"} =~ /wheelup$/ )
1666 {
1667 # wheel up
1668 if (weechat::config_boolean($options{"mouse_wheel"}))
1669 {
1670 weechat::command("", "/buffer -1");
1671 }
1672 }
1673 elsif ( $hash{"_key"} =~ /wheeldown$/ )
1674 {
1675 # wheel down
1676 if (weechat::config_boolean($options{"mouse_wheel"}))
1677 {
1678 weechat::command("", "/buffer +1");
1679 }
1680 }
1681 else
1682 {
1683 my $infolist = weechat::infolist_get("hook", "", "command,menu");
1684 my $has_menu_command = weechat::infolist_next($infolist);
1685 weechat::infolist_free($infolist);
1686
1687 if ( $has_menu_command && $hash{"_key"} =~ /button2/ )
1688 {
1689 if ($hash{"number"} eq $hash{"number2"})
1690 {
1691 weechat::command($hash{"pointer"}, "/menu buffer1 $hash{short_name} $hash{number}");
1692 }
1693 else
1694 {
1695 weechat::command($hash{"pointer"}, "/menu buffer2 $hash{short_name}/$hash{short_name2} $hash{number} $hash{number2}")
1696 }
1697 }
1698 else
1699 {
1700 move_buffer(%hash) if (weechat::config_boolean($options{"mouse_move_buffer"}));
1701 }
1702 }
1703 }
1704
1705 sub move_buffer
1706 {
1707 my %hash = @_;
1708 my $number2 = $hash{"number2"};
1709 if ($number2 eq "?")
1710 {
1711 # if number 2 is not known (end of gesture outside buffers list), then set it
1712 # according to mouse gesture
1713 $number2 = "1";
1714 if (($hash{"_key"} =~ /gesture-right/) || ($hash{"_key"} =~ /gesture-down/))
1715 {
1716 $number2 = "999999";
1717 if ($weechat_version >= 0x00030600)
1718 {
1719 my $hdata_buffer = weechat::hdata_get("buffer");
1720 my $last_gui_buffer = weechat::hdata_get_list($hdata_buffer, "last_gui_buffer");
1721 if ($last_gui_buffer)
1722 {
1723 $number2 = weechat::hdata_integer($hdata_buffer, $last_gui_buffer, "number") + 1;
1724 }
1725 }
1726 }
1727 }
1728 my $ptrbuf = weechat::current_buffer();
1729 weechat::command($hash{"pointer"}, "/buffer move ".$number2);
1730 }
1731
1732 sub check_immune_detached_buffers
1733 {
1734 my ($buffername) = @_;
1735 foreach ( @immune_detach_buffers ){
1736 my $immune_buffer = weechat::string_mask_to_regex($_);
1737 if ($buffername =~ /^$immune_buffer$/i)
1738 {
1739 return 1;
1740 }
1741 }
1742 return 0;
1743 }
1744
1745 sub check_detach_buffer_immediately
1746 {
1747 my ($buffername) = @_;
1748 foreach ( @detach_buffer_immediately ){
1749 my $detach_buffer = weechat::string_mask_to_regex($_);
1750 if ($buffername =~ /^$detach_buffer$/i)
1751 {
1752 return 1;
1753 }
1754 }
1755 return 0;
1756 }
1757
1758 sub shutdown_cb
1759 {
1760 weechat::command("", "/bar hide " . $SCRIPT_NAME) if ( weechat::config_boolean($options{"toggle_bar"}) eq 1 );
1761 return weechat::WEECHAT_RC_OK
1762 }
1763
1764 sub check_bar_item
1765 {
1766 my $item = 0;
1767 my $infolist = weechat::infolist_get("bar", "", "");
1768 while (weechat::infolist_next($infolist))
1769 {
1770 my $bar_items = weechat::infolist_string($infolist, "items");
1771 if (index($bar_items, $SCRIPT_NAME) != -1)
1772 {
1773 my $name = weechat::infolist_string($infolist, "name");
1774 if ($name ne $SCRIPT_NAME)
1775 {
1776 $item = 1;
1777 last;
1778 }
1779 }
1780 }
1781 weechat::infolist_free($infolist);
1782 return $item;
1783 }