Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notification close API #14

Merged
merged 1 commit into from Jan 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.rdoc
Expand Up @@ -37,13 +37,15 @@ http://github.com/splattael/libnotify/raw/master/libnotify.png
Libnotify.show(:icon_path => "emblem-default.png")
Libnotify.show(:icon_path => :"emblem-default")

# Update pre-existing notification
# Update pre-existing notification then close it
n = Libnotify.new(:summary => "hello", :body => "world")
n.update # identical to show! if not shown before
Kernel.sleep 1
n.update(:body => "my love") do |notify|
notify.summary = "goodbye"
end
Kernel.sleep 1
n.close


== Installation
Expand Down
4 changes: 3 additions & 1 deletion lib/libnotify.rb
Expand Up @@ -23,13 +23,15 @@ module Libnotify
# @example Hash syntax
# Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
#
# @example Update pre-existing notification
# @example Update pre-existing notification then close it
# n = Libnotify.new(:summary => "hello", :body => "world")
# n.update # identical to show! if not shown before
# Kernel.sleep 1
# n.update(:body => "my love") do |notify|
# notify.summary = "goodbye"
# end
# Kernel.sleep 1
# n.close
#
# @example Mixed syntax
# Libnotify.new(options) do |n|
Expand Down
5 changes: 5 additions & 0 deletions lib/libnotify/api.rb
Expand Up @@ -89,6 +89,11 @@ def update(options={}, &block)
end
end

# Close a previously shown notification.
def close
notify_notification_close(@notification, nil) if @notification
end

# @todo Simplify timeout=
def timeout=(timeout)
@timeout = case timeout
Expand Down
1 change: 1 addition & 0 deletions lib/libnotify/ffi.rb
Expand Up @@ -29,6 +29,7 @@ def self.attach_functions!
attach_function :notify_notification_set_hint_uint32, [:pointer, :string, :int], :void
attach_function :notify_notification_clear_hints, [:pointer], :void
attach_function :notify_notification_show, [:pointer, :pointer], :bool
attach_function :notify_notification_close, [:pointer, :pointer], :bool
end

def lookup_urgency(urgency)
Expand Down