aboutsummaryrefslogtreecommitdiffstats
path: root/activity_bar.pl
blob: b9bf4d76edbeb35c02223eb248df09fb7da71a70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use strict;
use warnings;

use IO::Socket::INET;

weechat::register(
	'activity_bar',
	'Teddy Wing',
	'1.0',
	'GPL-3.0-or-later',
	'Monitor activity in all buffers and update AnyBar',
	'shutdown',
	''
);

# Flush socket immediately.
$| = 1;

my $socket = IO::Socket::INET->new(
	PeerAddr => 'localhost',
	PeerPort => '1738',
	Proto => 'udp',
) or die "error: can't create socket: $!";

sub shutdown {
	$socket->close();
}


weechat::hook_print('', '', '', 0, 'print_cb', '');
weechat::hook_command(
	'activity_bar',
	'Activity Bar commands',
	'[clear]',
	'clear: change AnyBar icon to hollow',
	'clear',
	'activity_bar_command_cb',
	''
);

sub print_cb {
	my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message) = @_;

	my $buffer_type = weechat::buffer_get_string($buffer, 'localvar_type');

	if ($buffer_type eq 'private') {
		anybar_send('blue');
	}
	elsif ($highlight == 1) {
		anybar_send('purple');
	}
	else {
		anybar_send('orange');
	}

	return weechat::WEECHAT_RC_OK;
}

sub anybar_send {
	my ($message) = @_;

	$socket->send($message);
}

sub activity_bar_command_cb {
	my ($data, $buffer, $args) = @_;

	anybar_send('hollow');

	return weechat::WEECHAT_RC_OK;
}