comparison weechat/perl/autoload/buffers.pl @ 202:1bb19c7b3298

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