-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify-push.pl
executable file
·200 lines (163 loc) · 11.6 KB
/
notify-push.pl
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#! /usr/bin/perl -w
# Script to watch D-BUS for notify messages and update the ErgoDox Infinity display
# Still very rough
# Dependency: libnet-dbus-perl on Debian
# =================================================================================================
# Front matter
# =================================================================================================
use strict;
use v5.12;
# Set this to your ErgoDox serial port (e.g., /dev/ttyACM0, etc.)
my $TTY = "DEFINE-ME";
use Net::DBus;
use Net::DBus::Reactor;
use Net::DBus::Binding::Bus;
use Time::HiRes qw(usleep);
my $notifications = 0;
# =================================================================================================
# Main script
# =================================================================================================
# Need the Binding::Bus type, otherwise can't use add_match() below
my $bus = Net::DBus::Binding::Bus->new(type => &Net::DBus::Binding::Bus::SESSION);
# eavesdrop is required because Notify messages aren't for us
# for some reason, need to filter for Notify here AND check member in notify_filter()
$bus -> add_match("type='method_call',interface='org.freedesktop.Notifications',member='Notify'," .
"eavesdrop='true'");
# NotificationClosed is broadcast, so don't need to eavesdrop it
$bus -> add_match("type='signal',interface='org.freedesktop.Notifications'," .
"member='NotificationClosed'");
$bus -> add_filter(\¬ify_filter);
$bus -> add_filter(\&closed_filter);
my $reactor = Net::DBus::Reactor->new();
$reactor -> manage($bus);
$reactor -> run();
# End of script
# =================================================================================================
# Subroutines
# =================================================================================================
sub notify_filter
{
my $con = shift;
my $msg = shift;
my $type = $msg -> get_member();
return 0 if (!defined($type));
return 0 if ($type ne 'Notify');
# I *think* transients don't show up in notifications applet and shouldn't be counted
# This includes notifications for things like unplugging the ethernet cable
my @vals = $msg -> get_args_list();
foreach my $v (@vals)
{
return 0 if (ref($v) eq 'HASH' and exists($v->{'transient'}) and $v->{'transient'});
}
$notifications++;
display_count();
}
sub closed_filter
{
my $con = shift;
my $msg = shift;
my $type = $msg -> get_member();
if (defined($type) and $type eq 'NotificationClosed' and $notifications)
{
$notifications--;
display_count();
}
}
sub display_count
{
system('printf "lcdInit\r" >' . $TTY);
usleep 100_000;
if ($notifications == 0)
{
# Y X 0 1 2 3 4 5 6 7 8 9 A B C D E F
system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY);
system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY);
system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdColor 0x1076 0x0F31 0x0C95\r">' . $TTY);
}
elsif ($notifications == 1)
{
system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY);
system('printf "lcdDisp 0x0 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY);
system('printf "lcdDisp 0x1 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY);
system('printf "lcdDisp 0x2 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff\r">' . $TTY);
system('printf "lcdDisp 0x3 0x50 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY);
}
elsif ($notifications == 2)
{
system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY);
system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY);
system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY);
system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY);
system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY);
}
elsif ($notifications == 3)
{
system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY);
system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY);
system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY);
system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY);
system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY);
}
elsif ($notifications == 4)
{
system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x0 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY);
system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY);
system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY);
}
elsif ($notifications == 5)
{
system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY);
system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY);
system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY);
system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY);
system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY);
}
elsif ($notifications > 5)
{
system('printf "lcdDisp 0x0 0x40 0x00 0x00 0x00 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f\r">' . $TTY);
system('printf "lcdDisp 0x0 0x50 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0x3f 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x40 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0\r">' . $TTY);
system('printf "lcdDisp 0x1 0x50 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff 0xff 0xff 0xff 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x07\r">' . $TTY);
system('printf "lcdDisp 0x2 0x50 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x07 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x40 0x00 0x00 0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc\r">' . $TTY);
system('printf "lcdDisp 0x3 0x50 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0xfc 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x0 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x80 0x80 0x80\r">' . $TTY);
system('printf "lcdDisp 0x0 0x70 0x80 0x80 0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x1 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0xff 0xff 0xff\r">' . $TTY);
system('printf "lcdDisp 0x1 0x70 0xff 0xff 0xff 0xe0 0xe0 0xe0 0xe0 0xe0 0xe0 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x2 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x07 0x07 0x07 0x07 0x07 0x07 0xff 0xff 0xff\r">' . $TTY);
system('printf "lcdDisp 0x2 0x70 0xff 0xff 0xff 0x07 0x07 0x07 0x07 0x07 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdDisp 0x3 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x01 0x01\r">' . $TTY);
system('printf "lcdDisp 0x3 0x70 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00\r">' . $TTY);
system('printf "lcdColor 0xBCFC 0xB6F6 0x2D2D\r">' . $TTY);
}
}