Desktop-Notify:_0001-support_notification_actions.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From e84e1f23168ebfb51fc73c272061c295ed9952d8 Mon Sep 17 00:00:00 2001
  2. From: intrigeri <intrigeri@boum.org>
  3. Date: Sun, 8 Mar 2015 23:22:02 +0000
  4. Subject: [PATCH] Add support for a user-defined function to be called whenever
  5. an action is invoked.
  6. ---
  7. lib/Desktop/Notify.pm | 30 +++++++++++++++++++++++++++++-
  8. lib/Desktop/Notify/Notification.pm | 18 +++++++++++-------
  9. 2 files changed, 40 insertions(+), 8 deletions(-)
  10. diff --git a/lib/Desktop/Notify.pm b/lib/Desktop/Notify.pm
  11. index b8bb248..78f31d4 100644
  12. --- a/usr/share/perl5/Desktop/Notify.pm
  13. +++ b/usr/share/perl5/Desktop/Notify.pm
  14. @@ -106,6 +106,8 @@ sub new {
  15. $self->{app_name} = $opts{app_name} || basename($0);
  16. $self->{notify}->connect_to_signal('NotificationClosed',
  17. sub {$self->_close_cb(@_)});
  18. + $self->{notify}->connect_to_signal('ActionInvoked',
  19. + sub {$self->_action_cb(@_)});
  20. bless $self, $class;
  21. }
  22. @@ -140,6 +142,17 @@ sub _close_cb {
  23. delete $self->{notes}->{$nid};
  24. }
  25. +sub _action_cb {
  26. + my ($self, $nid, $action_key) = @_;
  27. + print __PACKAGE__, ": action invoked\n";
  28. + if ($self->{action_callback})
  29. + {
  30. + print "invoking callback\n";
  31. + $self->{action_callback}->($self->{notes}->{$nid}, $action_key);
  32. + }
  33. + # delete $self->{notes}->{$nid};
  34. +}
  35. +
  36. =head2 close_callback $coderef
  37. Sets a user-specified function to be called whenever a notification is closed.
  38. @@ -151,10 +164,25 @@ just closed.
  39. sub close_callback {
  40. my ($self, $cb) = @_;
  41. - print "callback is $cb\n";
  42. + print "close callback is $cb\n";
  43. $self->{close_callback} = $cb;
  44. }
  45. +=head2 action_callback $coderef
  46. +
  47. +Sets a user-specified function to be called whenever an action is invoked.
  48. +It will be called with two arguments, which are the Notification object on which
  49. +an action was invoked, and the key of the action invoked.
  50. +
  51. +=cut
  52. +
  53. +sub action_callback {
  54. + my ($self, $cb) = @_;
  55. +
  56. + print "action callback is $cb\n";
  57. + $self->{action_callback} = $cb;
  58. +}
  59. +
  60. =head1 AUTHOR
  61. Stephen Cavilia, C<< <sac at atomicradi.us> >>
  62. diff --git a/lib/Desktop/Notify/Notification.pm b/lib/Desktop/Notify/Notification.pm
  63. index ee3fe4a..e7710e8 100644
  64. --- a/usr/share/perl5/Desktop/Notify/Notification.pm
  65. +++ b/usr/share/perl5/Desktop/Notify/Notification.pm
  66. @@ -59,6 +59,7 @@ sub new {
  67. my $self = \%params;
  68. $self->{server} = $server;
  69. $self->{id} = undef;
  70. + $self->{actions} ||= {};
  71. bless $self, $class;
  72. }
  73. @@ -81,7 +82,7 @@ sub show {
  74. '',
  75. $self->{summary},
  76. $self->{body},
  77. - [],
  78. + [%{$self->{actions}}],
  79. {},
  80. $self->{timeout} || 0,
  81. );
  82. @@ -125,6 +126,15 @@ The summary text briefly describing the notification.
  83. The optional detailed body text. Can be empty.
  84. +=item actions
  85. +
  86. +Actions are sent over as a list of pairs. Each even element in the list
  87. +(starting at index 0) represents the identifier for the action. Each odd
  88. +element in the list is the localized string that will be displayed to the user.
  89. +
  90. +A user-specified function to be called whenever an action is invoked can be
  91. +specified with L<Desktop::Notify>'s L<action_callback> method.
  92. +
  93. =item timeout
  94. The timeout time in milliseconds since the display of the notification at which
  95. @@ -145,12 +155,6 @@ supported by L<Desktop::Notify> at this time
  96. The optional program icon of the calling application.
  97. -=item actions
  98. -
  99. -Actions are sent over as a list of pairs. Each even element in the list
  100. -(starting at index 0) represents the identifier for the action. Each odd
  101. -element in the list is the localized string that will be displayed to the user.
  102. -
  103. =item hints
  104. Optional hints that can be passed to the server from the client program.
  105. --
  106. 2.1.4