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