korgwm/Notifications.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 121 CC 3 SCAR 10.0
CC
3
Cov
0%
Notify
6.0
init
6.0
new
2.0
CRAP 2.7
1 #!/usr/bin/perl
2 # made by: KorG
3 # vim: cc=119 et sw=4 ts=4 :
4  
5 # Additional package to avoid any casual namespace mess with Net::DBus::Exporter
6 package Notifications;
7 use strict;
8 use warnings;
9 use feature 'signatures';
10  
11 use X11::korgwm::Common;
12 use Net::DBus::Exporter qw(org.freedesktop.Notifications);
13 use base qw(Net::DBus::Object);
14  
15 my $id = 1;
16  
17 sub new($class, $service) {
18 my $self = $class->SUPER::new($service, "/org/freedesktop/Notifications");
19 bless $self, $class;
20 }
21  
22 dbus_method("Notify",
23 [ "string", "uint32", "string", "string", "string", [array => "string"], [dict => "string", "string"], "int32" ],
24 [ "uint32" ]
25 );
26 sub Notify {
27 # See libnotify/notification-spec.xml for more info
28 my ($self, $app_name, $replace_id, $icon, $summary, $body, $actions, $hints, $expiration) = @_;
29 DEBUG9 and carp sprintf "Got D-Bus notification: (%s)", join ", ", map { $_ // "" }
30 $app_name, $replace_id, $icon, $summary, $body, $expiration;
31  
32 # So far I'll ignore messages with urgency == 0
33 if (ref $hints eq 'HASH' && $hints->{urgency}) {
34 # Make a window w/ WM_CLASS == ($app_name OR $icon OR $hints->{desktop-entry}) urgent if single match
35 my @found = &X11::korgwm::Window::urgent_by_class($app_name, $icon, $hints->{"desktop-entry"});
36  
37 DEBUG7 and carp sprintf "Got urgent notification for windows [%s] with class one of (%s)", "@found",
38 join "|", map { $_ // "" } $app_name, $icon, $hints->{'desktop-entry'};
39 }
40  
41 return $id++;
42 }
43  
44 dbus_method("GetCapabilities", [], [ [ array => "string" ] ]);
45 sub GetCapabilities { [ "body" ] }
46  
47 dbus_method("CloseNotification", [ "uint32" ], []);
48 sub CloseNotification { 1 }
49  
50 dbus_signal("NotificationClosed", [ "uint32", "uint32" ]);
51 sub NotificationClosed { 1 }
52  
53 dbus_method("GetServerInformation", [], [ ("string") x 4 ]);
54 sub GetServerInformation { ("Trimming The Herbs", "korgwm", "1.0", "1.2") }
55  
56 package X11::korgwm::Notifications;
57 use strict;
58 use warnings;
59 use feature 'signatures';
60  
61 use Carp;
62 use Net::DBus;
63 use AnyEvent::DBus;
64 use X11::korgwm::Common;
65  
66 # Establish Notifications server
67 sub init {
68 return unless $cfg->{notification_server};
69 my $bus = Net::DBus->session();
70 my $service = $bus->export_service("org.freedesktop.Notifications");
71 Notifications->new($service);
72 }
73  
74 push @X11::korgwm::extensions, \&init;
75  
76 1;