Skip to content

Instantly share code, notes, and snippets.

@erikh
Created November 29, 2009 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikh/244926 to your computer and use it in GitHub Desktop.
Save erikh/244926 to your computer and use it in GitHub Desktop.
################################################################################
#
# notify.pl - use libnotify to work like growl
#
# By Erik Hollensbe <erik@hollensbe.org>
#
# usage:
#
# See the CALLBACK_MAP below? Those are the defined message types.
#
# Set those in your "notify_types" separated by a space:
#
# /set notify_types PRIVATE HILIGHT
#
# Will give you notify pops on private messages and highlights (this is the
# default).
#
################################################################################
use strict;
use warnings;
use Net::DBus;
use CGI;
weechat::register(
"notify",
"Erik Hollensbe",
"1.0",
"BSD",
"dbus-capable libnotify integration",
"",
""
);
sub weechat_init {
weechat::hook_print("", "", "", 1, "print_hook", "");
}
sub print_hook {
my ($data, $buffer, $date, $tags_count, $tags, $displayed, $highlighted, $prefix, $message) = @_;
weechat::print("", "$data - $message\n");
return weechat::WEECHAT_RC_OK;
}
__END__
our %CALLBACK_MAP = (
#PRIVATE => \&event_msg,
#HILIGHT => \&event_print_text,
#PUBLIC => \&event_msg,
#NOTICE => \&event_msg,
#CTCP => \&event_ctcp,
#CHANMODE => \&event_channel_mode,
#USERMODE => \&event_user_mode,
#KICK => \&event_kick,
#BAN => \&event_ban,
#SNOTICE => \&event_server_msg,
);
sub launch_notifier {
my ($title, $message) = @_;
# taken without remorse from Desktop::Notify
my $object = Net::DBus->session
->get_service('org.freedesktop.Notifications')
->get_object('/org/freedesktop/Notifications', 'org.freedesktop.Notifications');
$object->Notify('weechat', 0, '', $title, CGI::escapeHTML($message), [], { }, get_notify_duration());
}
sub get_notify_duration { 5000 }
sub get_notify_types { ("PRIVATE"); }
#sub AUTOLOAD {
#our $AUTOLOAD;
#my $al = $AUTOLOAD;
## normalize $al to be uppercase and contain the subroutine name only
#($al) = $al =~ /([^:]+)$/;
#$al = uc $al;
#if (scalar grep /^(ALL|$al)$/, get_notify_types) {
#$CALLBACK_MAP{$al}->(@_);
#}
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment