-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver_notify.pl
More file actions
executable file
·55 lines (51 loc) · 1.54 KB
/
server_notify.pl
File metadata and controls
executable file
·55 lines (51 loc) · 1.54 KB
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
#!/usr/bin/perl -w
use strict;
use IO::Socket;
use File::Basename;
use Cwd 'abs_path';
my $scriptpath = dirname(abs_path($0));
my $weechat_icon="$scriptpath/icons/weechat_icon.png";
my $system_icon="$scriptpath/icons/system_icon.png";
my $HOST = '127.0.0.1';
my $PORT = '1216';
my $socket = IO::Socket::INET->new('LocalPort' => $PORT,
'Proto' => 'tcp',
'Listen' => 4)
or die "Can't create socket ($!)\n";
while (my $client = $socket->accept) {
my ($tag, $title, $summary,$x);
while (<$client>) {
my $buf = $_;
chomp $buf;
$x++;
if($x == 1){$tag = $buf;}
if($x == 2){$title = $buf;}
if($x == 3){
$summary = $buf;
message($tag,$title,$summary);
}
}
close $client
or die "Can't close ($!)\n";
}
sub message{
my $tag = $_[0];
my $title = $_[1];
my $summary = $_[2];
if($tag eq 'weechat'){
# see if weechat has focus, if not, send notification. Depends on terminal name starting with weechat
my $focus = `xwininfo -tree -id \$(xdpyinfo | awk '/focus/ {gsub(",", "", \$3); print \$3}') | grep Parent | awk -F\\" '{print \$2}'`;
if ($focus !~ /^weechat /){
$title =~ s/[<&]//g; # remove some characters that libnotify hates
$summary =~ s/[<&]//g;
my @args = ('/usr/bin/notify-send', $title, $summary, "--icon=$weechat_icon");
system @args;
}
}
if($tag eq 'system'){
$title =~ s/[<&]//g; # remove some characters that libnotify hates
$summary =~ s/[<&]//g;
my @args = ('/usr/bin/notify-send', $title, $summary, "--icon=$system_icon");
system @args;
}
}